You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2022/03/24 14:19:42 UTC

[netbeans] branch master updated: [3731] Fixing unused import handling for module-infos.

This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new be7c9bf  [3731] Fixing unused import handling for module-infos.
     new d4d9d64  Merge pull request #3770 from jlahoda/3731
be7c9bf is described below

commit be7c9bf9dd38a9887f42b2e130abac749c928fc8
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Sat Mar 12 15:59:26 2022 +0100

    [3731] Fixing unused import handling for module-infos.
---
 .../java/editor/base/imports/UnusedImports.java    |  1 +
 .../editor/base/semantic/UnusedImportsTest.java    | 42 +++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/imports/UnusedImports.java b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/imports/UnusedImports.java
index bb6ff12..fd40b6a 100644
--- a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/imports/UnusedImports.java
+++ b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/imports/UnusedImports.java
@@ -166,6 +166,7 @@ public class UnusedImports {
 	    scan(tree.getImports(), d);
 	    scan(tree.getPackageAnnotations(), d);
 	    scan(tree.getTypeDecls(), d);
+	    scan(tree.getModule(), d);
 	    return null;
         }
 
diff --git a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/UnusedImportsTest.java b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/UnusedImportsTest.java
index 069767e..e956717 100644
--- a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/UnusedImportsTest.java
+++ b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/UnusedImportsTest.java
@@ -41,6 +41,7 @@ import org.netbeans.api.lexer.Language;
 import org.netbeans.core.startup.Main;
 import org.netbeans.junit.NbTestCase;
 import org.netbeans.modules.java.editor.base.imports.UnusedImports;
+import org.netbeans.modules.java.source.parsing.JavacParser;
 import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
 import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
@@ -333,8 +334,44 @@ public class UnusedImportsTest extends NbTestCase {
                                                "}\n"));
     }
 
+    public void testModuleInfo() throws Exception {
+        SourceUtilsTestUtil.setSourceLevel(src, "11");
+        writeFilesAndWaitForScan(src,
+                                 new File("module-info.java",
+                                          "import java.util.List;\n" +
+                                          "import test.Ann;\n" +
+                                          "import test.Service1;\n" +
+                                          "import test.Service2;\n" +
+                                          "import test.Service2Impl;\n" +
+                                          "@Ann\n" +
+                                          "module m {\n" +
+                                          "    uses Service1;\n" +
+                                          "    uses Service2;\n" +
+                                          "    provides Service2 with Service2Impl;\n" +
+                                          "}\n"),
+                                 new File("test/Ann.java",
+                                          "package test;\n" +
+                                          "public @interface Ann { }"),
+                                 new File("test/Service1.java",
+                                          "package test;\n" +
+                                          "public interface Service1 { }"),
+                                 new File("test/Service2.java",
+                                          "package test;\n" +
+                                          "public interface Service2 { }"),
+                                 new File("test/Service2Impl.java",
+                                          "package test;\n" +
+                                          "public class Service2Impl implements Service2 { }"));
+
+        performUnusedImportsTestForFile("module-info.java",
+                                        "import java.util.List;\n");
+    }
+
     private void performUnusedImportsTest(String... golden) throws Exception {
-        CompilationInfo ci = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(src.getFileObject("test/Main.java")), Phase.RESOLVED);
+        performUnusedImportsTestForFile("test/Main.java", golden);
+    }
+
+    private void performUnusedImportsTestForFile(String fileName, String... golden) throws Exception {
+        CompilationInfo ci = SourceUtilsTestUtil.getCompilationInfo(JavaSource.forFileObject(src.getFileObject(fileName)), Phase.RESOLVED);
         SourceUtilsTestUtil2.disableConfinementTest();
         Document doc = ci.getSnapshot().getSource().getDocument(true);
         doc.putProperty(Language.class, JavaTokenId.language());
@@ -398,4 +435,7 @@ public class UnusedImportsTest extends NbTestCase {
         }
     }
 
+    static {
+        JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
+    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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