@@ -32,10 +32,10 @@ final class BnfAnnotator implements Annotator, DumbAware {
32
32
@ Override
33
33
public void annotate (@ NotNull PsiElement psiElement , @ NotNull AnnotationHolder annotationHolder ) {
34
34
PsiElement parent = psiElement .getParent ();
35
- if (parent instanceof BnfRule && (( BnfRule ) parent ) .getId () == psiElement ) {
36
- addRuleHighlighting (( BnfRule ) parent , psiElement , annotationHolder );
35
+ if (parent instanceof BnfRule rule && rule .getId () == psiElement ) {
36
+ addRuleHighlighting (rule , psiElement , annotationHolder );
37
37
}
38
- else if (parent instanceof BnfAttr && (( BnfAttr ) parent ) .getId () == psiElement ) {
38
+ else if (parent instanceof BnfAttr attr && attr .getId () == psiElement ) {
39
39
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
40
40
.range (psiElement )
41
41
.textAttributes (BnfSyntaxHighlighter .ATTRIBUTE )
@@ -47,9 +47,9 @@ else if (parent instanceof BnfModifier) {
47
47
.textAttributes (BnfSyntaxHighlighter .KEYWORD )
48
48
.create ();
49
49
}
50
- else if (parent instanceof BnfListEntry && (( BnfListEntry ) parent ) .getId () == psiElement ) {
51
- boolean hasValue = (( BnfListEntry ) parent ) .getLiteralExpression () != null ;
52
- BnfAttr attr = PsiTreeUtil .getParentOfType (parent , BnfAttr .class );
50
+ else if (parent instanceof BnfListEntry listEntry && listEntry .getId () == psiElement ) {
51
+ boolean hasValue = listEntry .getLiteralExpression () != null ;
52
+ BnfAttr attr = PsiTreeUtil .getParentOfType (listEntry , BnfAttr .class );
53
53
KnownAttribute <?> attribute = attr != null ? KnownAttribute .getCompatibleAttribute (attr .getName ()) : null ;
54
54
if (attribute == KnownAttribute .METHODS && !hasValue ) {
55
55
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
@@ -58,48 +58,56 @@ else if (parent instanceof BnfListEntry && ((BnfListEntry)parent).getId() == psi
58
58
.create ();
59
59
}
60
60
}
61
- else if (psiElement instanceof BnfReferenceOrToken ) {
61
+ else if (psiElement instanceof BnfReferenceOrToken refOrToken ) {
62
62
if (parent instanceof BnfAttr ) {
63
- String text = psiElement .getText ();
63
+ String text = refOrToken .getText ();
64
64
if ("true" .equals (text ) || "false" .equals (text )) {
65
65
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
66
- .range (psiElement )
66
+ .range (refOrToken )
67
67
.textAttributes (BnfSyntaxHighlighter .KEYWORD )
68
68
.create ();
69
69
return ;
70
70
}
71
71
}
72
- PsiReference reference = psiElement .getReference ();
72
+ PsiReference reference = refOrToken .getReference ();
73
73
Object resolve = reference == null ? null : reference .resolve ();
74
- if (resolve instanceof BnfRule ) {
75
- addRuleHighlighting (( BnfRule ) resolve , psiElement , annotationHolder );
74
+ if (resolve instanceof BnfRule rule ) {
75
+ addRuleHighlighting (rule , refOrToken , annotationHolder );
76
76
}
77
77
else if (resolve instanceof BnfAttr ) {
78
78
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
79
- .range (psiElement )
79
+ .range (refOrToken )
80
80
.textAttributes (BnfSyntaxHighlighter .ATTRIBUTE )
81
81
.create ();
82
82
}
83
- else if (GrammarUtil .isExternalReference (psiElement )) {
84
- if (resolve == null && parent instanceof BnfExternalExpression && (( BnfExternalExpression ) parent ) .getArguments ().isEmpty () &&
85
- ParserGeneratorUtil .Rule .isMeta (ParserGeneratorUtil .Rule .of (( BnfReferenceOrToken ) psiElement ))) {
83
+ else if (GrammarUtil .isExternalReference (refOrToken )) {
84
+ if (resolve == null && parent instanceof BnfExternalExpression extExpr && extExpr .getArguments ().isEmpty () &&
85
+ ParserGeneratorUtil .Rule .isMeta (ParserGeneratorUtil .Rule .of (refOrToken ))) {
86
86
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
87
87
.range (parent )
88
88
.textAttributes (BnfSyntaxHighlighter .META_PARAM )
89
89
.create ();
90
90
}
91
91
else {
92
92
annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
93
- .range (psiElement )
93
+ .range (refOrToken )
94
94
.textAttributes (BnfSyntaxHighlighter .EXTERNAL )
95
95
.create ();
96
96
}
97
97
}
98
98
else if (resolve == null ) {
99
- annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
100
- .range (psiElement )
101
- .textAttributes (BnfSyntaxHighlighter .TOKEN )
102
- .create ();
99
+ var text = refOrToken .getId ().getText ();
100
+ if (RuleGraphHelper .getTokenNameToTextMap ((BnfFile )refOrToken .getContainingFile ()).containsKey (text )) {
101
+ annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
102
+ .range (refOrToken )
103
+ .textAttributes (BnfSyntaxHighlighter .EXPLICIT_TOKEN )
104
+ .create ();
105
+ } else {
106
+ annotationHolder .newSilentAnnotation (HighlightSeverity .INFORMATION )
107
+ .range (refOrToken )
108
+ .textAttributes (BnfSyntaxHighlighter .IMPLICIT_TOKEN )
109
+ .create ();
110
+ }
103
111
}
104
112
}
105
113
else if (psiElement instanceof BnfStringLiteralExpression ) {
0 commit comments