Fix diagnostic range when some qualifier is unresolved in "@a.b.c.Anno"

#KT-7747 Fixed
This commit is contained in:
Pavel V. Talanov
2016-03-10 17:44:57 +03:00
parent 35271af07c
commit 597c571f25
6 changed files with 35 additions and 14 deletions
@@ -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())
}
}
@@ -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<KtAnnotationEntry>(
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 -------------------------------------------------------------------------------------------------------------
@@ -1,3 +1,5 @@
<!UNRESOLVED_REFERENCE!>@Ann<!> class A
<!UNRESOLVED_REFERENCE!>@Ann<!> class B
<!UNRESOLVED_REFERENCE!>@Ann<!>(1) class C
<!UNRESOLVED_REFERENCE!>@Ann<!>(1) class C
@kotlin.<!UNRESOLVED_REFERENCE!>Ann<!>(1) class D
@kotlin.annotation.<!UNRESOLVED_REFERENCE!>Ann<!>(1) class E
@@ -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
}
@@ -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);
}
+1 -1
View File
@@ -1 +1 @@
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: suppress">@file:suppress</error>(<error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here"><error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here">return <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error></error></error></error>)
@file:<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: suppress">suppress</error>(<error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here"><error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here">return <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error></error></error></error>)