From e9d280fb7e6f8a859aab0a38951a2366da3db97d Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 22 Mar 2012 22:02:33 +0400 Subject: [PATCH 01/38] Moved all highlighter/annotator classes to highlighter package. --- idea/src/META-INF/plugin.xml | 12 ++++++------ .../plugin/actions/ToggleErrorReportingAction.java | 2 +- .../DebugInfoAnnotator.java | 3 +-- .../jet/plugin/{ => highlighter}/JetHighlighter.java | 2 +- .../JetLineMarkerProvider.java | 2 +- .../{annotations => highlighter}/JetPsiChecker.java | 4 ++-- .../JetSyntaxHighlighterFactory.java | 2 +- .../LabelsAnnotator.java | 4 ++-- .../SoftKeywordsAnnotator.java | 3 +-- .../libraries/JetContentBasedFileSubstitutor.java | 2 +- 10 files changed, 17 insertions(+), 19 deletions(-) rename idea/src/org/jetbrains/jet/plugin/{annotations => highlighter}/DebugInfoAnnotator.java (98%) rename idea/src/org/jetbrains/jet/plugin/{ => highlighter}/JetHighlighter.java (99%) rename idea/src/org/jetbrains/jet/plugin/{annotations => highlighter}/JetLineMarkerProvider.java (99%) rename idea/src/org/jetbrains/jet/plugin/{annotations => highlighter}/JetPsiChecker.java (99%) rename idea/src/org/jetbrains/jet/plugin/{ => highlighter}/JetSyntaxHighlighterFactory.java (95%) rename idea/src/org/jetbrains/jet/plugin/{annotations => highlighter}/LabelsAnnotator.java (95%) rename idea/src/org/jetbrains/jet/plugin/{annotations => highlighter}/SoftKeywordsAnnotator.java (97%) diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 3bbd6dd0a8b..7cf9a1a8c01 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -64,7 +64,7 @@ - + @@ -122,10 +122,10 @@ - - - - + + + + @@ -136,7 +136,7 @@ - + diff --git a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java index 41c33912ea1..f7e51c28274 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java @@ -18,7 +18,7 @@ package org.jetbrains.jet.plugin.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import org.jetbrains.jet.plugin.annotations.JetPsiChecker; +import org.jetbrains.jet.plugin.highlighter.JetPsiChecker; /** * @author yole diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java similarity index 98% rename from idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java index fe144866701..09004d5fce4 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.plugin.annotations; +package org.jetbrains.jet.plugin.highlighter; import com.google.common.collect.Sets; import com.intellij.lang.annotation.AnnotationHolder; @@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.plugin.JetHighlighter; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import java.util.Collection; diff --git a/idea/src/org/jetbrains/jet/plugin/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java similarity index 99% rename from idea/src/org/jetbrains/jet/plugin/JetHighlighter.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index 15c6f57e089..d7a0e406080 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -17,7 +17,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin; +package org.jetbrains.jet.plugin.highlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.HighlighterColors; diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetLineMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java similarity index 99% rename from idea/src/org/jetbrains/jet/plugin/annotations/JetLineMarkerProvider.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java index 06de7bdf5e8..94f560c34ef 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetLineMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.plugin.annotations; +package org.jetbrains.jet.plugin.highlighter; import com.google.common.collect.Lists; import com.intellij.codeHighlighting.Pass; diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java similarity index 99% rename from idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index b8b0b9ad7ca..e6eee9fdc88 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.plugin.annotations; +package org.jetbrains.jet.plugin.highlighter; import com.google.common.collect.Sets; import com.intellij.codeInsight.intention.IntentionAction; @@ -39,7 +39,7 @@ import org.jetbrains.jet.lang.diagnostics.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.plugin.JetHighlighter; +import org.jetbrains.jet.plugin.highlighter.JetHighlighter; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory; import org.jetbrains.jet.plugin.quickfix.QuickFixes; diff --git a/idea/src/org/jetbrains/jet/plugin/JetSyntaxHighlighterFactory.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetSyntaxHighlighterFactory.java similarity index 95% rename from idea/src/org/jetbrains/jet/plugin/JetSyntaxHighlighterFactory.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/JetSyntaxHighlighterFactory.java index f09da3ffceb..39fce092f05 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetSyntaxHighlighterFactory.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetSyntaxHighlighterFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.jetbrains.jet.plugin; +package org.jetbrains.jet.plugin.highlighter; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/LabelsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java similarity index 95% rename from idea/src/org/jetbrains/jet/plugin/annotations/LabelsAnnotator.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java index 32e4f0baf2c..95e98b6643a 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/LabelsAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java @@ -17,7 +17,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.annotations; +package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; @@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.psi.JetPrefixExpression; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.psi.JetVisitorVoid; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.plugin.JetHighlighter; +import org.jetbrains.jet.plugin.highlighter.JetHighlighter; public class LabelsAnnotator implements Annotator { public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/SoftKeywordsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java similarity index 97% rename from idea/src/org/jetbrains/jet/plugin/annotations/SoftKeywordsAnnotator.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java index 8bfcadbd58e..f07a0a1d693 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/SoftKeywordsAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java @@ -17,7 +17,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.annotations; +package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.AnnotationHolder; @@ -28,7 +28,6 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.plugin.JetHighlighter; public class SoftKeywordsAnnotator implements Annotator { public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetContentBasedFileSubstitutor.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetContentBasedFileSubstitutor.java index dd6224fea61..78666ae3631 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetContentBasedFileSubstitutor.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetContentBasedFileSubstitutor.java @@ -25,7 +25,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.impl.compiled.ClsFileImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.plugin.JetHighlighter; +import org.jetbrains.jet.plugin.highlighter.JetHighlighter; /** * @author Evgeny Gerashchenko From da2f41843bf00b721533fc5d8f32c7edba879118 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 22 Mar 2012 22:21:44 +0400 Subject: [PATCH 02/38] Added simple color settings page for Kotlin. --- idea/src/META-INF/plugin.xml | 2 + .../highlighter/JetColorSettingsPage.java | 113 ++++++++++++++++++ .../plugin/highlighter/JetHighlighter.java | 2 +- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 7cf9a1a8c01..f7c6e2835f6 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -77,6 +77,8 @@ + + diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java new file mode 100644 index 00000000000..22ccb3bf900 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -0,0 +1,113 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +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 org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.JetIconProvider; + +import javax.swing.*; +import java.util.Collections; +import java.util.Map; + +public class JetColorSettingsPage implements ColorSettingsPage { + @Override + public Icon getIcon() { + return JetIconProvider.KOTLIN_ICON; + } + + @NotNull + @Override + public SyntaxHighlighter getHighlighter() { + return new JetHighlighter(); + } + + @NotNull + @Override + public String getDemoText() { + return "/* Block comment */\n" + + "import kotlin.util.*\n" + + " Bad characters: \\n #\n" + + "val globalConst = 0\n" + + "/**\n" + + " * Doc comment here for `SomeClass`\n" + + " * @see Iterator#next()\n" + + " */\n" + + "[Annotation]\n" + + "public class SomeClass(param : ATrait, reassignedParam : Array, val paramProperty: String?) { // some comment\n" + + " private field : T {\n" + + " return null\n" + + " }\n" + + " private open unusedField : Double = 12345.67890\n" + + " private anotherString : UnknownType = \"$field Another\\nStrin\\g\";\n" + + "\n" + + " {\n" + + " paramProperty.?length ?: 33\n" + + " val localVal : Int = \"IntelliJ\" // Error, incompatible types\n" + + " println(anotherString + field + localVar + globalConst)\n" + + " val time = Date.parse(\"1.2.3\") // Method is deprecated\n" + + " var reassignedValue = \"\" as Int\n" + + " reassignedValue++\n" + + " object : Runnable {\n" + + " override fun() {\n" + + " val a = localVar\n" + + " }\n" + + " }\n" + + " reassignedParam = Array(2)\n" + + " reassignedParam[0] = 1\n" + + " reassignedParam.foreach @lit {\n" + + " if (it == 0) return@lit\n" + + " println(it + localVar)\n" + + " }\n" + + " }\n" + + "}\n" + + "trait ATrait {\n" + + " fun memberFun(param : (Int) -> Int)\n" + + "}\n" + + "abstract class SomeAbstractClass {\n" + + "}"; + } + + @Override + public Map getAdditionalHighlightingTagToDescriptorMap() { + return Collections.emptyMap(); + } + + @NotNull + @Override + public AttributesDescriptor[] getAttributeDescriptors() { + return new AttributesDescriptor[]{ + new AttributesDescriptor("Keyword", JetHighlighter.JET_KEYWORD) + }; + } + + @NotNull + @Override + public ColorDescriptor[] getColorDescriptors() { + return ColorDescriptor.EMPTY_ARRAY; + } + + @NotNull + @Override + public String getDisplayName() { + return "Kotlin"; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index d7a0e406080..777618e064b 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -41,7 +41,7 @@ public class JetHighlighter extends SyntaxHighlighterBase { private static final Map keys1; private static final Map keys2; - private static final TextAttributesKey JET_KEYWORD = TextAttributesKey.createTextAttributesKey( + static final TextAttributesKey JET_KEYWORD = TextAttributesKey.createTextAttributesKey( "JET.KEYWORD", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); From fc236f93e5deeb46719f3a6109fd35f5bedc627e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 22 Mar 2012 22:31:59 +0400 Subject: [PATCH 03/38] Created JetHighlightingColors constant container and moved keyword text attributes key there. --- .../highlighter/JetColorSettingsPage.java | 2 +- .../plugin/highlighter/JetHighlighter.java | 9 ++---- .../highlighter/JetHighlightingColors.java | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 22ccb3bf900..2210f5ed6de 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -95,7 +95,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { @Override public AttributesDescriptor[] getAttributeDescriptors() { return new AttributesDescriptor[]{ - new AttributesDescriptor("Keyword", JetHighlighter.JET_KEYWORD) + new AttributesDescriptor(JetHighlightingColors.JET_KEYWORD.getExternalName(), JetHighlightingColors.JET_KEYWORD) }; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index 777618e064b..05841c2dd4d 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -41,11 +41,6 @@ public class JetHighlighter extends SyntaxHighlighterBase { private static final Map keys1; private static final Map keys2; - static final TextAttributesKey JET_KEYWORD = TextAttributesKey.createTextAttributesKey( - "JET.KEYWORD", - SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() - ); - public static final TextAttributesKey JET_SOFT_KEYWORD; static { TextAttributes attributes = SyntaxHighlighterColors.KEYWORD.getDefaultAttributes().clone(); @@ -173,9 +168,9 @@ public class JetHighlighter extends SyntaxHighlighterBase { keys2 = new HashMap(); - fillMap(keys1, JetTokens.KEYWORDS, JET_KEYWORD); + fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.JET_KEYWORD); - keys1.put(JetTokens.AS_SAFE, JET_KEYWORD); + keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.JET_KEYWORD); keys1.put(JetTokens.LABEL_IDENTIFIER, JET_LABEL_IDENTIFIER); keys1.put(JetTokens.ATAT, JET_LABEL_IDENTIFIER); keys1.put(JetTokens.FIELD_IDENTIFIER, JET_FIELD_IDENTIFIER); diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java new file mode 100644 index 00000000000..fedefc6639d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.openapi.editor.SyntaxHighlighterColors; +import com.intellij.openapi.editor.colors.TextAttributesKey; + +public class JetHighlightingColors { + public final static TextAttributesKey JET_KEYWORD = TextAttributesKey.createTextAttributesKey( + "Keyword", + SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() + ); + + private JetHighlightingColors() { + } +} From ea7962a81a2b765e5212f05b72f167c8552ca222 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 23 Mar 2012 00:19:34 +0400 Subject: [PATCH 04/38] Moved all text attribute keys from JetHighlighter to JetHighlightingColors, changing their colors. --- .../highlighter/DebugInfoAnnotator.java | 6 +- .../highlighter/JetColorSettingsPage.java | 27 ++- .../plugin/highlighter/JetHighlighter.java | 156 +++--------------- .../highlighter/JetHighlightingColors.java | 102 +++++++++++- .../jet/plugin/highlighter/JetPsiChecker.java | 11 +- .../plugin/highlighter/LabelsAnnotator.java | 5 +- .../highlighter/SoftKeywordsAnnotator.java | 10 +- 7 files changed, 161 insertions(+), 156 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java index 09004d5fce4..55760aed896 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java @@ -119,13 +119,13 @@ public class DebugInfoAnnotator implements Annotator { boolean unresolved = unresolvedReferences.contains(expression); JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression); if (declarationDescriptor != null && !ApplicationManager.getApplication().isUnitTestMode() && (ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) { - holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(JetHighlighter.JET_RESOLVED_TO_ERROR); + holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(JetHighlightingColors.RESOLVED_TO_ERROR); } if (resolved && unresolved) { - holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target).setTextAttributes(JetHighlighter.JET_DEBUG_INFO); + holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target).setTextAttributes(JetHighlightingColors.DEBUG_INFO); } else if (!resolved && !unresolved) { - holder.createErrorAnnotation(expression, "[DEBUG] Reference is not resolved to anything, but is not marked unresolved").setTextAttributes(JetHighlighter.JET_DEBUG_INFO); + holder.createErrorAnnotation(expression, "[DEBUG] Reference is not resolved to anything, but is not marked unresolved").setTextAttributes(JetHighlightingColors.DEBUG_INFO); } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 2210f5ed6de..f5f8968eaad 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.options.OptionsBundle; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; @@ -94,8 +95,32 @@ public class JetColorSettingsPage implements ColorSettingsPage { @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { + // TODO i18n return new AttributesDescriptor[]{ - new AttributesDescriptor(JetHighlightingColors.JET_KEYWORD.getExternalName(), JetHighlightingColors.JET_KEYWORD) + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), + new AttributesDescriptor("Soft keyword", JetHighlightingColors.SOFT_KEYWORD), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.number"), JetHighlightingColors.NUMBER), + + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.valid.escape.in.string"), JetHighlightingColors.VALID_STRING_ESCAPE), + + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), + new AttributesDescriptor("KDoc comment", JetHighlightingColors.DOC_COMMENT), + + new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), + + new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), + new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), + + new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), + new AttributesDescriptor("Function literal bracket", JetHighlightingColors.FUNCTION_LITERAL_BRACKET), + + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), + + new AttributesDescriptor("Automatically casted value", JetHighlightingColors.AUTO_CASTED_VALUE), + + new AttributesDescriptor("Label", JetHighlightingColors.LABEL), }; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index 05841c2dd4d..7164b512b90 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -20,20 +20,14 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.lexer.Lexer; -import com.intellij.openapi.editor.HighlighterColors; -import com.intellij.openapi.editor.SyntaxHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.editor.markup.EffectType; -import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; -import com.intellij.ui.Colors; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lexer.JetLexer; import org.jetbrains.jet.lexer.JetTokens; -import java.awt.*; import java.util.HashMap; import java.util.Map; @@ -41,118 +35,6 @@ public class JetHighlighter extends SyntaxHighlighterBase { private static final Map keys1; private static final Map keys2; - public static final TextAttributesKey JET_SOFT_KEYWORD; - static { - TextAttributes attributes = SyntaxHighlighterColors.KEYWORD.getDefaultAttributes().clone(); - attributes.setForegroundColor(Colors.DARK_RED); - JET_SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( - "JET.SOFT.KEYWORD", - attributes - ); - } - - public static final TextAttributesKey JET_FIELD_IDENTIFIER = TextAttributesKey.createTextAttributesKey( - "JET.FIELD.IDENTIFIER", -// TODO: proper attributes - SyntaxHighlighterColors.NUMBER.getDefaultAttributes() - ); - - public static final TextAttributesKey JET_PROPERTY_WITH_BACKING_FIELD_IDENTIFIER = TextAttributesKey.createTextAttributesKey( - "JET.PROPERTY.WITH.BACKING.FIELD.IDENTIFIER", -// TODO: proper attributes - SyntaxHighlighterColors.NUMBER.getDefaultAttributes() - ); - - public static final TextAttributesKey JET_LABEL_IDENTIFIER = TextAttributesKey.createTextAttributesKey( - "JET.LABEL.IDENTIFIER", -// TODO: proper attributes - SyntaxHighlighterColors.NUMBER.getDefaultAttributes() - ); - - private static final TextAttributesKey JET_NUMBER = TextAttributesKey.createTextAttributesKey( - "JET.NUMBER", - SyntaxHighlighterColors.NUMBER.getDefaultAttributes() - ); - - public static final TextAttributesKey JET_STRING = TextAttributesKey.createTextAttributesKey( - "JET.STRING", - SyntaxHighlighterColors.STRING.getDefaultAttributes() - ); - - public static final TextAttributesKey JET_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey( - "JET.STRING.ESCAPE", - SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes() - ); - - private static final TextAttributesKey JET_COMMENT; - static { - TextAttributes attributes = SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes().clone(); - attributes.setFontType(Font.PLAIN); - JET_COMMENT = TextAttributesKey.createTextAttributesKey( - "JET.COMMENT", - attributes - ); - } - - private static final TextAttributesKey JET_BAD_CHARACTER = TextAttributesKey.createTextAttributesKey( - "JET.BADCHARACTER", - HighlighterColors.BAD_CHARACTER.getDefaultAttributes() - ); - - public static final TextAttributesKey JET_AUTO_CAST_EXPRESSION; - - static { - TextAttributes clone = SyntaxHighlighterColors.STRING.getDefaultAttributes().clone(); - clone.setFontType(Font.PLAIN); -// TODO: proper attributes - JET_AUTO_CAST_EXPRESSION = TextAttributesKey.createTextAttributesKey("JET.AUTO.CAST.EXPRESSION", clone); - } - - public static final TextAttributesKey JET_WRAPPED_INTO_REF; - - static { - TextAttributes attributes = new TextAttributes(); - attributes.setEffectType(EffectType.LINE_UNDERSCORE); - attributes.setEffectColor(Color.BLACK); - JET_WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey("JET.WRAPPED.INTO.REF", attributes); - } - - public static final TextAttributesKey JET_AUTOCREATED_IT; - - static { - TextAttributes attributes = new TextAttributes(); - attributes.setFontType(Font.BOLD); -// TODO: proper attributes - JET_AUTOCREATED_IT = TextAttributesKey.createTextAttributesKey("JET.AUTO.CREATED.IT", attributes); - } - - public static final TextAttributesKey JET_FUNCTION_LITERAL_DELIMITER; - - static { - TextAttributes attributes = new TextAttributes(); - attributes.setFontType(Font.BOLD); -// TODO: proper attributes - JET_FUNCTION_LITERAL_DELIMITER = TextAttributesKey.createTextAttributesKey("JET.AUTO.CREATED.IT", attributes); - } - - public static final TextAttributesKey JET_DEBUG_INFO; - - static { - TextAttributes textAttributes = new TextAttributes(); - textAttributes.setEffectType(EffectType.ROUNDED_BOX); - textAttributes.setEffectColor(Color.BLACK); - JET_DEBUG_INFO = TextAttributesKey.createTextAttributesKey("JET.DEBUG.INFO", textAttributes); - } - - public static final TextAttributesKey JET_RESOLVED_TO_ERROR; - - static { - TextAttributes textAttributes = new TextAttributes(); - textAttributes.setEffectType(EffectType.ROUNDED_BOX); - textAttributes.setEffectColor(Color.RED); - JET_RESOLVED_TO_ERROR = TextAttributesKey.createTextAttributesKey("JET.RESOLVED.TO.ERROR", textAttributes); - } - @NotNull public Lexer getHighlightingLexer() { return new JetLexer(); @@ -168,30 +50,30 @@ public class JetHighlighter extends SyntaxHighlighterBase { keys2 = new HashMap(); - fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.JET_KEYWORD); + fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.KEYWORD); - keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.JET_KEYWORD); - keys1.put(JetTokens.LABEL_IDENTIFIER, JET_LABEL_IDENTIFIER); - keys1.put(JetTokens.ATAT, JET_LABEL_IDENTIFIER); - keys1.put(JetTokens.FIELD_IDENTIFIER, JET_FIELD_IDENTIFIER); - keys1.put(JetTokens.INTEGER_LITERAL, JET_NUMBER); - keys1.put(JetTokens.FLOAT_LITERAL, JET_NUMBER); + keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD); + keys1.put(JetTokens.LABEL_IDENTIFIER, JetHighlightingColors.LABEL); + keys1.put(JetTokens.ATAT, JetHighlightingColors.LABEL); + keys1.put(JetTokens.FIELD_IDENTIFIER, JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS); + keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER); + keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER); - keys1.put(JetTokens.OPEN_QUOTE, JET_STRING); - keys1.put(JetTokens.CLOSING_QUOTE, JET_STRING); - keys1.put(JetTokens.REGULAR_STRING_PART, JET_STRING); - keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_END, JET_STRING_ESCAPE); - keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_START, JET_STRING_ESCAPE); - keys1.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, JET_STRING_ESCAPE); + keys1.put(JetTokens.OPEN_QUOTE, JetHighlightingColors.STRING); + keys1.put(JetTokens.CLOSING_QUOTE, JetHighlightingColors.STRING); + keys1.put(JetTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING); + keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_END, JetHighlightingColors.VALID_STRING_ESCAPE); + keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); + keys1.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.ESCAPE_SEQUENCE, JET_STRING_ESCAPE); + keys1.put(JetTokens.ESCAPE_SEQUENCE, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.CHARACTER_LITERAL, JET_STRING); + keys1.put(JetTokens.CHARACTER_LITERAL, JetHighlightingColors.STRING); - keys1.put(JetTokens.EOL_COMMENT, JET_COMMENT); - keys1.put(JetTokens.BLOCK_COMMENT, JET_COMMENT); - keys1.put(JetTokens.DOC_COMMENT, JET_COMMENT); + keys1.put(JetTokens.EOL_COMMENT, JetHighlightingColors.LINE_COMMENT); + keys1.put(JetTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT); + keys1.put(JetTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT); - keys1.put(TokenType.BAD_CHARACTER, JET_BAD_CHARACTER); + keys1.put(TokenType.BAD_CHARACTER, JetHighlightingColors.BAD_CHARACTER); } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index fedefc6639d..a1c5c518430 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -16,15 +16,113 @@ package org.jetbrains.jet.plugin.highlighter; +import com.intellij.openapi.editor.HighlighterColors; import com.intellij.openapi.editor.SyntaxHighlighterColors; +import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.editor.markup.EffectType; +import com.intellij.openapi.editor.markup.TextAttributes; + +import java.awt.*; public class JetHighlightingColors { - public final static TextAttributesKey JET_KEYWORD = TextAttributesKey.createTextAttributesKey( - "Keyword", + public final static TextAttributesKey KEYWORD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_KEYWORD", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); + public static final TextAttributesKey SOFT_KEYWORD; + + static { + TextAttributes attributes = SyntaxHighlighterColors.KEYWORD.getDefaultAttributes().clone(); + attributes.setFontType(Font.PLAIN); + SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_SOFT_KEYWORD", + attributes + ); + } + + public static final TextAttributesKey NUMBER = TextAttributesKey.createTextAttributesKey( + "KOTLIN_NUMBER", + SyntaxHighlighterColors.NUMBER.getDefaultAttributes() + ); + + public static final TextAttributesKey STRING = TextAttributesKey.createTextAttributesKey( + "KOTLIN_STRING", + SyntaxHighlighterColors.STRING.getDefaultAttributes() + ); + + public static final TextAttributesKey VALID_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_VALID_STRING_ESCAPE", + SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes() + ); + + public static final TextAttributesKey LINE_COMMENT = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LINE_COMMENT", + SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes() + ); + + public static final TextAttributesKey BLOCK_COMMENT = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BLOCK_COMMENT", + SyntaxHighlighterColors.JAVA_BLOCK_COMMENT.getDefaultAttributes() + ); + + public static final TextAttributesKey DOC_COMMENT = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DOC_COMMENT", + SyntaxHighlighterColors.DOC_COMMENT.getDefaultAttributes() + ); + + // TODO review: is it needed? + public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( + "KOTLIN_WRAPPED_INTO_REF", + new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, Font.PLAIN) + ); + + public static final TextAttributesKey INSTANCE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD", + CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey INSTANCE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_INSTANCE_BACKING_FIELD_ACCESS", + CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = TextAttributesKey.createTextAttributesKey( + "KOTLIN_CLOSURE_DEFAULT_PARAMETER", + new TextAttributes(null, null, null, null, Font.BOLD) + ); + + public static final TextAttributesKey FUNCTION_LITERAL_BRACKET = TextAttributesKey.createTextAttributesKey( + "KOTLIN_FUNCTION_LITERAL_BRACKET", + new TextAttributes(null, null, null, null, Font.BOLD) + ); + + public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BAD_CHARACTER", + HighlighterColors.BAD_CHARACTER.getDefaultAttributes() + ); + + public static final TextAttributesKey AUTO_CASTED_VALUE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_AUTO_CASTED_VALUE", + new TextAttributes(STRING.getDefaultAttributes().getForegroundColor(), null, null, null, Font.PLAIN) + ); + + public static final TextAttributesKey LABEL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LABEL", + new TextAttributes(new Color(74, 134, 232), null, null, null, Font.PLAIN) + ); + + public static final TextAttributesKey DEBUG_INFO = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DEBUG_INFO", + new TextAttributes(null, null, Color.BLACK, EffectType.ROUNDED_BOX, Font.PLAIN) + ); + + public static final TextAttributesKey RESOLVED_TO_ERROR = TextAttributesKey.createTextAttributesKey( + "KOTLIN_RESOLVED_TO_ERROR", + new TextAttributes(null, null, Color.RED, EffectType.ROUNDED_BOX, Font.PLAIN) + ); + private JetHighlightingColors() { } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index e6eee9fdc88..58a90f5d83f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -39,7 +39,6 @@ import org.jetbrains.jet.lang.diagnostics.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.plugin.highlighter.JetHighlighter; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory; import org.jetbrains.jet.plugin.quickfix.QuickFixes; @@ -94,7 +93,7 @@ public class JetPsiChecker implements Annotator { if (target instanceof ValueParameterDescriptor) { ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target; if (bindingContext.get(AUTO_CREATED_IT, parameterDescriptor)) { - holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlighter.JET_AUTOCREATED_IT); + holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER); } } @@ -106,7 +105,8 @@ public class JetPsiChecker implements Annotator { if (target instanceof VariableDescriptor) { VariableDescriptor variableDescriptor = (VariableDescriptor) target; if (bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor)) { - holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes(JetHighlighter.JET_WRAPPED_INTO_REF); + holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + JetHighlightingColors.WRAPPED_INTO_REF); } } @@ -126,7 +126,8 @@ public class JetPsiChecker implements Annotator { public void visitExpression(@NotNull JetExpression expression) { JetType autoCast = bindingContext.get(AUTOCAST, expression); if (autoCast != null) { - holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes(JetHighlighter.JET_AUTO_CAST_EXPRESSION); + holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes( + JetHighlightingColors.AUTO_CASTED_VALUE); } expression.acceptChildren(this); } @@ -295,7 +296,7 @@ public class JetPsiChecker implements Annotator { holder.createInfoAnnotation( nameIdentifier, "This property has a backing field") - .setTextAttributes(JetHighlighter.JET_PROPERTY_WITH_BACKING_FIELD_IDENTIFIER); + .setTextAttributes(JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java index 95e98b6643a..e01d16845d1 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java @@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.psi.JetPrefixExpression; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.psi.JetVisitorVoid; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.plugin.highlighter.JetHighlighter; public class LabelsAnnotator implements Annotator { public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { @@ -38,7 +37,7 @@ public class LabelsAnnotator implements Annotator { public void visitPrefixExpression(JetPrefixExpression expression) { JetSimpleNameExpression operationSign = expression.getOperationReference(); if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) { - holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlighter.JET_LABEL_IDENTIFIER); + holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL); } } @@ -46,7 +45,7 @@ public class LabelsAnnotator implements Annotator { public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) { JetSimpleNameExpression targetLabel = expression.getTargetLabel(); if (targetLabel != null) { - holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlighter.JET_LABEL_IDENTIFIER); + holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL); } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java index f07a0a1d693..9b9079d5f1f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java @@ -36,7 +36,7 @@ public class SoftKeywordsAnnotator implements Annotator { public void visitElement(PsiElement element) { if (element instanceof LeafPsiElement) { if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { - holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlighter.JET_SOFT_KEYWORD); + holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); } } } @@ -54,14 +54,14 @@ public class SoftKeywordsAnnotator implements Annotator { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { if (ApplicationManager.getApplication().isUnitTestMode()) return; JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); - holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER); + holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); ASTNode closingBraceNode = functionLiteral.getClosingBraceNode(); if (closingBraceNode != null) { - holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER); + holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); } ASTNode arrowNode = functionLiteral.getArrowNode(); if (arrowNode != null) { - holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER); + holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); } } }); @@ -73,7 +73,7 @@ public class SoftKeywordsAnnotator implements Annotator { if (userType.getQualifier() == null) { JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); if (referenceExpression != null) { - holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlighter.JET_SOFT_KEYWORD); + holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); } } } From 382124e3a21bf59c31c91bbcdaeb3999832d9daf Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 28 Mar 2012 18:48:21 +0400 Subject: [PATCH 05/38] Restored code authorship mark. --- .../jet/plugin/actions/ToggleErrorReportingAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java index f7e51c28274..7211bf2f739 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java @@ -21,7 +21,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.jet.plugin.highlighter.JetPsiChecker; /** - * @author yole + * @author Andrey Breslav */ public class ToggleErrorReportingAction extends AnAction { @Override From 76a3428350237792bf9d126ac1eb762b3a33dd56 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 28 Mar 2012 19:17:44 +0400 Subject: [PATCH 06/38] Converted ToggleErrorReportingAction to real toggle action with immediate effect. --- idea/src/META-INF/plugin.xml | 2 +- .../actions/ToggleErrorReportingAction.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index f7c6e2835f6..caf29ab9868 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -40,7 +40,7 @@ + text="Error Reporting Enabled"> diff --git a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java index 7211bf2f739..eace7a6aac8 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/ToggleErrorReportingAction.java @@ -16,16 +16,23 @@ package org.jetbrains.jet.plugin.actions; -import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ToggleAction; import org.jetbrains.jet.plugin.highlighter.JetPsiChecker; /** * @author Andrey Breslav */ -public class ToggleErrorReportingAction extends AnAction { +public class ToggleErrorReportingAction extends ToggleAction { @Override - public void actionPerformed(AnActionEvent e) { - JetPsiChecker.setErrorReportingEnabled(!JetPsiChecker.isErrorReportingEnabled()); + public boolean isSelected(AnActionEvent e) { + return JetPsiChecker.isErrorReportingEnabled(); + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + JetPsiChecker.setErrorReportingEnabled(state); + DaemonCodeAnalyzer.getInstance(e.getProject()).restart(); } } From 99a8ab6b0115a5350e0064ea81998c8bcf9361e8 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 28 Mar 2012 19:31:45 +0400 Subject: [PATCH 07/38] Made debug info visible only when IDEA is in internal mode. --- .../jet/plugin/highlighter/DebugInfoAnnotator.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java index 55760aed896..135ee272c60 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DebugInfoAnnotator.java @@ -51,19 +51,13 @@ public class DebugInfoAnnotator implements Annotator { public static final TokenSet EXCLUDED = TokenSet.create(COLON, AS_KEYWORD, AS_SAFE, IS_KEYWORD, NOT_IS, OROR, ANDAND, EQ, EQEQEQ, EXCLEQEQEQ, ELVIS, EXCLEXCL); - private static volatile boolean debugInfoEnabled = true; - - public static void setDebugInfoEnabled(boolean value) { - debugInfoEnabled = value; - } - public static boolean isDebugInfoEnabled() { - return debugInfoEnabled; + return ApplicationManager.getApplication().isInternal(); } @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { - if (!debugInfoEnabled || !JetPsiChecker.isErrorReportingEnabled()) { + if (!isDebugInfoEnabled() || !JetPsiChecker.isErrorReportingEnabled()) { return; } From 3328dda81a61137f714443da16ee33ee7656532e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:00:52 +0400 Subject: [PATCH 08/38] Extracted BackingFieldHighlightingVisitor and corresponding abstract superclasses from JetPsiChecker. --- .../AfterAnalysisHighlightingVisitor.java | 29 ++++++++ .../BackingFieldHighlightingVisitor.java | 68 +++++++++++++++++++ .../highlighter/HighlightingVisitor.java | 28 ++++++++ .../jet/plugin/highlighter/JetPsiChecker.java | 41 +---------- 4 files changed, 126 insertions(+), 40 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/AfterAnalysisHighlightingVisitor.java create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/HighlightingVisitor.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/AfterAnalysisHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/AfterAnalysisHighlightingVisitor.java new file mode 100644 index 00000000000..55399cc865d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/AfterAnalysisHighlightingVisitor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.AnnotationHolder; +import org.jetbrains.jet.lang.resolve.BindingContext; + +abstract class AfterAnalysisHighlightingVisitor extends HighlightingVisitor { + protected BindingContext bindingContext; + + protected AfterAnalysisHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder); + this.bindingContext = bindingContext; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java new file mode 100644 index 00000000000..903fadd93b5 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java @@ -0,0 +1,68 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; +import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; + +class BackingFieldHighlightingVisitor extends AfterAnalysisHighlightingVisitor { + BackingFieldHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder, bindingContext); + } + + @Override + public void visitProperty(@NotNull JetProperty property) { + VariableDescriptor propertyDescriptor = bindingContext.get(BindingContext.VARIABLE, property); + if (propertyDescriptor instanceof PropertyDescriptor) { + Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor)propertyDescriptor); + if (Boolean.TRUE.equals(backingFieldRequired)) { + putBackingFieldAnnotation(holder, property); + } + } + } + + @Override + public void visitParameter(@NotNull JetParameter parameter) { + PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); + if (propertyDescriptor != null) { + Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor); + if (Boolean.TRUE.equals(backingFieldRequired)) { + putBackingFieldAnnotation(holder, parameter); + } + } + } + + @Override + public void visitJetElement(@NotNull JetElement element) { + element.acceptChildren(this); + } + + private static void putBackingFieldAnnotation(@NotNull AnnotationHolder holder, @NotNull JetNamedDeclaration element) { + PsiElement nameIdentifier = element.getNameIdentifier(); + if (nameIdentifier != null) { + holder.createInfoAnnotation( + nameIdentifier, + "This property has a backing field") + .setTextAttributes(JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD); + } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/HighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/HighlightingVisitor.java new file mode 100644 index 00000000000..62c7145a825 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/HighlightingVisitor.java @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.AnnotationHolder; +import org.jetbrains.jet.lang.psi.JetVisitorVoid; + +abstract class HighlightingVisitor extends JetVisitorVoid { + protected AnnotationHolder holder; + + protected HighlightingVisitor(AnnotationHolder holder) { + this.holder = holder; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 58a90f5d83f..9609e657853 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -32,7 +32,6 @@ import com.intellij.psi.PsiReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.diagnostics.*; @@ -84,7 +83,7 @@ public class JetPsiChecker implements Annotator { } } - highlightBackingFields(holder, file, bindingContext); + file.acceptChildren(new BackingFieldHighlightingVisitor(holder, bindingContext)); file.acceptChildren(new JetVisitorVoid() { @Override @@ -261,42 +260,4 @@ public class JetPsiChecker implements Annotator { if (textRanges.isEmpty()) return null; return holder.createErrorAnnotation(textRanges.get(0), getMessage(diagnostic)); } - - - private void highlightBackingFields(@NotNull final AnnotationHolder holder, @NotNull JetFile file, @NotNull final BindingContext bindingContext) { - file.acceptChildren(new JetVisitorVoid() { - @Override - public void visitProperty(@NotNull JetProperty property) { - VariableDescriptor propertyDescriptor = bindingContext.get(BindingContext.VARIABLE, property); - if (propertyDescriptor instanceof PropertyDescriptor) { - if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) propertyDescriptor)) { - putBackingfieldAnnotation(holder, property); - } - } - } - - @Override - public void visitParameter(@NotNull JetParameter parameter) { - PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); - if (propertyDescriptor != null && bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) { - putBackingfieldAnnotation(holder, parameter); - } - } - - @Override - public void visitJetElement(@NotNull JetElement element) { - element.acceptChildren(this); - } - }); - } - - private void putBackingfieldAnnotation(@NotNull AnnotationHolder holder, @NotNull JetNamedDeclaration element) { - PsiElement nameIdentifier = element.getNameIdentifier(); - if (nameIdentifier != null) { - holder.createInfoAnnotation( - nameIdentifier, - "This property has a backing field") - .setTextAttributes(JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD); - } - } } From e92d8fcda7245a256b50ca89411f5f9b7f7586a0 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:30:33 +0400 Subject: [PATCH 09/38] Extracted VariablesHighlightingVisitor from JetPsiChecker. --- .../jet/plugin/highlighter/JetPsiChecker.java | 95 ++++--------------- .../VariablesHighlightingVisitor.java | 87 +++++++++++++++++ 2 files changed, 103 insertions(+), 79 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 9609e657853..7cbbffdcd22 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.highlighter; import com.google.common.collect.Sets; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; @@ -31,13 +30,9 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.diagnostics.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory; import org.jetbrains.jet.plugin.quickfix.QuickFixes; @@ -46,13 +41,10 @@ import java.util.Collection; import java.util.List; import java.util.Set; -import static org.jetbrains.jet.lang.resolve.BindingContext.*; - /** * @author abreslav */ public class JetPsiChecker implements Annotator { - private static volatile boolean errorReportingEnabled = true; public static void setErrorReportingEnabled(boolean value) { @@ -66,16 +58,15 @@ public class JetPsiChecker implements Annotator { @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { if (element instanceof JetFile) { - JetFile file = (JetFile) element; + JetFile file = (JetFile)element; try { - final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); + BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); if (errorReportingEnabled) { Collection diagnostics = Sets.newLinkedHashSet(bindingContext.getDiagnostics()); Set redeclarations = Sets.newHashSet(); for (Diagnostic diagnostic : diagnostics) { - // This is needed because we have the same context for all files if (diagnostic.getPsiFile() != file) continue; @@ -84,58 +75,7 @@ public class JetPsiChecker implements Annotator { } file.acceptChildren(new BackingFieldHighlightingVisitor(holder, bindingContext)); - - file.acceptChildren(new JetVisitorVoid() { - @Override - public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { - DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression); - if (target instanceof ValueParameterDescriptor) { - ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target; - if (bindingContext.get(AUTO_CREATED_IT, parameterDescriptor)) { - holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER); - } - } - - markVariableAsWrappedIfNeeded(expression.getNode(), target); - super.visitSimpleNameExpression(expression); - } - - private void markVariableAsWrappedIfNeeded(@NotNull ASTNode node, DeclarationDescriptor target) { - if (target instanceof VariableDescriptor) { - VariableDescriptor variableDescriptor = (VariableDescriptor) target; - if (bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor)) { - holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( - JetHighlightingColors.WRAPPED_INTO_REF); - } - - } - } - - @Override - public void visitProperty(@NotNull JetProperty property) { - DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property); - PsiElement nameIdentifier = property.getNameIdentifier(); - if (nameIdentifier != null) { - markVariableAsWrappedIfNeeded(nameIdentifier.getNode(), declarationDescriptor); - } - super.visitProperty(property); - } - - @Override - public void visitExpression(@NotNull JetExpression expression) { - JetType autoCast = bindingContext.get(AUTOCAST, expression); - if (autoCast != null) { - holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes( - JetHighlightingColors.AUTO_CASTED_VALUE); - } - expression.acceptChildren(this); - } - - @Override - public void visitJetElement(@NotNull JetElement element) { - element.acceptChildren(this); - } - }); + file.acceptChildren(new VariablesHighlightingVisitor(holder, bindingContext)); } catch (ProcessCanceledException e) { throw e; @@ -153,26 +93,24 @@ public class JetPsiChecker implements Annotator { } } - private void registerDiagnosticAnnotations( - @NotNull Diagnostic diagnostic, - @NotNull Set redeclarations, - @NotNull final AnnotationHolder holder - ) { + private static void registerDiagnosticAnnotations(@NotNull Diagnostic diagnostic, + @NotNull Set redeclarations, + @NotNull final AnnotationHolder holder) { List textRanges = diagnostic.getTextRanges(); if (diagnostic.getSeverity() == Severity.ERROR) { if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) { return; } if (diagnostic instanceof UnresolvedReferenceDiagnostic) { - UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic; + UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic)diagnostic; JetReferenceExpression referenceExpression = unresolvedReferenceDiagnostic.getPsiElement(); PsiReference reference = referenceExpression.getReference(); if (reference instanceof MultiRangeReference) { - MultiRangeReference mrr = (MultiRangeReference) reference; + MultiRangeReference mrr = (MultiRangeReference)reference; for (TextRange range : mrr.getRanges()) { Annotation annotation = holder.createErrorAnnotation( - range.shiftRight(referenceExpression.getTextOffset()), - diagnostic.getMessage()); + range.shiftRight(referenceExpression.getTextOffset()), + diagnostic.getMessage()); registerQuickFix(annotation, diagnostic); @@ -191,7 +129,7 @@ public class JetPsiChecker implements Annotator { } if (diagnostic instanceof RedeclarationDiagnostic) { - RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic; + RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic)diagnostic; registerQuickFix(markRedeclaration(redeclarations, redeclarationDiagnostic, holder), diagnostic); return; } @@ -218,10 +156,7 @@ public class JetPsiChecker implements Annotator { * Add a quick fix if and return modified annotation. */ @Nullable - private Annotation registerQuickFix( - @Nullable Annotation annotation, - @NotNull Diagnostic diagnostic) { - + private static Annotation registerQuickFix(@Nullable Annotation annotation, @NotNull Diagnostic diagnostic) { if (annotation == null) { return null; } @@ -246,7 +181,7 @@ public class JetPsiChecker implements Annotator { } @NotNull - private String getMessage(@NotNull Diagnostic diagnostic) { + private static String getMessage(@NotNull Diagnostic diagnostic) { if (ApplicationManager.getApplication().isInternal() || ApplicationManager.getApplication().isUnitTestMode()) { return "[" + diagnostic.getFactory().getName() + "] " + diagnostic.getMessage(); } @@ -254,7 +189,9 @@ public class JetPsiChecker implements Annotator { } @Nullable - private Annotation markRedeclaration(@NotNull Set redeclarations, @NotNull RedeclarationDiagnostic diagnostic, @NotNull AnnotationHolder holder) { + private static Annotation markRedeclaration(@NotNull Set redeclarations, + @NotNull RedeclarationDiagnostic diagnostic, + @NotNull AnnotationHolder holder) { if (!redeclarations.add(diagnostic.getPsiElement())) return null; List textRanges = diagnostic.getTextRanges(); if (textRanges.isEmpty()) return null; diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java new file mode 100644 index 00000000000..9b18f41fdb6 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.types.JetType; + +import static org.jetbrains.jet.lang.resolve.BindingContext.*; + +class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { + VariablesHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder, bindingContext); + } + + @Override + public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { + DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression); + if (target instanceof ValueParameterDescriptor) { + ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target; + if (Boolean.TRUE.equals(bindingContext.get(AUTO_CREATED_IT, parameterDescriptor))) { + holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes( + JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER); + } + } + + markVariableAsWrappedIfNeeded(expression.getNode(), target); + super.visitSimpleNameExpression(expression); + } + + private void markVariableAsWrappedIfNeeded(@NotNull ASTNode node, DeclarationDescriptor target) { + if (target instanceof VariableDescriptor) { + VariableDescriptor variableDescriptor = (VariableDescriptor) target; + if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { + holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + JetHighlightingColors.WRAPPED_INTO_REF); + } + + } + } + + @Override + public void visitProperty(@NotNull JetProperty property) { + DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property); + PsiElement nameIdentifier = property.getNameIdentifier(); + if (nameIdentifier != null) { + markVariableAsWrappedIfNeeded(nameIdentifier.getNode(), declarationDescriptor); + } + super.visitProperty(property); + } + + @Override + public void visitExpression(@NotNull JetExpression expression) { + JetType autoCast = bindingContext.get(AUTOCAST, expression); + if (autoCast != null) { + holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes( + JetHighlightingColors.AUTO_CASTED_VALUE); + } + expression.acceptChildren(this); + } + + @Override + public void visitJetElement(@NotNull JetElement element) { + element.acceptChildren(this); + } +} From f41548a6642fc3206bc0bb21c783e8b0767a7899 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:45:11 +0400 Subject: [PATCH 10/38] Converted SoftKeywordsAnnotator to extra visitor invoked from JetPsiChecker. --- idea/src/META-INF/plugin.xml | 1 - .../jet/plugin/highlighter/JetPsiChecker.java | 2 + .../highlighter/SoftKeywordsAnnotator.java | 81 ------------------- .../SoftKeywordsHighlightingVisitor.java | 80 ++++++++++++++++++ 4 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index caf29ab9868..77a8b4a1d62 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -124,7 +124,6 @@ - diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 7cbbffdcd22..b4e5790d540 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -57,6 +57,8 @@ public class JetPsiChecker implements Annotator { @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { + element.accept(new SoftKeywordsHighlightingVisitor(holder)); + if (element instanceof JetFile) { JetFile file = (JetFile)element; diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java deleted file mode 100644 index 9b9079d5f1f..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsAnnotator.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * @author max - */ -package org.jetbrains.jet.plugin.highlighter; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.annotation.AnnotationHolder; -import com.intellij.lang.annotation.Annotator; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.impl.source.tree.LeafPsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lexer.JetTokens; - -public class SoftKeywordsAnnotator implements Annotator { - public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { - element.accept(new JetVisitorVoid() { - @Override - public void visitElement(PsiElement element) { - if (element instanceof LeafPsiElement) { - if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { - holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); - } - } - } - - @Override - public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { - JetTypeReference typeReference = annotationEntry.getTypeReference(); - if (typeReference != null) { - JetTypeElement typeElement = typeReference.getTypeElement(); - markAnnotationIdentifiers(typeElement, holder); - } - } - - @Override - public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { - if (ApplicationManager.getApplication().isUnitTestMode()) return; - JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); - holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); - ASTNode closingBraceNode = functionLiteral.getClosingBraceNode(); - if (closingBraceNode != null) { - holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); - } - ASTNode arrowNode = functionLiteral.getArrowNode(); - if (arrowNode != null) { - holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); - } - } - }); - } - - private void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) { - if (typeElement instanceof JetUserType) { - JetUserType userType = (JetUserType) typeElement; - if (userType.getQualifier() == null) { - JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); - if (referenceExpression != null) { - holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); - } - } - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java new file mode 100644 index 00000000000..0aa1ea36870 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @author max + */ +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.impl.source.tree.LeafPsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lexer.JetTokens; + +class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { + SoftKeywordsHighlightingVisitor(AnnotationHolder holder) { + super(holder); + } + + @Override + public void visitElement(PsiElement element) { + if (element instanceof LeafPsiElement) { + if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { + holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); + } + } + } + + @Override + public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { + JetTypeReference typeReference = annotationEntry.getTypeReference(); + if (typeReference != null) { + JetTypeElement typeElement = typeReference.getTypeElement(); + markAnnotationIdentifiers(typeElement, holder); + } + } + + @Override + public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { + if (ApplicationManager.getApplication().isUnitTestMode()) return; + JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); + holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + ASTNode closingBraceNode = functionLiteral.getClosingBraceNode(); + if (closingBraceNode != null) { + holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + } + ASTNode arrowNode = functionLiteral.getArrowNode(); + if (arrowNode != null) { + holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + } + } + + private static void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) { + if (typeElement instanceof JetUserType) { + JetUserType userType = (JetUserType) typeElement; + if (userType.getQualifier() == null) { + JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); + if (referenceExpression != null) { + holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); + } + } + } + } +} From 0079df05b0fba6ee8a3995cff10a1e477995629a Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:49:07 +0400 Subject: [PATCH 11/38] Converted LabelsAnnotator to extra visitor invoked from JetPsiChecker. --- idea/src/META-INF/plugin.xml | 1 - .../jet/plugin/highlighter/JetPsiChecker.java | 3 +- ...or.java => LabelsHighlightingVisitor.java} | 36 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) rename idea/src/org/jetbrains/jet/plugin/highlighter/{LabelsAnnotator.java => LabelsHighlightingVisitor.java} (50%) diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 77a8b4a1d62..72df4056f05 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -124,7 +124,6 @@ - diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index b4e5790d540..b26abca8fc1 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -58,7 +58,8 @@ public class JetPsiChecker implements Annotator { @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { element.accept(new SoftKeywordsHighlightingVisitor(holder)); - + element.accept(new LabelsHighlightingVisitor(holder)); + if (element instanceof JetFile) { JetFile file = (JetFile)element; diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java similarity index 50% rename from idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java rename to idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java index e01d16845d1..1e8ec30382c 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java @@ -29,26 +29,24 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.psi.JetVisitorVoid; import org.jetbrains.jet.lexer.JetTokens; -public class LabelsAnnotator implements Annotator { - public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { -// if (ApplicationManager.getApplication().isUnitTestMode()) return; - element.accept(new JetVisitorVoid() { - @Override - public void visitPrefixExpression(JetPrefixExpression expression) { - JetSimpleNameExpression operationSign = expression.getOperationReference(); - if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) { - holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL); - } - } +class LabelsHighlightingVisitor extends HighlightingVisitor { + LabelsHighlightingVisitor(AnnotationHolder holder) { + super(holder); + } - @Override - public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) { - JetSimpleNameExpression targetLabel = expression.getTargetLabel(); - if (targetLabel != null) { - holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL); - } - } + @Override + public void visitPrefixExpression(JetPrefixExpression expression) { + JetSimpleNameExpression operationSign = expression.getOperationReference(); + if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) { + holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL); + } + } - }); + @Override + public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) { + JetSimpleNameExpression targetLabel = expression.getTargetLabel(); + if (targetLabel != null) { + holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL); + } } } From 494b489075d1897851a5eba762d7de21866d7f42 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 14:56:20 +0400 Subject: [PATCH 12/38] Moved list of used visitors to separate methods in JetPsiChecker. --- .../jet/plugin/highlighter/JetPsiChecker.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index b26abca8fc1..55bac4696e8 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -55,10 +55,25 @@ public class JetPsiChecker implements Annotator { return errorReportingEnabled; } + private static HighlightingVisitor[] getBeforeAnalysisVisitors(AnnotationHolder holder) { + return new HighlightingVisitor[]{ + new SoftKeywordsHighlightingVisitor(holder), + new LabelsHighlightingVisitor(holder), + }; + } + + private static HighlightingVisitor[] getAfterAnalysisVisitor(AnnotationHolder holder, BindingContext bindingContext) { + return new AfterAnalysisHighlightingVisitor[]{ + new BackingFieldHighlightingVisitor(holder, bindingContext), + new VariablesHighlightingVisitor(holder, bindingContext), + }; + } + @Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { - element.accept(new SoftKeywordsHighlightingVisitor(holder)); - element.accept(new LabelsHighlightingVisitor(holder)); + for (HighlightingVisitor visitor : getBeforeAnalysisVisitors(holder)) { + element.accept(visitor); + } if (element instanceof JetFile) { JetFile file = (JetFile)element; @@ -77,8 +92,9 @@ public class JetPsiChecker implements Annotator { } } - file.acceptChildren(new BackingFieldHighlightingVisitor(holder, bindingContext)); - file.acceptChildren(new VariablesHighlightingVisitor(holder, bindingContext)); + for (HighlightingVisitor visitor : getAfterAnalysisVisitor(holder, bindingContext)) { + file.acceptChildren(visitor); + } } catch (ProcessCanceledException e) { throw e; From f28a490a1e38e9972dbb4b0b295232ee4f4c71e6 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 18:20:04 +0400 Subject: [PATCH 13/38] Removed line markers for everything except for overriding functions. --- .../highlighter/JetLineMarkerProvider.java | 203 ++++++------------ 1 file changed, 66 insertions(+), 137 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java index 94f560c34ef..2a98b1cd32f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java @@ -27,17 +27,15 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Function; -import com.intellij.util.PlatformIcons; -import com.intellij.util.PsiIconUtil; import com.intellij.util.PsiNavigateUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.resolve.DescriptorRenderer; @@ -57,151 +55,82 @@ public class JetLineMarkerProvider implements LineMarkerProvider { @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { - JetFile file = (JetFile) element.getContainingFile(); + JetFile file = (JetFile)element.getContainingFile(); if (file == null) return null; + if (!(element instanceof JetNamedFunction)) return null; + JetNamedFunction jetFunction = (JetNamedFunction)element; + final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); - if (element instanceof JetClass) { - JetClass jetClass = (JetClass) element; - ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, jetClass); - String text = classDescriptor == null ? "Unresolved" : DescriptorRenderer.HTML.render(classDescriptor); - return createLineMarkerInfo(jetClass, text); - } + final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); + if (functionDescriptor == null) return null; + final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); + if (overriddenFunctions.size() == 0) return null; - if (element instanceof JetProperty) { - JetProperty jetProperty = (JetProperty) element; - final VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, jetProperty); - if (variableDescriptor instanceof PropertyDescriptor) { - return createLineMarkerInfo(element, DescriptorRenderer.HTML.render(variableDescriptor)); - } - } - - if (element instanceof JetNamedFunction) { - JetNamedFunction jetFunction = (JetNamedFunction) element; - - final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); - if (functionDescriptor == null) return null; - final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); - Icon icon = isMember(functionDescriptor) ? (overriddenFunctions.isEmpty() ? PlatformIcons.METHOD_ICON : OVERRIDING_FUNCTION) : PlatformIcons.FUNCTION_ICON; - return new LineMarkerInfo( - jetFunction, jetFunction.getTextOffset(), icon, Pass.UPDATE_ALL, - new Function() { - @Override - public String fun(JetNamedFunction jetFunction) { - StringBuilder builder = new StringBuilder(); - builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); - int overrideCount = overriddenFunctions.size(); - if (overrideCount >= 1) { - builder.append(" overrides ").append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); - } - if (overrideCount > 1) { - int count = overrideCount - 1; - builder.append(" and ").append(count).append(" other function"); - if (count > 1) { - builder.append("s"); - } - } - - return builder.toString(); - } - }, - new GutterIconNavigationHandler() { - @Override - public void navigate(MouseEvent event, JetNamedFunction elt) { - if (overriddenFunctions.isEmpty()) return; - final List list = Lists.newArrayList(); - for (FunctionDescriptor overriddenFunction : overriddenFunctions) { - PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenFunction); - list.add(declarationPsiElement); - } - if (list.isEmpty()) { - String myEmptyText = "empty text"; - final JComponent renderer = HintUtil.createErrorLabel(myEmptyText); - final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); - if (event != null) { - popup.show(new RelativePoint(event)); - } - return; - } - if (list.size() == 1) { - PsiNavigateUtil.navigate(list.iterator().next()); - } - else { - final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { - @Override - public String getElementText(PsiElement element) { - if (element instanceof JetNamedFunction) { - JetNamedFunction function = (JetNamedFunction) element; - return DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.FUNCTION, function)); - } - return super.getElementText(element); - } - }, DescriptorRenderer.HTML.render(functionDescriptor)); - if (event != null) { - popup.show(new RelativePoint(event)); - } - } - } - } - ); - } - - if (element instanceof JetNamespaceHeader) { - JetNamespaceHeader header = (JetNamespaceHeader) element; - if (header.getNameIdentifier() != null) { - return createLineMarkerInfo(header, - DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.NAMESPACE, file))); - } - } - - if (element instanceof JetObjectDeclaration && !(element.getParent() instanceof JetExpression)) { - JetObjectDeclaration jetObjectDeclaration = (JetObjectDeclaration) element; - - return new LineMarkerInfo( - jetObjectDeclaration, jetObjectDeclaration.getTextOffset(), PlatformIcons.ANONYMOUS_CLASS_ICON, Pass.UPDATE_ALL, - new Function() { - @Override - public String fun(JetObjectDeclaration jetObjectDeclaration) { - ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, jetObjectDeclaration); - if (classDescriptor != null) { - return DescriptorRenderer.HTML.renderAsObject(classDescriptor); - } - return "<none>"; - } - }, - new GutterIconNavigationHandler() { - @Override - public void navigate(MouseEvent e, JetObjectDeclaration elt) { - } - } - ); - } - - return null; - } - - private LineMarkerInfo createLineMarkerInfo(T element, final String text) { - return new LineMarkerInfo( - element, element.getTextOffset(), PsiIconUtil.getProvidersIcon(element, Iconable.ICON_FLAG_CLOSED), Pass.UPDATE_ALL, - new Function() { + return new LineMarkerInfo( + jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL, + new Function() { @Override - public String fun(T jetNamespace) { - return text; + public String fun(JetNamedFunction jetFunction) { + StringBuilder builder = new StringBuilder(); + builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); + int overrideCount = overriddenFunctions.size(); + if (overrideCount >= 1) { + builder.append(" overrides ").append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); + } + if (overrideCount > 1) { + int count = overrideCount - 1; + builder.append(" and ").append(count).append(" other function"); + if (count > 1) { + builder.append("s"); + } + } + + return builder.toString(); } }, - new GutterIconNavigationHandler() { + new GutterIconNavigationHandler() { @Override - public void navigate(MouseEvent e, T elt) { + public void navigate(MouseEvent event, JetNamedFunction elt) { + if (overriddenFunctions.isEmpty()) return; + final List list = Lists.newArrayList(); + for (FunctionDescriptor overriddenFunction : overriddenFunctions) { + PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenFunction); + list.add(declarationPsiElement); + } + if (list.isEmpty()) { + String myEmptyText = "empty text"; + final JComponent renderer = HintUtil.createErrorLabel(myEmptyText); + final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); + if (event != null) { + popup.show(new RelativePoint(event)); + } + return; + } + if (list.size() == 1) { + PsiNavigateUtil.navigate(list.iterator().next()); + } + else { + final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { + @Override + public String getElementText(PsiElement element) { + if (element instanceof JetNamedFunction) { + JetNamedFunction function = (JetNamedFunction) element; + return DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.FUNCTION, function)); + } + return super.getElementText(element); + } + }, DescriptorRenderer.HTML.render(functionDescriptor)); + if (event != null) { + popup.show(new RelativePoint(event)); + } + } } } ); } - private boolean isMember(@NotNull SimpleFunctionDescriptor functionDescriptor) { - return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor; - } - @Override public void collectSlowLineMarkers(List elements, Collection result) { } From f57ebac1ff50961081f250ab5b300a609d4261fd Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 18:27:18 +0400 Subject: [PATCH 14/38] Marks are different for overriding and implementing functions. --- .../highlighter/JetLineMarkerProvider.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java index 2a98b1cd32f..7bc61aefefa 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java @@ -33,6 +33,7 @@ import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Function; import com.intellij.util.PsiNavigateUtil; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.Modality; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetNamedFunction; @@ -50,8 +51,8 @@ import java.util.Set; * @author abreslav */ public class JetLineMarkerProvider implements LineMarkerProvider { - - public static final Icon OVERRIDING_FUNCTION = IconLoader.getIcon("/general/overridingMethod.png"); + public static final Icon OVERRIDING_MARK = IconLoader.getIcon("/gutter/overridingMethod.png"); + public static final Icon IMPLEMENTING_MARK = IconLoader.getIcon("/gutter/implementingMethod.png"); @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { @@ -68,8 +69,18 @@ public class JetLineMarkerProvider implements LineMarkerProvider { final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); if (overriddenFunctions.size() == 0) return null; + boolean allOverriddenAbstract = true; + for (FunctionDescriptor function : overriddenFunctions) { + allOverriddenAbstract &= function.getModality() == Modality.ABSTRACT; + } + + final String implementsOrOverrides = allOverriddenAbstract ? "implements" : "overrides"; + return new LineMarkerInfo( - jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL, + jetFunction, + jetFunction.getTextOffset(), + allOverriddenAbstract ? IMPLEMENTING_MARK : OVERRIDING_MARK, + Pass.UPDATE_ALL, new Function() { @Override public String fun(JetNamedFunction jetFunction) { @@ -77,7 +88,8 @@ public class JetLineMarkerProvider implements LineMarkerProvider { builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); int overrideCount = overriddenFunctions.size(); if (overrideCount >= 1) { - builder.append(" overrides ").append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); + builder.append(" ").append(implementsOrOverrides).append(" "); + builder.append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); } if (overrideCount > 1) { int count = overrideCount - 1; From 6aadf4400d24c237260a77bd5ca36fc692e32ddc Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 18:35:04 +0400 Subject: [PATCH 15/38] Added implements/overrides line marks for properties. --- .../highlighter/JetLineMarkerProvider.java | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java index 7bc61aefefa..1b91f3f9523 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java @@ -28,15 +28,16 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.IconLoader; import com.intellij.psi.PsiElement; -import com.intellij.psi.util.PsiUtilBase; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Function; import com.intellij.util.PsiNavigateUtil; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.Modality; -import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetNamedFunction; +import org.jetbrains.jet.lang.psi.JetProperty; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.resolve.DescriptorRenderer; @@ -55,45 +56,46 @@ public class JetLineMarkerProvider implements LineMarkerProvider { public static final Icon IMPLEMENTING_MARK = IconLoader.getIcon("/gutter/implementingMethod.png"); @Override - public LineMarkerInfo getLineMarkerInfo(PsiElement element) { + public LineMarkerInfo getLineMarkerInfo(final PsiElement element) { JetFile file = (JetFile)element.getContainingFile(); if (file == null) return null; - if (!(element instanceof JetNamedFunction)) return null; - JetNamedFunction jetFunction = (JetNamedFunction)element; + if (!(element instanceof JetNamedFunction || element instanceof JetProperty)) return null; final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); - final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); - if (functionDescriptor == null) return null; - final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); - if (overriddenFunctions.size() == 0) return null; + final DeclarationDescriptor descriptor = + bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); + if (!(descriptor instanceof CallableMemberDescriptor)) return null; + final Set overriddenMembers = ((CallableMemberDescriptor)descriptor).getOverriddenDescriptors(); + if (overriddenMembers.size() == 0) return null; boolean allOverriddenAbstract = true; - for (FunctionDescriptor function : overriddenFunctions) { + for (CallableMemberDescriptor function : overriddenMembers) { allOverriddenAbstract &= function.getModality() == Modality.ABSTRACT; } final String implementsOrOverrides = allOverriddenAbstract ? "implements" : "overrides"; + final String memberKind = element instanceof JetNamedFunction ? "function" : "property"; - return new LineMarkerInfo( - jetFunction, - jetFunction.getTextOffset(), + return new LineMarkerInfo( + element, + element.getTextOffset(), allOverriddenAbstract ? IMPLEMENTING_MARK : OVERRIDING_MARK, Pass.UPDATE_ALL, - new Function() { + new Function() { @Override - public String fun(JetNamedFunction jetFunction) { + public String fun(PsiElement element) { StringBuilder builder = new StringBuilder(); - builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); - int overrideCount = overriddenFunctions.size(); + builder.append(DescriptorRenderer.HTML.render(descriptor)); + int overrideCount = overriddenMembers.size(); if (overrideCount >= 1) { builder.append(" ").append(implementsOrOverrides).append(" "); - builder.append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); + builder.append(DescriptorRenderer.HTML.render(overriddenMembers.iterator().next())); } if (overrideCount > 1) { int count = overrideCount - 1; - builder.append(" and ").append(count).append(" other function"); + builder.append(" and ").append(count).append(" other ").append(memberKind); if (count > 1) { builder.append("s"); } @@ -102,13 +104,13 @@ public class JetLineMarkerProvider implements LineMarkerProvider { return builder.toString(); } }, - new GutterIconNavigationHandler() { + new GutterIconNavigationHandler() { @Override - public void navigate(MouseEvent event, JetNamedFunction elt) { - if (overriddenFunctions.isEmpty()) return; + public void navigate(MouseEvent event, PsiElement elt) { + if (overriddenMembers.isEmpty()) return; final List list = Lists.newArrayList(); - for (FunctionDescriptor overriddenFunction : overriddenFunctions) { - PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenFunction); + for (CallableMemberDescriptor overriddenMember : overriddenMembers) { + PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenMember); list.add(declarationPsiElement); } if (list.isEmpty()) { @@ -124,7 +126,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider { PsiNavigateUtil.navigate(list.iterator().next()); } else { - final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { + final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { @Override public String getElementText(PsiElement element) { if (element instanceof JetNamedFunction) { @@ -133,7 +135,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider { } return super.getElementText(element); } - }, DescriptorRenderer.HTML.render(functionDescriptor)); + }, DescriptorRenderer.HTML.render(descriptor)); if (event != null) { popup.show(new RelativePoint(event)); } From c65425edac870807b4fadae630181c2bf0c7019b Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 18:39:01 +0400 Subject: [PATCH 16/38] Made soft keywords bold by default. --- .../plugin/highlighter/JetHighlightingColors.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index a1c5c518430..67152e7c09e 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -31,16 +31,10 @@ public class JetHighlightingColors { SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); - public static final TextAttributesKey SOFT_KEYWORD; - - static { - TextAttributes attributes = SyntaxHighlighterColors.KEYWORD.getDefaultAttributes().clone(); - attributes.setFontType(Font.PLAIN); - SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_SOFT_KEYWORD", - attributes - ); - } + public static final TextAttributesKey SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_SOFT_KEYWORD", + SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() + ); public static final TextAttributesKey NUMBER = TextAttributesKey.createTextAttributesKey( "KOTLIN_NUMBER", From cd180949295d76cd9f74f2fad3cae6ec8f347c57 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 20:00:45 +0400 Subject: [PATCH 17/38] Added special highlighting for invalid string escape. --- .../jet/plugin/highlighter/JetColorSettingsPage.java | 1 + .../jet/plugin/highlighter/JetHighlightingColors.java | 5 +++++ .../jetbrains/jet/plugin/highlighter/JetPsiChecker.java | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index f5f8968eaad..11ed1ca98e0 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -103,6 +103,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.valid.escape.in.string"), JetHighlightingColors.VALID_STRING_ESCAPE), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string"), JetHighlightingColors.INVALID_STRING_ESCAPE), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 67152e7c09e..96f3fd62730 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -51,6 +51,11 @@ public class JetHighlightingColors { SyntaxHighlighterColors.VALID_STRING_ESCAPE.getDefaultAttributes() ); + public static final TextAttributesKey INVALID_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_INVALID_STRING_ESCAPE", + SyntaxHighlighterColors.INVALID_STRING_ESCAPE.getDefaultAttributes() + ); + public static final TextAttributesKey LINE_COMMENT = TextAttributesKey.createTextAttributesKey( "KOTLIN_LINE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes() diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 55bac4696e8..4ce6180a790 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -147,6 +147,13 @@ public class JetPsiChecker implements Annotator { return; } + if (diagnostic.getFactory() == Errors.ILLEGAL_ESCAPE_SEQUENCE) { + for (TextRange textRange : diagnostic.getTextRanges()) { + Annotation annotation = holder.createErrorAnnotation(textRange, diagnostic.getMessage()); + annotation.setTextAttributes(JetHighlightingColors.INVALID_STRING_ESCAPE); + } + } + if (diagnostic instanceof RedeclarationDiagnostic) { RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic)diagnostic; registerQuickFix(markRedeclaration(redeclarations, redeclarationDiagnostic, holder), diagnostic); From 7e4cfb5f3e1b6f0dbd012077af410ad93872ff88 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 20:50:36 +0400 Subject: [PATCH 18/38] Added highlighting for operator signs and other punctuation. --- .../highlighter/JetColorSettingsPage.java | 12 +++- .../plugin/highlighter/JetHighlighter.java | 16 ++++++ .../highlighter/JetHighlightingColors.java | 55 +++++++++++++++++-- .../SoftKeywordsHighlightingVisitor.java | 6 +- 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 11ed1ca98e0..3e7ac7a0088 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -105,6 +105,17 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.valid.escape.in.string"), JetHighlightingColors.VALID_STRING_ESCAPE), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string"), JetHighlightingColors.INVALID_STRING_ESCAPE), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.operator.sign"), JetHighlightingColors.OPERATOR_SIGN), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parentheses"), JetHighlightingColors.PARENTHESIS), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.braces"), JetHighlightingColors.BRACES), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.brackets"), JetHighlightingColors.BRACKETS), + new AttributesDescriptor("Function literal braces", JetHighlightingColors.FUNCTION_LITERAL_BRACES), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.comma"), JetHighlightingColors.COMMA), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.semicolon"), JetHighlightingColors.SEMICOLON), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.dot"), JetHighlightingColors.DOT), + new AttributesDescriptor("Safe access dot", JetHighlightingColors.SAFE_ACCESS), + new AttributesDescriptor("Arrow", JetHighlightingColors.ARROW), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), new AttributesDescriptor("KDoc comment", JetHighlightingColors.DOC_COMMENT), @@ -115,7 +126,6 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), - new AttributesDescriptor("Function literal bracket", JetHighlightingColors.FUNCTION_LITERAL_BRACKET), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index 7164b512b90..cfdfa989d44 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -24,6 +24,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lexer.JetLexer; import org.jetbrains.jet.lexer.JetTokens; @@ -59,6 +60,21 @@ public class JetHighlighter extends SyntaxHighlighterBase { keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER); keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER); + fillMap(keys1, JetTokens.OPERATIONS.minus( + TokenSet.create(JetTokens.IDENTIFIER, JetTokens.LABEL_IDENTIFIER)).minus( + JetTokens.KEYWORDS), JetHighlightingColors.OPERATOR_SIGN); + keys1.put(JetTokens.LPAR, JetHighlightingColors.PARENTHESIS); + keys1.put(JetTokens.RPAR, JetHighlightingColors.PARENTHESIS); + keys1.put(JetTokens.LBRACE, JetHighlightingColors.BRACES); + keys1.put(JetTokens.RBRACE, JetHighlightingColors.BRACES); + keys1.put(JetTokens.LBRACKET, JetHighlightingColors.BRACKETS); + keys1.put(JetTokens.RBRACKET, JetHighlightingColors.BRACKETS); + keys1.put(JetTokens.COMMA, JetHighlightingColors.COMMA); + keys1.put(JetTokens.SEMICOLON, JetHighlightingColors.SEMICOLON); + keys1.put(JetTokens.DOT, JetHighlightingColors.DOT); + keys1.put(JetTokens.SAFE_ACCESS, JetHighlightingColors.SAFE_ACCESS); + keys1.put(JetTokens.ARROW, JetHighlightingColors.ARROW); + keys1.put(JetTokens.OPEN_QUOTE, JetHighlightingColors.STRING); keys1.put(JetTokens.CLOSING_QUOTE, JetHighlightingColors.STRING); keys1.put(JetTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING); diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 96f3fd62730..34030dad8cd 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -56,6 +56,56 @@ public class JetHighlightingColors { SyntaxHighlighterColors.INVALID_STRING_ESCAPE.getDefaultAttributes() ); + public static final TextAttributesKey OPERATOR_SIGN = TextAttributesKey.createTextAttributesKey( + "KOTLIN_OPERATION_SIGN", + SyntaxHighlighterColors.OPERATION_SIGN.getDefaultAttributes() + ); + + public static final TextAttributesKey PARENTHESIS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_PARENTHESIS", + SyntaxHighlighterColors.PARENTHS.getDefaultAttributes() + ); + + public static final TextAttributesKey BRACES = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BRACES", + SyntaxHighlighterColors.BRACES.getDefaultAttributes() + ); + + public static final TextAttributesKey BRACKETS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BRACKETS", + SyntaxHighlighterColors.BRACKETS.getDefaultAttributes() + ); + + public static final TextAttributesKey FUNCTION_LITERAL_BRACES = TextAttributesKey.createTextAttributesKey( + "KOTLIN_FUNCTION_LITERAL_BRACES", + new TextAttributes(null, null, null, null, Font.BOLD) + ); + + public static final TextAttributesKey COMMA = TextAttributesKey.createTextAttributesKey( + "KOTLIN_COMMA", + SyntaxHighlighterColors.COMMA.getDefaultAttributes() + ); + + public static final TextAttributesKey SEMICOLON = TextAttributesKey.createTextAttributesKey( + "KOTLIN_SEMICOLON", + SyntaxHighlighterColors.JAVA_SEMICOLON.getDefaultAttributes() + ); + + public static final TextAttributesKey DOT = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DOT", + SyntaxHighlighterColors.DOT.getDefaultAttributes() + ); + + public static final TextAttributesKey SAFE_ACCESS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_SAFE_ACCESS", + SyntaxHighlighterColors.DOT.getDefaultAttributes() + ); + + public static final TextAttributesKey ARROW = TextAttributesKey.createTextAttributesKey( + "KOTLIN_ARROW", + SyntaxHighlighterColors.PARENTHS.getDefaultAttributes() + ); + public static final TextAttributesKey LINE_COMMENT = TextAttributesKey.createTextAttributesKey( "KOTLIN_LINE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes() @@ -92,11 +142,6 @@ public class JetHighlightingColors { new TextAttributes(null, null, null, null, Font.BOLD) ); - public static final TextAttributesKey FUNCTION_LITERAL_BRACKET = TextAttributesKey.createTextAttributesKey( - "KOTLIN_FUNCTION_LITERAL_BRACKET", - new TextAttributes(null, null, null, null, Font.BOLD) - ); - public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey( "KOTLIN_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes() diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java index 0aa1ea36870..27f90d405c9 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java @@ -55,14 +55,14 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { if (ApplicationManager.getApplication().isUnitTestMode()) return; JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); - holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); ASTNode closingBraceNode = functionLiteral.getClosingBraceNode(); if (closingBraceNode != null) { - holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); } ASTNode arrowNode = functionLiteral.getArrowNode(); if (arrowNode != null) { - holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACKET); + holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); } } From 537b2733dcb981838619b7dd878187579dab1539 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 21:42:01 +0400 Subject: [PATCH 19/38] Added settings for highlighting KDoc parts. --- .../plugin/highlighter/JetColorSettingsPage.java | 3 +++ .../plugin/highlighter/JetHighlightingColors.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 3e7ac7a0088..5b7ed79569f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -119,6 +119,9 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), new AttributesDescriptor("KDoc comment", JetHighlightingColors.DOC_COMMENT), + new AttributesDescriptor("KDoc tag", JetHighlightingColors.DOC_COMMENT_TAG), + new AttributesDescriptor("KDoc tag value", JetHighlightingColors.DOC_COMMENT_TAG_VALUE), + new AttributesDescriptor("KDoc markup", JetHighlightingColors.DOC_COMMENT_MARKUP), new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 34030dad8cd..26377385413 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -121,6 +121,21 @@ public class JetHighlightingColors { SyntaxHighlighterColors.DOC_COMMENT.getDefaultAttributes() ); + public static final TextAttributesKey DOC_COMMENT_TAG = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DOC_COMMENT_TAG", + SyntaxHighlighterColors.DOC_COMMENT_TAG.getDefaultAttributes() + ); + + public static final TextAttributesKey DOC_COMMENT_TAG_VALUE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DOC_COMMENT_TAG_VALUE", + CodeInsightColors.DOC_COMMENT_TAG_VALUE.getDefaultAttributes() + ); + + public static final TextAttributesKey DOC_COMMENT_MARKUP = TextAttributesKey.createTextAttributesKey( + "KOTLIN_DOC_COMMENT_MARKUP", + SyntaxHighlighterColors.DOC_COMMENT_MARKUP.getDefaultAttributes() + ); + // TODO review: is it needed? public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( "KOTLIN_WRAPPED_INTO_REF", From 7efc1bcb5cace97a9eda0455624718b83ac57505 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 22:56:25 +0400 Subject: [PATCH 20/38] Added highlighting for classes, abstract classes, traits and type parameters. --- .../highlighter/JetColorSettingsPage.java | 5 ++ .../highlighter/JetHighlightingColors.java | 20 +++++ .../jet/plugin/highlighter/JetPsiChecker.java | 1 + .../TypeKindHighlightingVisitor.java | 87 +++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 5b7ed79569f..8c5d66d661a 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -123,6 +123,11 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("KDoc tag value", JetHighlightingColors.DOC_COMMENT_TAG_VALUE), new AttributesDescriptor("KDoc markup", JetHighlightingColors.DOC_COMMENT_MARKUP), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.class"), JetHighlightingColors.CLASS), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), + new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), + new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 26377385413..d035acadc2a 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -136,6 +136,26 @@ public class JetHighlightingColors { SyntaxHighlighterColors.DOC_COMMENT_MARKUP.getDefaultAttributes() ); + public static final TextAttributesKey CLASS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_CLASS", + CodeInsightColors.CLASS_NAME_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey TYPE_PARAMETER = TextAttributesKey.createTextAttributesKey( + "KOTLIN_TYPE_PARAMETER", + CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey ABSTRACT_CLASS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_ABSTRACT_CLASS", + CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey TRAIT = TextAttributesKey.createTextAttributesKey( + "KOTLIN_TRAIT", + CodeInsightColors.INTERFACE_NAME_ATTRIBUTES.getDefaultAttributes() + ); + // TODO review: is it needed? public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( "KOTLIN_WRAPPED_INTO_REF", diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 4ce6180a790..d136a1bb452 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -59,6 +59,7 @@ public class JetPsiChecker implements Annotator { return new HighlightingVisitor[]{ new SoftKeywordsHighlightingVisitor(holder), new LabelsHighlightingVisitor(holder), + new TypeKindHighlightingVisitor(holder), }; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java new file mode 100644 index 00000000000..53d89a91639 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.Annotation; +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lexer.JetTokens; + +/** + * @author Evgeny Gerashchenko + * @since 3/29/12 + */ +class TypeKindHighlightingVisitor extends HighlightingVisitor { + protected TypeKindHighlightingVisitor(AnnotationHolder holder) { + super(holder); + } + + private void visitNameExpression(JetExpression expression) { + PsiReference ref = expression.getReference(); + if (ref == null) return; + PsiElement target = ref.resolve(); + if (target instanceof JetClass) { + highlightClassByKind((JetClass)target, expression); + } else if (target instanceof JetTypeParameter) { + holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.TYPE_PARAMETER); + } + } + + @Override + public void visitSimpleNameExpression(JetSimpleNameExpression expression) { + visitNameExpression(expression); + } + + @Override + public void visitQualifiedExpression(JetQualifiedExpression expression) { + visitNameExpression(expression); + } + + @Override + public void visitTypeParameter(JetTypeParameter parameter) { + PsiElement identifier = parameter.getNameIdentifier(); + if (identifier != null) { + holder.createInfoAnnotation(identifier, null).setTextAttributes(JetHighlightingColors.TYPE_PARAMETER); + } + } + + @Override + public void visitClass(JetClass klass) { + PsiElement identifier = klass.getNameIdentifier(); + if (identifier != null) { + highlightClassByKind(klass, identifier); + } + } + + private void highlightClassByKind(@NotNull JetClass klass, @NotNull PsiElement whatToHighlight) { + TextAttributesKey textAttributes = JetHighlightingColors.CLASS; + if (klass.isTrait()) { + textAttributes = JetHighlightingColors.TRAIT; + } else { + JetModifierList modifierList = klass.getModifierList(); + if (modifierList != null && modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { + textAttributes = JetHighlightingColors.ABSTRACT_CLASS; + } + } + Annotation annotation = holder.createInfoAnnotation(whatToHighlight, null); + annotation.setTextAttributes(textAttributes); + } +} From f8618fb9b1a15809f9fbf97fcb85528209471236 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 23:16:35 +0400 Subject: [PATCH 21/38] Made highlighting for annotations valid. Renamed "Soft keyword" entry to "Built-in annotation" --- .../highlighter/JetColorSettingsPage.java | 3 ++- .../highlighter/JetHighlightingColors.java | 9 +++++-- .../SoftKeywordsHighlightingVisitor.java | 24 +------------------ .../TypeKindHighlightingVisitor.java | 22 +++++++++++++++-- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 8c5d66d661a..1a705153847 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -98,7 +98,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { // TODO i18n return new AttributesDescriptor[]{ new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), - new AttributesDescriptor("Soft keyword", JetHighlightingColors.SOFT_KEYWORD), + new AttributesDescriptor("Built-in annotation", JetHighlightingColors.BUILTIN_ANNOTATION), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.number"), JetHighlightingColors.NUMBER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), @@ -127,6 +127,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), + new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index d035acadc2a..c135138e569 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -31,8 +31,8 @@ public class JetHighlightingColors { SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); - public static final TextAttributesKey SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_SOFT_KEYWORD", + public static final TextAttributesKey BUILTIN_ANNOTATION = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BUILTIN_ANNOTATION", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); @@ -156,6 +156,11 @@ public class JetHighlightingColors { CodeInsightColors.INTERFACE_NAME_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey ANNOTATION = TextAttributesKey.createTextAttributesKey( + "KOTLIN_ANNOTATION", + CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() + ); + // TODO review: is it needed? public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( "KOTLIN_WRAPPED_INTO_REF", diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java index 27f90d405c9..4dacbfc30cf 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java @@ -24,7 +24,6 @@ import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.tree.LeafPsiElement; -import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetTokens; @@ -37,20 +36,11 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { public void visitElement(PsiElement element) { if (element instanceof LeafPsiElement) { if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { - holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); + holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.KEYWORD); } } } - @Override - public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { - JetTypeReference typeReference = annotationEntry.getTypeReference(); - if (typeReference != null) { - JetTypeElement typeElement = typeReference.getTypeElement(); - markAnnotationIdentifiers(typeElement, holder); - } - } - @Override public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { if (ApplicationManager.getApplication().isUnitTestMode()) return; @@ -65,16 +55,4 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); } } - - private static void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) { - if (typeElement instanceof JetUserType) { - JetUserType userType = (JetUserType) typeElement; - if (userType.getQualifier() == null) { - JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); - if (referenceExpression != null) { - holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); - } - } - } - } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java index 53d89a91639..a72c6a1b857 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java @@ -34,6 +34,20 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { super(holder); } + @Override + public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { + JetTypeReference typeReference = annotationEntry.getTypeReference(); + if (typeReference == null) return; + JetTypeElement typeElement = typeReference.getTypeElement(); + if (!(typeElement instanceof JetUserType)) return; + JetUserType userType = (JetUserType)typeElement; + if (userType.getQualifier() != null) return; + JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); + if (referenceExpression != null) { + holder.createInfoAnnotation(referenceExpression.getNode(), null).setTextAttributes(JetHighlightingColors.ANNOTATION); + } + } + private void visitNameExpression(JetExpression expression) { PsiReference ref = expression.getReference(); if (ref == null) return; @@ -77,8 +91,12 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { textAttributes = JetHighlightingColors.TRAIT; } else { JetModifierList modifierList = klass.getModifierList(); - if (modifierList != null && modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { - textAttributes = JetHighlightingColors.ABSTRACT_CLASS; + if (modifierList != null) { + if (modifierList.hasModifier(JetTokens.ANNOTATION_KEYWORD)) { + textAttributes = JetHighlightingColors.ANNOTATION; + } else if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { + textAttributes = JetHighlightingColors.ABSTRACT_CLASS; + } } } Annotation annotation = holder.createInfoAnnotation(whatToHighlight, null); From 696e6828ea10c9e184adbf9f0084d6fa3d27993e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 15:24:48 +0400 Subject: [PATCH 22/38] Added highlighting for local variables. --- .../highlighter/JetColorSettingsPage.java | 4 ++- .../highlighter/JetHighlightingColors.java | 13 ++++++++-- .../VariablesHighlightingVisitor.java | 26 ++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 1a705153847..b62dba85a99 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -129,7 +129,9 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), - new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), + new AttributesDescriptor("Closure or anonymous object bound variable", JetHighlightingColors.WRAPPED_INTO_REF), + new AttributesDescriptor("Read-only local variable (val)", JetHighlightingColors.LOCAL_VAL), + new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index c135138e569..8d51c8c4c5d 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -161,10 +161,19 @@ public class JetHighlightingColors { CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() ); - // TODO review: is it needed? + public static final TextAttributesKey LOCAL_VAL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LOCAL_VAL", + CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey LOCAL_VAR = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LOCAL_VAR", + CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() + ); + public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( "KOTLIN_WRAPPED_INTO_REF", - new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, Font.PLAIN) + CodeInsightColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES.getDefaultAttributes() ); public static final TextAttributesKey INSTANCE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index 9b18f41fdb6..b53c1ff8ee0 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -16,14 +16,17 @@ package org.jetbrains.jet.plugin.highlighter; -import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.psi.JetElement; +import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.psi.JetProperty; +import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; @@ -45,18 +48,21 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } } - markVariableAsWrappedIfNeeded(expression.getNode(), target); + highlightVariable(expression, target); super.visitSimpleNameExpression(expression); } - private void markVariableAsWrappedIfNeeded(@NotNull ASTNode node, DeclarationDescriptor target) { - if (target instanceof VariableDescriptor) { - VariableDescriptor variableDescriptor = (VariableDescriptor) target; + private void highlightVariable(@NotNull PsiElement elementToHighlight, DeclarationDescriptor descriptor) { + if (descriptor instanceof LocalVariableDescriptor) { + LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { - holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( JetHighlightingColors.WRAPPED_INTO_REF); } - + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( + variableDescriptor.isVar() ? + JetHighlightingColors.LOCAL_VAR : + JetHighlightingColors.LOCAL_VAL); } } @@ -65,7 +71,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property); PsiElement nameIdentifier = property.getNameIdentifier(); if (nameIdentifier != null) { - markVariableAsWrappedIfNeeded(nameIdentifier.getNode(), declarationDescriptor); + highlightVariable(nameIdentifier, declarationDescriptor); } super.visitProperty(property); } @@ -77,7 +83,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes( JetHighlightingColors.AUTO_CASTED_VALUE); } - expression.acceptChildren(this); + super.visitExpression(expression); } @Override From 06cae390e7685bd121760d1cbc519af5aca3910c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 19:00:01 +0400 Subject: [PATCH 23/38] Added highlighting for properties depending on their container and presence of backing field. --- .../BackingFieldHighlightingVisitor.java | 68 ------------- .../highlighter/JetColorSettingsPage.java | 5 + .../plugin/highlighter/JetHighlighter.java | 1 - .../highlighter/JetHighlightingColors.java | 28 +++++- .../jet/plugin/highlighter/JetPsiChecker.java | 2 +- .../PropertiesHighlightingVisitor.java | 95 +++++++++++++++++++ 6 files changed, 127 insertions(+), 72 deletions(-) delete mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java deleted file mode 100644 index 903fadd93b5..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/BackingFieldHighlightingVisitor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.highlighter; - -import com.intellij.lang.annotation.AnnotationHolder; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.BindingContext; - -class BackingFieldHighlightingVisitor extends AfterAnalysisHighlightingVisitor { - BackingFieldHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { - super(holder, bindingContext); - } - - @Override - public void visitProperty(@NotNull JetProperty property) { - VariableDescriptor propertyDescriptor = bindingContext.get(BindingContext.VARIABLE, property); - if (propertyDescriptor instanceof PropertyDescriptor) { - Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor)propertyDescriptor); - if (Boolean.TRUE.equals(backingFieldRequired)) { - putBackingFieldAnnotation(holder, property); - } - } - } - - @Override - public void visitParameter(@NotNull JetParameter parameter) { - PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); - if (propertyDescriptor != null) { - Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor); - if (Boolean.TRUE.equals(backingFieldRequired)) { - putBackingFieldAnnotation(holder, parameter); - } - } - } - - @Override - public void visitJetElement(@NotNull JetElement element) { - element.acceptChildren(this); - } - - private static void putBackingFieldAnnotation(@NotNull AnnotationHolder holder, @NotNull JetNamedDeclaration element) { - PsiElement nameIdentifier = element.getNameIdentifier(); - if (nameIdentifier != null) { - holder.createInfoAnnotation( - nameIdentifier, - "This property has a backing field") - .setTextAttributes(JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index b62dba85a99..a04b165ff4f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -133,9 +133,14 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Read-only local variable (val)", JetHighlightingColors.LOCAL_VAL), new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), + new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), + new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), + new AttributesDescriptor("Namespace property with backing field", JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD), + new AttributesDescriptor("Namespace property backing field access", JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS), + new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index cfdfa989d44..be74e14d5ea 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -56,7 +56,6 @@ public class JetHighlighter extends SyntaxHighlighterBase { keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD); keys1.put(JetTokens.LABEL_IDENTIFIER, JetHighlightingColors.LABEL); keys1.put(JetTokens.ATAT, JetHighlightingColors.LABEL); - keys1.put(JetTokens.FIELD_IDENTIFIER, JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS); keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER); keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER); diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 8d51c8c4c5d..cd36eec9c19 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -176,9 +176,17 @@ public class JetHighlightingColors { CodeInsightColors.IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey INSTANCE_PROPERTY = TextAttributesKey.createTextAttributesKey( + "KOTLIN_INSTANCE_PROPERTY", + CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + public static final TextAttributesKey INSTANCE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( "KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD", - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + TextAttributes + .fromFlyweight(CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + .getFlyweight().withEffectType(EffectType.BOLD_DOTTED_LINE).withEffectColor( + CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); public static final TextAttributesKey INSTANCE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( @@ -186,6 +194,22 @@ public class JetHighlightingColors { CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey NAMESPACE_PROPERTY = TextAttributesKey.createTextAttributesKey( + "KOTLIN_NAMESPACE_PROPERTY", + CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey NAMESPACE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_NAMESPACE_PROPERTY_WITH_BACKING_FIELD", + TextAttributes.fromFlyweight(CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() + .getFlyweight().withEffectType(EffectType.BOLD_DOTTED_LINE).withEffectColor( + CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); + + public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS", + CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = TextAttributesKey.createTextAttributesKey( "KOTLIN_CLOSURE_DEFAULT_PARAMETER", new TextAttributes(null, null, null, null, Font.BOLD) @@ -203,7 +227,7 @@ public class JetHighlightingColors { public static final TextAttributesKey LABEL = TextAttributesKey.createTextAttributesKey( "KOTLIN_LABEL", - new TextAttributes(new Color(74, 134, 232), null, null, null, Font.PLAIN) + new TextAttributes(new Color(0x4a86e8), null, null, null, Font.PLAIN) ); public static final TextAttributesKey DEBUG_INFO = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index d136a1bb452..820443ce9c7 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -65,7 +65,7 @@ public class JetPsiChecker implements Annotator { private static HighlightingVisitor[] getAfterAnalysisVisitor(AnnotationHolder holder, BindingContext bindingContext) { return new AfterAnalysisHighlightingVisitor[]{ - new BackingFieldHighlightingVisitor(holder, bindingContext), + new PropertiesHighlightingVisitor(holder, bindingContext), new VariablesHighlightingVisitor(holder, bindingContext), }; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java new file mode 100644 index 00000000000..6ad441e6fa4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; +import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lexer.JetTokens; + +class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { + PropertiesHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder, bindingContext); + } + + @Override + public void visitSimpleNameExpression(JetSimpleNameExpression expression) { + // TODO highlight extension properties + DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); + if (!(target instanceof PropertyDescriptor)) { + return; + } + + boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; + if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { + holder.createInfoAnnotation(expression, null).setTextAttributes( + (namespace ? + JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS : + JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS) + ); + } else { + putPropertyAnnotation(expression, namespace, false); + } + } + + @Override + public void visitProperty(@NotNull JetProperty property) { + PsiElement nameIdentifier = property.getNameIdentifier(); + if (nameIdentifier == null) return; + VariableDescriptor propertyDescriptor = bindingContext.get(BindingContext.VARIABLE, property); + if (propertyDescriptor instanceof PropertyDescriptor) { + Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor)propertyDescriptor); + boolean namespace = propertyDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor; + putPropertyAnnotation(nameIdentifier, namespace, Boolean.TRUE.equals(backingFieldRequired)); + } + } + + @Override + public void visitParameter(@NotNull JetParameter parameter) { + PsiElement nameIdentifier = parameter.getNameIdentifier(); + if (nameIdentifier == null) return; + PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); + if (propertyDescriptor != null) { + Boolean backingFieldRequired = bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor); + putPropertyAnnotation(nameIdentifier, false, Boolean.TRUE.equals(backingFieldRequired)); + } + } + + @Override + public void visitJetElement(@NotNull JetElement element) { + element.acceptChildren(this); + } + + private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) { + holder.createInfoAnnotation( + elementToHighlight, + "This property has a backing field") + .setTextAttributes(withBackingField ? + (namespace + ? JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD + : JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD) : + (namespace + ? JetHighlightingColors.NAMESPACE_PROPERTY + : JetHighlightingColors.INSTANCE_PROPERTY)); + } +} From 06e27d7a8c893f188fa4bcb1d81b434107c19404 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 19:45:41 +0400 Subject: [PATCH 24/38] Added highlighting for extension properties. Fixed a couple of property-highlighting problems. Made visitProperty() recursive to avoid skipping getters/setters parsing. Tuned style for properties with backing fields a little. --- .../jet/plugin/highlighter/JetColorSettingsPage.java | 2 ++ .../jet/plugin/highlighter/JetHighlightingColors.java | 11 ++++++++--- .../highlighter/PropertiesHighlightingVisitor.java | 9 ++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index a04b165ff4f..7539696df3c 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -141,6 +141,8 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Namespace property with backing field", JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD), new AttributesDescriptor("Namespace property backing field access", JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS), + new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), + new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index cd36eec9c19..5161be6dac3 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -185,7 +185,7 @@ public class JetHighlightingColors { "KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD", TextAttributes .fromFlyweight(CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.BOLD_DOTTED_LINE).withEffectColor( + .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); @@ -202,12 +202,17 @@ public class JetHighlightingColors { public static final TextAttributesKey NAMESPACE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( "KOTLIN_NAMESPACE_PROPERTY_WITH_BACKING_FIELD", TextAttributes.fromFlyweight(CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.BOLD_DOTTED_LINE).withEffectColor( + .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( "KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS", - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() + CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey( + "KOTLIN_EXTENSION_PROPERTY", + CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() ); public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java index 6ad441e6fa4..bf2b740394d 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lexer.JetTokens; class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { @@ -34,12 +35,16 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { @Override public void visitSimpleNameExpression(JetSimpleNameExpression expression) { - // TODO highlight extension properties DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); if (!(target instanceof PropertyDescriptor)) { return; } + if (((PropertyDescriptor)target).getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) { + holder.createInfoAnnotation(expression, null).setTextAttributes( + JetHighlightingColors.EXTENSION_PROPERTY); + } + boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { holder.createInfoAnnotation(expression, null).setTextAttributes( @@ -62,6 +67,8 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { boolean namespace = propertyDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor; putPropertyAnnotation(nameIdentifier, namespace, Boolean.TRUE.equals(backingFieldRequired)); } + + super.visitProperty(property); } @Override From 80c70616f04c7f85bbb7c8a516809ebf07644261 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 19:59:38 +0400 Subject: [PATCH 25/38] Made styles for properties cascading, and therefore easier to tune. --- .../highlighter/JetColorSettingsPage.java | 8 ++--- .../highlighter/JetHighlightingColors.java | 28 +++++------------ .../PropertiesHighlightingVisitor.java | 30 ++++++++----------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 7539696df3c..450be1cc166 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -134,13 +134,9 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), - new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), - new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), - new AttributesDescriptor("Namespace property with backing field", JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor("Namespace property backing field access", JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS), - + new AttributesDescriptor("Property with backing field", JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD), + new AttributesDescriptor("Property backing field access", JetHighlightingColors.BACKING_FIELD_ACCESS), new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 5161be6dac3..ddae95925df 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -181,33 +181,19 @@ public class JetHighlightingColors { CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey INSTANCE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD", - TextAttributes - .fromFlyweight(CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) - ); - - public static final TextAttributesKey INSTANCE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( - "KOTLIN_INSTANCE_BACKING_FIELD_ACCESS", - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() - ); - public static final TextAttributesKey NAMESPACE_PROPERTY = TextAttributesKey.createTextAttributesKey( "KOTLIN_NAMESPACE_PROPERTY", CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey NAMESPACE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_NAMESPACE_PROPERTY_WITH_BACKING_FIELD", - TextAttributes.fromFlyweight(CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( - CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); + public static final TextAttributesKey PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_PROPERTY_WITH_BACKING_FIELD", + new TextAttributes(null, null, INSTANCE_PROPERTY.getDefaultAttributes().getForegroundColor(), EffectType.LINE_UNDERSCORE, 0) +); - public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( - "KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS", - CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() + public static final TextAttributesKey BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BACKING_FIELD_ACCESS", + new TextAttributes() ); public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java index bf2b740394d..f12ed88d807 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -46,14 +46,9 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; + putPropertyAnnotation(expression, namespace, false); if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { - holder.createInfoAnnotation(expression, null).setTextAttributes( - (namespace ? - JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS : - JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS) - ); - } else { - putPropertyAnnotation(expression, namespace, false); + holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.BACKING_FIELD_ACCESS); } } @@ -88,15 +83,16 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) { - holder.createInfoAnnotation( - elementToHighlight, - "This property has a backing field") - .setTextAttributes(withBackingField ? - (namespace - ? JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD - : JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD) : - (namespace - ? JetHighlightingColors.NAMESPACE_PROPERTY - : JetHighlightingColors.INSTANCE_PROPERTY)); + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( + namespace + ? JetHighlightingColors.NAMESPACE_PROPERTY + : JetHighlightingColors.INSTANCE_PROPERTY + ); + if (withBackingField) { + holder.createInfoAnnotation( + elementToHighlight, + "This property has a backing field") + .setTextAttributes(JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD); + } } } From 5863111124baea8fa4a9275b8ca651a652a8d654 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 20:25:06 +0400 Subject: [PATCH 26/38] Replaced "local var" and "local val" styles with "local variable" and "mutable variable/parameter/property". --- .../highlighter/JetColorSettingsPage.java | 5 +- .../highlighter/JetHighlightingColors.java | 10 +-- .../VariablesHighlightingVisitor.java | 64 +++++++++++-------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 450be1cc166..b3ceb75d972 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -129,9 +129,10 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), + new AttributesDescriptor("Mutable variable, parameter or property", JetHighlightingColors.MUTABLE_VARIABLE), + + new AttributesDescriptor("Local variable", JetHighlightingColors.LOCAL_VARIABLE), new AttributesDescriptor("Closure or anonymous object bound variable", JetHighlightingColors.WRAPPED_INTO_REF), - new AttributesDescriptor("Read-only local variable (val)", JetHighlightingColors.LOCAL_VAL), - new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index ddae95925df..59a8e5e27c6 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -161,14 +161,14 @@ public class JetHighlightingColors { CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey LOCAL_VAL = TextAttributesKey.createTextAttributesKey( - "KOTLIN_LOCAL_VAL", + public static final TextAttributesKey LOCAL_VARIABLE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LOCAL_VARIABLE", CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey LOCAL_VAR = TextAttributesKey.createTextAttributesKey( - "KOTLIN_LOCAL_VAR", - CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() + public static final TextAttributesKey MUTABLE_VARIABLE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_MUTABLE_VARIABLE", + new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, 0) ); public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index b53c1ff8ee0..59ac567f2a1 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -23,10 +23,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.psi.JetElement; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.psi.JetProperty; -import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; +import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; @@ -37,9 +34,17 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super(holder, bindingContext); } + @Override + public void visitJetElement(@NotNull JetElement element) { + element.acceptChildren(this); + } + @Override public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression); + if (target == null) { + return; + } if (target instanceof ValueParameterDescriptor) { ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target; if (Boolean.TRUE.equals(bindingContext.get(AUTO_CREATED_IT, parameterDescriptor))) { @@ -52,28 +57,16 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super.visitSimpleNameExpression(expression); } - private void highlightVariable(@NotNull PsiElement elementToHighlight, DeclarationDescriptor descriptor) { - if (descriptor instanceof LocalVariableDescriptor) { - LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; - if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { - holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( - JetHighlightingColors.WRAPPED_INTO_REF); - } - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( - variableDescriptor.isVar() ? - JetHighlightingColors.LOCAL_VAR : - JetHighlightingColors.LOCAL_VAL); - } + @Override + public void visitProperty(@NotNull JetProperty property) { + visitVariableDeclaration(property); + super.visitProperty(property); } @Override - public void visitProperty(@NotNull JetProperty property) { - DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property); - PsiElement nameIdentifier = property.getNameIdentifier(); - if (nameIdentifier != null) { - highlightVariable(nameIdentifier, declarationDescriptor); - } - super.visitProperty(property); + public void visitParameter(JetParameter parameter) { + visitVariableDeclaration(parameter); + super.visitParameter(parameter); } @Override @@ -86,8 +79,27 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super.visitExpression(expression); } - @Override - public void visitJetElement(@NotNull JetElement element) { - element.acceptChildren(this); + private void visitVariableDeclaration(JetNamedDeclaration declaration) { + DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, declaration); + PsiElement nameIdentifier = declaration.getNameIdentifier(); + if (nameIdentifier != null && declarationDescriptor != null) { + highlightVariable(nameIdentifier, declarationDescriptor); + } + } + + private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) { + if (descriptor instanceof VariableDescriptor) { + if (((VariableDescriptor)descriptor).isVar()) { + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.MUTABLE_VARIABLE); + } + } + if (descriptor instanceof LocalVariableDescriptor) { + LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; + if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { + holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + JetHighlightingColors.WRAPPED_INTO_REF); + } + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.LOCAL_VARIABLE); + } } } From 25bbc912e9416b707a2972becb3c7cd7f84ba1c0 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 20:33:30 +0400 Subject: [PATCH 27/38] Replaced underlining with light purple background for properties with backing fields. --- .../jetbrains/jet/plugin/highlighter/JetHighlightingColors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 59a8e5e27c6..1d76edfb713 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -188,7 +188,7 @@ public class JetHighlightingColors { public static final TextAttributesKey PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( "KOTLIN_PROPERTY_WITH_BACKING_FIELD", - new TextAttributes(null, null, INSTANCE_PROPERTY.getDefaultAttributes().getForegroundColor(), EffectType.LINE_UNDERSCORE, 0) + new TextAttributes(null, new Color(0xf5d7ef), null, null, 0) ); public static final TextAttributesKey BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( From bf8e53efad5ac8305d9531ec581c7e6062deee88 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 20:46:59 +0400 Subject: [PATCH 28/38] Added highlighting for parameters. --- .../plugin/highlighter/JetColorSettingsPage.java | 1 + .../highlighter/JetHighlightingColors.java | 11 ++++++++--- .../VariablesHighlightingVisitor.java | 16 +++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index b3ceb75d972..226871dc80f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -132,6 +132,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Mutable variable, parameter or property", JetHighlightingColors.MUTABLE_VARIABLE), new AttributesDescriptor("Local variable", JetHighlightingColors.LOCAL_VARIABLE), + new AttributesDescriptor("Parameter", JetHighlightingColors.PARAMETER), new AttributesDescriptor("Closure or anonymous object bound variable", JetHighlightingColors.WRAPPED_INTO_REF), new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 1d76edfb713..b25f4e589b8 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -161,14 +161,19 @@ public class JetHighlightingColors { CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey MUTABLE_VARIABLE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_MUTABLE_VARIABLE", + new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, 0) + ); + public static final TextAttributesKey LOCAL_VARIABLE = TextAttributesKey.createTextAttributesKey( "KOTLIN_LOCAL_VARIABLE", CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey MUTABLE_VARIABLE = TextAttributesKey.createTextAttributesKey( - "KOTLIN_MUTABLE_VARIABLE", - new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, 0) + public static final TextAttributesKey PARAMETER = TextAttributesKey.createTextAttributesKey( + "KOTLIN_PARAMETER", + CodeInsightColors.PARAMETER_ATTRIBUTES.getDefaultAttributes() ); public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index 59ac567f2a1..34ca797f29c 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -89,17 +89,23 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) { if (descriptor instanceof VariableDescriptor) { - if (((VariableDescriptor)descriptor).isVar()) { + VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor; + if (variableDescriptor.isVar()) { holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.MUTABLE_VARIABLE); } - } - if (descriptor instanceof LocalVariableDescriptor) { - LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; + if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( JetHighlightingColors.WRAPPED_INTO_REF); } - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.LOCAL_VARIABLE); + + if (descriptor instanceof LocalVariableDescriptor) { + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.LOCAL_VARIABLE); + } + + if (descriptor instanceof ValueParameterDescriptor) { + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.PARAMETER); + } } } } From 028cc74970520331f2a5974b2688b02edb8c2f94 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 15:35:18 +0400 Subject: [PATCH 29/38] Changed highlighting for auto-casted value from green foreground to light green background. --- .../jetbrains/jet/plugin/highlighter/JetHighlightingColors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index b25f4e589b8..4cd1f3171a8 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -218,7 +218,7 @@ public class JetHighlightingColors { public static final TextAttributesKey AUTO_CASTED_VALUE = TextAttributesKey.createTextAttributesKey( "KOTLIN_AUTO_CASTED_VALUE", - new TextAttributes(STRING.getDefaultAttributes().getForegroundColor(), null, null, null, Font.PLAIN) + new TextAttributes(null, new Color(0xdbffdb), null, null, Font.PLAIN) ); public static final TextAttributesKey LABEL = TextAttributesKey.createTextAttributesKey( From 8a4e07e3e59fd91c22caa909d52367f16b1cecc4 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 17:09:12 +0400 Subject: [PATCH 30/38] Added highlighting for function/constructor calls and declarations. --- .../FunctionsHighlightingVisitor.java | 99 +++++++++++++++++++ .../highlighter/JetColorSettingsPage.java | 5 + .../highlighter/JetHighlightingColors.java | 25 +++++ .../jet/plugin/highlighter/JetPsiChecker.java | 1 + 4 files changed, 130 insertions(+) create mode 100644 idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java new file mode 100644 index 00000000000..6cb32e4a138 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java @@ -0,0 +1,99 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.highlighter; + +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.psi.PsiElement; +import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; + +/** + * @author Evgeny Gerashchenko + * @since 4/2/12 + */ +public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisitor { + public FunctionsHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder, bindingContext); + } + + @Override + public void visitJetElement(JetElement element) { + element.acceptChildren(this); + } + + @Override + public void visitNamedFunction(JetNamedFunction function) { + PsiElement nameIdentifier = function.getNameIdentifier(); + if (nameIdentifier != null) { + holder.createInfoAnnotation(nameIdentifier, null).setTextAttributes( + JetHighlightingColors.FUNCTION_DECLARATION); + } + + super.visitNamedFunction(function); + } + + @Override + public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) { + JetConstructorCalleeExpression calleeExpression = call.getCalleeExpression(); + JetTypeReference typeRef = calleeExpression.getTypeReference(); + if (typeRef != null) { + JetTypeElement typeElement = typeRef.getTypeElement(); + if (typeElement instanceof JetUserType) { + JetSimpleNameExpression nameExpression = ((JetUserType)typeElement).getReferenceExpression(); + if (nameExpression != null) { + holder.createInfoAnnotation(nameExpression, null).setTextAttributes( + JetHighlightingColors.CONSTRUCTOR_CALL); + } + } + } + super.visitDelegationToSuperCallSpecifier(call); + } + + @Override + public void visitCallExpression(JetCallExpression expression) { + JetExpression callee = expression.getCalleeExpression(); + if (callee instanceof JetReferenceExpression) { + DeclarationDescriptor calleeDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetReferenceExpression)callee); + if (calleeDescriptor != null) { + if (calleeDescriptor instanceof ConstructorDescriptor) { + holder.createInfoAnnotation(callee, null).setTextAttributes( + JetHighlightingColors.CONSTRUCTOR_CALL); + } + else if (calleeDescriptor instanceof FunctionDescriptor) { + FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor; + if (fun.getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) { + holder.createInfoAnnotation(callee, null).setTextAttributes( + JetHighlightingColors.EXTENSION_FUNCTION_CALL); + } + else if (fun.getContainingDeclaration() instanceof NamespaceDescriptor) { + holder.createInfoAnnotation(callee, null).setTextAttributes(JetHighlightingColors.NAMESPACE_FUNCTION_CALL); + } + else { + holder.createInfoAnnotation(callee, null).setTextAttributes(JetHighlightingColors.FUNCTION_CALL); + } + } + } + } + + super.visitCallExpression(expression); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 226871dc80f..b9d4580a0f5 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -142,6 +142,11 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), + new AttributesDescriptor("Function declaration", JetHighlightingColors.FUNCTION_DECLARATION), + new AttributesDescriptor("Function call", JetHighlightingColors.FUNCTION_CALL), + new AttributesDescriptor("Namespace function call", JetHighlightingColors.NAMESPACE_FUNCTION_CALL), + new AttributesDescriptor("Extension function call", JetHighlightingColors.EXTENSION_FUNCTION_CALL), + new AttributesDescriptor("Constructor call", JetHighlightingColors.CONSTRUCTOR_CALL), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 4cd1f3171a8..b3ca1bda1c9 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -211,6 +211,31 @@ public class JetHighlightingColors { new TextAttributes(null, null, null, null, Font.BOLD) ); + public static final TextAttributesKey FUNCTION_DECLARATION = TextAttributesKey.createTextAttributesKey( + "KOTLIN_FUNCTION_DECLARATION", + CodeInsightColors.METHOD_DECLARATION_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey FUNCTION_CALL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_FUNCTION_CALL", + CodeInsightColors.METHOD_CALL_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey NAMESPACE_FUNCTION_CALL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_NAMESPACE_FUNCTION_CALL", + CodeInsightColors.STATIC_METHOD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey EXTENSION_FUNCTION_CALL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_EXTENSION_FUNCTION_CALL", + CodeInsightColors.STATIC_METHOD_ATTRIBUTES.getDefaultAttributes() + ); + + public static final TextAttributesKey CONSTRUCTOR_CALL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_CONSTRUCTOR", + CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES.getDefaultAttributes() + ); + public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey( "KOTLIN_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes() diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 820443ce9c7..f4a458d3440 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -66,6 +66,7 @@ public class JetPsiChecker implements Annotator { private static HighlightingVisitor[] getAfterAnalysisVisitor(AnnotationHolder holder, BindingContext bindingContext) { return new AfterAnalysisHighlightingVisitor[]{ new PropertiesHighlightingVisitor(holder, bindingContext), + new FunctionsHighlightingVisitor(holder, bindingContext), new VariablesHighlightingVisitor(holder, bindingContext), }; } From 99b922e582f31a4ef12a0edddf1e5aea88aeaf1d Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 17:27:58 +0400 Subject: [PATCH 31/38] Made proper highlighting for variables invoked as functions. --- .../highlighter/FunctionsHighlightingVisitor.java | 7 ++----- .../highlighter/PropertiesHighlightingVisitor.java | 8 ++++---- .../highlighter/VariablesHighlightingVisitor.java | 10 ++++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java index 6cb32e4a138..0fd08a965a0 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java @@ -18,10 +18,7 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.psi.PsiElement; -import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -78,7 +75,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit holder.createInfoAnnotation(callee, null).setTextAttributes( JetHighlightingColors.CONSTRUCTOR_CALL); } - else if (calleeDescriptor instanceof FunctionDescriptor) { + else if (calleeDescriptor instanceof FunctionDescriptor && !(calleeDescriptor instanceof VariableAsFunctionDescriptor)) { FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor; if (fun.getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) { holder.createInfoAnnotation(callee, null).setTextAttributes( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java index f12ed88d807..f5ef640253e 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -19,10 +19,7 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; -import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -36,6 +33,9 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { @Override public void visitSimpleNameExpression(JetSimpleNameExpression expression) { DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); + if (target instanceof VariableAsFunctionDescriptor) { + target = ((VariableAsFunctionDescriptor)target).getVariableDescriptor(); + } if (!(target instanceof PropertyDescriptor)) { return; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index 34ca797f29c..74cd97b6b91 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -19,10 +19,7 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor; -import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; @@ -88,6 +85,11 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) { + if (descriptor instanceof VariableAsFunctionDescriptor) { + descriptor = ((VariableAsFunctionDescriptor)descriptor).getVariableDescriptor(); + //noinspection ConstantConditions + if (descriptor == null) return; + } if (descriptor instanceof VariableDescriptor) { VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor; if (variableDescriptor.isVar()) { From 09229a6f0762d6b3dc9436b1be4da1fd026a1fdb Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 17:33:33 +0400 Subject: [PATCH 32/38] Removed unnecessary keys2 map from JetHighlighter. --- .../plugin/highlighter/JetHighlighter.java | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java index be74e14d5ea..6f99c1f92ae 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlighter.java @@ -33,8 +33,7 @@ import java.util.HashMap; import java.util.Map; public class JetHighlighter extends SyntaxHighlighterBase { - private static final Map keys1; - private static final Map keys2; + private static final Map keys; @NotNull public Lexer getHighlightingLexer() { @@ -43,52 +42,50 @@ public class JetHighlighter extends SyntaxHighlighterBase { @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { - return pack(keys1.get(tokenType), keys2.get(tokenType)); + return pack(keys.get(tokenType)); } static { - keys1 = new HashMap(); - keys2 = new HashMap(); + keys = new HashMap(); + fillMap(keys, JetTokens.KEYWORDS, JetHighlightingColors.KEYWORD); - fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.KEYWORD); + keys.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD); + keys.put(JetTokens.LABEL_IDENTIFIER, JetHighlightingColors.LABEL); + keys.put(JetTokens.ATAT, JetHighlightingColors.LABEL); + keys.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER); + keys.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER); - keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD); - keys1.put(JetTokens.LABEL_IDENTIFIER, JetHighlightingColors.LABEL); - keys1.put(JetTokens.ATAT, JetHighlightingColors.LABEL); - keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER); - keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER); - - fillMap(keys1, JetTokens.OPERATIONS.minus( + fillMap(keys, JetTokens.OPERATIONS.minus( TokenSet.create(JetTokens.IDENTIFIER, JetTokens.LABEL_IDENTIFIER)).minus( JetTokens.KEYWORDS), JetHighlightingColors.OPERATOR_SIGN); - keys1.put(JetTokens.LPAR, JetHighlightingColors.PARENTHESIS); - keys1.put(JetTokens.RPAR, JetHighlightingColors.PARENTHESIS); - keys1.put(JetTokens.LBRACE, JetHighlightingColors.BRACES); - keys1.put(JetTokens.RBRACE, JetHighlightingColors.BRACES); - keys1.put(JetTokens.LBRACKET, JetHighlightingColors.BRACKETS); - keys1.put(JetTokens.RBRACKET, JetHighlightingColors.BRACKETS); - keys1.put(JetTokens.COMMA, JetHighlightingColors.COMMA); - keys1.put(JetTokens.SEMICOLON, JetHighlightingColors.SEMICOLON); - keys1.put(JetTokens.DOT, JetHighlightingColors.DOT); - keys1.put(JetTokens.SAFE_ACCESS, JetHighlightingColors.SAFE_ACCESS); - keys1.put(JetTokens.ARROW, JetHighlightingColors.ARROW); + keys.put(JetTokens.LPAR, JetHighlightingColors.PARENTHESIS); + keys.put(JetTokens.RPAR, JetHighlightingColors.PARENTHESIS); + keys.put(JetTokens.LBRACE, JetHighlightingColors.BRACES); + keys.put(JetTokens.RBRACE, JetHighlightingColors.BRACES); + keys.put(JetTokens.LBRACKET, JetHighlightingColors.BRACKETS); + keys.put(JetTokens.RBRACKET, JetHighlightingColors.BRACKETS); + keys.put(JetTokens.COMMA, JetHighlightingColors.COMMA); + keys.put(JetTokens.SEMICOLON, JetHighlightingColors.SEMICOLON); + keys.put(JetTokens.DOT, JetHighlightingColors.DOT); + keys.put(JetTokens.SAFE_ACCESS, JetHighlightingColors.SAFE_ACCESS); + keys.put(JetTokens.ARROW, JetHighlightingColors.ARROW); - keys1.put(JetTokens.OPEN_QUOTE, JetHighlightingColors.STRING); - keys1.put(JetTokens.CLOSING_QUOTE, JetHighlightingColors.STRING); - keys1.put(JetTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING); - keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_END, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); + keys.put(JetTokens.OPEN_QUOTE, JetHighlightingColors.STRING); + keys.put(JetTokens.CLOSING_QUOTE, JetHighlightingColors.STRING); + keys.put(JetTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING); + keys.put(JetTokens.LONG_TEMPLATE_ENTRY_END, JetHighlightingColors.VALID_STRING_ESCAPE); + keys.put(JetTokens.LONG_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); + keys.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.ESCAPE_SEQUENCE, JetHighlightingColors.VALID_STRING_ESCAPE); + keys.put(JetTokens.ESCAPE_SEQUENCE, JetHighlightingColors.VALID_STRING_ESCAPE); - keys1.put(JetTokens.CHARACTER_LITERAL, JetHighlightingColors.STRING); + keys.put(JetTokens.CHARACTER_LITERAL, JetHighlightingColors.STRING); - keys1.put(JetTokens.EOL_COMMENT, JetHighlightingColors.LINE_COMMENT); - keys1.put(JetTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT); - keys1.put(JetTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT); + keys.put(JetTokens.EOL_COMMENT, JetHighlightingColors.LINE_COMMENT); + keys.put(JetTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT); + keys.put(JetTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT); - keys1.put(TokenType.BAD_CHARACTER, JetHighlightingColors.BAD_CHARACTER); + keys.put(TokenType.BAD_CHARACTER, JetHighlightingColors.BAD_CHARACTER); } } From 2b72f4f7f9e62e37280387f1c5b093dac16f80f5 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 17:38:23 +0400 Subject: [PATCH 33/38] Made proper tooltips for autocasted values and wrapped-in-a-ref values. --- .../jet/plugin/highlighter/VariablesHighlightingVisitor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index 74cd97b6b91..82e53cc1061 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.resolve.DescriptorRenderer; import static org.jetbrains.jet.lang.resolve.BindingContext.*; @@ -70,7 +71,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { public void visitExpression(@NotNull JetExpression expression) { JetType autoCast = bindingContext.get(AUTOCAST, expression); if (autoCast != null) { - holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes( + holder.createInfoAnnotation(expression, "Automatically cast to " + DescriptorRenderer.TEXT.renderType(autoCast)).setTextAttributes( JetHighlightingColors.AUTO_CASTED_VALUE); } super.visitExpression(expression); @@ -97,7 +98,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { - holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + holder.createInfoAnnotation(elementToHighlight, "Wrapped into a reference object to be modified when captured in a closure").setTextAttributes( JetHighlightingColors.WRAPPED_INTO_REF); } From 3b2eebf5ed341333b69e03b740104e2c7c978517 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 18:50:48 +0400 Subject: [PATCH 34/38] Moved text of color settings to JetBundle. --- .../jetbrains/jet/plugin/JetBundle.properties | 29 +++++++++- .../highlighter/JetColorSettingsPage.java | 58 ++++++++++--------- 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index f8784df1890..8823feeaef3 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -46,4 +46,31 @@ macro.variable.of.type=kotlinVariable() macro.iterable.variable=kotlinIterableVariable() macro.suggest.variable.name=kotlinSuggestVariableName() macro.fun.parameters=functionParameters() -macro.fun.anonymousSuper=anonymousSuper() \ No newline at end of file +macro.fun.anonymousSuper=anonymousSuper() + +options.jet.attribute.descriptor.builtin.annotation=Built-in annotation +options.jet.attribute.descriptor.closure.braces=Function literal braces +options.jet.attribute.descriptor.safe.access=Safe access dot +options.jet.attribute.descriptor.arrow=Arrow +options.jet.attribute.descriptor.kdoc.comment=KDoc comment +options.jet.attribute.descriptor.kdoc.tag=KDoc tag +options.jet.attribute.descriptor.kdoc.tag.value=KDoc tag value +options.jet.attribute.descriptor.kdoc.markup=KDoc markup +options.jet.attribute.descriptor.trait=Trait +options.jet.attribute.descriptor.annotation=Annotation +options.jet.attribute.descriptor.var=Mutable variable, parameter or property (var) +options.jet.attribute.descriptor.local.variable=Local variable +options.jet.attribute.descriptor.bound.variable=Function literal or anonymous object bound variable +options.jet.attribute.descriptor.instance.property=Instance property +options.jet.attribute.descriptor.namespace.property=Namespace property +options.jet.attribute.descriptor.property.with.backing=Property with backing field +options.jet.attribute.descriptor.backing.field.access=Backing field access +options.jet.attribute.descriptor.extension.property=Extension property +options.jet.attribute.descriptor.it=Function literal default parameter +options.jet.attribute.descriptor.fun=Function declaration +options.jet.attribute.descriptor.fun.call=Function call +options.jet.attribute.descriptor.namespace.fun.call=Namespace function call +options.jet.attribute.descriptor.extension.fun.call=Extension function call +options.jet.attribute.descriptor.constructor.call=Constructor call +options.jet.attribute.descriptor.auto.casted=Automatically casted value +options.jet.attribute.descriptor.label=Label diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index b9d4580a0f5..57fe3eef47a 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -23,6 +23,7 @@ import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.JetBundle; import org.jetbrains.jet.plugin.JetIconProvider; import javax.swing.*; @@ -95,10 +96,9 @@ public class JetColorSettingsPage implements ColorSettingsPage { @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { - // TODO i18n return new AttributesDescriptor[]{ new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), - new AttributesDescriptor("Built-in annotation", JetHighlightingColors.BUILTIN_ANNOTATION), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.builtin.annotation"), JetHighlightingColors.BUILTIN_ANNOTATION), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.number"), JetHighlightingColors.NUMBER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), @@ -109,50 +109,52 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parentheses"), JetHighlightingColors.PARENTHESIS), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.braces"), JetHighlightingColors.BRACES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.brackets"), JetHighlightingColors.BRACKETS), - new AttributesDescriptor("Function literal braces", JetHighlightingColors.FUNCTION_LITERAL_BRACES), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.closure.braces"), JetHighlightingColors.FUNCTION_LITERAL_BRACES), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.comma"), JetHighlightingColors.COMMA), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.semicolon"), JetHighlightingColors.SEMICOLON), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.dot"), JetHighlightingColors.DOT), - new AttributesDescriptor("Safe access dot", JetHighlightingColors.SAFE_ACCESS), - new AttributesDescriptor("Arrow", JetHighlightingColors.ARROW), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.safe.access"), JetHighlightingColors.SAFE_ACCESS), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.arrow"), JetHighlightingColors.ARROW), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), - new AttributesDescriptor("KDoc comment", JetHighlightingColors.DOC_COMMENT), - new AttributesDescriptor("KDoc tag", JetHighlightingColors.DOC_COMMENT_TAG), - new AttributesDescriptor("KDoc tag value", JetHighlightingColors.DOC_COMMENT_TAG_VALUE), - new AttributesDescriptor("KDoc markup", JetHighlightingColors.DOC_COMMENT_MARKUP), + + // KDoc highlighting options are temporarily disabled, until actual highlighting and parsing of them is implemented + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.comment"), JetHighlightingColors.DOC_COMMENT), + //new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.tag"), JetHighlightingColors.DOC_COMMENT_TAG), + //new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.tag.value"), JetHighlightingColors.DOC_COMMENT_TAG_VALUE), + //new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.kdoc.markup"), JetHighlightingColors.DOC_COMMENT_MARKUP), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.class"), JetHighlightingColors.CLASS), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), - new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), - new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.trait"), JetHighlightingColors.TRAIT), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.annotation"), JetHighlightingColors.ANNOTATION), - new AttributesDescriptor("Mutable variable, parameter or property", JetHighlightingColors.MUTABLE_VARIABLE), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.var"), JetHighlightingColors.MUTABLE_VARIABLE), - new AttributesDescriptor("Local variable", JetHighlightingColors.LOCAL_VARIABLE), - new AttributesDescriptor("Parameter", JetHighlightingColors.PARAMETER), - new AttributesDescriptor("Closure or anonymous object bound variable", JetHighlightingColors.WRAPPED_INTO_REF), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.local.variable"), JetHighlightingColors.LOCAL_VARIABLE), + new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parameter"), JetHighlightingColors.PARAMETER), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.bound.variable"), JetHighlightingColors.WRAPPED_INTO_REF), - new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), - new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), - new AttributesDescriptor("Property with backing field", JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor("Property backing field access", JetHighlightingColors.BACKING_FIELD_ACCESS), - new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.instance.property"), JetHighlightingColors.INSTANCE_PROPERTY), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.namespace.property"), JetHighlightingColors.NAMESPACE_PROPERTY), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.property.with.backing"), JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.backing.field.access"), JetHighlightingColors.BACKING_FIELD_ACCESS), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.extension.property"), JetHighlightingColors.EXTENSION_PROPERTY), - new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), - new AttributesDescriptor("Function declaration", JetHighlightingColors.FUNCTION_DECLARATION), - new AttributesDescriptor("Function call", JetHighlightingColors.FUNCTION_CALL), - new AttributesDescriptor("Namespace function call", JetHighlightingColors.NAMESPACE_FUNCTION_CALL), - new AttributesDescriptor("Extension function call", JetHighlightingColors.EXTENSION_FUNCTION_CALL), - new AttributesDescriptor("Constructor call", JetHighlightingColors.CONSTRUCTOR_CALL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.it"), JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.fun"), JetHighlightingColors.FUNCTION_DECLARATION), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.fun.call"), JetHighlightingColors.FUNCTION_CALL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.namespace.fun.call"), JetHighlightingColors.NAMESPACE_FUNCTION_CALL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.extension.fun.call"), JetHighlightingColors.EXTENSION_FUNCTION_CALL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.constructor.call"), JetHighlightingColors.CONSTRUCTOR_CALL), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), - new AttributesDescriptor("Automatically casted value", JetHighlightingColors.AUTO_CASTED_VALUE), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.auto.casted"), JetHighlightingColors.AUTO_CASTED_VALUE), - new AttributesDescriptor("Label", JetHighlightingColors.LABEL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.label"), JetHighlightingColors.LABEL), }; } From 8a7d1eaeb8b3fc33ddafdebd2c9d33cf7519d727 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 19:34:57 +0400 Subject: [PATCH 35/38] Reworked sample text in color settings page. Made it compact, but rich. --- .../highlighter/JetColorSettingsPage.java | 56 ++++++++----------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 57fe3eef47a..58d0cb2324c 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -46,45 +46,35 @@ public class JetColorSettingsPage implements ColorSettingsPage { @Override public String getDemoText() { return "/* Block comment */\n" + - "import kotlin.util.*\n" + - " Bad characters: \\n #\n" + - "val globalConst = 0\n" + + "import kotlin.util.* // line comment\n" + + "\n" + + " Bad character: \\n\n" + "/**\n" + " * Doc comment here for `SomeClass`\n" + " * @see Iterator#next()\n" + " */\n" + - "[Annotation]\n" + - "public class SomeClass(param : ATrait, reassignedParam : Array, val paramProperty: String?) { // some comment\n" + - " private field : T {\n" + - " return null\n" + - " }\n" + - " private open unusedField : Double = 12345.67890\n" + - " private anotherString : UnknownType = \"$field Another\\nStrin\\g\";\n" + + "[Deprecated]\n" + + "public class MyClass>(var prop1 : Int) {\n" + + " fun foo(nullable : String?, r : Runnable, f : () -> Int) {\n" + + " println(\"length is ${nullable?.length} \\e\")\n" + + " val ints = java.util.ArrayList(2)\n" + + " ints[0] = 102 + f()\n" + + " var ref = ints.size()\n" + + " if (!ints.empty) {\n" + + " ints.forEach @lit {\n" + + " if (it == null) return @lit\n" + + " println(it + ref)\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + "\n" + - " {\n" + - " paramProperty.?length ?: 33\n" + - " val localVal : Int = \"IntelliJ\" // Error, incompatible types\n" + - " println(anotherString + field + localVar + globalConst)\n" + - " val time = Date.parse(\"1.2.3\") // Method is deprecated\n" + - " var reassignedValue = \"\" as Int\n" + - " reassignedValue++\n" + - " object : Runnable {\n" + - " override fun() {\n" + - " val a = localVar\n" + - " }\n" + - " }\n" + - " reassignedParam = Array(2)\n" + - " reassignedParam[0] = 1\n" + - " reassignedParam.foreach @lit {\n" + - " if (it == 0) return@lit\n" + - " println(it + localVar)\n" + - " }\n" + - " }\n" + + "var globalCounter : Int = 5\n" + + "get() {\n" + + " return $globalCounter\n" + "}\n" + - "trait ATrait {\n" + - " fun memberFun(param : (Int) -> Int)\n" + - "}\n" + - "abstract class SomeAbstractClass {\n" + + "\n" + + "public abstract class Abstract {\n" + "}"; } From 8f6e6065ff7d30a85b22c7a4e29132629a55f7eb Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 2 Apr 2012 21:52:51 +0400 Subject: [PATCH 36/38] Added markup in settings page sample. --- .../highlighter/JetColorSettingsPage.java | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 58d0cb2324c..8e80f0f4016 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -27,7 +27,9 @@ import org.jetbrains.jet.plugin.JetBundle; import org.jetbrains.jet.plugin.JetIconProvider; import javax.swing.*; -import java.util.Collections; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; import java.util.Map; public class JetColorSettingsPage implements ColorSettingsPage { @@ -46,41 +48,52 @@ public class JetColorSettingsPage implements ColorSettingsPage { @Override public String getDemoText() { return "/* Block comment */\n" + - "import kotlin.util.* // line comment\n" + + "import kotlin.util.* // line comment\n" + "\n" + " Bad character: \\n\n" + "/**\n" + " * Doc comment here for `SomeClass`\n" + " * @see Iterator#next()\n" + " */\n" + - "[Deprecated]\n" + - "public class MyClass>(var prop1 : Int) {\n" + - " fun foo(nullable : String?, r : Runnable, f : () -> Int) {\n" + - " println(\"length is ${nullable?.length} \\e\")\n" + - " val ints = java.util.ArrayList(2)\n" + - " ints[0] = 102 + f()\n" + - " var ref = ints.size()\n" + - " if (!ints.empty) {\n" + - " ints.forEach @lit {\n" + - " if (it == null) return @lit\n" + - " println(it + ref)\n" + - " }\n" + + "[Deprecated]\n" + + "public class MyClass<out T : Iterable<T>>(var prop1 : Int) {\n" + + " fun foo(nullable : String?, r : Runnable, f : () -> Int) {\n" + + " println(\"length is ${nullable?.length} \\e\")\n" + + " val ints = java.util.ArrayList(2)\n" + + " ints[0] = 102 + f()\n" + + " var ref = ints.size()\n" + + " if (!ints.empty) {\n" + + " ints.forEach @lit {\n" + + " if (it == null) return @lit\n" + + " println(it + ref)\n" + + " }\n" + " }\n" + " }\n" + "}\n" + "\n" + - "var globalCounter : Int = 5\n" + - "get() {\n" + - " return $globalCounter\n" + + "var globalCounter : Int = 5\n" + + "get() {\n" + + " return $globalCounter\n" + "}\n" + "\n" + - "public abstract class Abstract {\n" + + "public abstract class Abstract {\n" + "}"; } @Override public Map getAdditionalHighlightingTagToDescriptorMap() { - return Collections.emptyMap(); + Map map = new HashMap(); + for (Field field : JetHighlightingColors.class.getFields()) { + if (Modifier.isStatic(field.getModifiers())) { + try { + map.put(field.getName(), (TextAttributesKey) field.get(null)); + } + catch (IllegalAccessException e) { + assert false; + } + } + } + return map; } @NotNull From c989b2e5ba6fd646470d9963289eb1768622c87b Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 4 Apr 2012 16:01:36 +0400 Subject: [PATCH 37/38] Updated "Autocasts" test data in JetPsiCheckerTest. Replaced types with their FQ names. --- idea/testData/checker/infos/Autocasts.jet | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/idea/testData/checker/infos/Autocasts.jet b/idea/testData/checker/infos/Autocasts.jet index 4197d78d269..a6ce30da598 100644 --- a/idea/testData/checker/infos/Autocasts.jet +++ b/idea/testData/checker/infos/Autocasts.jet @@ -147,78 +147,78 @@ fun f15(a : A?) { fun getStringLength(obj : Any) : Char? { if (obj !is String) return null - return obj.get(0) // no cast to String is needed + return obj.get(0) // no cast to jet.String is needed } -fun toInt(i: Int?): Int = if (i != null) i else 0 +fun toInt(i: Int?): Int = if (i != null) i else 0 fun illegalWhenBody(a: Any): Int = when(a) { - is Int -> a + is Int -> a is String -> a else -> 1 } fun illegalWhenBlock(a: Any): Int { when(a) { - is Int -> return a + is Int -> return a is String -> return a else -> return 1 } } fun declarations(a: Any?) { if (a is String) { - val p4: #(Int, String) = #(2, a) + val p4: #(Int, String) = #(2, a) } if (a is String?) { if (a != null) { - val s: String = a + val s: String = a } } if (a != null) { if (a is String?) { - val s: String = a + val s: String = a } } } fun vars(a: Any?) { var b: Int = 0 if (a is Int) { - b = a + b = a } } fun tuples(a: Any?) { if (a != null) { - val s: #(Any, String) = #(a, a) + val s: #(Any, String) = #(a, a) } if (a is String) { - val s: #(Any, String) = #(a, a) + val s: #(Any, String) = #(a, a) } fun illegalTupleReturnType(): #(Any, String) = #(a, a) if (a is String) { - fun legalTupleReturnType(): #(Any, String) = #(a, a) + fun legalTupleReturnType(): #(Any, String) = #(a, a) } val illegalFunctionLiteral: Function0 = { a } val illegalReturnValueInFunctionLiteral: Function0 = { (): Int -> a } if (a is Int) { - val legalFunctionLiteral: Function0 = { a } - val alsoLegalFunctionLiteral: Function0 = { (): Int -> a } + val legalFunctionLiteral: Function0 = { a } + val alsoLegalFunctionLiteral: Function0 = { (): Int -> a } } } fun returnFunctionLiteralBlock(a: Any?): Function0 { - if (a is Int) return { a } + if (a is Int) return { a } else return { 1 } } fun returnFunctionLiteral(a: Any?): Function0 = - if (a is Int) { (): Int -> a } + if (a is Int) { (): Int -> a } else { () -> 1 } fun illegalTupleReturnType(a: Any): #(Any, String) = #(a, a) -fun declarationInsidePattern(x: #(Any, Any)): String = when(x) { is #(val a is String, *) -> a; else -> "something" } +fun declarationInsidePattern(x: #(Any, Any)): String = when(x) { is #(val a is String, *) -> a; else -> "something" } fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") - a.toString() + a.toString() } if (a is Int || a is String) { a.compareTo("") @@ -227,9 +227,9 @@ fun mergeAutocasts(a: Any?) { is String, is Any -> a.compareTo("") } if (a is String && a is Any) { - val i: Int = a.compareTo("") + val i: Int = a.compareTo("") } - if (a is String && a.compareTo("") == 0) {} + if (a is String && a.compareTo("") == 0) {} if (a is String || a.compareTo("") == 0) {} } From 5d926963170417010e8492241544598cbd18917c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 4 Apr 2012 16:13:21 +0400 Subject: [PATCH 38/38] Disabled names highlighting in tests. --- .../FunctionsHighlightingVisitor.java | 16 ++++++---------- .../jet/plugin/highlighter/JetPsiChecker.java | 13 +++++++++++++ .../highlighter/LabelsHighlightingVisitor.java | 8 ++------ .../PropertiesHighlightingVisitor.java | 11 ++++------- .../TypeKindHighlightingVisitor.java | 18 +++++++++--------- .../VariablesHighlightingVisitor.java | 6 +++--- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java index 0fd08a965a0..d58bc0a6654 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java @@ -41,8 +41,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit public void visitNamedFunction(JetNamedFunction function) { PsiElement nameIdentifier = function.getNameIdentifier(); if (nameIdentifier != null) { - holder.createInfoAnnotation(nameIdentifier, null).setTextAttributes( - JetHighlightingColors.FUNCTION_DECLARATION); + JetPsiChecker.highlightName(holder, nameIdentifier, JetHighlightingColors.FUNCTION_DECLARATION); } super.visitNamedFunction(function); @@ -57,8 +56,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit if (typeElement instanceof JetUserType) { JetSimpleNameExpression nameExpression = ((JetUserType)typeElement).getReferenceExpression(); if (nameExpression != null) { - holder.createInfoAnnotation(nameExpression, null).setTextAttributes( - JetHighlightingColors.CONSTRUCTOR_CALL); + JetPsiChecker.highlightName(holder, nameExpression, JetHighlightingColors.CONSTRUCTOR_CALL); } } } @@ -72,20 +70,18 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit DeclarationDescriptor calleeDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetReferenceExpression)callee); if (calleeDescriptor != null) { if (calleeDescriptor instanceof ConstructorDescriptor) { - holder.createInfoAnnotation(callee, null).setTextAttributes( - JetHighlightingColors.CONSTRUCTOR_CALL); + JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL); } else if (calleeDescriptor instanceof FunctionDescriptor && !(calleeDescriptor instanceof VariableAsFunctionDescriptor)) { FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor; if (fun.getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) { - holder.createInfoAnnotation(callee, null).setTextAttributes( - JetHighlightingColors.EXTENSION_FUNCTION_CALL); + JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL); } else if (fun.getContainingDeclaration() instanceof NamespaceDescriptor) { - holder.createInfoAnnotation(callee, null).setTextAttributes(JetHighlightingColors.NAMESPACE_FUNCTION_CALL); + JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.NAMESPACE_FUNCTION_CALL); } else { - holder.createInfoAnnotation(callee, null).setTextAttributes(JetHighlightingColors.FUNCTION_CALL); + JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index f4a458d3440..dfb763f872b 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -23,6 +23,7 @@ import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.TextRange; import com.intellij.psi.MultiRangeReference; @@ -55,6 +56,18 @@ public class JetPsiChecker implements Annotator { return errorReportingEnabled; } + static boolean isNamesHighlightingEnabled() { + return !ApplicationManager.getApplication().isUnitTestMode(); + } + + static void highlightName(@NotNull AnnotationHolder holder, + @NotNull PsiElement psiElement, + @NotNull TextAttributesKey attributesKey) { + if (isNamesHighlightingEnabled()) { + holder.createInfoAnnotation(psiElement, null).setTextAttributes(attributesKey); + } + } + private static HighlightingVisitor[] getBeforeAnalysisVisitors(AnnotationHolder holder) { return new HighlightingVisitor[]{ new SoftKeywordsHighlightingVisitor(holder), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java index 1e8ec30382c..a97798f6dcc 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/LabelsHighlightingVisitor.java @@ -20,13 +20,9 @@ package org.jetbrains.jet.plugin.highlighter; import com.intellij.lang.annotation.AnnotationHolder; -import com.intellij.lang.annotation.Annotator; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetLabelQualifiedExpression; import org.jetbrains.jet.lang.psi.JetPrefixExpression; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; -import org.jetbrains.jet.lang.psi.JetVisitorVoid; import org.jetbrains.jet.lexer.JetTokens; class LabelsHighlightingVisitor extends HighlightingVisitor { @@ -38,7 +34,7 @@ class LabelsHighlightingVisitor extends HighlightingVisitor { public void visitPrefixExpression(JetPrefixExpression expression) { JetSimpleNameExpression operationSign = expression.getOperationReference(); if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) { - holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlightingColors.LABEL); + JetPsiChecker.highlightName(holder, operationSign, JetHighlightingColors.LABEL); } } @@ -46,7 +42,7 @@ class LabelsHighlightingVisitor extends HighlightingVisitor { public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) { JetSimpleNameExpression targetLabel = expression.getTargetLabel(); if (targetLabel != null) { - holder.createInfoAnnotation(targetLabel, null).setTextAttributes(JetHighlightingColors.LABEL); + JetPsiChecker.highlightName(holder, targetLabel, JetHighlightingColors.LABEL); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java index f5ef640253e..47e24abdbbb 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -41,14 +41,13 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } if (((PropertyDescriptor)target).getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) { - holder.createInfoAnnotation(expression, null).setTextAttributes( - JetHighlightingColors.EXTENSION_PROPERTY); + JetPsiChecker.highlightName(holder, expression, JetHighlightingColors.EXTENSION_PROPERTY); } boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; putPropertyAnnotation(expression, namespace, false); if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { - holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.BACKING_FIELD_ACCESS); + JetPsiChecker.highlightName(holder, expression, JetHighlightingColors.BACKING_FIELD_ACCESS); } } @@ -83,10 +82,8 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) { - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( - namespace - ? JetHighlightingColors.NAMESPACE_PROPERTY - : JetHighlightingColors.INSTANCE_PROPERTY + JetPsiChecker.highlightName(holder, elementToHighlight, + namespace ? JetHighlightingColors.NAMESPACE_PROPERTY : JetHighlightingColors.INSTANCE_PROPERTY ); if (withBackingField) { holder.createInfoAnnotation( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java index a72c6a1b857..650e9f6b35a 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.plugin.highlighter; -import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.psi.PsiElement; @@ -51,11 +50,13 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { private void visitNameExpression(JetExpression expression) { PsiReference ref = expression.getReference(); if (ref == null) return; - PsiElement target = ref.resolve(); - if (target instanceof JetClass) { - highlightClassByKind((JetClass)target, expression); - } else if (target instanceof JetTypeParameter) { - holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.TYPE_PARAMETER); + if (JetPsiChecker.isNamesHighlightingEnabled()) { + PsiElement target = ref.resolve(); + if (target instanceof JetClass) { + highlightClassByKind((JetClass)target, expression); + } else if (target instanceof JetTypeParameter) { + JetPsiChecker.highlightName(holder, expression, JetHighlightingColors.TYPE_PARAMETER); + } } } @@ -73,7 +74,7 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { public void visitTypeParameter(JetTypeParameter parameter) { PsiElement identifier = parameter.getNameIdentifier(); if (identifier != null) { - holder.createInfoAnnotation(identifier, null).setTextAttributes(JetHighlightingColors.TYPE_PARAMETER); + JetPsiChecker.highlightName(holder, identifier, JetHighlightingColors.TYPE_PARAMETER); } } @@ -99,7 +100,6 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { } } } - Annotation annotation = holder.createInfoAnnotation(whatToHighlight, null); - annotation.setTextAttributes(textAttributes); + JetPsiChecker.highlightName(holder, whatToHighlight, textAttributes); } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index 82e53cc1061..148ee928e5a 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -94,7 +94,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { if (descriptor instanceof VariableDescriptor) { VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor; if (variableDescriptor.isVar()) { - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.MUTABLE_VARIABLE); + JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.MUTABLE_VARIABLE); } if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { @@ -103,11 +103,11 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } if (descriptor instanceof LocalVariableDescriptor) { - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.LOCAL_VARIABLE); + JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.LOCAL_VARIABLE); } if (descriptor instanceof ValueParameterDescriptor) { - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.PARAMETER); + JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.PARAMETER); } } }