lahodaj commented on code in PR #8827:
URL: https://github.com/apache/netbeans/pull/8827#discussion_r2347963375


##########
java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java:
##########
@@ -1268,8 +1312,21 @@ private CompilationUnitTree 
addImports(CompilationUnitTree cut, List<? extends I
             }
         }
         
-        // check for possible name clashes originating from adding the package 
imports
-        Set<Element> explicitNamedImports = new HashSet<Element>();
+        // Add modulesToImport to the importScope, to check name clashes, if 
any
+        if (!modulesToImport.isEmpty()) {
+            for (ModuleElement m : modulesToImport) {
+                for (Element e : m.getEnclosedElements()) {

Review Comment:
   This should probably use `ElementUtilities.transitivelyExportedPackages`, 
which is intended to mirror the `import module` semantics.



##########
java/java.hints/src/org/netbeans/modules/java/hints/OrganizeImports.java:
##########
@@ -213,21 +223,27 @@ public int compare(ImportTree o1, ImportTree o2) {
                         return 0;
                     String s1 = o1.getQualifiedIdentifier().toString();
                     String s2 = o2.getQualifiedIdentifier().toString();
-                    int bal = groups.getGroupId(s1, o1.isStatic()) - 
groups.getGroupId(s2, o2.isStatic());
+                    int bal;
+                    if (o1.isModule()) bal = o2.isModule() ? 0 : 1; // Place 
module imports last
+                    else if (o2.isModule()) bal = -1;               // Place 
module imports last
+                    else bal = groups.getGroupId(s1, o1.isStatic()) - 
groups.getGroupId(s2, o2.isStatic());
                     return bal == 0 ? s1.compareTo(s2) : bal;
                 }
             });
         }
         CompilationUnitTree cut = 
maker.CompilationUnit(cu.getPackageAnnotations(), cu.getPackageName(), imps, 
cu.getTypeDecls(), cu.getSourceFile());
         ((JCCompilationUnit)cut).packge = ((JCCompilationUnit)cu).packge;
-        if (starImports != null || staticStarImports != null) {
+        if (!starImports.isEmpty() || !staticStarImports.isEmpty()) {

Review Comment:
   Sorry, but this is changes semantics. Before, given `startImports` was never 
`null`, the scope was always set. Now, it may or may not be set, and that's 
possibly problematic. I am not completely sure if setting the scopes is 
necessary, but given the existing code sets them, I would suggest to continue 
to do that unconditionally. (And the same for `moduleImportScope`, I guess.)



##########
java/java.source.base/test/unit/src/org/netbeans/api/java/source/GeneratorUtilitiesTest.java:
##########
@@ -610,6 +610,88 @@ public void validate(CompilationInfo info) {
         }, false);
     }
 
+    public void testAddImportsWithModule1() throws Exception {
+        performTest("test/Process.java", "package test;\nimport 
java.util.Collections;\npublic class Process {\npublic static void 
main(String... args) {\n" +

Review Comment:
   Nit: I would probably use a text block for the snippet.



##########
java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java:
##########
@@ -940,6 +941,18 @@ protected int diffImport(JCImport oldT, JCImport newT, 
int[] bounds) {
         return bounds[1];
     }
 
+    protected int diffModuleImport(JCModuleImport oldT, JCModuleImport newT, 
int[] bounds) {

Review Comment:
   It would be good to add test for this here:
   
`java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ImportsTest.java`



##########
java/java.source.base/src/org/netbeans/api/java/source/GeneratorUtilities.java:
##########
@@ -1355,13 +1412,32 @@ private CompilationUnitTree 
addImports(CompilationUnitTree cut, List<? extends I
                     el = currentToImportElement.getEnclosingElement();
                     break;
             }
-            Integer cnt = el == null ? Integer.valueOf(0) : isStatic ? 
typeCounts.get((TypeElement)el) : pkgCounts.get((PackageElement)el);
-            if (explicitNamedImports.contains(currentToImportElement))
+            final int cnt;
+            if (explicitNamedImports.contains(currentToImportElement)) {
                 cnt = 0;
+            } else {
+                Integer enclosingStarCnt = el == null ? null : isStatic ? 
typeCounts.get((TypeElement)el) :  pkgCounts.get((PackageElement)el);

Review Comment:
   I may need to think of this logic again, but seems reasonable at this time.



-- 
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