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/17 11:58:55 UTC

[GitHub] [netbeans] ppisl opened a new pull request #3802: [NETBEANS-4826] Fixing java indexing in Groovy

ppisl opened a new pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802


   This will turn back on indexing of Groovy files in Java. This means that Groovy classes can now be offered in java source files.  The Groovy file is used to create virtual Java source code that is indexed and stored in the java index. This will not only enable indexing, but features like code completion, hyperlinks, goto navigation should also work. 
   
   More fixes were needed to get this working again. There are also a few fixes, such as:
   static arrays and methods are offered as arrays and methods in import statements - they were previously offered as classes in code completion. 
   
   Translated with www.DeepL.com/Translator (free version)


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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802#discussion_r832299976



##########
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:
       Done
   




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


[GitHub] [netbeans] ppisl merged pull request #3802: [NETBEANS-4826] Fixing java indexing in Groovy

Posted by GitBox <gi...@apache.org>.
ppisl merged pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802


   


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


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

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802#discussion_r831562838



##########
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:
       Can we have import statement like `import Whatever.class` ? 




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


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

Posted by GitBox <gi...@apache.org>.
ppisl commented on a change in pull request #3802:
URL: https://github.com/apache/netbeans/pull/3802#discussion_r831562838



##########
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:
       It will do nothing. You can not have a statement `import Whatever.class.` and also the word `class` is LITERAL_class, so the location will not be set INSIDE_IMPORT.




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


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

Posted by GitBox <gi...@apache.org>.
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