diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 148c23a2b45..7fd3e67123b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -219,7 +219,7 @@ object PositioningStrategies { return ranges } } - return listOf(element.getCalleeHighlightingRange()) + return listOf(element.getHighlightingRange()) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 7bb5c0de127..ea6ba046d9e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -150,16 +150,21 @@ fun KtExpression.getQualifiedExpressionForReceiverOrThis(): KtExpression { fun KtExpression.isDotReceiver(): Boolean = (parent as? KtDotQualifiedExpression)?.getReceiverExpression() == this -fun KtElement.getCalleeHighlightingRange(): TextRange { - val annotationEntry: KtAnnotationEntry = +fun KtReferenceExpression.getHighlightingRange(): TextRange { + // include '@' symbol if the reference is the first segment of KtAnnotationEntry + // if "Deprecated" is highlighted then '@' should be highlighted too in "@Deprecated" + val annotationEntry = PsiTreeUtil.getParentOfType( this, KtAnnotationEntry::class.java, /* strict = */false, KtValueArgumentList::class.java - ) ?: return textRange + ) - val startOffset = annotationEntry.getAtSymbol()?.getTextRange()?.getStartOffset() - ?: annotationEntry.getCalleeExpression()!!.startOffset - - return TextRange(startOffset, annotationEntry.getCalleeExpression()!!.endOffset) + val atSymbol = annotationEntry?.atSymbol + return if (atSymbol != null && atSymbol.endOffset == this.startOffset) { + TextRange(atSymbol.startOffset, this.endOffset) + } + else { + this.textRange + } } // ---------- Block expression ------------------------------------------------------------------------------------------------------------- diff --git a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.kt b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.kt index 2f6867c828f..a6cadb8f310 100644 --- a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.kt +++ b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.kt @@ -1,3 +1,5 @@ @Ann class A @Ann class B -@Ann(1) class C \ No newline at end of file +@Ann(1) class C +@kotlin.Ann(1) class D +@kotlin.annotation.Ann(1) class E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.txt b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.txt index c847af33fc8..102dd469cc9 100644 --- a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.txt +++ b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.txt @@ -20,3 +20,17 @@ package public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +@[ERROR : kotlin.Ann]() public final class D { + public constructor D() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@[ERROR : kotlin.annotation.Ann]() public final class E { + public constructor E() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.java index 4f3a44aec02..759472bb59a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -61,7 +61,7 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } private void highlightAnnotation(@NotNull KtSimpleNameExpression expression) { - TextRange toHighlight = KtPsiUtilKt.getCalleeHighlightingRange(expression); + TextRange toHighlight = KtPsiUtilKt.getHighlightingRange(expression); NameHighlighter.highlightName(holder, toHighlight, KotlinHighlightingColors.ANNOTATION); } diff --git a/idea/testData/checker/recovery/returnInFileAnnotation.kt b/idea/testData/checker/recovery/returnInFileAnnotation.kt index d1ab3ebef9f..4efd92d81ab 100644 --- a/idea/testData/checker/recovery/returnInFileAnnotation.kt +++ b/idea/testData/checker/recovery/returnInFileAnnotation.kt @@ -1 +1 @@ -@file:suppress(return a) \ No newline at end of file +@file:suppress(return a) \ No newline at end of file