Skip to content

Commit efc97a8

Browse files
committed
Impl. color settings page for Expression Language Syntax Highlighter
1 parent 3501738 commit efc97a8

File tree

3 files changed

+84
-10
lines changed

3 files changed

+84
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package fr.adrienbrault.idea.symfony2plugin.expressionLanguage;
2+
3+
import com.intellij.openapi.editor.colors.TextAttributesKey;
4+
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
5+
import com.intellij.openapi.options.colors.AttributesDescriptor;
6+
import com.intellij.openapi.options.colors.ColorDescriptor;
7+
import com.intellij.openapi.options.colors.ColorSettingsPage;
8+
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
import javax.swing.*;
13+
import java.util.Map;
14+
15+
public class ExpressionLanguageColorSettingsPage implements ColorSettingsPage {
16+
17+
private static final AttributesDescriptor[] ATTRIBUTE_DESCRIPTORS = new AttributesDescriptor[]{
18+
new AttributesDescriptor("Number", ExpressionLanguageSyntaxHighlighter.NUMBER),
19+
new AttributesDescriptor("String", ExpressionLanguageSyntaxHighlighter.STRING),
20+
new AttributesDescriptor("Identifier", ExpressionLanguageSyntaxHighlighter.IDENTIFIER),
21+
new AttributesDescriptor("Keyword", ExpressionLanguageSyntaxHighlighter.KEYWORD),
22+
};
23+
24+
@Nullable
25+
@Override
26+
public Icon getIcon() {
27+
return Symfony2Icons.SYMFONY;
28+
}
29+
30+
@NotNull
31+
@Override
32+
public SyntaxHighlighter getHighlighter() {
33+
return new ExpressionLanguageSyntaxHighlighter();
34+
}
35+
36+
@NotNull
37+
@Override
38+
public String getDemoText() {
39+
return "article.getCommentCount(true) > 100 and article.category not in [\"misc\", null, true] === false";
40+
}
41+
42+
@NotNull
43+
@Override
44+
public String getDisplayName() {
45+
return "Symfony Expression Language";
46+
}
47+
48+
@NotNull
49+
@Override
50+
public AttributesDescriptor[] getAttributeDescriptors() {
51+
return ATTRIBUTE_DESCRIPTORS;
52+
}
53+
54+
@NotNull
55+
@Override
56+
public ColorDescriptor[] getColorDescriptors() {
57+
return ColorDescriptor.EMPTY_ARRAY;
58+
}
59+
60+
@Override
61+
public @Nullable
62+
Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
63+
return null;
64+
}
65+
}
66+

src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageSyntaxHighlighter.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.intellij.openapi.editor.colors.TextAttributesKey;
66
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
77
import com.intellij.psi.tree.IElementType;
8+
import com.intellij.psi.tree.java.IKeywordElementType;
89
import fr.adrienbrault.idea.symfony2plugin.expressionLanguage.psi.ExpressionLanguageTypes;
910
import org.jetbrains.annotations.NotNull;
1011

@@ -14,15 +15,13 @@ public class ExpressionLanguageSyntaxHighlighter extends SyntaxHighlighterBase {
1415

1516
public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
1617
public static final TextAttributesKey STRING = createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING);
17-
public static final TextAttributesKey ID = createTextAttributesKey("ID", DefaultLanguageHighlighterColors.IDENTIFIER);
1818
public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
19-
public static final TextAttributesKey FUNCTION_CALL = createTextAttributesKey("FUNCTION_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL);
19+
public static final TextAttributesKey KEYWORD = createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
2020

2121
private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER};
2222
private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING};
23-
private static final TextAttributesKey[] ID_KEYS = new TextAttributesKey[]{ID};
2423
private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER};
25-
private static final TextAttributesKey[] FUNCTION_CALL_KEYS = new TextAttributesKey[]{FUNCTION_CALL};
24+
private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
2625
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
2726

2827
@NotNull
@@ -39,13 +38,21 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
3938
} else if (tokenType.equals(ExpressionLanguageTypes.STRING)) {
4039
return STRING_KEYS;
4140
} else if (tokenType.equals(ExpressionLanguageTypes.ID)) {
42-
return ID_KEYS;
43-
} else if (tokenType.equals(ExpressionLanguageTypes.IDENTIFIER)) {
4441
return IDENTIFIER_KEYS;
45-
} else if (tokenType.equals(ExpressionLanguageTypes.CALL_EXPR)) {
46-
return FUNCTION_CALL_KEYS;
47-
} else {
48-
return EMPTY_KEYS;
42+
} else if (tokenType.equals(ExpressionLanguageTypes.TRUE)) {
43+
return KEYWORD_KEYS;
44+
} else if (tokenType.equals(ExpressionLanguageTypes.FALSE)) {
45+
return KEYWORD_KEYS;
46+
} else if (tokenType.equals(ExpressionLanguageTypes.NULL)) {
47+
return KEYWORD_KEYS;
48+
} else if (tokenType.equals(ExpressionLanguageTypes.OP_IN)) {
49+
return KEYWORD_KEYS;
50+
} else if (tokenType.equals(ExpressionLanguageTypes.OP_NOT_IN)) {
51+
return KEYWORD_KEYS;
52+
} else if (tokenType.equals(ExpressionLanguageTypes.OP_MATCHES)) {
53+
return KEYWORD_KEYS;
4954
}
55+
56+
return EMPTY_KEYS;
5057
}
5158
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
<lang.parserDefinition language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageParserDefinition" />
225225
<lang.syntaxHighlighterFactory language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageSyntaxHighlighterFactory" />
226226
<lang.braceMatcher language="Symfony Expression Language" implementationClass="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageBraceMatcher" />
227+
<colorSettingsPage implementation="fr.adrienbrault.idea.symfony2plugin.expressionLanguage.ExpressionLanguageColorSettingsPage"/>
227228

228229
<codeInsight.lineMarkerProvider language="PHP" implementationClass="fr.adrienbrault.idea.symfony2plugin.config.ServiceLineMarkerProvider"/>
229230
<codeInsight.lineMarkerProvider language="PHP" implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.ControllerMethodLineMarkerProvider"/>

0 commit comments

Comments
 (0)