Support any constant expressions as annotation arguments

This commit is contained in:
Alexander Udalov
2013-09-02 23:03:08 +04:00
parent a17328f9d3
commit e62a2bbf2f
11 changed files with 135 additions and 12 deletions
@@ -32,10 +32,12 @@ public abstract class JavaAnnotationArgumentImpl extends JavaElementImpl<PsiAnno
@NotNull
/* package */ static JavaAnnotationArgument create(@NotNull PsiAnnotationMemberValue argument, @Nullable Name name) {
if (argument instanceof PsiLiteralExpression) {
return new JavaLiteralAnnotationArgumentImpl((PsiLiteralExpression) argument, name);
Object value = JavaPsiFacade.getInstance(argument.getProject()).getConstantEvaluationHelper().computeConstantExpression(argument);
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);
}
else if (argument instanceof PsiArrayInitializerMemberValue) {
@@ -16,26 +16,28 @@
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.jet.lang.resolve.java.structure.JavaLiteralAnnotationArgument;
import org.jetbrains.jet.lang.resolve.name.Name;
public class JavaLiteralAnnotationArgumentImpl extends JavaAnnotationArgumentImpl implements JavaLiteralAnnotationArgument {
protected JavaLiteralAnnotationArgumentImpl(@NotNull PsiLiteralExpression psiLiteralExpression, @Nullable Name name) {
super(psiLiteralExpression, name);
public class JavaLiteralAnnotationArgumentImpl implements JavaLiteralAnnotationArgument {
private final Name name;
private final Object value;
public JavaLiteralAnnotationArgumentImpl(@Nullable Name name, @Nullable Object value) {
this.name = name;
this.value = value;
}
@NotNull
@Override
public PsiLiteralExpression getPsi() {
return (PsiLiteralExpression) super.getPsi();
@Nullable
public Name getName() {
return name;
}
@Override
@Nullable
public Object getValue() {
return getPsi().getValue();
return value;
}
}