From 5d926963170417010e8492241544598cbd18917c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 4 Apr 2012 16:13:21 +0400 Subject: [PATCH] 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); } } }