EnumValue now has a ClassDescriptor for its enum entry

This commit is contained in:
Alexander Udalov
2013-11-13 20:45:08 +04:00
parent 83ef095093
commit a5d6d6719c
6 changed files with 45 additions and 50 deletions
@@ -19,9 +19,8 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
@@ -141,13 +140,10 @@ public final class JavaAnnotationArgumentResolver {
ClassDescriptor enumClass = classResolver.resolveClass(fqName, INCLUDE_KOTLIN_SOURCES, taskList);
if (enumClass == null) return null;
for (VariableDescriptor variableDescriptor : getEnumEntriesScope(enumClass).getProperties(field.getName())) {
if (variableDescriptor.getReceiverParameter() == null) {
return new EnumValue((PropertyDescriptor) variableDescriptor);
}
}
ClassifierDescriptor classifier = getEnumEntriesScope(enumClass).getClassifier(field.getName());
if (!(classifier instanceof ClassDescriptor)) return null;
return null;
return new EnumValue((ClassDescriptor) classifier);
}
@Nullable
@@ -44,8 +44,7 @@ import javax.inject.Inject;
import java.io.IOException;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.IGNORE_KOTLIN_SOURCES;
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.kotlinFqNameToJavaFqName;
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.naiveKotlinFqName;
@@ -185,15 +184,9 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
private CompileTimeConstant<?> enumEntryValue(@NotNull JvmClassName enumClassName, @NotNull Name name) {
ClassDescriptor enumClass = resolveClass(enumClassName);
if (enumClass.getKind() == ClassKind.ENUM_CLASS) {
ClassDescriptor classObject = enumClass.getClassObjectDescriptor();
if (classObject != null) {
Collection<VariableDescriptor> properties = classObject.getDefaultType().getMemberScope().getProperties(name);
if (properties.size() == 1) {
VariableDescriptor property = properties.iterator().next();
if (property instanceof PropertyDescriptor) {
return new EnumValue((PropertyDescriptor) property);
}
}
ClassifierDescriptor classifier = getEnumEntriesScope(enumClass).getClassifier(name);
if (classifier instanceof ClassDescriptor) {
return new EnumValue((ClassDescriptor) classifier);
}
}
return ErrorValue.create("Unresolved enum entry: " + enumClassName.getInternalName() + "." + name);
@@ -17,29 +17,30 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public class EnumValue implements CompileTimeConstant<PropertyDescriptor> {
private final PropertyDescriptor value;
public class EnumValue implements CompileTimeConstant<ClassDescriptor> {
private final ClassDescriptor value;
public EnumValue(@NotNull PropertyDescriptor value) {
public EnumValue(@NotNull ClassDescriptor value) {
this.value = value;
}
@Override
@NotNull
public PropertyDescriptor getValue() {
public ClassDescriptor getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
return value.getType();
JetType type = value.getClassObjectType();
assert type != null : "Enum entry should have a class object: " + value;
return type;
}
@Override
@@ -49,7 +50,7 @@ public class EnumValue implements CompileTimeConstant<PropertyDescriptor> {
@Override
public String toString() {
return value.getType() + "." + value.getName();
return getType(KotlinBuiltIns.getInstance()) + "." + value.getName();
}
@Override
@@ -57,9 +58,7 @@ public class EnumValue implements CompileTimeConstant<PropertyDescriptor> {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EnumValue enumValue = (EnumValue) o;
return value.equals(enumValue.value);
return value.equals(((EnumValue) o).value);
}
@Override
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
@@ -63,7 +62,7 @@ public class InlineUtil {
}
else {
assert argument instanceof EnumValue : "Inline annotation parameter should be inline entry but was: " + argument + "!";
PropertyDescriptor value = ((EnumValue)argument).getValue();
ClassDescriptor value = ((EnumValue) argument).getValue();
String name = value.getName().asString();
return name.equals(InlineStrategy.IN_PLACE.name()) ? InlineStrategy.IN_PLACE : InlineStrategy.AS_FUNCTION;
}