mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
constant expressions check: discard polyadic expressions of non-primitive/Strings types (IDEA-104347)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
@@ -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);}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user