11package schemely .highlighter ;
22
33import com .intellij .lexer .Lexer ;
4+ import com .intellij .openapi .editor .DefaultLanguageHighlighterColors ;
45import com .intellij .openapi .editor .HighlighterColors ;
56import com .intellij .openapi .editor .SyntaxHighlighterColors ;
67import com .intellij .openapi .editor .colors .TextAttributesKey ;
78import com .intellij .openapi .editor .markup .TextAttributes ;
89import com .intellij .openapi .fileTypes .SyntaxHighlighterBase ;
910import com .intellij .psi .tree .IElementType ;
11+ import com .intellij .psi .tree .TokenSet ;
1012import org .jetbrains .annotations .NonNls ;
1113import org .jetbrains .annotations .NotNull ;
1214import schemely .lexer .SchemeLexer ;
2022
2123public class SchemeSyntaxHighlighter extends SyntaxHighlighterBase implements Tokens
2224{
23- private static final Map <IElementType , TextAttributesKey > ATTRIBUTES = new HashMap <IElementType , TextAttributesKey >();
25+ private static final Map <IElementType , TextAttributesKey [] > ATTRIBUTES = new HashMap <IElementType , TextAttributesKey [] >();
2426
2527 @ NotNull
2628 public Lexer getHighlightingLexer ()
@@ -31,7 +33,13 @@ public Lexer getHighlightingLexer()
3133 @ NotNull
3234 public TextAttributesKey [] getTokenHighlights (IElementType tokenType )
3335 {
34- return pack (ATTRIBUTES .get (tokenType ));
36+ TextAttributesKey [] Keys = ATTRIBUTES .get (tokenType );
37+ if (null == Keys ) {
38+ // System.out.println("tokenType: " + tokenType.toString());
39+ return EMPTY_KEYS ;
40+ } else {
41+ return Keys ;
42+ }
3543 }
3644
3745 @ NonNls
@@ -66,6 +74,11 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType)
6674 @ NonNls
6775 static final String QUOTED_NUMBER_ID = "Quoted number" ;
6876
77+ @ NonNls
78+ static final String DOT_ID = "Dot" ;
79+ @ NonNls
80+ static final String COMMA_ID = "Comma" ;
81+
6982
7083 // Registering TextAttributes
7184 static
@@ -85,6 +98,8 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType)
8598 createTextAttributesKey (QUOTED_TEXT_ID , brighter (HighlighterColors .TEXT ));
8699 createTextAttributesKey (QUOTED_STRING_ID , brighter (SyntaxHighlighterColors .STRING ));
87100 createTextAttributesKey (QUOTED_NUMBER_ID , brighter (SyntaxHighlighterColors .NUMBER ));
101+ createTextAttributesKey (DOT_ID , brighter (SyntaxHighlighterColors .DOT ));
102+ createTextAttributesKey (COMMA_ID , brighter (SyntaxHighlighterColors .COMMA ));
88103 }
89104
90105 public static TextAttributesKey LINE_COMMENT = createTextAttributesKey (COMMENT_ID );
@@ -102,21 +117,59 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType)
102117 public static TextAttributesKey QUOTED_TEXT = createTextAttributesKey (QUOTED_TEXT_ID );
103118 public static TextAttributesKey QUOTED_STRING = createTextAttributesKey (QUOTED_STRING_ID );
104119 public static TextAttributesKey QUOTED_NUMBER = createTextAttributesKey (QUOTED_NUMBER_ID );
120+ public static TextAttributesKey DOT = createTextAttributesKey (DOT_ID );
121+ public static TextAttributesKey COMMA = createTextAttributesKey (COMMA_ID );
122+
123+ public static TextAttributesKey [] LINE_COMMENT_KEYS = new TextAttributesKey []{createTextAttributesKey (COMMENT_ID )};
124+ public static TextAttributesKey [] BLOCK_COMMENT_KEYS = new TextAttributesKey []{createTextAttributesKey (BLOCK_COMMENT_ID )};
125+ public static TextAttributesKey [] IDENTIFIER_KEYS = new TextAttributesKey []{createTextAttributesKey (IDENTIFIER_ID )};
126+ public static TextAttributesKey [] NUMBER_KEYS = new TextAttributesKey []{createTextAttributesKey (NUMBER_ID )};
127+ public static TextAttributesKey [] STRING_KEYS = new TextAttributesKey []{createTextAttributesKey (STRING_ID )};
128+ public static TextAttributesKey [] BRACE_KEYS = new TextAttributesKey []{createTextAttributesKey (BRACES_ID )};
129+ public static TextAttributesKey [] PAREN_KEYS = new TextAttributesKey []{createTextAttributesKey (PAREN_ID )};
130+ public static TextAttributesKey [] LITERAL_KEYS = new TextAttributesKey []{createTextAttributesKey (LITERAL_ID )};
131+ public static TextAttributesKey [] CHAR_KEYS = new TextAttributesKey []{createTextAttributesKey (CHAR_ID )};
132+ public static TextAttributesKey [] BAD_CHARACTER_KEYS = new TextAttributesKey []{createTextAttributesKey (BAD_CHARACTER_ID )};
133+ public static TextAttributesKey [] KEYWORD_KEYS = new TextAttributesKey []{createTextAttributesKey (KEYWORD_ID )};
134+ public static TextAttributesKey [] SPECIAL_KEYS = new TextAttributesKey []{createTextAttributesKey (SPECIAL_ID )};
135+ public static TextAttributesKey [] QUOTED_TEXT_KEYS = new TextAttributesKey []{createTextAttributesKey (QUOTED_TEXT_ID )};
136+ public static TextAttributesKey [] QUOTED_STRING_KEYS = new TextAttributesKey []{createTextAttributesKey (QUOTED_STRING_ID )};
137+ public static TextAttributesKey [] QUOTED_NUMBER_KEYS = new TextAttributesKey []{createTextAttributesKey (QUOTED_NUMBER_ID )};
138+ public static TextAttributesKey [] DOT_KEYS = new TextAttributesKey []{createTextAttributesKey (DOT_ID )};
139+ public static TextAttributesKey [] COMMA_KEYS = new TextAttributesKey []{createTextAttributesKey (COMMA_ID )};
140+ public static TextAttributesKey [] EMPTY_KEYS = new TextAttributesKey [0 ];
105141
106142 static
107143 {
108- fillMap (ATTRIBUTES , LINE_COMMENT , Tokens .COMMENT );
109- fillMap (ATTRIBUTES , BLOCK_COMMENT , Tokens .BLOCK_COMMENT );
110- fillMap (ATTRIBUTES , NUMBER , NUMBER_LITERAL );
111- fillMap (ATTRIBUTES , Tokens .STRINGS , STRING );
112- fillMap (ATTRIBUTES , BRACE , Tokens .LEFT_SQUARE , Tokens .RIGHT_SQUARE , Tokens .LEFT_CURLY , Tokens .RIGHT_CURLY );
113- fillMap (ATTRIBUTES , PAREN , Tokens .LEFT_PAREN , Tokens .RIGHT_PAREN );
114- fillMap (ATTRIBUTES , LITERAL , Tokens .BOOLEAN_LITERAL );
115- fillMap (ATTRIBUTES , CHAR , Tokens .CHAR_LITERAL );
116- fillMap (ATTRIBUTES , SPECIAL , Tokens .SPECIAL );
117- fillMap (ATTRIBUTES , IDENTIFIER , Tokens .IDENTIFIER );
144+ newFillMap (ATTRIBUTES , LINE_COMMENT_KEYS , Tokens .COMMENT );
145+ newFillMap (ATTRIBUTES , BLOCK_COMMENT_KEYS , Tokens .BLOCK_COMMENT );
146+ newFillMap (ATTRIBUTES , NUMBER_KEYS , NUMBER_LITERAL );
147+ newFillMap (ATTRIBUTES , STRING_KEYS , Tokens .STRINGS );
148+ newFillMap (ATTRIBUTES , BRACE_KEYS , Tokens .LEFT_SQUARE , Tokens .RIGHT_SQUARE , Tokens .LEFT_CURLY , Tokens .RIGHT_CURLY );
149+ newFillMap (ATTRIBUTES , PAREN_KEYS , Tokens .LEFT_PAREN , Tokens .RIGHT_PAREN );
150+ newFillMap (ATTRIBUTES , LITERAL_KEYS , Tokens .BOOLEAN_LITERAL );
151+ newFillMap (ATTRIBUTES , CHAR_KEYS , Tokens .CHAR_LITERAL );
152+ newFillMap (ATTRIBUTES , SPECIAL_KEYS , Tokens .SPECIAL );
153+ newFillMap (ATTRIBUTES , IDENTIFIER_KEYS , Tokens .IDENTIFIERS );
154+ newFillMap (ATTRIBUTES , DOT_KEYS , Tokens .DOT );
155+ newFillMap (ATTRIBUTES , COMMA_KEYS , Tokens .COMMA , Tokens .COMMA_AT );
156+ }
157+
158+ protected static void newFillMap (@ NotNull Map <IElementType , TextAttributesKey []> map , TextAttributesKey [] value , @ NotNull TokenSet keys ) {
159+ newFillMap (map , value , keys .getTypes ());
160+ }
161+
162+ protected static void newFillMap (@ NotNull Map <IElementType , TextAttributesKey []> map , TextAttributesKey [] value , @ NotNull IElementType ... types ) {
163+ IElementType [] var3 = types ;
164+ int var4 = types .length ;
165+
166+ for (int var5 = 0 ; var5 < var4 ; ++var5 ) {
167+ IElementType type = var3 [var5 ];
168+ map .put (type , value );
169+ }
118170 }
119171
172+
120173 private static TextAttributes defaultFor (TextAttributesKey key )
121174 {
122175 return key .getDefaultAttributes ();
0 commit comments