IDEA-69645 (bad code is green: attribute value must be constant)

This commit is contained in:
Bas Leijdekkers
2011-05-16 19:37:27 +02:00
parent 72063660af
commit af4873b8aa
2 changed files with 10 additions and 4 deletions

View File

@@ -173,8 +173,9 @@ public class AnnotationsHighlightUtil {
Set<String> names = new HashSet<String>();
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for (PsiNameValuePair attribute : attributes) {
if (attribute.getName() != null) {
names.add(attribute.getName());
final String name = attribute.getName();
if (name != null) {
names.add(name);
}
else {
names.add(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME);
@@ -211,8 +212,9 @@ public class AnnotationsHighlightUtil {
@Nullable
public static HighlightInfo checkConstantExpression(PsiExpression expression) {
if (expression.getParent() instanceof PsiAnnotationMethod || expression.getParent() instanceof PsiNameValuePair) {
if (PsiType.NULL.equals(expression.getType()) || !PsiUtil.isConstantExpression(expression)) {
final PsiElement parent = expression.getParent();
if (parent instanceof PsiAnnotationMethod || parent instanceof PsiNameValuePair || parent instanceof PsiArrayInitializerMemberValue) {
if (!PsiUtil.isConstantExpression(expression)) {
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, JavaErrorMessages.message("annotation.nonconstant.attribute.value"));
}
}

View File

@@ -1,10 +1,14 @@
@interface Ann {
int i ();
String[] j();
}
class D {
int field;
@Ann(i=<error descr="Attribute value must be constant">field</error>) void foo () {}
@Ann(j={<error descr="Attribute value must be constant">null</error>}) void bar() {}
}
@interface ManistaDouble