mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
IDEA-69645 (bad code is green: attribute value must be constant)
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user