From b4a1f42b8e70cee018697c97273c23168ef7ee0d Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Sun, 23 Jun 2019 12:16:36 -0500 Subject: [PATCH] Fix for #916: add more color/style fallbacks --- .../GroovySemanticReconciler.java | 68 +++++++++++-------- .../preferences/PreferenceConstants.java | 28 ++++---- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/GroovySemanticReconciler.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/GroovySemanticReconciler.java index 7521d1be56..ddcc69a0bc 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/GroovySemanticReconciler.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/highlighting/GroovySemanticReconciler.java @@ -17,6 +17,7 @@ import static org.codehaus.groovy.eclipse.editor.highlighting.HighlightedTypedPosition.HighlightKind.DEPRECATED; import static org.codehaus.groovy.eclipse.editor.highlighting.HighlightedTypedPosition.HighlightKind.UNKNOWN; +import static org.eclipse.jdt.ui.PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -40,8 +41,10 @@ import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer; import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingPresenter; +import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings; import org.eclipse.jdt.internal.ui.text.JavaPresentationReconciler; import org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener; +import org.eclipse.jdt.ui.text.IJavaColorConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.Position; @@ -58,28 +61,28 @@ public class GroovySemanticReconciler implements IJavaReconcilingListener { private static final String GROOVY_HIGHLIGHT_PREFERENCE = PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR.replaceFirst("\\.color$", ""); private static final String STRING_HIGHLIGHT_PREFERENCE = PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_STRINGS_COLOR.replaceFirst("\\.color$", ""); - private static final String NUMBER_HIGHLIGHT_PREFERENCE = "semanticHighlighting.number"; - private static final String COMMENT_HIGHLIGHT_PREFERENCE = "java_single_line_comment"; + private static final String NUMBER_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.NUMBER; + private static final String COMMENT_HIGHLIGHT_PREFERENCE = IJavaColorConstants.JAVA_SINGLE_LINE_COMMENT; private static final String KEYWORD_HIGHLIGHT_PREFERENCE = PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_KEYWORDS_COLOR.replaceFirst("\\.color$", ""); private static final String RESERVED_HIGHLIGHT_PREFERENCE = PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_PRIMITIVES_COLOR.replaceFirst("\\.color$", ""); - private static final String DEPRECATED_HIGHLIGHT_PREFERENCE = "semanticHighlighting.deprecatedMember"; - - private static final String VARIABLE_HIGHLIGHT_PREFERENCE = "semanticHighlighting.localVariable"; - private static final String PARAMETER_HIGHLIGHT_PREFERENCE = "semanticHighlighting.parameterVariable"; - private static final String ATTRIBUTE_HIGHLIGHT_PREFERENCE = "semanticHighlighting.annotationElementReference"; - private static final String OBJECT_FIELD_HIGHLIGHT_PREFERENCE = "semanticHighlighting.field"; - private static final String STATIC_FIELD_HIGHLIGHT_PREFERENCE = "semanticHighlighting.staticField"; - private static final String STATIC_VALUE_HIGHLIGHT_PREFERENCE = "semanticHighlighting.staticFinalField"; - private static final String OBJECT_METHOD_HIGHLIGHT_PREFERENCE = "semanticHighlighting.method"; - private static final String STATIC_METHOD_HIGHLIGHT_PREFERENCE = "semanticHighlighting.staticMethodInvocation"; - private static final String METHOD_DECLARATION_HIGHLIGHT_PREFERENCE = "semanticHighlighting.methodDeclarationName"; - - private static final String CLASS_HIGHLIGHT_PREFERENCE = "semanticHighlighting.class"; - private static final String ABSTRACT_CLASS_HIGHLIGHT_PREFERENCE = "semanticHighlighting.abstractClass"; - private static final String INTERFACE_HIGHLIGHT_PREFERENCE = "semanticHighlighting.interface"; + private static final String DEPRECATED_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.DEPRECATED_MEMBER; + + private static final String VARIABLE_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.LOCAL_VARIABLE; + private static final String PARAMETER_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.PARAMETER_VARIABLE; + private static final String ATTRIBUTE_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.ANNOTATION_ELEMENT_REFERENCE; + private static final String OBJECT_FIELD_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.FIELD; + private static final String STATIC_FIELD_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.STATIC_FIELD; + private static final String STATIC_VALUE_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.STATIC_FINAL_FIELD; + private static final String OBJECT_METHOD_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.METHOD; + private static final String STATIC_METHOD_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.STATIC_METHOD_INVOCATION; + private static final String METHOD_DECLARATION_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.METHOD_DECLARATION; + + private static final String CLASS_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.CLASS; + private static final String ABSTRACT_CLASS_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.ABSTRACT_CLASS; + private static final String INTERFACE_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.INTERFACE; private static final String ANNOTATION_HIGHLIGHT_PREFERENCE = PreferenceConstants.GROOVY_EDITOR_HIGHLIGHT_ANNOTATION_COLOR.replaceFirst("\\.color$", ""); - private static final String ENUMERATION_HIGHLIGHT_PREFERENCE = "semanticHighlighting.enum"; - private static final String PLACEHOLDER_HIGHLIGHT_PREFERENCE = "semanticHighlighting.typeParameter"; + private static final String ENUMERATION_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.ENUM; + private static final String PLACEHOLDER_HIGHLIGHT_PREFERENCE = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.TYPE_VARIABLE; private static final String TRAIT_HIGHLIGHT_PREFERENCE = GROOVY_HIGHLIGHT_PREFERENCE; // these types have package-private visibility @@ -128,10 +131,10 @@ public class GroovySemanticReconciler implements IJavaReconcilingListener { private Object staticFieldHighlighting; private Object staticValueHighlighting; - private Object methodDefHighlighting; private Object methodUseHighlighting; private Object groovyMethodUseHighlighting; private Object staticMethodUseHighlighting; + private Object methodDeclarationHighlighting; private Object classHighlighting; private Object traitHighlighting; @@ -178,20 +181,20 @@ public GroovySemanticReconciler() { commentRefHighlighting = newHighlightingStyle(commentColor); keywordRefHighlighting = newHighlightingStyle(keywordColor, loadStyleFrom(prefs, KEYWORD_HIGHLIGHT_PREFERENCE)); reservedRefHighlighting = newHighlightingStyle(reservedColor, loadStyleFrom(prefs, RESERVED_HIGHLIGHT_PREFERENCE)); - deprecatedRefHighlighting = newHighlightingStyle(null, loadStyleFrom(prefs, DEPRECATED_HIGHLIGHT_PREFERENCE)); - undefinedRefHighlighting = newHighlightingStyle(null, TextAttribute.UNDERLINE); + deprecatedRefHighlighting = newHighlightingStyle(loadStyleFrom(prefs, DEPRECATED_HIGHLIGHT_PREFERENCE)); + undefinedRefHighlighting = newHighlightingStyle(TextAttribute.UNDERLINE); localHighlighting = newHighlightingStyle(variableColor, loadStyleFrom(prefs, VARIABLE_HIGHLIGHT_PREFERENCE)); - paramHighlighting = newHighlightingStyle(parameterColor, loadStyleFrom(prefs, PARAMETER_HIGHLIGHT_PREFERENCE)); + paramHighlighting = parameterColor == null ? localHighlighting : newHighlightingStyle(parameterColor, loadStyleFrom(prefs, PARAMETER_HIGHLIGHT_PREFERENCE)); objectFieldHighlighting = newHighlightingStyle(objectFieldColor, loadStyleFrom(prefs, OBJECT_FIELD_HIGHLIGHT_PREFERENCE)); - staticFieldHighlighting = newHighlightingStyle(staticFieldColor, loadStyleFrom(prefs, STATIC_FIELD_HIGHLIGHT_PREFERENCE)); - staticValueHighlighting = newHighlightingStyle(staticValueColor, loadStyleFrom(prefs, STATIC_VALUE_HIGHLIGHT_PREFERENCE)); + staticFieldHighlighting = staticFieldColor == null ? objectFieldHighlighting : newHighlightingStyle(staticFieldColor, loadStyleFrom(prefs, STATIC_FIELD_HIGHLIGHT_PREFERENCE)); + staticValueHighlighting = staticValueColor == null ? staticFieldHighlighting : newHighlightingStyle(staticValueColor, loadStyleFrom(prefs, STATIC_VALUE_HIGHLIGHT_PREFERENCE)); - methodDefHighlighting = newHighlightingStyle(methodDeclColor, loadStyleFrom(prefs, METHOD_DECLARATION_HIGHLIGHT_PREFERENCE)); methodUseHighlighting = newHighlightingStyle(methodCallColor, loadStyleFrom(prefs, OBJECT_METHOD_HIGHLIGHT_PREFERENCE)); - groovyMethodUseHighlighting = newHighlightingStyle(groovyColor, loadStyleFrom(prefs, GROOVY_HIGHLIGHT_PREFERENCE)); - staticMethodUseHighlighting = newHighlightingStyle(staticCallColor, loadStyleFrom(prefs, STATIC_METHOD_HIGHLIGHT_PREFERENCE)); + groovyMethodUseHighlighting = groovyColor == null ? methodUseHighlighting : newHighlightingStyle(groovyColor, loadStyleFrom(prefs, GROOVY_HIGHLIGHT_PREFERENCE)); + staticMethodUseHighlighting = staticCallColor == null ? methodUseHighlighting : newHighlightingStyle(staticCallColor, loadStyleFrom(prefs, STATIC_METHOD_HIGHLIGHT_PREFERENCE)); + methodDeclarationHighlighting = methodDeclColor == null ? methodUseHighlighting : newHighlightingStyle(methodDeclColor, loadStyleFrom(prefs, METHOD_DECLARATION_HIGHLIGHT_PREFERENCE)); classHighlighting = newHighlightingStyle(classColor, loadStyleFrom(prefs, CLASS_HIGHLIGHT_PREFERENCE)); traitHighlighting = newHighlightingStyle(traitColor, loadStyleFrom(prefs, TRAIT_HIGHLIGHT_PREFERENCE)); @@ -236,9 +239,14 @@ protected Object newHighlightingStyle(Color color) { return ReflectionUtils.invokeConstructor(HIGHLIGHTING_STYLE, new TextAttribute(color), Boolean.TRUE); } + protected Object newHighlightingStyle(int style) { + //return new HighlightingStyle(new TextAttribute(color), true); + return ReflectionUtils.invokeConstructor(HIGHLIGHTING_STYLE, new TextAttribute(null, null, style), Boolean.TRUE); + } + protected Object newHighlightingStyle(Color color, int style) { //return new HighlightingStyle(new TextAttribute(color, null, style), true); - return ReflectionUtils.invokeConstructor(HIGHLIGHTING_STYLE, new TextAttribute(color, null, style), Boolean.TRUE); + return ReflectionUtils.invokeConstructor(HIGHLIGHTING_STYLE, new TextAttribute(color, null, style), color == null ? Boolean.FALSE : Boolean.TRUE); } protected void setHighlightingStyle(Position pos, Object val) { @@ -411,7 +419,7 @@ private Position newHighlightedPosition(HighlightedTypedPosition pos) { case CTOR: case METHOD: case STATIC_METHOD: - style = methodDefHighlighting; + style = methodDeclarationHighlighting; break; case CTOR_CALL: case METHOD_CALL: diff --git a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/preferences/PreferenceConstants.java b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/preferences/PreferenceConstants.java index dba6fa95bd..c040508279 100644 --- a/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/preferences/PreferenceConstants.java +++ b/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/preferences/PreferenceConstants.java @@ -1,11 +1,11 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,33 +15,35 @@ */ package org.codehaus.groovy.eclipse.preferences; +import static org.eclipse.jdt.ui.PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; +import static org.eclipse.jdt.ui.PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX; + import org.codehaus.groovy.eclipse.GroovyPlugin; import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings; import org.eclipse.jdt.ui.text.IJavaColorConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.texteditor.ChainedPreferenceStore; public interface PreferenceConstants { - String GROOVY_EDITOR_HIGHLIGHT = "groovy.editor.highlight"; - - String GROOVY_SEMANTIC_HIGHLIGHTING = "groovy.semantic.highlighting"; + String GROOVY_EDITOR_HIGHLIGHT_PREFIX = "groovy.editor.highlight."; - String GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR = GROOVY_EDITOR_HIGHLIGHT + ".gjdk.color"; + String GROOVY_EDITOR_HIGHLIGHT_GJDK_COLOR = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "gjdk" + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; - String GROOVY_EDITOR_HIGHLIGHT_KEYWORDS_COLOR = GROOVY_EDITOR_HIGHLIGHT + ".javakeywords.color"; + String GROOVY_EDITOR_HIGHLIGHT_KEYWORDS_COLOR = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "javakeywords" + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; - String GROOVY_EDITOR_HIGHLIGHT_PRIMITIVES_COLOR = GROOVY_EDITOR_HIGHLIGHT + ".javatypes.color"; + String GROOVY_EDITOR_HIGHLIGHT_PRIMITIVES_COLOR = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "javatypes" + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; - String GROOVY_EDITOR_HIGHLIGHT_ASSERT_COLOR = GROOVY_EDITOR_HIGHLIGHT + ".assert.color"; + String GROOVY_EDITOR_HIGHLIGHT_ASSERT_COLOR = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "assert" + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; - String GROOVY_EDITOR_HIGHLIGHT_RETURN_COLOR = GROOVY_EDITOR_HIGHLIGHT + ".return.color"; + String GROOVY_EDITOR_HIGHLIGHT_RETURN_COLOR = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "return" + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; String GROOVY_EDITOR_HIGHLIGHT_STRINGS_COLOR = IJavaColorConstants.JAVA_STRING; - String GROOVY_EDITOR_HIGHLIGHT_SLASHY_STRINGS = GROOVY_EDITOR_HIGHLIGHT + ".slashy"; + String GROOVY_EDITOR_HIGHLIGHT_SLASHY_STRINGS = GROOVY_EDITOR_HIGHLIGHT_PREFIX + "slashy"; - String GROOVY_EDITOR_HIGHLIGHT_ANNOTATION_COLOR = "semanticHighlighting.annotation.color"; + String GROOVY_EDITOR_HIGHLIGHT_ANNOTATION_COLOR = EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + SemanticHighlightings.ANNOTATION + EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX; String GROOVY_EDITOR_HIGHLIGHT_BRACKET_COLOR = IJavaColorConstants.JAVA_BRACKET; @@ -51,6 +53,8 @@ public interface PreferenceConstants { String GROOVY_EDITOR_BOLD_SUFFIX = "_bold"; + String GROOVY_SEMANTIC_HIGHLIGHTING = "groovy.semantic.highlighting"; + static IPreferenceStore getPreferenceStore() { return new ChainedPreferenceStore(new IPreferenceStore[] {GroovyPlugin.getDefault().getPreferenceStore(), JavaPlugin.getDefault().getPreferenceStore()}); }