IDEA-75781 Allow color configuration for 'Class Declaration' vs. just 'Class'

Added ability to configure coloring settings for anonymous java classes
This commit is contained in:
Denis.Zhdanov
2011-10-27 17:51:00 +04:00
parent 57fec2ccfb
commit 1daf5e29eb
7 changed files with 26 additions and 6 deletions
@@ -68,8 +68,8 @@ public class HighlightNamesUtil {
@Nullable
public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, final EditorColorsScheme colorsScheme) {
HighlightInfoType type = getClassNameHighlightType(aClass);
if (type != null && elementToHighlight != null) {
HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight);
if (elementToHighlight != null) {
TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme);
TextRange range = elementToHighlight.getTextRange();
if (elementToHighlight instanceof PsiJavaCodeReferenceElement) {
@@ -154,7 +154,11 @@ public class HighlightNamesUtil {
return null;
}
private static HighlightInfoType getClassNameHighlightType(PsiClass aClass) {
@NotNull
private static HighlightInfoType getClassNameHighlightType(@Nullable PsiClass aClass, @Nullable PsiElement element) {
if (element instanceof PsiJavaCodeReferenceElement && element.getParent() instanceof PsiAnonymousClass) {
return HighlightInfoType.ANONYMOUS_CLASS_NAME;
}
if (aClass != null) {
if (aClass.isAnnotationType()) return HighlightInfoType.ANNOTATION_NAME;
if (aClass.isInterface()) return HighlightInfoType.INTERFACE_NAME;
@@ -59,6 +59,7 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.javadoc.markup"), SyntaxHighlighterColors.DOC_COMMENT_MARKUP),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.class"), CodeInsightColors.CLASS_NAME_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.anonymous.class"), CodeInsightColors.ANONYMOUS_CLASS_NAME_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.interface"), CodeInsightColors.INTERFACE_NAME_ATTRIBUTES),
@@ -104,6 +105,7 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor
ourTags.put("static_method", CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
ourTags.put("param", CodeInsightColors.PARAMETER_ATTRIBUTES);
ourTags.put("class", CodeInsightColors.CLASS_NAME_ATTRIBUTES);
ourTags.put("anonymousClass", CodeInsightColors.ANONYMOUS_CLASS_NAME_ATTRIBUTES);
ourTags.put("typeParameter", CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES);
ourTags.put("abstractClass", CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES);
ourTags.put("interface", CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
@@ -164,7 +166,7 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor
" long <localVar>time</localVar> = <class>Date</class>.<static_method><deprecated>parse</deprecated></static_method>(\"1.2.3\"); // Method is deprecated\n" +
" int <reassignedLocalVar>reassignedValue</reassignedLocalVar> = this.<warning>staticField</warning>; \n" +
" <reassignedLocalVar>reassignedValue</reassignedLocalVar> ++; \n" +
" new <constructorCall>SomeClass</constructorCall>() {\n" +
" new <anonymousClass>SomeClass</anonymousClass>() {\n" +
" {\n" +
" int <localVar>a</localVar> = <implicitAnonymousParameter>localVar</implicitAnonymousParameter>;\n" +
" }\n" +
@@ -149,13 +149,16 @@ public class HighlightInfo implements Segment {
return EditorColorsManager.getInstance().getGlobalScheme();
}
public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull PsiElement element, String description) {
public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type,
@NotNull PsiElement element,
@Nullable String description)
{
return createHighlightInfo(type, element, description, htmlEscapeToolTip(description));
}
@Nullable
@NonNls
public static String htmlEscapeToolTip(String description) {
public static String htmlEscapeToolTip(@Nullable String description) {
return description == null ? null : "<html><body>"+ XmlStringUtil.escapeString(description)+"</body></html>";
}
@@ -292,6 +295,7 @@ public class HighlightInfo implements Segment {
if (type == HighlightInfoType.INTERFACE_NAME) return false;
if (type == HighlightInfoType.ABSTRACT_CLASS_NAME) return false;
if (type == HighlightInfoType.CLASS_NAME) return false;
if (type == HighlightInfoType.ANONYMOUS_CLASS_NAME) return false;
return true;
}
@@ -76,6 +76,7 @@ public interface HighlightInfoType {
HighlightInfoType CONSTRUCTOR_DECLARATION = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES);
HighlightInfoType STATIC_METHOD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
HighlightInfoType CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CLASS_NAME_ATTRIBUTES);
HighlightInfoType ANONYMOUS_CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANONYMOUS_CLASS_NAME_ATTRIBUTES);
HighlightInfoType INTERFACE_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
HighlightInfoType TYPE_PARAMETER_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES);
HighlightInfoType ABSTRACT_CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES);
@@ -39,6 +39,7 @@ public interface CodeInsightColors {
TextAttributesKey STATIC_FIELD_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("STATIC_FIELD_ATTRIBUTES");
TextAttributesKey PARAMETER_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("PARAMETER_ATTRIBUTES");
TextAttributesKey CLASS_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("CLASS_NAME_ATTRIBUTES");
TextAttributesKey ANONYMOUS_CLASS_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("ANONYMOUS_CLASS_NAME_ATTRIBUTES");
TextAttributesKey TYPE_PARAMETER_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("TYPE_PARAMETER_NAME_ATTRIBUTES");
TextAttributesKey INTERFACE_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("INTERFACE_NAME_ATTRIBUTES");
TextAttributesKey ABSTRACT_CLASS_NAME_ATTRIBUTES = TextAttributesKey.createTextAttributesKey("ABSTRACT_CLASS_NAME_ATTRIBUTES");
@@ -66,6 +66,7 @@ options.java.attribute.descriptor.warning=Warning
options.java.attribute.descriptor.deprecated.symbol=Deprecated symbol
options.java.attribute.descriptor.unused.symbol=Unused symbol
options.java.attribute.descriptor.class=Class
options.java.attribute.descriptor.anonymous.class=Anonymous class
options.java.attribute.descriptor.type.parameter=Type parameter
options.java.attribute.descriptor.abstract.class=Abstract class
options.java.attribute.descriptor.interface=Interface
@@ -418,6 +418,13 @@
<option name="EFFECT_COLOR"/>
</value>
</option>
<option name="ANONYMOUS_CLASS_NAME_ATTRIBUTES">
<value>
<option name="FOREGROUND"/>
<option name="BACKGROUND"/>
<option name="EFFECT_COLOR"/>
</value>
</option>
<option name="TYPE_PARAMETER_NAME_ATTRIBUTES">
<value>
<option name="FOREGROUND"/>