From 3c0c08c6655c57e18f61a2993c43832871c309a8 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 25 May 2012 16:50:28 +0400 Subject: [PATCH] Base class for class descriptors extracted. Will be used for lazy resolve --- .../lang/descriptors/ClassDescriptorBase.java | 61 +++++++++++++++++++ .../MutableClassDescriptorLite.java | 30 +-------- 2 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java new file mode 100644 index 00000000000..289fc8f2677 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java @@ -0,0 +1,61 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.descriptors; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.scopes.JetScope; +import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope; +import org.jetbrains.jet.lang.types.*; + +import java.util.List; +import java.util.Map; + +/** + * @author abreslav + */ +public abstract class ClassDescriptorBase extends MutableDeclarationDescriptor implements ClassDescriptor { + public ClassDescriptorBase(DeclarationDescriptor containingDeclaration) { + super(containingDeclaration); + } + + protected abstract JetScope getScopeForMemberLookup(); + + @NotNull + @Override + public JetScope getMemberScope(List typeArguments) { + assert typeArguments.size() == getTypeConstructor().getParameters().size(); + if (typeArguments.isEmpty()) return getScopeForMemberLookup(); + + List typeParameters = getTypeConstructor().getParameters(); + Map substitutionContext = SubstitutionUtils.buildSubstitutionContext(typeParameters, typeArguments); + + // Unsafe substitutor is OK, because no recursion can hurt us upon a trivial substitution: + // all the types are written explicitly in the code already, they can not get infinite. + // One exception is *-projections, but they need to be handled separately anyways. + TypeSubstitutor substitutor = TypeSubstitutor.createUnsafe(substitutionContext); + return new SubstitutingScope(getScopeForMemberLookup(), substitutor); + } + + @NotNull + @Override + public ClassDescriptor substitute(TypeSubstitutor substitutor) { + if (substitutor.isEmpty()) { + return this; + } + return new LazySubstitutingClassDescriptor(this, substitutor); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java index 88d89a1cd63..4321e6afae2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java @@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper; import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -36,8 +35,8 @@ import java.util.*; /** * @author Stepan Koltsov */ -public class MutableClassDescriptorLite extends MutableDeclarationDescriptor - implements ClassDescriptor, WithDeferredResolve { +public class MutableClassDescriptorLite extends ClassDescriptorBase + implements WithDeferredResolve { private ConstructorDescriptor primaryConstructor; private final Set constructors = Sets.newLinkedHashSet(); @@ -120,22 +119,6 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor return (WritableScope) scopeForMemberLookup; } - @NotNull - @Override - public JetScope getMemberScope(List typeArguments) { - assert typeArguments.size() == typeConstructor.getParameters().size(); - if (typeArguments.isEmpty()) return scopeForMemberLookup; - - List typeParameters = getTypeConstructor().getParameters(); - Map substitutionContext = SubstitutionUtils.buildSubstitutionContext(typeParameters, typeArguments); - - // Unsafe substitutor is OK, because no recursion can hurt us upon a trivial substitution: - // all the types are written explicitly in the code already, they can not get infinite. - // One exception is *-projections, but they need to be handled separately anyways. - TypeSubstitutor substitutor = TypeSubstitutor.createUnsafe(substitutionContext); - return new SubstitutingScope(scopeForMemberLookup, substitutor); - } - @NotNull @Override @@ -148,15 +131,6 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor return scopeForMemberLookup; } - @NotNull - @Override - public ClassDescriptor substitute(TypeSubstitutor substitutor) { - if (substitutor.isEmpty()) { - return this; - } - return new LazySubstitutingClassDescriptor(this, substitutor); - } - @Override public JetType getClassObjectType() { if (classObjectType == null && classObjectDescriptor != null) {