Skip to content

Commit 16bbbdd

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

File tree

3 files changed

+83
-10
lines changed

3 files changed

+83
-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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ public class ExpressionLanguageSyntaxHighlighter extends SyntaxHighlighterBase {
1414

1515
public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
1616
public static final TextAttributesKey STRING = createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING);
17-
public static final TextAttributesKey ID = createTextAttributesKey("ID", DefaultLanguageHighlighterColors.IDENTIFIER);
1817
public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
19-
public static final TextAttributesKey FUNCTION_CALL = createTextAttributesKey("FUNCTION_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL);
18+
public static final TextAttributesKey KEYWORD = createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
2019

2120
private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER};
2221
private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING};
23-
private static final TextAttributesKey[] ID_KEYS = new TextAttributesKey[]{ID};
2422
private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER};
25-
private static final TextAttributesKey[] FUNCTION_CALL_KEYS = new TextAttributesKey[]{FUNCTION_CALL};
23+
private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
2624
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
2725

2826
@NotNull
@@ -39,13 +37,21 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
3937
} else if (tokenType.equals(ExpressionLanguageTypes.STRING)) {
4038
return STRING_KEYS;
4139
} else if (tokenType.equals(ExpressionLanguageTypes.ID)) {
42-
return ID_KEYS;
43-
} else if (tokenType.equals(ExpressionLanguageTypes.IDENTIFIER)) {
4440
return IDENTIFIER_KEYS;
45-
} else if (tokenType.equals(ExpressionLanguageTypes.CALL_EXPR)) {
46-
return FUNCTION_CALL_KEYS;
47-
} else {
48-
return EMPTY_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;
4953
}
54+
55+
return EMPTY_KEYS;
5056
}
5157
}

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)