junichi11 commented on code in PR #8196:
URL: https://github.com/apache/netbeans/pull/8196#discussion_r1929703782


##########
php/php.project/src/org/netbeans/modules/php/project/ComputeTestMethodAnnotations.java:
##########
@@ -142,59 +178,72 @@ public void run() {
         }
     }
 
-    private List<TestMethod> getTestMethods(Document document) {
-        List<TestMethod> testMethods = new ArrayList<>();
-        FileObject fileObject = NbEditorUtilities.getFileObject(document);
-        if (fileObject != null) {
-            PhpProject project = PhpProjectUtils.getPhpProject(fileObject);
-            assert project != null;
-            PhpModule phpModule = project.getPhpModule();
-            for (PhpTestingProvider testingProvider : 
project.getTestingProviders()) {
+    /**
+     * Get test methods for the first available testing provider.
+     *
+     * @return test methods
+     */
+    private List<TestMethod> getTestMethods() {
+        FileObject fileObject = 
NbEditorUtilities.getFileObject(handledDocument);
+        if (fileObject == null) {
+            return Collections.emptyList();
+        }
+        PhpProject project = PhpProjectUtils.getPhpProject(fileObject);
+        if (project == null) {
+            return Collections.emptyList();
+        }
+        PhpTestingProvider testingProvider = 
getFirstTestingProvider(handledDocument);
+        if (testingProvider == null) {
+            return Collections.emptyList();
+        }
+        return getTestMethods(fileObject, testingProvider, 
project.getPhpModule());
+    }
 
-                if (!document.equals(handledDocument)) {
+    private List<TestMethod> getTestMethods(FileObject fileObject, 
PhpTestingProvider testingProvider, PhpModule phpModule) {
+        List<TestMethod> testMethods = new ArrayList<>();
+        Collection<PhpClass> phpClasses = getPhpClasses(fileObject);
+        for (PhpClass phpClass : phpClasses) {
+            // check whether the document tab has already been switched to 
another one
+            if (!handledDocument.equals(getLastFocusedDocument())) {

Review Comment:
   Probably, expected condition is not `!document.equals(handledDocument)` but 
this. Am I wrong??



##########
php/php.project/src/org/netbeans/modules/php/project/ComputeTestMethodAnnotations.java:
##########
@@ -82,52 +82,88 @@ public void unregister() {
 
     @Override
     public void propertyChange(PropertyChangeEvent event) {
-        assert SwingUtilities.isEventDispatchThread() : "UI thread expected 
but is: " + Thread.currentThread().getName();
-
+        assert SwingUtilities.isEventDispatchThread() : "UI thread expected 
but is: " + Thread.currentThread().getName(); // NOI18N
+        Document document = getLastFocusedDocument();
+        if (document == null) {
+            return;
+        }
+        PhpTestingProvider testingProvider = getFirstTestingProvider(document);
+        if (testingProvider == null) {
+            return;
+        }
+        // don't add the listener if this document is not a test file

Review Comment:
   We should avoid adding the listener for all php files.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to