|
| 1 | +package fr.adrienbrault.idea.symfony2plugin.expressionLanguage; |
| 2 | + |
| 3 | +import com.intellij.lexer.Lexer; |
| 4 | +import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; |
| 5 | +import com.intellij.openapi.editor.colors.TextAttributesKey; |
| 6 | +import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; |
| 7 | +import com.intellij.psi.tree.IElementType; |
| 8 | +import fr.adrienbrault.idea.symfony2plugin.expressionLanguage.psi.ExpressionLanguageTypes; |
| 9 | +import org.jetbrains.annotations.NotNull; |
| 10 | + |
| 11 | +import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; |
| 12 | + |
| 13 | +public class ExpressionLanguageSyntaxHighlighter extends SyntaxHighlighterBase { |
| 14 | + |
| 15 | + public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER); |
| 16 | + public static final TextAttributesKey STRING = createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING); |
| 17 | + public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER); |
| 18 | + public static final TextAttributesKey KEYWORD = createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD); |
| 19 | + |
| 20 | + private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER}; |
| 21 | + private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING}; |
| 22 | + private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER}; |
| 23 | + private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD}; |
| 24 | + private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; |
| 25 | + |
| 26 | + @NotNull |
| 27 | + @Override |
| 28 | + public Lexer getHighlightingLexer() { |
| 29 | + return new ExpressionLanguageLexerAdapter(); |
| 30 | + } |
| 31 | + |
| 32 | + @NotNull |
| 33 | + @Override |
| 34 | + public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { |
| 35 | + if (tokenType.equals(ExpressionLanguageTypes.NUMBER)) { |
| 36 | + return NUMBER_KEYS; |
| 37 | + } else if (tokenType.equals(ExpressionLanguageTypes.STRING)) { |
| 38 | + return STRING_KEYS; |
| 39 | + } else if (tokenType.equals(ExpressionLanguageTypes.ID)) { |
| 40 | + return IDENTIFIER_KEYS; |
| 41 | + } else if (tokenType.equals(ExpressionLanguageTypes.TRUE)) { |
| 42 | + return KEYWORD_KEYS; |
| 43 | + } else if (tokenType.equals(ExpressionLanguageTypes.FALSE)) { |
| 44 | + return KEYWORD_KEYS; |
| 45 | + } else if (tokenType.equals(ExpressionLanguageTypes.NULL)) { |
| 46 | + return KEYWORD_KEYS; |
| 47 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_IN)) { |
| 48 | + return KEYWORD_KEYS; |
| 49 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_NOT_IN)) { |
| 50 | + return KEYWORD_KEYS; |
| 51 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_MATCHES)) { |
| 52 | + return KEYWORD_KEYS; |
| 53 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_AND_KW)) { |
| 54 | + return KEYWORD_KEYS; |
| 55 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_OR_KW)) { |
| 56 | + return KEYWORD_KEYS; |
| 57 | + } else if (tokenType.equals(ExpressionLanguageTypes.OP_NOT_KW)) { |
| 58 | + return KEYWORD_KEYS; |
| 59 | + } |
| 60 | + |
| 61 | + return EMPTY_KEYS; |
| 62 | + } |
| 63 | +} |
0 commit comments