invalid annotation type detection based on type element (IDEA-142884)

This commit is contained in:
Anna Kozlova
2015-07-21 18:36:10 +02:00
parent 2469bb7be0
commit 7677f61dc5
5 changed files with 10 additions and 10 deletions
@@ -321,12 +321,11 @@ public class AnnotationsHighlightUtil {
}
@Nullable
static HighlightInfo checkValidAnnotationType(final PsiTypeElement typeElement) {
PsiType type = typeElement.getType();
if (type.accept(AnnotationReturnTypeVisitor.INSTANCE).booleanValue()) {
static HighlightInfo checkValidAnnotationType(PsiType type, final PsiTypeElement typeElement) {
if (type != null && type.accept(AnnotationReturnTypeVisitor.INSTANCE).booleanValue()) {
return null;
}
String description = JavaErrorMessages.message("annotation.invalid.annotation.member.type");
String description = JavaErrorMessages.message("annotation.invalid.annotation.member.type", type != null ? type.getPresentableText() : type);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
}
@@ -276,7 +276,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
myHolder.add(AnnotationsHighlightUtil.checkMemberValueType(value, returnType));
}
myHolder.add(AnnotationsHighlightUtil.checkValidAnnotationType(method.getReturnTypeElement()));
myHolder.add(AnnotationsHighlightUtil.checkValidAnnotationType(method.getReturnType(), method.getReturnTypeElement()));
final PsiClass aClass = method.getContainingClass();
myHolder.add(AnnotationsHighlightUtil.checkCyclicMemberType(method.getReturnTypeElement(), aClass));
myHolder.add(AnnotationsHighlightUtil.checkClashesWithSuperMethods(method));
@@ -11,7 +11,7 @@ annotation.not.applicable=''@{0}'' not applicable to {1}
annotation.non.constant.attribute.value=Attribute value must be constant
annotation.non.class.literal.attribute.value=Attribute value must be a class literal
annotation.non.enum.constant.attribute.value=Attribute value must be an enum constant
annotation.invalid.annotation.member.type=Invalid type for annotation member
annotation.invalid.annotation.member.type=Invalid type ''{0}'' for annotation member
annotation.cyclic.element.type=Cyclic annotation element type
annotation.annotation.type.expected=Annotation type expected
annotation.members.may.not.have.throws.list=@interface members may not have throws list
@@ -3,7 +3,7 @@
Class <error descr="@interface member clashes with 'annotationType()' in java.lang.annotation.Annotation">annotationType</error>();
int value();
boolean equals();
<error descr="Invalid type for annotation member">void</error> <error descr="@interface member clashes with 'finalize()' in java.lang.Object">finalize</error>();
<error descr="Invalid type for annotation member">void</error> registerNatives();
<error descr="Invalid type 'void' for annotation member">void</error> <error descr="@interface member clashes with 'finalize()' in java.lang.Object">finalize</error>();
<error descr="Invalid type 'void' for annotation member">void</error> registerNatives();
}
@@ -1,8 +1,9 @@
class Clazz {}
@interface Ann {
<error descr="Invalid type for annotation member">Clazz</error> i ();
<error descr="Invalid type 'Clazz' for annotation member">Clazz</error> i ();
<error descr="Cyclic annotation element type">Ann</error> j ();
<error descr="Invalid type for annotation member">void</error> f();
<error descr="Invalid type 'void' for annotation member">void</error> f();
<error descr="Invalid type 'int[][]' for annotation member">int[]</error> intDblArray()[];
}