diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/BeforeResolveHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/BeforeResolveHighlightingVisitor.kt index f5765ba2832..a67ec3dff91 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/BeforeResolveHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/BeforeResolveHighlightingVisitor.kt @@ -20,7 +20,9 @@ import com.intellij.lang.annotation.AnnotationHolder import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtExpressionWithLabel import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtValueArgument import org.jetbrains.kotlin.psi.KtVisitorVoid @@ -31,16 +33,16 @@ internal class BeforeResolveHighlightingVisitor(private val holder: AnnotationHo override fun visitElement(element: PsiElement) { val elementType = element.node.elementType - val attributes = when (elementType) { - in KtTokens.SOFT_KEYWORDS -> { + val attributes = when { + element is KDocLink -> KotlinHighlightingColors.KDOC_LINK + + elementType in KtTokens.SOFT_KEYWORDS -> { when (elementType) { in KtTokens.MODIFIER_KEYWORDS -> KotlinHighlightingColors.BUILTIN_ANNOTATION else -> KotlinHighlightingColors.KEYWORD } } - - KtTokens.SAFE_ACCESS -> KotlinHighlightingColors.SAFE_ACCESS - + elementType == KtTokens.SAFE_ACCESS -> KotlinHighlightingColors.SAFE_ACCESS else -> return } @@ -71,4 +73,11 @@ internal class BeforeResolveHighlightingVisitor(private val holder: AnnotationHo val eq = argument.equalsToken ?: return holder.createInfoAnnotation(TextRange(argumentName.startOffset, eq.endOffset), null).textAttributes = KotlinHighlightingColors.NAMED_ARGUMENT } + + override fun visitExpressionWithLabel(expression: KtExpressionWithLabel) { + val targetLabel = expression.getTargetLabel() + if (targetLabel != null) { + NameHighlighter.highlightName(holder, targetLabel, KotlinHighlightingColors.LABEL) + } + } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinBeforeResolveHighlightingPass.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinBeforeResolveHighlightingPass.kt index ff6c3fd0554..b8f2be0f3b1 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinBeforeResolveHighlightingPass.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinBeforeResolveHighlightingPass.kt @@ -33,7 +33,6 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiRecursiveElementVisitor -import org.jetbrains.kotlin.idea.kdoc.KDocHighlightingVisitor import org.jetbrains.kotlin.psi.KtFile class KotlinBeforeResolveHighlightingPass( @@ -45,15 +44,11 @@ class KotlinBeforeResolveHighlightingPass( override fun doCollectInformation(progress: ProgressIndicator) { val annotationHolder = AnnotationHolderImpl(AnnotationSession(file)) - val visitors = listOf( - BeforeResolveHighlightingVisitor(annotationHolder), - LabelsHighlightingVisitor(annotationHolder), - KDocHighlightingVisitor(annotationHolder) - ) + val visitor = BeforeResolveHighlightingVisitor(annotationHolder) file.accept(object : PsiRecursiveElementVisitor(){ override fun visitElement(element: PsiElement) { super.visitElement(element) - visitors.forEach { element.accept(it) } + element.accept(visitor) } }) this.annotationHolder = annotationHolder diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/LabelsHighlightingVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/LabelsHighlightingVisitor.java deleted file mode 100644 index 7193e771738..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/LabelsHighlightingVisitor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2015 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.kotlin.idea.highlighter; - -import com.intellij.lang.annotation.AnnotationHolder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.psi.KtExpressionWithLabel; -import org.jetbrains.kotlin.psi.KtSimpleNameExpression; -import org.jetbrains.kotlin.psi.KtVisitorVoid; - -class LabelsHighlightingVisitor extends KtVisitorVoid { - private final AnnotationHolder holder; - - LabelsHighlightingVisitor(AnnotationHolder holder) { - this.holder = holder; - } - - @Override - public void visitExpressionWithLabel(@NotNull KtExpressionWithLabel expression) { - KtSimpleNameExpression targetLabel = expression.getTargetLabel(); - if (targetLabel != null) { - NameHighlighter.highlightName(holder, targetLabel, KotlinHighlightingColors.LABEL); - } - } -} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocHighlightingVisitor.kt deleted file mode 100644 index 2e417f78ae8..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocHighlightingVisitor.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2015 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.kotlin.idea.kdoc - -import com.intellij.lang.annotation.AnnotationHolder -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiElementVisitor -import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors -import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink - -class KDocHighlightingVisitor(private val holder: AnnotationHolder): PsiElementVisitor() { - override fun visitElement(element: PsiElement) { - if (element is KDocLink) { - holder.createInfoAnnotation(element, null).textAttributes = KotlinHighlightingColors.KDOC_LINK - } - } -}