From efc97a8a0e7de4f30a83aeb736c10435de0fe1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Sat, 5 Jun 2021 12:14:21 +0200 Subject: [PATCH] Impl. color settings page for Expression Language Syntax Highlighter --- .../ExpressionLanguageColorSettingsPage.java | 66 +++++++++++++++++++ .../ExpressionLanguageSyntaxHighlighter.java | 27 +++++--- src/main/resources/META-INF/plugin.xml | 1 + 3 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageColorSettingsPage.java diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageColorSettingsPage.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageColorSettingsPage.java new file mode 100644 index 000000000..2b4c4cce6 --- /dev/null +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageColorSettingsPage.java @@ -0,0 +1,66 @@ +package fr.adrienbrault.idea.symfony2plugin.expressionLanguage; + +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.options.colors.AttributesDescriptor; +import com.intellij.openapi.options.colors.ColorDescriptor; +import com.intellij.openapi.options.colors.ColorSettingsPage; +import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Map; + +public class ExpressionLanguageColorSettingsPage implements ColorSettingsPage { + + private static final AttributesDescriptor[] ATTRIBUTE_DESCRIPTORS = new AttributesDescriptor[]{ + new AttributesDescriptor("Number", ExpressionLanguageSyntaxHighlighter.NUMBER), + new AttributesDescriptor("String", ExpressionLanguageSyntaxHighlighter.STRING), + new AttributesDescriptor("Identifier", ExpressionLanguageSyntaxHighlighter.IDENTIFIER), + new AttributesDescriptor("Keyword", ExpressionLanguageSyntaxHighlighter.KEYWORD), + }; + + @Nullable + @Override + public Icon getIcon() { + return Symfony2Icons.SYMFONY; + } + + @NotNull + @Override + public SyntaxHighlighter getHighlighter() { + return new ExpressionLanguageSyntaxHighlighter(); + } + + @NotNull + @Override + public String getDemoText() { + return "article.getCommentCount(true) > 100 and article.category not in [\"misc\", null, true] === false"; + } + + @NotNull + @Override + public String getDisplayName() { + return "Symfony Expression Language"; + } + + @NotNull + @Override + public AttributesDescriptor[] getAttributeDescriptors() { + return ATTRIBUTE_DESCRIPTORS; + } + + @NotNull + @Override + public ColorDescriptor[] getColorDescriptors() { + return ColorDescriptor.EMPTY_ARRAY; + } + + @Override + public @Nullable + Map getAdditionalHighlightingTagToDescriptorMap() { + return null; + } +} + diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageSyntaxHighlighter.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageSyntaxHighlighter.java index a7c6dd346..614511fa3 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageSyntaxHighlighter.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/expressionLanguage/ExpressionLanguageSyntaxHighlighter.java @@ -5,6 +5,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.java.IKeywordElementType; import fr.adrienbrault.idea.symfony2plugin.expressionLanguage.psi.ExpressionLanguageTypes; import org.jetbrains.annotations.NotNull; @@ -14,15 +15,13 @@ public class ExpressionLanguageSyntaxHighlighter extends SyntaxHighlighterBase { public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER); public static final TextAttributesKey STRING = createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING); - public static final TextAttributesKey ID = createTextAttributesKey("ID", DefaultLanguageHighlighterColors.IDENTIFIER); public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER); - public static final TextAttributesKey FUNCTION_CALL = createTextAttributesKey("FUNCTION_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL); + public static final TextAttributesKey KEYWORD = createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD); private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER}; private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING}; - private static final TextAttributesKey[] ID_KEYS = new TextAttributesKey[]{ID}; private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER}; - private static final TextAttributesKey[] FUNCTION_CALL_KEYS = new TextAttributesKey[]{FUNCTION_CALL}; + private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD}; private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; @NotNull @@ -39,13 +38,21 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { } else if (tokenType.equals(ExpressionLanguageTypes.STRING)) { return STRING_KEYS; } else if (tokenType.equals(ExpressionLanguageTypes.ID)) { - return ID_KEYS; - } else if (tokenType.equals(ExpressionLanguageTypes.IDENTIFIER)) { return IDENTIFIER_KEYS; - } else if (tokenType.equals(ExpressionLanguageTypes.CALL_EXPR)) { - return FUNCTION_CALL_KEYS; - } else { - return EMPTY_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.TRUE)) { + return KEYWORD_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.FALSE)) { + return KEYWORD_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.NULL)) { + return KEYWORD_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.OP_IN)) { + return KEYWORD_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.OP_NOT_IN)) { + return KEYWORD_KEYS; + } else if (tokenType.equals(ExpressionLanguageTypes.OP_MATCHES)) { + return KEYWORD_KEYS; } + + return EMPTY_KEYS; } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 9b2d6799e..1c4388a98 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -224,6 +224,7 @@ +