Drop ClassifierDescriptor#getClassObjectType()

Introduce utility for ClassDescriptor to use where necessary
This commit is contained in:
Pavel V. Talanov
2015-04-01 16:02:57 +03:00
parent b930f71b79
commit 5fe8bb4a92
16 changed files with 68 additions and 88 deletions
@@ -56,10 +56,6 @@ public interface ClassDescriptor extends ClassifierDescriptor, MemberDescriptor,
@Override
ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor);
@Nullable
@Override
JetType getClassObjectType();
/**
* @return nested object declared as 'companion' if one is present.
*/
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeConstructor;
@@ -27,7 +26,4 @@ public interface ClassifierDescriptor extends DeclarationDescriptorNonRoot {
@NotNull
JetType getDefaultType();
@Nullable
JetType getClassObjectType();
}
@@ -18,10 +18,8 @@ package org.jetbrains.kotlin.descriptors.impl;
import kotlin.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.SubstitutingScope;
@@ -75,13 +73,6 @@ public abstract class AbstractClassDescriptor implements ClassDescriptor {
@NotNull
protected abstract JetScope getScopeForMemberLookup();
@Nullable
@Override
public JetType getClassObjectType() {
ClassDescriptor classObject = DescriptorUtilPackage.getClassObjectDescriptor(this);
return classObject == null ? null : classObject.getDefaultType();
}
@NotNull
@Override
public JetScope getUnsubstitutedInnerClassesScope() {
@@ -150,12 +150,6 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
return defaultType.invoke();
}
@Override
public JetType getClassObjectType() {
// TODO: companion object bounds
return null;
}
@NotNull
@Override
public Set<JetType> getLowerBounds() {
@@ -163,11 +163,6 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
return new LazySubstitutingClassDescriptor(this, TypeSubstitutor.create(substitutor.getSubstitution(), getSubstitutor().getSubstitution()));
}
@Override
public JetType getClassObjectType() {
return original.getClassObjectType();
}
@Override
public ClassDescriptor getCompanionObjectDescriptor() {
return original.getCompanionObjectDescriptor();
@@ -16,12 +16,15 @@
package org.jetbrains.kotlin.resolve.descriptorUtil
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.descriptors.ClassKind.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassKind.ENUM_CLASS
import org.jetbrains.kotlin.descriptors.ClassKind.ENUM_ENTRY
import org.jetbrains.kotlin.descriptors.ClassKind.OBJECT
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.JetType
public fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = getCompanionObjectDescriptor() ?: this
@@ -57,11 +60,14 @@ public val ClassDescriptor.classId: ClassId
throw IllegalStateException("Illegal container: $owner")
}
/** If a literal of this class can be used as a value returns the class which represents the type of this value */
public val ClassDescriptor.classObjectDescriptor: ClassDescriptor?
public val ClassDescriptor.hasClassObjectType: Boolean get() = classObjectType != null
/** If a literal of this class can be used as a value, returns the type of this value */
public val ClassDescriptor.classObjectType: JetType?
get() {
return when (this.getKind()) {
val correspondingDescriptor = when (this.getKind()) {
OBJECT -> this
// enum entry has the type of enum class
ENUM_ENTRY -> {
val container = this.getContainingDeclaration()
assert(container is ClassDescriptor && container.getKind() == ENUM_CLASS)
@@ -69,6 +75,7 @@ public val ClassDescriptor.classObjectDescriptor: ClassDescriptor?
}
else -> getCompanionObjectDescriptor()
}
return correspondingDescriptor?.getDefaultType()
}
public val DeclarationDescriptorWithVisibility.isEffectivelyPublicApi: Boolean
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.kotlin.types.JetType;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getClassObjectType;
public class EnumValue extends CompileTimeConstant<ClassDescriptor> {
public EnumValue(@NotNull ClassDescriptor value, boolean usesVariableAsConstant) {
@@ -31,8 +33,8 @@ public class EnumValue extends CompileTimeConstant<ClassDescriptor> {
@NotNull
@Override
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
JetType type = value.getClassObjectType();
assert type != null : "Enum entry should have a companion object: " + value;
JetType type = getClassObjectType(value);
assert type != null : "Enum entry must have a class object type: " + value;
return type;
}