Support any constant expressions as annotation arguments
This commit is contained in:
+5
-3
@@ -32,10 +32,12 @@ public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl<PsiAnno
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
|
||||||
if (argument instanceof PsiLiteralExpression) {
|
Object value = JavaPsiFacade.getInstance(argument.getProject()).getConstantEvaluationHelper().computeConstantExpression(argument);
|
||||||
return new JavaLiteralAnnotationArgumentImpl((PsiLiteralExpression) argument, name);
|
if (value != null || argument instanceof PsiLiteralExpression) {
|
||||||
|
return new JavaLiteralAnnotationArgumentImpl(name, value);
|
||||||
}
|
}
|
||||||
else if (argument instanceof PsiReferenceExpression) {
|
|
||||||
|
if (argument instanceof PsiReferenceExpression) {
|
||||||
return new JavaReferenceAnnotationArgumentImpl((PsiReferenceExpression) argument, name);
|
return new JavaReferenceAnnotationArgumentImpl((PsiReferenceExpression) argument, name);
|
||||||
}
|
}
|
||||||
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
else if (argument instanceof PsiArrayInitializerMemberValue) {
|
||||||
|
|||||||
+11
-9
@@ -16,26 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||||
|
|
||||||
import com.intellij.psi.PsiLiteralExpression;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaLiteralAnnotationArgument;
|
import org.jetbrains.jet.lang.resolve.java.structure.JavaLiteralAnnotationArgument;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
public class JavaLiteralAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaLiteralAnnotationArgument {
|
public class JavaLiteralAnnotationArgumentImpl implements JavaLiteralAnnotationArgument {
|
||||||
protected JavaLiteralAnnotationArgumentImpl(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
|
private final Name name;
|
||||||
super(psiLiteralExpression, name);
|
private final Object value;
|
||||||
|
|
||||||
|
public JavaLiteralAnnotationArgumentImpl(@Nullable Name name, @Nullable Object value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public PsiLiteralExpression getPsi() {
|
@Nullable
|
||||||
return (PsiLiteralExpression) super.getPsi();
|
public Name getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return getPsi().getValue();
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public class AnnotationWithArithmeticExpressionInParam {
|
||||||
|
public @interface Anno {
|
||||||
|
int value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Anno(2 * 8 + 13 * (239 - 237))
|
||||||
|
public static class Class {}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public open class AnnotationWithArithmeticExpressionInParam : java.lang.Object {
|
||||||
|
public constructor AnnotationWithArithmeticExpressionInParam()
|
||||||
|
|
||||||
|
public final annotation class Anno : jet.Annotation {
|
||||||
|
public constructor Anno(/*0*/ value: jet.Int)
|
||||||
|
public abstract fun value(): jet.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
test.AnnotationWithArithmeticExpressionInParam.Anno(value = 42.toInt(): jet.Int) public open class Class : java.lang.Object {
|
||||||
|
public constructor Class()
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface AnnotationWithStringConcatenationInParam {
|
||||||
|
public @interface Anno {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Anno("he" + "l" + "lo")
|
||||||
|
public static class Class { }
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait AnnotationWithStringConcatenationInParam : java.lang.Object {
|
||||||
|
|
||||||
|
public final annotation class Anno : jet.Annotation {
|
||||||
|
public constructor Anno(/*0*/ value: jet.String?)
|
||||||
|
public abstract fun value(): jet.String?
|
||||||
|
}
|
||||||
|
|
||||||
|
test.AnnotationWithStringConcatenationInParam.Anno(value = "hello": jet.String) public open class Class : java.lang.Object {
|
||||||
|
public constructor Class()
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface AnnotationWithStringConstantInParam {
|
||||||
|
public static final String HEL = "hel";
|
||||||
|
|
||||||
|
public @interface Anno {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Anno(HEL + "lo")
|
||||||
|
public static class Class { }
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait AnnotationWithStringConstantInParam : java.lang.Object {
|
||||||
|
|
||||||
|
public final annotation class Anno : jet.Annotation {
|
||||||
|
public constructor Anno(/*0*/ value: jet.String?)
|
||||||
|
public abstract fun value(): jet.String?
|
||||||
|
}
|
||||||
|
|
||||||
|
test.AnnotationWithStringConstantInParam.Anno(value = "hello": jet.String) public open class Class : java.lang.Object {
|
||||||
|
public constructor Class()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
package AnnotationWithStringConstantInParam {
|
||||||
|
public val HEL: jet.String
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface AnnotationWithStringInParam {
|
||||||
|
public @interface Anno {
|
||||||
|
String value();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Anno("hello")
|
||||||
|
public static class Class { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait AnnotationWithStringInParam : java.lang.Object {
|
||||||
|
|
||||||
|
public final annotation class Anno : jet.Annotation {
|
||||||
|
public constructor Anno(/*0*/ value: jet.String?)
|
||||||
|
public abstract fun value(): jet.String?
|
||||||
|
}
|
||||||
|
|
||||||
|
test.AnnotationWithStringInParam.Anno(value = "hello": jet.String) public open class Class : java.lang.Object {
|
||||||
|
public constructor Class()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1065,6 +1065,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithAnnotationInParam.java");
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithAnnotationInParam.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AnnotationWithArithmeticExpressionInParam.java")
|
||||||
|
public void testAnnotationWithArithmeticExpressionInParam() throws Exception {
|
||||||
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithArithmeticExpressionInParam.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("AnnotationWithArrayOfEnumInParam.java")
|
@TestMetadata("AnnotationWithArrayOfEnumInParam.java")
|
||||||
public void testAnnotationWithArrayOfEnumInParam() throws Exception {
|
public void testAnnotationWithArrayOfEnumInParam() throws Exception {
|
||||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithArrayOfEnumInParam.java");
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithArrayOfEnumInParam.java");
|
||||||
@@ -1090,6 +1095,21 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithPrimitiveValueInParam.java");
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithPrimitiveValueInParam.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AnnotationWithStringConcatenationInParam.java")
|
||||||
|
public void testAnnotationWithStringConcatenationInParam() throws Exception {
|
||||||
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithStringConcatenationInParam.java");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AnnotationWithStringConstantInParam.java")
|
||||||
|
public void testAnnotationWithStringConstantInParam() throws Exception {
|
||||||
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithStringConstantInParam.java");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AnnotationWithStringInParam.java")
|
||||||
|
public void testAnnotationWithStringInParam() throws Exception {
|
||||||
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/AnnotationWithStringInParam.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("CustomAnnotation.java")
|
@TestMetadata("CustomAnnotation.java")
|
||||||
public void testCustomAnnotation() throws Exception {
|
public void testCustomAnnotation() throws Exception {
|
||||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/CustomAnnotation.java");
|
doTestCompiledJava("compiler/testData/loadJava/compiledJava/annotations/CustomAnnotation.java");
|
||||||
|
|||||||
Reference in New Issue
Block a user