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