constant expressions check: discard polyadic expressions of non-primitive/Strings types (IDEA-104347)

This commit is contained in:
anna
2013-04-03 10:52:04 +02:00
parent 25f1fa203f
commit c14be903d9
3 changed files with 28 additions and 0 deletions

View File

@@ -87,6 +87,11 @@ public class IsConstantExpressionVisitor extends JavaElementVisitor {
for (PsiExpression operand : expression.getOperands()) {
operand.accept(this);
if (!myIsConstant) return;
final PsiType type = operand.getType();
if (type != null && !(type instanceof PsiPrimitiveType) && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
myIsConstant = false;
return;
}
}
}

View File

@@ -0,0 +1,22 @@
@interface Foo {
String value();
}
@Foo(<error descr="Attribute value must be constant">"myclass: " + Bar.class</error>)
class Bar {}
@Foo("myclass: Bazz")
class Bazz{}
@Foo("myclass:" + "Bazz1")
class Bazz1{}
@Foo(Const.CONST + Const.CONST)
class Bazz2{}
@Foo(<error descr="Incompatible types. Found: 'java.lang.Class<FooBar>', required: 'java.lang.String'">FooBar.class</error>)
class FooBar {}
class Const {
public static final String CONST = "const";
}

View File

@@ -172,4 +172,5 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
public void testAmbiguousMethodCallIDEA100314() { doTest(false, false); }
public void testInstanceMemberNotAccessibleInStaticContext() { doTest(false, false); }
public void testRejectedTypeParamsForConstructor() { doTest(false, false); }
public void testAnnotationArgs() throws Exception { doTest(false, false);}
}