Changed highlighting range for unresolved annotation name to not include '@'

#KT-11529 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-03-22 18:34:59 +03:00
parent 0fdba49315
commit f0ef04a6a8
19 changed files with 51 additions and 53 deletions
@@ -20,10 +20,10 @@ import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
import org.jetbrains.kotlin.resolve.BindingContext;
class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
@@ -61,8 +61,20 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
}
private void highlightAnnotation(@NotNull KtSimpleNameExpression expression) {
TextRange toHighlight = KtPsiUtilKt.getHighlightingRange(expression);
NameHighlighter.highlightName(holder, toHighlight, KotlinHighlightingColors.ANNOTATION);
TextRange range = expression.getTextRange();
// include '@' symbol if the reference is the first segment of KtAnnotationEntry
// if "Deprecated" is highlighted then '@' should be highlighted too in "@Deprecated"
KtAnnotationEntry annotationEntry = PsiTreeUtil.getParentOfType(
expression, KtAnnotationEntry.class, /* strict = */false, KtValueArgumentList.class);
if (annotationEntry != null) {
PsiElement atSymbol = annotationEntry.getAtSymbol();
if (atSymbol != null) {
range = new TextRange(atSymbol.getTextRange().getStartOffset(), expression.getTextRange().getEndOffset());
}
}
NameHighlighter.highlightName(holder, range, KotlinHighlightingColors.ANNOTATION);
}
@Override