Do not create empty static scope instances for non-enum classes
This commit is contained in:
+2
-2
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.lazy.data.KtObjectInfo;
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass;
|
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinEnum;
|
||||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
||||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||||
@@ -128,7 +128,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
|||||||
|
|
||||||
this.unsubstitutedMemberScope = createMemberScope(c, this.declarationProvider);
|
this.unsubstitutedMemberScope = createMemberScope(c, this.declarationProvider);
|
||||||
this.kind = classLikeInfo.getClassKind();
|
this.kind = classLikeInfo.getClassKind();
|
||||||
this.staticScope = new StaticScopeForKotlinClass(this);
|
this.staticScope = kind == ClassKind.ENUM_CLASS ? new StaticScopeForKotlinEnum(this) : MemberScope.Empty.INSTANCE;
|
||||||
|
|
||||||
this.typeConstructor = new LazyClassTypeConstructor();
|
this.typeConstructor = new LazyClassTypeConstructor();
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.builtins.functions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
|
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor.Kind
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor
|
||||||
@@ -26,7 +25,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||||
@@ -62,7 +61,6 @@ class FunctionClassDescriptor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val staticScope = StaticScopeForKotlinClass(this)
|
|
||||||
private val typeConstructor = FunctionTypeConstructor()
|
private val typeConstructor = FunctionTypeConstructor()
|
||||||
private val memberScope = FunctionClassScope(storageManager, this)
|
private val memberScope = FunctionClassScope(storageManager, this)
|
||||||
|
|
||||||
@@ -88,7 +86,7 @@ class FunctionClassDescriptor(
|
|||||||
|
|
||||||
override fun getContainingDeclaration() = containingDeclaration
|
override fun getContainingDeclaration() = containingDeclaration
|
||||||
|
|
||||||
override fun getStaticScope() = staticScope
|
override fun getStaticScope() = MemberScope.Empty
|
||||||
|
|
||||||
override fun getTypeConstructor(): TypeConstructor = typeConstructor
|
override fun getTypeConstructor(): TypeConstructor = typeConstructor
|
||||||
|
|
||||||
@@ -120,7 +118,7 @@ class FunctionClassDescriptor(
|
|||||||
val typeConstructor = descriptor.typeConstructor
|
val typeConstructor = descriptor.typeConstructor
|
||||||
|
|
||||||
// Substitute all type parameters of the super class with our last type parameters
|
// Substitute all type parameters of the super class with our last type parameters
|
||||||
val arguments = getParameters().takeLast(typeConstructor.parameters.size).map {
|
val arguments = parameters.takeLast(typeConstructor.parameters.size).map {
|
||||||
TypeProjectionImpl(it.defaultType)
|
TypeProjectionImpl(it.defaultType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass;
|
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||||
@@ -37,7 +36,6 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
|||||||
private final Modality modality;
|
private final Modality modality;
|
||||||
private final ClassKind kind;
|
private final ClassKind kind;
|
||||||
private final TypeConstructor typeConstructor;
|
private final TypeConstructor typeConstructor;
|
||||||
private final MemberScope staticScope = new StaticScopeForKotlinClass(this);
|
|
||||||
|
|
||||||
private MemberScope unsubstitutedMemberScope;
|
private MemberScope unsubstitutedMemberScope;
|
||||||
private Set<ConstructorDescriptor> constructors;
|
private Set<ConstructorDescriptor> constructors;
|
||||||
@@ -108,7 +106,7 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public MemberScope getStaticScope() {
|
public MemberScope getStaticScope() {
|
||||||
return staticScope;
|
return MemberScope.Empty.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+1
-3
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.OverridingUtil;
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl;
|
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass;
|
|
||||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
||||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||||
import org.jetbrains.kotlin.storage.StorageManager;
|
import org.jetbrains.kotlin.storage.StorageManager;
|
||||||
@@ -46,7 +45,6 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
|||||||
private final TypeConstructor typeConstructor;
|
private final TypeConstructor typeConstructor;
|
||||||
private final ConstructorDescriptor primaryConstructor;
|
private final ConstructorDescriptor primaryConstructor;
|
||||||
private final MemberScope scope;
|
private final MemberScope scope;
|
||||||
private final MemberScope staticScope = new StaticScopeForKotlinClass(this);
|
|
||||||
private final NotNullLazyValue<Collection<Name>> enumMemberNames;
|
private final NotNullLazyValue<Collection<Name>> enumMemberNames;
|
||||||
private final Annotations annotations;
|
private final Annotations annotations;
|
||||||
|
|
||||||
@@ -102,7 +100,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public MemberScope getStaticScope() {
|
public MemberScope getStaticScope() {
|
||||||
return staticScope;
|
return MemberScope.Empty.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+7
-15
@@ -27,27 +27,19 @@ import org.jetbrains.kotlin.utils.Printer
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
// We don't need to track lookups here since this scope used only for introduce special Enum class members
|
// We don't need to track lookups here since this scope used only for introduce special Enum class members
|
||||||
class StaticScopeForKotlinClass(
|
class StaticScopeForKotlinEnum(private val containingClass: ClassDescriptor) : MemberScopeImpl() {
|
||||||
private val containingClass: ClassDescriptor
|
init {
|
||||||
) : MemberScopeImpl() {
|
assert(containingClass.kind == ClassKind.ENUM_CLASS) { "Class should be an enum: $containingClass" }
|
||||||
|
}
|
||||||
|
|
||||||
override fun getContributedClassifier(name: Name, location: LookupLocation) = null // TODO
|
override fun getContributedClassifier(name: Name, location: LookupLocation) = null // TODO
|
||||||
|
|
||||||
private val functions: List<FunctionDescriptor> by lazy {
|
private val functions: List<FunctionDescriptor> by lazy {
|
||||||
if (containingClass.kind != ClassKind.ENUM_CLASS) {
|
listOf(createEnumValueOfMethod(containingClass), createEnumValuesMethod(containingClass))
|
||||||
listOf<FunctionDescriptor>()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
listOf(createEnumValueOfMethod(containingClass), createEnumValuesMethod(containingClass))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val properties: List<PropertyDescriptor> by lazy {
|
private val properties: List<PropertyDescriptor> by lazy {
|
||||||
if (containingClass.kind != ClassKind.ENUM_CLASS) {
|
listOf(createEnumValuesProperty(containingClass))
|
||||||
listOf<PropertyDescriptor>()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
listOf(createEnumValuesProperty(containingClass))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
|
||||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.OverridingStrategy
|
|||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass
|
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinEnum
|
||||||
import org.jetbrains.kotlin.serialization.Flags
|
import org.jetbrains.kotlin.serialization.Flags
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||||
@@ -63,7 +63,7 @@ class DeserializedClassDescriptor(
|
|||||||
|
|
||||||
private val classId = nameResolver.getClassId(classProto.fqName)
|
private val classId = nameResolver.getClassId(classProto.fqName)
|
||||||
|
|
||||||
private val staticScope = StaticScopeForKotlinClass(this)
|
private val staticScope = if (kind == ClassKind.ENUM_CLASS) StaticScopeForKotlinEnum(this) else MemberScope.Empty
|
||||||
private val typeConstructor = DeserializedClassTypeConstructor()
|
private val typeConstructor = DeserializedClassTypeConstructor()
|
||||||
private val memberScope = DeserializedClassMemberScope()
|
private val memberScope = DeserializedClassMemberScope()
|
||||||
private val nestedClasses = NestedClassDescriptors()
|
private val nestedClasses = NestedClassDescriptors()
|
||||||
|
|||||||
Reference in New Issue
Block a user