From a4599ef5e25042af9eb6a792d05d8fbf94847bd0 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 19 Aug 2015 18:57:22 +0300 Subject: [PATCH] Clean up MutableClassDescriptor --- .../codegen/CollectionStubMethodGenerator.kt | 3 +- .../kotlin/codegen/JvmRuntimeTypes.java | 2 +- .../impl/MutableClassDescriptor.java | 165 ++---------------- 3 files changed, 14 insertions(+), 156 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt index ffeed167bf9..477ebb0a4d9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt @@ -27,7 +27,6 @@ import org.jetbrains.kotlin.resolve.OverridingUtil import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature -import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.JetTypeChecker import org.jetbrains.org.objectweb.asm.Opcodes.ACC_ABSTRACT @@ -193,7 +192,7 @@ class CollectionStubMethodGenerator( } private fun createSyntheticSubclass(): Pair> { - val child = MutableClassDescriptor(descriptor.getContainingDeclaration(), JetScope.Empty, ClassKind.CLASS, false, + val child = MutableClassDescriptor(descriptor.getContainingDeclaration(), ClassKind.CLASS, false, Name.special(""), descriptor.getSource()) child.setModality(Modality.FINAL) child.setVisibility(Visibilities.PUBLIC) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java index 492048c5675..8bc835eb74b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java @@ -61,7 +61,7 @@ public class JvmRuntimeTypes { @NotNull private static ClassDescriptor createClass(@NotNull PackageFragmentDescriptor packageFragment, @NotNull String name) { MutableClassDescriptor descriptor = new MutableClassDescriptor( - packageFragment, packageFragment.getMemberScope(), ClassKind.CLASS, false, Name.identifier(name), SourceElement.NO_SOURCE + packageFragment, ClassKind.CLASS, false, Name.identifier(name), SourceElement.NO_SOURCE ); descriptor.setModality(Modality.FINAL); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/descriptors/impl/MutableClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/impl/MutableClassDescriptor.java index 700b51a6a35..5ddf104600a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/descriptors/impl/MutableClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/impl/MutableClassDescriptor.java @@ -16,20 +16,21 @@ package org.jetbrains.kotlin.descriptors.impl; -import com.google.common.collect.Sets; -import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.resolve.scopes.*; +import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.storage.LockBasedStorageManager; -import org.jetbrains.kotlin.types.*; +import org.jetbrains.kotlin.types.JetType; +import org.jetbrains.kotlin.types.TypeConstructor; +import org.jetbrains.kotlin.types.TypeConstructorImpl; +import org.jetbrains.kotlin.types.TypeUtils; import java.util.*; -public class MutableClassDescriptor extends ClassDescriptorBase implements ClassDescriptorWithResolutionScopes { +public class MutableClassDescriptor extends ClassDescriptorBase implements ClassDescriptor { private final ClassKind kind; private final boolean isInner; @@ -37,26 +38,10 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class private Visibility visibility; private TypeConstructor typeConstructor; private List typeParameters; - private Collection supertypes = new ArrayList(); - - private final Set constructors = Sets.newLinkedHashSet(); - private ConstructorDescriptor primaryConstructor; - - private final Set declaredCallableMembers = Sets.newLinkedHashSet(); - private final Set properties = Sets.newLinkedHashSet(); - private final Set functions = Sets.newLinkedHashSet(); - - private final MutableScopeForMemberResolution mutableScopeForMemberResolution; - private final JetScope scopeForMemberResolution; - // This scope contains type parameters but does not contain inner classes - private final WritableScope scopeForSupertypeResolution; - private JetScope scopeForInitializers; //contains members + primary constructor value parameters + map for backing fields - private final JetScope unsubstitutedMemberScope; - private final JetScope staticScope = new StaticScopeForKotlinClass(this); + private final Collection supertypes = new ArrayList(); public MutableClassDescriptor( @NotNull DeclarationDescriptor containingDeclaration, - @NotNull JetScope outerScope, @NotNull ClassKind kind, boolean isInner, @NotNull Name name, @@ -67,25 +52,11 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class this.kind = kind; this.isInner = isInner; - - RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING; - - this.unsubstitutedMemberScope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, this, redeclarationHandler, "MemberLookup", null, this) - .changeLockLevel(WritableScope.LockLevel.BOTH); - this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler, "SupertypeResolution") - .changeLockLevel(WritableScope.LockLevel.BOTH); - this.mutableScopeForMemberResolution = new MutableScopeForMemberResolution(); - - if (kind == ClassKind.INTERFACE) { - setUpScopeForInitializers(this); - } - - this.scopeForMemberResolution = new ChainedScope(this, "MemberResolutionWithStatic", mutableScopeForMemberResolution, staticScope); } @Nullable @Override - public MutableClassDescriptor getCompanionObjectDescriptor() { + public ClassDescriptor getCompanionObjectDescriptor() { return null; } @@ -137,15 +108,6 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class return typeConstructor; } - @NotNull - public Collection getSupertypes() { - return supertypes; - } - - public void setSupertypes(@NotNull Collection supertypes) { - this.supertypes = supertypes; - } - public void addSupertype(@NotNull JetType supertype) { assert !supertype.isError() : "Error types must be filtered out in DescriptorResolver"; if (TypeUtils.getClassDescriptor(supertype) != null) { @@ -154,50 +116,16 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class } } - public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) { - assert primaryConstructor == null : "Primary constructor assigned twice " + this; - primaryConstructor = constructorDescriptor; - - constructors.add(constructorDescriptor); - - ((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(new DelegatingType() { - @Override - protected JetType getDelegate() { - return getDefaultType(); - } - }); - - if (constructorDescriptor.isPrimary()) { - setUpScopeForInitializers(constructorDescriptor); - } - } - @NotNull @Override public Set getConstructors() { - return constructors; + return Collections.emptySet(); } @Override @Nullable public ConstructorDescriptor getUnsubstitutedPrimaryConstructor() { - return primaryConstructor; - } - - @NotNull - public Set getFunctions() { - return functions; - } - - @NotNull - public Set getProperties() { - return properties; - } - - @Override - @NotNull - public Set getDeclaredCallableMembers() { - return declaredCallableMembers; + return null; } public void setTypeParameterDescriptors(@NotNull List typeParameters) { @@ -205,10 +133,6 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class throw new IllegalStateException("Type parameters are already set for " + getName()); } this.typeParameters = new ArrayList(typeParameters); - for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { - scopeForSupertypeResolution.addClassifierDescriptor(typeParameterDescriptor); - } - scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING); } public void createTypeConstructor() { @@ -224,87 +148,22 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class for (FunctionDescriptor functionDescriptor : getConstructors()) { ((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType()); } - mutableScopeForMemberResolution.setImplicitReceiver(getThisAsReceiverParameter()); - } - - @Override - @NotNull - public JetScope getScopeForClassHeaderResolution() { - return scopeForSupertypeResolution; - } - - @Override - @NotNull - public JetScope getScopeForMemberDeclarationResolution() { - return scopeForMemberResolution; - } - - @Override - @NotNull - public JetScope getScopeForInitializerResolution() { - if (scopeForInitializers == null) { - throw new IllegalStateException("Scope for initializers queried before the primary constructor is set"); - } - return scopeForInitializers; - } - - private void setUpScopeForInitializers(@NotNull DeclarationDescriptor containingDeclaration) { - this.scopeForInitializers = new WritableScopeImpl( - scopeForMemberResolution, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Initializers") - .changeLockLevel(WritableScope.LockLevel.BOTH); } @Override @NotNull public JetScope getUnsubstitutedMemberScope() { - return unsubstitutedMemberScope; + return JetScope.Empty.INSTANCE$; // used for getDefaultType } @NotNull @Override public JetScope getStaticScope() { - return staticScope; + return JetScope.Empty.INSTANCE$; } @Override public String toString() { return DeclarationDescriptorImpl.toString(this); } - - private class MutableScopeForMemberResolution extends AbstractScopeAdapter { - private ReceiverParameterDescriptor implicitReceiver = null; - private List implicitReceiversHierarchy = null; - - @NotNull - @Override - protected JetScope getWorkerScope() { - return scopeForSupertypeResolution; - } - - @NotNull - @Override - public DeclarationDescriptor getContainingDeclaration() { - return MutableClassDescriptor.this; - } - - public void setImplicitReceiver(@NotNull ReceiverParameterDescriptor implicitReceiver) { - if (this.implicitReceiver != null) { - throw new UnsupportedOperationException("Receiver redeclared"); - } - if (this.implicitReceiversHierarchy != null) { - throw new UnsupportedOperationException("Receiver hierarchy already computed"); - } - this.implicitReceiver = implicitReceiver; - this.implicitReceiversHierarchy = KotlinPackage.plus(Collections.singletonList(implicitReceiver), super.getImplicitReceiversHierarchy()); - } - - @NotNull - @Override - public List getImplicitReceiversHierarchy() { - if (implicitReceiversHierarchy != null) - return implicitReceiversHierarchy; - else - return super.getImplicitReceiversHierarchy(); - } - } }