Java property as annotation parameter
This commit is contained in:
+20
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
@@ -164,6 +166,14 @@ public final class JavaCompileTimeConstResolver {
|
||||
|
||||
@Nullable
|
||||
private static CompileTimeConstant<?> getCompileTimeConstFromLiteralExpression(PsiLiteralExpression value) {
|
||||
return getCompileTimeConstFromLiteralExpressionWithExpectedType(value, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CompileTimeConstant<?> getCompileTimeConstFromLiteralExpressionWithExpectedType(
|
||||
@NotNull PsiLiteralExpression value,
|
||||
@Nullable JetType expectedType
|
||||
) {
|
||||
Object literalValue = value.getValue();
|
||||
if (literalValue instanceof String) {
|
||||
return new StringValue((String) literalValue);
|
||||
@@ -178,6 +188,16 @@ public final class JavaCompileTimeConstResolver {
|
||||
return new CharValue((Character) literalValue);
|
||||
}
|
||||
else if (literalValue instanceof Integer) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
if (builtIns.getShortType().equals(expectedType)) {
|
||||
return new ShortValue(((Integer) literalValue).shortValue());
|
||||
}
|
||||
else if (builtIns.getByteType().equals(expectedType)) {
|
||||
return new ByteValue(((Integer) literalValue).byteValue());
|
||||
}
|
||||
else if (builtIns.getCharType().equals(expectedType)) {
|
||||
return new CharValue((char) ((Integer)literalValue).intValue());
|
||||
}
|
||||
return new IntValue((Integer) literalValue);
|
||||
}
|
||||
else if (literalValue instanceof Long) {
|
||||
|
||||
+15
-6
@@ -17,22 +17,20 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeFieldSignatureData;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation;
|
||||
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
||||
import org.jetbrains.jet.lang.resolve.java.provider.PsiDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
||||
import org.jetbrains.jet.lang.resolve.java.wrapper.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -243,6 +241,17 @@ public final class JavaPropertyResolver {
|
||||
if (scopeData.getDeclarationOrigin() == JAVA) {
|
||||
trace.record(JavaBindingContext.IS_DECLARED_IN_JAVA, propertyDescriptor);
|
||||
}
|
||||
|
||||
if (AnnotationUtils.isPropertyAcceptableAsAnnotationParameter(propertyDescriptor) && psiData.getCharacteristicPsi() instanceof PsiField) {
|
||||
PsiExpression initializer = ((PsiField) psiData.getCharacteristicPsi()).getInitializer();
|
||||
if (initializer instanceof PsiLiteralExpression) {
|
||||
CompileTimeConstant<?> constant = JavaCompileTimeConstResolver.getCompileTimeConstFromLiteralExpressionWithExpectedType(
|
||||
(PsiLiteralExpression) initializer, propertyType);
|
||||
if (constant != null) {
|
||||
trace.record(BindingContext.COMPILE_TIME_INITIALIZER, propertyDescriptor, constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user