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/10/11 15:17:13 UTC

[GitHub] [netbeans] lkishalmi opened a new pull request, #4773: Improve support for ANTLRv4 Grammars

lkishalmi opened a new pull request, #4773:
URL: https://github.com/apache/netbeans/pull/4773

   This one adds support for occurrence finder for modes and channels.
   
   The code completion has been separated for ANTLVv3 and ANTLRv4. I've added some heuristics to make it better for v4, based on the real ANTLRv4 Lexer. Though there is still room for improvement.
   
   I'd like to finish mu indentation support before NB16, but I thought this is complete enough for review.


-- 
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] lkishalmi commented on a diff in pull request #4773: Improve support for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on code in PR #4773:
URL: https://github.com/apache/netbeans/pull/4773#discussion_r992943602


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java:
##########
@@ -93,20 +101,37 @@ protected boolean processingFinished() {
 
     public static class Reference {
         public final String name;
-        public FileObject source;
-        public OffsetRange defOffset;
-        public final List<OffsetRange> occurances = new ArrayList<>();
+        public final OffsetRange defOffset;
 
-        public Reference(String name, FileObject source, OffsetRange defOffset) {
+        public Reference(String name, OffsetRange defOffset) {
             this.name = name;
-            this.source = source;
             this.defOffset = defOffset;
         }
     }
 
     protected final FileObject getFileObject() {
         return getSnapshot().getSource().getFileObject();
     }
+    
+    public final List<? extends OffsetRange> getOccurrences(String refName) {
+        ArrayList<OffsetRange> ret = new ArrayList<>();
+        if (references.containsKey(refName)) {
+            ret.add(references.get(refName).defOffset);
+        }
+        if (occurrences.containsKey(refName)) {
+            ret.addAll(occurrences.get(refName));
+        }
+        return !ret.isEmpty() ? ret : Collections.emptyList();
+    } 
+    
+    protected final void markOccurrence(String refName, OffsetRange or) {
+        List<OffsetRange> ol = occurrences.get(refName);
+        if (ol == null) {
+            ol = new ArrayList<>();
+            occurrences.put(refName, ol);
+        }
+        ol.add(or);

Review Comment:
   Thanks! I've learned something new today!



-- 
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] lkishalmi commented on a diff in pull request #4773: Improve support for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on code in PR #4773:
URL: https://github.com/apache/netbeans/pull/4773#discussion_r992943848


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java:
##########
@@ -148,7 +148,7 @@ public Problem prepare(RefactoringElementsBag refactoringElements) {
                         if(ref.defOffset != null) {
                             ranges.add(ref.defOffset);
                         }
-                        ranges.addAll(ref.occurances);
+                        ranges.addAll(result.getOccurrences(name));

Review Comment:
   True. Thank you!



-- 
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] lkishalmi merged pull request #4773: Improve support for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi merged PR #4773:
URL: https://github.com/apache/netbeans/pull/4773


-- 
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] lkishalmi commented on pull request #4773: Improve support for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on PR #4773:
URL: https://github.com/apache/netbeans/pull/4773#issuecomment-1275522522

   Also fixed a potential NPE on refactoring. It'd happen when the find usages would be repeated from the UI button.


-- 
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] matthiasblaesing commented on a diff in pull request #4773: Improve support for ANTLRv4 Grammars

Posted by GitBox <gi...@apache.org>.
matthiasblaesing commented on code in PR #4773:
URL: https://github.com/apache/netbeans/pull/4773#discussion_r992669678


##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java:
##########
@@ -93,20 +101,37 @@ protected boolean processingFinished() {
 
     public static class Reference {
         public final String name;
-        public FileObject source;
-        public OffsetRange defOffset;
-        public final List<OffsetRange> occurances = new ArrayList<>();
+        public final OffsetRange defOffset;
 
-        public Reference(String name, FileObject source, OffsetRange defOffset) {
+        public Reference(String name, OffsetRange defOffset) {
             this.name = name;
-            this.source = source;
             this.defOffset = defOffset;
         }
     }
 
     protected final FileObject getFileObject() {
         return getSnapshot().getSource().getFileObject();
     }
+    
+    public final List<? extends OffsetRange> getOccurrences(String refName) {
+        ArrayList<OffsetRange> ret = new ArrayList<>();
+        if (references.containsKey(refName)) {
+            ret.add(references.get(refName).defOffset);
+        }
+        if (occurrences.containsKey(refName)) {
+            ret.addAll(occurrences.get(refName));
+        }
+        return !ret.isEmpty() ? ret : Collections.emptyList();

Review Comment:
   I would directly return `ret`. I don't see a gain by special casing the empty case.



##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/refactoring/Refactoring.java:
##########
@@ -148,7 +148,7 @@ public Problem prepare(RefactoringElementsBag refactoringElements) {
                         if(ref.defOffset != null) {
                             ranges.add(ref.defOffset);
                         }
-                        ranges.addAll(ref.occurances);
+                        ranges.addAll(result.getOccurrences(name));

Review Comment:
   This needs to be pulled out of the if. I tested this:
   
   - I opened `LexBasic.g4` from the `antlr4` package
   - I ran "Find Usage" in `Ws`
   
   I only got the results from `LexBasic.g4` and was missing the occurrences from `ANTLR4Lexer.g4`. `ref` is `NULL` for the latter, but there are still occurrences. Pulling out this call fixes it.



##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrParserResult.java:
##########
@@ -93,20 +101,37 @@ protected boolean processingFinished() {
 
     public static class Reference {
         public final String name;
-        public FileObject source;
-        public OffsetRange defOffset;
-        public final List<OffsetRange> occurances = new ArrayList<>();
+        public final OffsetRange defOffset;
 
-        public Reference(String name, FileObject source, OffsetRange defOffset) {
+        public Reference(String name, OffsetRange defOffset) {
             this.name = name;
-            this.source = source;
             this.defOffset = defOffset;
         }
     }
 
     protected final FileObject getFileObject() {
         return getSnapshot().getSource().getFileObject();
     }
+    
+    public final List<? extends OffsetRange> getOccurrences(String refName) {
+        ArrayList<OffsetRange> ret = new ArrayList<>();
+        if (references.containsKey(refName)) {
+            ret.add(references.get(refName).defOffset);
+        }
+        if (occurrences.containsKey(refName)) {
+            ret.addAll(occurrences.get(refName));
+        }
+        return !ret.isEmpty() ? ret : Collections.emptyList();
+    } 
+    
+    protected final void markOccurrence(String refName, OffsetRange or) {
+        List<OffsetRange> ol = occurrences.get(refName);
+        if (ol == null) {
+            ol = new ArrayList<>();
+            occurrences.put(refName, ol);
+        }
+        ol.add(or);

Review Comment:
   ```suggestion
           occurrences.computeIfAbsent(refName, s -> new ArrayList<>()).add(or);
   ```



##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrStructureScanner.java:
##########
@@ -18,6 +18,7 @@
  */
 package org.netbeans.modules.languages.antlr;
 
+import java.util.ArrayList;

Review Comment:
   Looks like an unnecessary change.



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