Skip to content

Commit 950ec3f

Browse files
committed
Context sensitive value keyword
1 parent 4f150d3 commit 950ec3f

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,11 @@ boolean record = false;
963963
tl.moveNext();
964964
record = true;
965965
}
966+
Token valueToken = tl.firstIdentifier(getCurrentPath(), "value");
967+
if (valueToken != null) {
968+
contextKeywords.add(valueToken);
969+
tl.moveNext();
970+
}
966971
firstIdentifier(tree.getSimpleName().toString());
967972

968973
//XXX:????
@@ -1077,7 +1082,7 @@ public Void scan(Tree tree, Void p) {
10771082
contextKeywords.add(t);
10781083
}
10791084
} else if (tree != null && tree.getKind() == Kind.MODIFIERS) {
1080-
visitModifier(tree);
1085+
visitModifier(tree);
10811086
}
10821087
return super.scan(tree, p);
10831088
}
@@ -1100,6 +1105,11 @@ private void visitModifier(Tree tree) {
11001105
if (t != null) {
11011106
contextKeywords.add(t);
11021107
}
1108+
} else if (tree.toString().contains("value")) {// NOI18N
1109+
t = firstIdentifierToken("value"); //NOI18N
1110+
if (t != null) {
1111+
contextKeywords.add(t);
1112+
}
11031113
}
11041114
}
11051115

java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/Utilities.java

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.logging.Level;
4444
import javax.swing.text.BadLocationException;
4545
import javax.swing.text.Document;
46-
import java.util.HashSet;
4746
import java.util.List;
4847
import java.util.Map;
4948
import java.util.Set;
@@ -514,14 +513,13 @@ private static int findBodyStartImpl(CompilationInfo info, Tree cltree, Compilat
514513

515514
public static int findBodyStart(final CompilationInfo info, final Tree cltree, final CompilationUnitTree cu, final SourcePositions positions, final Document doc) {
516515
Kind kind = cltree.getKind();
517-
if (!TreeUtilities.CLASS_TREE_KINDS.contains(kind) && kind != Kind.METHOD && !cltree.getKind().toString().equals("RECORD"))
516+
if (!TreeUtilities.CLASS_TREE_KINDS.contains(kind) && kind != Kind.METHOD) {
518517
throw new IllegalArgumentException("Unsupported kind: "+ kind);
518+
}
519519
final int[] result = new int[1];
520520

521-
doc.render(new Runnable() {
522-
public void run() {
523-
result[0] = findBodyStartImpl(info, cltree, cu, positions, doc);
524-
}
521+
doc.render(() -> {
522+
result[0] = findBodyStartImpl(info, cltree, cu, positions, doc);
525523
});
526524

527525
return result[0];
@@ -562,10 +560,8 @@ private static int findLastBracketImpl(Tree tree, CompilationUnitTree cu, Source
562560
public static int findLastBracket(final Tree tree, final CompilationUnitTree cu, final SourcePositions positions, final Document doc) {
563561
final int[] result = new int[1];
564562

565-
doc.render(new Runnable() {
566-
public void run() {
567-
result[0] = findLastBracketImpl(tree, cu, positions, doc);
568-
}
563+
doc.render(() -> {
564+
result[0] = findLastBracketImpl(tree, cu, positions, doc);
569565
});
570566

571567
return result[0];
@@ -579,7 +575,7 @@ private static Token<JavaTokenId> createHighlightImpl(CompilationInfo info, Docu
579575
//XXX: do not use instanceof:
580576
if (leaf instanceof MethodTree || leaf instanceof VariableTree || leaf instanceof ClassTree
581577
|| leaf instanceof MemberSelectTree || leaf instanceof AnnotatedTypeTree || leaf instanceof MemberReferenceTree
582-
|| "BINDING_PATTERN".equals(leaf.getKind().name())) {
578+
|| leaf.getKind() == Kind.BINDING_PATTERN) {
583579
return findIdentifierSpan(info, doc, tree);
584580
}
585581

@@ -617,34 +613,16 @@ public static Token<JavaTokenId> getToken(final CompilationInfo info, final Docu
617613
@SuppressWarnings("unchecked")
618614
final Token<JavaTokenId>[] result = new Token[1];
619615

620-
doc.render(new Runnable() {
621-
public void run() {
622-
result[0] = createHighlightImpl(info, doc, tree);
623-
}
616+
doc.render(() -> {
617+
result[0] = createHighlightImpl(info, doc, tree);
624618
});
625619

626620
return result[0];
627621
}
628622

629-
private static final Set<String> keywords;
630-
private static final Set<String> nonCtorKeywords;
631-
632-
static {
633-
keywords = new HashSet<String>();
634-
635-
keywords.add("true");
636-
keywords.add("false");
637-
keywords.add("null");
638-
keywords.add("this");
639-
keywords.add("super");
640-
keywords.add("class");
623+
private static final Set<String> keywords = Set.of("true", "false", "null", "this", "super", "class");
624+
private static final Set<String> nonCtorKeywords = Set.of("true", "false", "null", "class");
641625

642-
nonCtorKeywords = new HashSet<String>(keywords);
643-
nonCtorKeywords.remove("this");
644-
nonCtorKeywords.remove("super");
645-
646-
}
647-
648626
public static boolean isKeyword(Tree tree) {
649627
if (tree.getKind() == Kind.IDENTIFIER) {
650628
return keywords.contains(((IdentifierTree) tree).getName().toString());

0 commit comments

Comments
 (0)