You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/03/18 08:58:22 UTC

[GitHub] [netbeans] sdedic commented on a change in pull request #3802: [NETBEANS-4826] Fixing java indexing in Groovy

sdedic commented on a change in pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802#discussion_r829791964



##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java
##########
@@ -298,19 +298,28 @@ private CaretLocation getCaretLocationFromRequest() {
         boolean openBraceBeforePosition = false;
         // is there package statement?
         boolean afterPackagePosition = false;
-
+        boolean canBeImport = true;
+        
         ts.move(position);
 
         while (ts.isValid() && ts.movePrevious() && ts.offset() >= 0) {
             Token<GroovyTokenId> t = ts.token();
             if (t.id() == GroovyTokenId.LBRACE) {
                 openBraceBeforePosition = true;
+                canBeImport = false;
             } else if (t.id() == GroovyTokenId.LITERAL_class || t.id() == GroovyTokenId.LITERAL_interface || t.id() == GroovyTokenId.LITERAL_trait) {
                 classDefBeforePosition = true;
                 break;
             } else if (t.id() == GroovyTokenId.LITERAL_package) {
                 afterPackagePosition = true;
                 break;
+            } else if (canBeImport && t.id() == GroovyTokenId.LITERAL_import) {
+                return CaretLocation.INSIDE_IMPORT;
+            }
+            
+            if (canBeImport && !(t.id() == GroovyTokenId.DOT || t.id() == GroovyTokenId.IDENTIFIER

Review comment:
       Q: how will this react in context like `Whatever.class.` ?

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/TypesCompletion.java
##########
@@ -313,12 +314,24 @@ private void addToProposalUsingFilter(Set<TypeHolder> alreadyPresent, TypeHolder
         if (constructorCompletion && typeName.toUpperCase().equals(request.getPrefix().toUpperCase())) {
             return;
         }
+        
+        if (type.getHandle() != null
+                &&!(type.getHandle().getKind().isClass() || type.getHandle().getKind().isInterface())
+                && request.location != CaretLocation.INSIDE_IMPORT) {
+            return;
+        }
 
+        String ownerFQN = GroovyUtils.stripClassName(fqnTypeName);

Review comment:
       Use `GroovyUtils.getPackageName()`, returns name w/o trailing dot.

##########
File path: groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/TypesCompletion.java
##########
@@ -313,12 +314,24 @@ private void addToProposalUsingFilter(Set<TypeHolder> alreadyPresent, TypeHolder
         if (constructorCompletion && typeName.toUpperCase().equals(request.getPrefix().toUpperCase())) {
             return;
         }
+        
+        if (type.getHandle() != null
+                &&!(type.getHandle().getKind().isClass() || type.getHandle().getKind().isInterface())
+                && request.location != CaretLocation.INSIDE_IMPORT) {
+            return;
+        }
 
+        String ownerFQN = GroovyUtils.stripClassName(fqnTypeName);
+        if (!ownerFQN.isEmpty() && ownerFQN.endsWith("."))  {
+            ownerFQN = ownerFQN.substring(0, ownerFQN.length() - 1);
+        }
+        
         // We are dealing with prefix for some class type
         JavaElementHandle jh = null;
         if (type.getHandle() != null) {
-            jh = new JavaElementHandle(fqnTypeName, typeName, type.getHandle(), Collections.emptyList(), Collections.emptySet());
+            jh = new JavaElementHandle(typeName, ownerFQN, type.getHandle(), Collections.emptyList(), Collections.emptySet());

Review comment:
       Uh-oh ... this was a stupid bug; thanks.




-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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

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