2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.options
.colors
.pages
;
18 import com
.intellij
.application
.options
.colors
.InspectionColorSettingsPage
;
19 import com
.intellij
.codeInsight
.daemon
.impl
.HighlightInfoType
;
20 import com
.intellij
.codeInsight
.daemon
.impl
.SeveritiesProvider
;
21 import com
.intellij
.ide
.highlighter
.JavaFileHighlighter
;
22 import com
.intellij
.openapi
.editor
.HighlighterColors
;
23 import com
.intellij
.openapi
.editor
.SyntaxHighlighterColors
;
24 import com
.intellij
.openapi
.editor
.colors
.CodeInsightColors
;
25 import com
.intellij
.openapi
.editor
.colors
.TextAttributesKey
;
26 import com
.intellij
.openapi
.extensions
.Extensions
;
27 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
28 import com
.intellij
.openapi
.fileTypes
.SyntaxHighlighter
;
29 import com
.intellij
.openapi
.options
.OptionsBundle
;
30 import com
.intellij
.openapi
.options
.colors
.AttributesDescriptor
;
31 import com
.intellij
.openapi
.options
.colors
.ColorDescriptor
;
32 import com
.intellij
.openapi
.options
.colors
.ColorSettingsPage
;
33 import com
.intellij
.pom
.java
.LanguageLevel
;
34 import org
.jetbrains
.annotations
.NonNls
;
35 import org
.jetbrains
.annotations
.NotNull
;
40 public class JavaColorSettingsPage
implements ColorSettingsPage
, InspectionColorSettingsPage
{
41 private static final AttributesDescriptor
[] ourDescriptors
= new AttributesDescriptor
[] {
42 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.keyword"), SyntaxHighlighterColors
.KEYWORD
),
43 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.number"), SyntaxHighlighterColors
.NUMBER
),
45 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.string"), SyntaxHighlighterColors
.STRING
),
46 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.valid.escape.in.string"), SyntaxHighlighterColors
.VALID_STRING_ESCAPE
),
47 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.invalid.escape.in.string"), SyntaxHighlighterColors
.INVALID_STRING_ESCAPE
),
49 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.operator.sign"), SyntaxHighlighterColors
.OPERATION_SIGN
),
50 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.parentheses"), SyntaxHighlighterColors
.PARENTHS
),
51 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.braces"), SyntaxHighlighterColors
.BRACES
),
52 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.brackets"), SyntaxHighlighterColors
.BRACKETS
),
53 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.comma"), SyntaxHighlighterColors
.COMMA
),
54 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.semicolon"), SyntaxHighlighterColors
.JAVA_SEMICOLON
),
55 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.dot"), SyntaxHighlighterColors
.DOT
),
57 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.line.comment"), SyntaxHighlighterColors
.LINE_COMMENT
),
58 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.block.comment"), SyntaxHighlighterColors
.JAVA_BLOCK_COMMENT
),
59 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.javadoc.comment"), SyntaxHighlighterColors
.DOC_COMMENT
),
60 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.javadoc.tag"), SyntaxHighlighterColors
.DOC_COMMENT_TAG
),
61 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.javadoc.markup"), SyntaxHighlighterColors
.DOC_COMMENT_MARKUP
),
63 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.class"), CodeInsightColors
.CLASS_NAME_ATTRIBUTES
),
64 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.type.parameter"), CodeInsightColors
.TYPE_PARAMETER_NAME_ATTRIBUTES
),
65 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.abstract.class"), CodeInsightColors
.ABSTRACT_CLASS_NAME_ATTRIBUTES
),
66 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.interface"), CodeInsightColors
.INTERFACE_NAME_ATTRIBUTES
),
67 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.local.variable"), CodeInsightColors
.LOCAL_VARIABLE_ATTRIBUTES
),
68 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.reassigned.local.variable"), CodeInsightColors
.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES
),
69 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.reassigned.parameter"), CodeInsightColors
.REASSIGNED_PARAMETER_ATTRIBUTES
),
70 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.implicit.anonymous.parameter"), CodeInsightColors
.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES
),
71 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.instance.field"), CodeInsightColors
.INSTANCE_FIELD_ATTRIBUTES
),
72 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.static.field"), CodeInsightColors
.STATIC_FIELD_ATTRIBUTES
),
73 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.parameter"), CodeInsightColors
.PARAMETER_ATTRIBUTES
),
74 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.method.call"), CodeInsightColors
.METHOD_CALL_ATTRIBUTES
),
75 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.method.declaration"), CodeInsightColors
.METHOD_DECLARATION_ATTRIBUTES
),
76 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.constructor.call"), CodeInsightColors
.CONSTRUCTOR_CALL_ATTRIBUTES
),
77 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.constructor.declaration"), CodeInsightColors
.CONSTRUCTOR_DECLARATION_ATTRIBUTES
),
78 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.static.method"), CodeInsightColors
.STATIC_METHOD_ATTRIBUTES
),
80 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.matched.brace"), CodeInsightColors
.MATCHED_BRACE_ATTRIBUTES
),
81 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.unmatched.brace"), CodeInsightColors
.UNMATCHED_BRACE_ATTRIBUTES
),
82 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.bad.character"), HighlighterColors
.BAD_CHARACTER
),
84 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.annotation.name"), CodeInsightColors
.ANNOTATION_NAME_ATTRIBUTES
),
85 new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.annotation.attribute.name"), CodeInsightColors
.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES
)
88 private static final ColorDescriptor
[] ourColorDescriptors
= new ColorDescriptor
[]{
89 new ColorDescriptor(OptionsBundle
.message("options.java.color.descriptor.method.separator.color"), CodeInsightColors
.METHOD_SEPARATORS_COLOR
, ColorDescriptor
.Kind
.FOREGROUND
)
93 @NonNls private static final Map
<String
, TextAttributesKey
> ourTags
= new HashMap
<String
, TextAttributesKey
>();
95 ourTags
.put("field", CodeInsightColors
.INSTANCE_FIELD_ATTRIBUTES
);
96 ourTags
.put("unusedField", CodeInsightColors
.NOT_USED_ELEMENT_ATTRIBUTES
);
97 ourTags
.put("error", CodeInsightColors
.ERRORS_ATTRIBUTES
);
98 ourTags
.put("warning", CodeInsightColors
.WARNINGS_ATTRIBUTES
);
99 ourTags
.put("info", CodeInsightColors
.INFO_ATTRIBUTES
);
100 ourTags
.put("server_problems", CodeInsightColors
.GENERIC_SERVER_ERROR_OR_WARNING
);
101 ourTags
.put("server_duplicate", CodeInsightColors
.DUPLICATE_FROM_SERVER
);
102 ourTags
.put("unknownType", CodeInsightColors
.WRONG_REFERENCES_ATTRIBUTES
);
103 ourTags
.put("localVar", CodeInsightColors
.LOCAL_VARIABLE_ATTRIBUTES
);
104 ourTags
.put("reassignedLocalVar", CodeInsightColors
.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES
);
105 ourTags
.put("reassignedParameter", CodeInsightColors
.REASSIGNED_PARAMETER_ATTRIBUTES
);
106 ourTags
.put("implicitAnonymousParameter", CodeInsightColors
.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES
);
107 ourTags
.put("static", CodeInsightColors
.STATIC_FIELD_ATTRIBUTES
);
108 ourTags
.put("deprecated", CodeInsightColors
.DEPRECATED_ATTRIBUTES
);
109 ourTags
.put("constructorCall", CodeInsightColors
.CONSTRUCTOR_CALL_ATTRIBUTES
);
110 ourTags
.put("constructorDeclaration", CodeInsightColors
.CONSTRUCTOR_DECLARATION_ATTRIBUTES
);
111 ourTags
.put("methodCall", CodeInsightColors
.METHOD_CALL_ATTRIBUTES
);
112 ourTags
.put("methodDeclaration", CodeInsightColors
.METHOD_DECLARATION_ATTRIBUTES
);
113 ourTags
.put("static_method", CodeInsightColors
.STATIC_METHOD_ATTRIBUTES
);
114 ourTags
.put("param", CodeInsightColors
.PARAMETER_ATTRIBUTES
);
115 ourTags
.put("class", CodeInsightColors
.CLASS_NAME_ATTRIBUTES
);
116 ourTags
.put("typeParameter", CodeInsightColors
.TYPE_PARAMETER_NAME_ATTRIBUTES
);
117 ourTags
.put("abstractClass", CodeInsightColors
.ABSTRACT_CLASS_NAME_ATTRIBUTES
);
118 ourTags
.put("interface", CodeInsightColors
.INTERFACE_NAME_ATTRIBUTES
);
119 ourTags
.put("annotationName", CodeInsightColors
.ANNOTATION_NAME_ATTRIBUTES
);
120 ourTags
.put("annotationAttributeName", CodeInsightColors
.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES
);
124 public String
getDisplayName() {
125 return OptionsBundle
.message("options.java.display.name");
128 public Icon
getIcon() {
129 return StdFileTypes
.JAVA
.getIcon();
133 public AttributesDescriptor
[] getAttributeDescriptors() {
134 List
<AttributesDescriptor
> descriptors
= new ArrayList
<AttributesDescriptor
>();
135 descriptors
.addAll(Arrays
.asList(ourDescriptors
));
136 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors
.WRONG_REFERENCES_ATTRIBUTES
));
137 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors
.DEPRECATED_ATTRIBUTES
));
138 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors
.NOT_USED_ELEMENT_ATTRIBUTES
));
139 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.error"), CodeInsightColors
.ERRORS_ATTRIBUTES
));
140 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.warning"), CodeInsightColors
.WARNINGS_ATTRIBUTES
));
141 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.info"), CodeInsightColors
.INFO_ATTRIBUTES
));
142 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors
.GENERIC_SERVER_ERROR_OR_WARNING
));
143 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors
.DUPLICATE_FROM_SERVER
));
144 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.color.descriptor.full.coverage"), CodeInsightColors
.LINE_FULL_COVERAGE
));
145 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.color.descriptor.partial.coverage"), CodeInsightColors
.LINE_PARTIAL_COVERAGE
));
146 descriptors
.add(new AttributesDescriptor(OptionsBundle
.message("options.java.color.descriptor.none.coverage"), CodeInsightColors
.LINE_NONE_COVERAGE
));
147 for (SeveritiesProvider provider
: Extensions
.getExtensions(SeveritiesProvider
.EP_NAME
)) {
148 for (HighlightInfoType highlightInfoType
: provider
.getSeveritiesHighlightInfoTypes()) {
149 final TextAttributesKey attributesKey
= highlightInfoType
.getAttributesKey();
150 descriptors
.add(new AttributesDescriptor(attributesKey
.myExternalName
, attributesKey
));
153 return descriptors
.toArray(new AttributesDescriptor
[descriptors
.size()]);
157 public ColorDescriptor
[] getColorDescriptors() {
158 return ourColorDescriptors
;
162 public SyntaxHighlighter
getHighlighter() {
163 return new JavaFileHighlighter(LanguageLevel
.HIGHEST
);
167 public String
getDemoText() {
169 "/* Block comment */\n" +
170 "import <class>java.util.Date</class>;\n" +
171 " Bad characters: \\n #\n" +
173 " * Doc comment here for <code>SomeClass</code>\n" +
174 " * @see <class>Math</class>#<methodCall>sin</methodCall>(double)\n" +
176 "<annotationName>@Annotation</annotationName> (<annotationAttributeName>name</annotationAttributeName>=value)\n" +
177 "public class <class>SomeClass</class><<typeParameter>T</typeParameter> extends <interface>Runnable</interface>> { // some comment\n" +
178 " private <typeParameter>T</typeParameter> <field>field</field> = null;\n" +
179 " private double <unusedField>unusedField</unusedField> = 12345.67890;\n" +
180 " private <unknownType>UnknownType</unknownType> <field>anotherString</field> = \"Another\\nStrin\\g\";\n" +
181 " public static int <static>staticField</static> = 0;\n" +
183 " public <constructorDeclaration>SomeClass</constructorDeclaration>(<interface>AnInterface</interface> <param>param</param>, int[] <reassignedParameter>reassignedParam</reassignedParameter>) {\n" +
184 " <error>int <localVar>localVar</localVar> = \"IntelliJ\"</error>; // Error, incompatible types\n" +
185 " <class>System</class>.<static>out</static>.<methodCall>println</methodCall>(<field>anotherString</field> + <field>field</field> + <localVar>localVar</localVar>);\n" +
186 " long <localVar>time</localVar> = <class>Date</class>.<static_method><deprecated>parse</deprecated></static_method>(\"1.2.3\"); // Method is deprecated\n" +
187 " int <reassignedLocalVar>reassignedValue</reassignedLocalVar> = this.<warning>staticField</warning>; \n" +
188 " <reassignedLocalVar>reassignedValue</reassignedLocalVar> ++; \n" +
189 " new <constructorCall>SomeClass</constructorCall>() {\n" +
191 " int <localVar>a</localVar> = <implicitAnonymousParameter>localVar</implicitAnonymousParameter>;\n" +
194 " <reassignedParameter>reassignedParam</reassignedParameter> = new int[2];\n" +
197 "interface <interface>AnInterface</interface> {\n" +
198 " int <static>CONSTANT</static> = 2;\n" +
199 " void <methodDeclaration>method</methodDeclaration>();\n" +
201 "abstract class <abstractClass>SomeAbstractClass</abstractClass> {\n" +
205 public Map
<String
,TextAttributesKey
> getAdditionalHighlightingTagToDescriptorMap() {