diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 1ee55bb828d699a13a62edf0accb35c19f8fe314..55635016e5ce7a25c46e8a10e10be750991cafe3 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -83,7 +83,6 @@ public class JetPsiChecker implements Annotator { return new HighlightingVisitor[]{ new SoftKeywordsHighlightingVisitor(holder), new LabelsHighlightingVisitor(holder), - new TypeKindHighlightingVisitor(holder), }; } @@ -92,6 +91,7 @@ public class JetPsiChecker implements Annotator { new PropertiesHighlightingVisitor(holder, bindingContext), new FunctionsHighlightingVisitor(holder, bindingContext), new VariablesHighlightingVisitor(holder, bindingContext), + new TypeKindHighlightingVisitor(holder, bindingContext), }; } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java index 26fbaa06f89d7bab9be75a0e4efc18c79b8ed7d1..161a166199472bc731d6b15f68191aa24ecbe834 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java @@ -21,87 +21,70 @@ 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.descriptors.*; import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lexer.JetTokens; +import org.jetbrains.jet.lang.resolve.BindingContext; /** * @author Evgeny Gerashchenko * @since 3/29/12 */ -class TypeKindHighlightingVisitor extends HighlightingVisitor { - protected TypeKindHighlightingVisitor(AnnotationHolder holder) { - super(holder); +class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor { + TypeKindHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) { + super(holder, bindingContext); } @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) { + public void visitSimpleNameExpression(JetSimpleNameExpression expression) { PsiReference ref = expression.getReference(); if (ref == null) return; if (JetPsiChecker.isNamesHighlightingEnabled()) { - PsiElement target = ref.resolve(); - if (target instanceof JetClass) { - highlightClassByKind((JetClass)target, expression); + DeclarationDescriptor referenceTarget = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); + if (referenceTarget instanceof ConstructorDescriptor) { + referenceTarget = referenceTarget.getContainingDeclaration(); } - else if (target instanceof JetTypeParameter) { + + if (referenceTarget instanceof ClassDescriptor) { + highlightClassByKind((ClassDescriptor) referenceTarget, expression); + } + else if (referenceTarget instanceof TypeParameterDescriptor) { JetPsiChecker.highlightName(holder, expression, 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) { JetPsiChecker.highlightName(holder, identifier, JetHighlightingColors.TYPE_PARAMETER); } + super.visitTypeParameter(parameter); } @Override public void visitClass(JetClass klass) { PsiElement identifier = klass.getNameIdentifier(); - if (identifier != null) { - highlightClassByKind(klass, identifier); + ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, klass); + if (identifier != null && classDescriptor != null) { + highlightClassByKind(classDescriptor, identifier); } + super.visitClass(klass); } - 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) { - if (modifierList.hasModifier(JetTokens.ANNOTATION_KEYWORD)) { - textAttributes = JetHighlightingColors.ANNOTATION; - } - else if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { - textAttributes = JetHighlightingColors.ABSTRACT_CLASS; - } - } + private void highlightClassByKind(@NotNull ClassDescriptor classDescriptor, @NotNull PsiElement whatToHighlight) { + TextAttributesKey textAttributes; + switch (classDescriptor.getKind()) { + case TRAIT: + textAttributes = JetHighlightingColors.TRAIT; + break; + case ANNOTATION_CLASS: + textAttributes = JetHighlightingColors.ANNOTATION; + break; + default: + textAttributes = classDescriptor.getModality() == Modality.ABSTRACT + ? JetHighlightingColors.ABSTRACT_CLASS + : JetHighlightingColors.CLASS; } JetPsiChecker.highlightName(holder, whatToHighlight, textAttributes); } diff --git a/idea/testData/highlighter/JavaTypes.kt b/idea/testData/highlighter/JavaTypes.kt new file mode 100644 index 0000000000000000000000000000000000000000..5ebcdd3cf16e86aefecec9b7d809a71b969f497d --- /dev/null +++ b/idea/testData/highlighter/JavaTypes.kt @@ -0,0 +1,2 @@ +Override class TheClass : Runnable, Thread() { +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java b/idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java index 1cfe67566afa99e0c3a3cd259dae6b1508f73d27..9892279f7a464dfb5466d397633ff72564766a3f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/NamesHighlightingTest.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.plugin; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; +import com.intellij.openapi.projectRoots.Sdk; import org.jetbrains.jet.plugin.highlighter.JetPsiChecker; /** @@ -40,6 +41,15 @@ public class NamesHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testJavaTypes() throws Exception { + doTest(); + } + + @Override + protected Sdk getProjectJDK() { + return PluginTestCaseBase.jdkFromIdeaHome(); + } + private void doTest() throws Exception { doTest(getTestName(false) + ".kt", false, true); }