Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ public static HighlightInfo checkMemberValueType(@Nullable PsiAnnotationMemberVa
}

@RequiredReadAction
public static HighlightInfo checkDuplicateAnnotations(@Nonnull PsiAnnotation annotationToCheck, @Nonnull LanguageLevel languageLevel) {
public static HighlightInfo.Builder checkDuplicateAnnotations(
@Nonnull PsiAnnotation annotationToCheck,
@Nonnull LanguageLevel languageLevel
) {
PsiAnnotationOwner owner = annotationToCheck.getOwner();
if (owner == null) {
return null;
Expand All @@ -244,8 +247,7 @@ else if (isAnnotationRepeatedTwice(owner, annotationType.getQualifiedName())) {
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(element)
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateAnnotation())
.create();
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateAnnotation());
}

PsiAnnotation metaAnno =
Expand All @@ -254,16 +256,14 @@ else if (isAnnotationRepeatedTwice(owner, annotationType.getQualifiedName())) {
LocalizeValue explanation = JavaErrorLocalize.annotationNonRepeatable(annotationType.getQualifiedName());
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(element)
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateExplained(explanation))
.create();
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateExplained(explanation));
}

String explanation = doCheckRepeatableAnnotation(metaAnno);
if (explanation != null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(element)
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateExplained(explanation))
.create();
.descriptionAndTooltip(JavaErrorLocalize.annotationDuplicateExplained(explanation));
}

PsiClass container = getRepeatableContainer(metaAnno);
Expand Down Expand Up @@ -381,14 +381,13 @@ public static HighlightInfo checkMissingAttributes(PsiAnnotation annotation) {

@Nullable
@RequiredReadAction
public static HighlightInfo checkConstantExpression(PsiExpression expression) {
public static HighlightInfo.Builder checkConstantExpression(PsiExpression expression) {
PsiElement parent = expression.getParent();
if (PsiUtil.isAnnotationMethod(parent) || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue) {
if (!PsiUtil.isConstantExpression(expression)) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(expression)
.descriptionAndTooltip(JavaErrorLocalize.annotationNonConstantAttributeValue())
.create();
.descriptionAndTooltip(JavaErrorLocalize.annotationNonConstantAttributeValue());
}
}

Expand Down Expand Up @@ -416,7 +415,11 @@ public static HighlightInfo checkValidAnnotationType(PsiType type, PsiTypeElemen

@Nullable
@RequiredReadAction
public static HighlightInfo checkApplicability(@Nonnull PsiAnnotation annotation, @Nonnull LanguageLevel level, @Nonnull PsiFile file) {
public static HighlightInfo.Builder checkApplicability(
@Nonnull PsiAnnotation annotation,
@Nonnull LanguageLevel level,
@Nonnull PsiFile file
) {
if (ANY_ANNOTATION_ALLOWED.accepts(annotation)) {
return null;
}
Expand All @@ -433,9 +436,9 @@ public static HighlightInfo checkApplicability(@Nonnull PsiAnnotation annotation
}

if (!(owner instanceof PsiModifierList)) {
HighlightInfo info = HighlightUtil.checkFeature(annotation, JavaFeature.TYPE_ANNOTATIONS, level, file);
if (info != null) {
return info;
HighlightInfo.Builder hlBuilder = HighlightUtil.checkFeature(annotation, JavaFeature.TYPE_ANNOTATIONS, level, file);
if (hlBuilder != null) {
return hlBuilder;
}
}

Expand All @@ -445,15 +448,18 @@ public static HighlightInfo checkApplicability(@Nonnull PsiAnnotation annotation
}

if (applicable == null) {
return annotationError(annotation, JavaErrorLocalize.annotationNotApplicable(nameRef.getText(), targets[0].getPresentableText()));
return annotationError(
annotation,
JavaErrorLocalize.annotationNotApplicable(nameRef.getText(), targets[0].getPresentableText())
);
}

if (applicable == PsiAnnotation.TargetType.TYPE_USE) {
if (owner instanceof PsiClassReferenceType classRefType) {
PsiJavaCodeReferenceElement ref = classRefType.getReference();
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null) {
return info;
HighlightInfo.Builder hlBuilder = checkReferenceTarget(annotation, ref);
if (hlBuilder != null) {
return hlBuilder;
}
}
else if (owner instanceof PsiModifierList modifierList) {
Expand All @@ -467,9 +473,9 @@ else if (owner instanceof PsiModifierList modifierList) {
}
if (!(type instanceof PsiPrimitiveType)) {
PsiJavaCodeReferenceElement ref = getOutermostReferenceElement(typeElement.getInnermostComponentReferenceElement());
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null) {
return info;
HighlightInfo.Builder hlBuilder = checkReferenceTarget(annotation, ref);
if (hlBuilder != null) {
return hlBuilder;
}
}
}
Expand All @@ -486,17 +492,16 @@ else if (owner instanceof PsiTypeElement) {
}

@RequiredReadAction
private static HighlightInfo annotationError(PsiAnnotation annotation, LocalizeValue message) {
private static HighlightInfo.Builder annotationError(PsiAnnotation annotation, LocalizeValue message) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(annotation)
.descriptionAndTooltip(message)
.registerFix(new DeleteAnnotationAction(annotation))
.create();
.registerFix(new DeleteAnnotationAction(annotation));
}

@Nullable
@RequiredReadAction
private static HighlightInfo checkReferenceTarget(PsiAnnotation annotation, @Nullable PsiJavaCodeReferenceElement ref) {
private static HighlightInfo.Builder checkReferenceTarget(PsiAnnotation annotation, @Nullable PsiJavaCodeReferenceElement ref) {
if (ref == null) {
return null;
}
Expand Down
Loading
Loading