Refine highlighting of '@'
- Do not highlight '@' as separate token. - Highlight '@' the same way as element where it's located: annotation, label or modifier. - Extend text range when positioning unresolved reference in annotation with '@'. Note that currently '@' is collapsed with modifiers tokens
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.JetNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.JetKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getCalleeHighlightingRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import kotlin.platform.platformStatic
|
||||
@@ -226,7 +227,7 @@ public object PositioningStrategies {
|
||||
return ranges
|
||||
}
|
||||
}
|
||||
return listOf(element.getTextRange())
|
||||
return listOf(element.getCalleeHighlightingRange())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.JetNodeTypes;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
|
||||
|
||||
@@ -101,4 +103,8 @@ public class JetAnnotationEntry extends JetElementImplStub<KotlinAnnotationEntry
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getAtSymbol() {
|
||||
return findChildByType(JetTokens.AT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,3 +570,15 @@ private fun JetAnnotationsContainer.collectAnnotationEntriesFromPsi() =
|
||||
else -> emptyList<JetAnnotationEntry>()
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetElement.getCalleeHighlightingRange(): TextRange {
|
||||
val annotationEntry: JetAnnotationEntry =
|
||||
PsiTreeUtil.getParentOfType<JetAnnotationEntry>(
|
||||
this, javaClass<JetAnnotationEntry>(), /* strict = */false, javaClass<JetValueArgumentList>()
|
||||
) ?: return getTextRange()
|
||||
|
||||
val startOffset = annotationEntry.getAtSymbol()?.getTextRange()?.getStartOffset()
|
||||
?: annotationEntry.getCalleeExpression().getTextRange().getStartOffset()
|
||||
|
||||
return TextRange(startOffset, annotationEntry.getCalleeExpression().getTextRange().getEndOffset())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<!UNRESOLVED_REFERENCE!>@Ann<!> class A
|
||||
<!UNRESOLVED_REFERENCE!>Ann<!> class B
|
||||
<!UNRESOLVED_REFERENCE!>@Ann<!>(1) class C
|
||||
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
[ERROR : Ann]() internal final class A {
|
||||
public constructor A()
|
||||
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 : Ann]() internal final class B {
|
||||
public constructor B()
|
||||
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 : Ann]() internal final class C {
|
||||
public constructor C()
|
||||
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
|
||||
}
|
||||
@@ -801,6 +801,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedReferenceRange.kt")
|
||||
public void testUnresolvedReferenceRange() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WrongAnnotationArgsOnObject.kt")
|
||||
public void testWrongAnnotationArgsOnObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/WrongAnnotationArgsOnObject.kt");
|
||||
|
||||
Reference in New Issue
Block a user