4
4
import org .ice1000 .devkt .openapi .ExtendedDevKtLanguage ;
5
5
import org .jetbrains .annotations .NotNull ;
6
6
import org .jetbrains .annotations .Nullable ;
7
+ import org .jetbrains .kotlin .com .intellij .lexer .LayeredLexer ;
8
+ import org .jetbrains .kotlin .com .intellij .lexer .Lexer ;
9
+ import org .jetbrains .kotlin .com .intellij .lexer .StringLiteralLexer ;
10
+ import org .jetbrains .kotlin .com .intellij .openapi .project .Project ;
7
11
import org .jetbrains .kotlin .com .intellij .psi .StringEscapesTokenTypes ;
8
12
import org .jetbrains .kotlin .com .intellij .psi .tree .IElementType ;
9
13
@@ -17,8 +21,7 @@ public String getLineCommentStart() {
17
21
}
18
22
19
23
@ Override
20
- public @ NotNull
21
- Icon getIcon () {
24
+ public @ NotNull Icon getIcon () {
22
25
return JsonFileType .INSTANCE .getIcon ();
23
26
}
24
27
@@ -27,19 +30,37 @@ public Json() {
27
30
}
28
31
29
32
@ Override
30
- public boolean satisfies (String fileName ) {
33
+ public boolean satisfies (@ NotNull String fileName ) {
31
34
return fileName .endsWith (".json" ) || fileName .equals (".pinpoint" );
32
35
}
33
36
37
+ public @ NotNull Lexer createLexer (@ NotNull Project project ) {
38
+ LayeredLexer layeredLexer = new LayeredLexer (new JsonLexer ());
39
+ layeredLexer .registerSelfStoppingLayer (new StringLiteralLexer ('\"' ,
40
+ JsonElementTypes .DOUBLE_QUOTED_STRING ,
41
+ false ,
42
+ "/" ,
43
+ false ,
44
+ false ), new IElementType []{JsonElementTypes .DOUBLE_QUOTED_STRING }, IElementType .EMPTY_ARRAY );
45
+ layeredLexer .registerSelfStoppingLayer (new StringLiteralLexer ('\'' ,
46
+ JsonElementTypes .SINGLE_QUOTED_STRING ,
47
+ false ,
48
+ "/" ,
49
+ false ,
50
+ false ), new IElementType []{JsonElementTypes .SINGLE_QUOTED_STRING }, IElementType .EMPTY_ARRAY );
51
+ return layeredLexer ;
52
+ }
53
+
34
54
@ Override
35
- public @ Nullable
36
- T attributesOf (IElementType iElementType , ColorScheme <? extends T > colorScheme ) {
55
+ public @ Nullable T attributesOf (@ NotNull IElementType iElementType , @ NotNull ColorScheme <? extends T > colorScheme ) {
37
56
if (iElementType == JsonElementTypes .LINE_COMMENT ) return colorScheme .getLineComments ();
38
57
else if (iElementType == JsonElementTypes .BLOCK_COMMENT ) return colorScheme .getBlockComments ();
39
58
else if (iElementType == JsonElementTypes .NUMBER ) return colorScheme .getNumbers ();
40
59
else if (iElementType == JsonElementTypes .SINGLE_QUOTED_STRING ) return colorScheme .getString ();
41
60
else if (iElementType == JsonElementTypes .DOUBLE_QUOTED_STRING ) return colorScheme .getProperty ();
42
61
else if (iElementType == StringEscapesTokenTypes .VALID_STRING_ESCAPE_TOKEN ) return colorScheme .getStringEscape ();
62
+ else if (iElementType == StringEscapesTokenTypes .INVALID_UNICODE_ESCAPE_TOKEN ) return colorScheme .getUnknown ();
63
+ else if (iElementType == StringEscapesTokenTypes .INVALID_CHARACTER_ESCAPE_TOKEN ) return colorScheme .getUnknown ();
43
64
else if (iElementType == JsonElementTypes .IDENTIFIER ) return colorScheme .getIdentifiers ();
44
65
else if (iElementType == JsonElementTypes .COLON ) return colorScheme .getColon ();
45
66
else if (iElementType == JsonElementTypes .COMMA ) return colorScheme .getComma ();
0 commit comments