Move values/valueOf creation logic to EnumClassObjectDescriptor
This commit is contained in:
+19
-3
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.descriptors.impl
|
||||
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
@@ -31,6 +32,8 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope.LockLevel
|
||||
import org.jetbrains.jet.lang.types.DelegatingType
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
public class EnumClassObjectDescriptor(
|
||||
storageManager: StorageManager,
|
||||
@@ -53,9 +56,9 @@ public class EnumClassObjectDescriptor(
|
||||
val enumType = object : DelegatingType() {
|
||||
override fun getDelegate() = (getContainingDeclaration() as ClassDescriptor).getDefaultType()
|
||||
}
|
||||
val enumArrayType = KotlinBuiltIns.getInstance().getArrayType(enumType)
|
||||
scope.addFunctionDescriptor(DescriptorFactory.createEnumClassObjectValuesMethod(this, enumArrayType))
|
||||
scope.addFunctionDescriptor(DescriptorFactory.createEnumClassObjectValueOfMethod(this, enumType))
|
||||
|
||||
scope.addFunctionDescriptor(createEnumClassObjectValuesMethod(enumType))
|
||||
scope.addFunctionDescriptor(createEnumClassObjectValueOfMethod(enumType))
|
||||
|
||||
val sink = object : OverridingUtil.DescriptorSink {
|
||||
override fun addToScope(fakeOverride: CallableMemberDescriptor) {
|
||||
@@ -80,6 +83,19 @@ public class EnumClassObjectDescriptor(
|
||||
scope.changeLockLevel(LockLevel.READING)
|
||||
}
|
||||
|
||||
private fun createEnumClassObjectValuesMethod(enumType: JetType): SimpleFunctionDescriptor {
|
||||
val enumArrayType = KotlinBuiltIns.getInstance().getArrayType(enumType)
|
||||
val values = SimpleFunctionDescriptorImpl.create(this, Annotations.EMPTY, Name.identifier("values"), SYNTHESIZED)
|
||||
return values.initialize(null, getThisAsReceiverParameter(), listOf(), listOf(), enumArrayType, Modality.FINAL, Visibilities.PUBLIC)
|
||||
}
|
||||
|
||||
private fun createEnumClassObjectValueOfMethod(enumType: JetType): SimpleFunctionDescriptor {
|
||||
val values = SimpleFunctionDescriptorImpl.create(this, Annotations.EMPTY, Name.identifier("valueOf"), SYNTHESIZED)
|
||||
val parameter = ValueParameterDescriptorImpl(values, null, 0, Annotations.EMPTY, Name.identifier("value"),
|
||||
KotlinBuiltIns.getInstance().getStringType(), false, null)
|
||||
return values.initialize(null, getThisAsReceiverParameter(), listOf(), listOf(parameter), enumType, Modality.FINAL, Visibilities.PUBLIC)
|
||||
}
|
||||
|
||||
override fun getScopeForMemberLookup(): JetScope = scope
|
||||
|
||||
override fun getClassObjectDescriptor(): ClassDescriptor? = null
|
||||
|
||||
@@ -20,11 +20,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyGetterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertySetterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ReceiverParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -32,9 +33,6 @@ import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getDefaultConstructorVisibility;
|
||||
|
||||
public class DescriptorFactory {
|
||||
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
|
||||
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
|
||||
|
||||
private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl {
|
||||
public DefaultConstructorDescriptor(@NotNull ClassDescriptor containingClass) {
|
||||
super(containingClass, null, Annotations.EMPTY, true, Kind.DECLARATION);
|
||||
@@ -82,44 +80,6 @@ public class DescriptorFactory {
|
||||
return constructor instanceof DefaultConstructorDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
SimpleFunctionDescriptorImpl.create(classObject, Annotations.EMPTY, VALUES_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
SimpleFunctionDescriptorImpl.create(classObject, Annotations.EMPTY, VALUE_OF_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED);
|
||||
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
values,
|
||||
null,
|
||||
0,
|
||||
Annotations.EMPTY,
|
||||
Name.identifier("value"),
|
||||
KotlinBuiltIns.getInstance().getStringType(),
|
||||
false,
|
||||
null);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singletonList(parameterDescriptor),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ReceiverParameterDescriptor createReceiverParameterForCallable(
|
||||
@NotNull CallableDescriptor owner,
|
||||
|
||||
Reference in New Issue
Block a user