name and containingDeclaration pulled up

This commit is contained in:
Andrey Breslav
2013-09-24 15:02:17 -07:00
parent 6bed3cdc59
commit 0d84565570
8 changed files with 109 additions and 130 deletions
@@ -64,8 +64,6 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
private final NestedClassDescriptors nestedClasses;
private final NestedClassDescriptors nestedObjects;
private final Name name;
private final DeclarationDescriptor containingDeclaration;
private final DeserializedClassTypeConstructor typeConstructor;
private final Modality modality;
private final Visibility visibility;
@@ -84,20 +82,20 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
@NotNull ProtoBuf.Class classProto,
@Nullable TypeDeserializer outerTypeDeserializer
) {
super(containingDeclaration, nameResolver.getName(classProto.getName()));
this.classId = classId;
this.classProto = classProto;
this.descriptorFinder = descriptorFinder;
this.name = nameResolver.getName(classProto.getName());
TypeDeserializer notNullTypeDeserializer = new TypeDeserializer(storageManager, outerTypeDeserializer, nameResolver,
descriptorFinder, "Deserializer for class " + name, NONE);
descriptorFinder, "Deserializer for class " + getName(), NONE);
DescriptorDeserializer outerDeserializer = DescriptorDeserializer.create(storageManager, notNullTypeDeserializer,
this, nameResolver, annotationResolver);
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(classProto.getTypeParameterCount());
this.deserializer = outerDeserializer.createChildDeserializer(this, classProto.getTypeParameterList(), typeParameters);
this.typeDeserializer = deserializer.getTypeDeserializer();
this.containingDeclaration = containingDeclaration;
this.typeConstructor = new DeserializedClassTypeConstructor(typeParameters);
this.memberScope = new DeserializedClassMemberScope(storageManager, this);
this.innerClassesScope = new InnerClassesScopeWrapper(memberScope);
@@ -153,12 +151,6 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
return result;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
@NotNull
@Override
public TypeConstructor getTypeConstructor() {
@@ -189,12 +181,6 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
return isInner;
}
@NotNull
@Override
public Name getName() {
return name;
}
private List<AnnotationDescriptor> computeAnnotations() {
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
return Collections.emptyList();
@@ -69,8 +69,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
private final JetClassLikeInfo originalClassInfo;
private final ClassMemberDeclarationProvider declarationProvider;
private final Name name;
private final DeclarationDescriptor containingDeclaration;
private final LazyClassTypeConstructor typeConstructor;
private final Modality modality;
private final Visibility visibility;
@@ -94,8 +92,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
@NotNull Name name,
@NotNull JetClassLikeInfo classLikeInfo
) {
super(containingDeclaration, name);
this.resolveSession = resolveSession;
this.name = name;
if (classLikeInfo.getCorrespondingClassOrObject() != null) {
this.resolveSession.getTrace().record(BindingContext.CLASS, classLikeInfo.getCorrespondingClassOrObject(), this);
@@ -104,8 +102,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
this.originalClassInfo = classLikeInfo;
JetClassLikeInfo classLikeInfoForMembers =
classLikeInfo.getClassKind() != ClassKind.ENUM_CLASS ? classLikeInfo : noEnumEntries(classLikeInfo);
this.declarationProvider = resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfoForMembers);
this.containingDeclaration = containingDeclaration;
this.declarationProvider =
resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfoForMembers);
this.unsubstitutedMemberScope = new LazyClassMemberScope(resolveSession, declarationProvider, this);
this.unsubstitutedInnerClassesScope = new InnerClassesScopeWrapper(unsubstitutedMemberScope);
@@ -181,7 +179,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
@NotNull
private JetScope computeScopeForClassHeaderResolution() {
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + name);
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + getName());
for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
scope.addClassifierDescriptor(typeParameterDescriptor);
}
@@ -201,7 +199,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
@NotNull
private JetScope computeScopeForMemberDeclarationResolution() {
WritableScopeImpl thisScope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with 'this' for " + name);
WritableScopeImpl thisScope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with 'this' for " + getName());
thisScope.addLabeledDeclaration(this);
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
@@ -227,7 +225,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + name);
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + getName());
for (ValueParameterDescriptor valueParameterDescriptor : primaryConstructor.getValueParameters()) {
scope.addVariableDescriptor(valueParameterDescriptor);
}
@@ -250,12 +248,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
return unsubstitutedMemberScope.getPrimaryConstructor();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
@NotNull
@Override
public TypeConstructor getTypeConstructor() {
@@ -352,12 +344,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
}
}
@NotNull
@Override
public Name getName() {
return name;
}
@Override
public String toString() {
return "lazy class " + getName().toString();
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptorLite;
import org.jetbrains.jet.lang.resolve.java.scope.JavaClassNonStaticMembersScope;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
@@ -37,10 +38,11 @@ public class ClassDescriptorFromJvmBytecode extends MutableClassDescriptorLite {
public ClassDescriptorFromJvmBytecode(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Name name,
@NotNull ClassKind kind,
boolean isInner
) {
super(containingDeclaration, kind, isInner);
super(containingDeclaration, name, kind, isInner);
}
@@ -271,11 +271,10 @@ public final class JavaClassResolver {
@NotNull ClassOrNamespaceDescriptor containingDeclaration
) {
ClassDescriptorFromJvmBytecode classDescriptor =
new ClassDescriptorFromJvmBytecode(containingDeclaration, determineClassKind(javaClass), isInnerClass(javaClass));
new ClassDescriptorFromJvmBytecode(containingDeclaration, javaClass.getName(), determineClassKind(javaClass), isInnerClass(javaClass));
cache(javaClassToKotlinFqName(fqName), classDescriptor);
classDescriptor.setName(javaClass.getName());
JavaTypeParameterResolver.Initializer typeParameterInitializer = typeParameterResolver.resolveTypeParameters(classDescriptor, javaClass);
classDescriptor.setTypeParameterDescriptors(typeParameterInitializer.getDescriptors());
@@ -462,9 +461,8 @@ public final class JavaClassResolver {
@NotNull
private ClassDescriptorFromJvmBytecode createSyntheticClassObject(@NotNull ClassDescriptor containing, @NotNull JavaClass javaClass) {
ClassDescriptorFromJvmBytecode classObjectDescriptor =
new ClassDescriptorFromJvmBytecode(containing, ClassKind.CLASS_OBJECT, false);
new ClassDescriptorFromJvmBytecode(containing, getClassObjectName(containing.getName()), ClassKind.CLASS_OBJECT, false);
classObjectDescriptor.setName(getClassObjectName(containing.getName()));
classObjectDescriptor.setModality(Modality.FINAL);
classObjectDescriptor.setVisibility(containing.getVisibility());
classObjectDescriptor.setTypeParameterDescriptors(Collections.<TypeParameterDescriptor>emptyList());
@@ -0,0 +1,83 @@
package org.jetbrains.jet.lang.descriptors.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
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;
public abstract class AbstractClassDescriptor implements ClassDescriptor {
protected final Name name;
protected volatile JetType defaultType;
public AbstractClassDescriptor(@NotNull Name name) {
this.name = name;
}
@NotNull
@Override
public Name getName() {
return name;
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return this;
}
protected abstract JetScope getScopeForMemberLookup();
@NotNull
@Override
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Illegal number of type arguments: expected "
+ getTypeConstructor().getParameters().size() + " but was " + typeArguments.size()
+ " for " + getTypeConstructor() + " " + getTypeConstructor().getParameters();
if (typeArguments.isEmpty()) return getScopeForMemberLookup();
List<TypeParameterDescriptor> typeParameters = getTypeConstructor().getParameters();
Map<TypeConstructor, TypeProjection> 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(@NotNull TypeSubstitutor substitutor) {
if (substitutor.isEmpty()) {
return this;
}
return new LazySubstitutingClassDescriptor(this, substitutor);
}
@NotNull
@Override
public JetType getDefaultType() {
if (defaultType == null) {
defaultType = TypeUtils.makeUnsubstitutedType(this, getScopeForMemberLookup());
}
return defaultType;
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
visitor.visitClassDescriptor(this, null);
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitClassDescriptor(this, data);
}
}
@@ -17,72 +17,21 @@
package org.jetbrains.jet.lang.descriptors.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.List;
import java.util.Map;
public abstract class ClassDescriptorBase extends AbstractClassDescriptor {
public abstract class ClassDescriptorBase implements ClassDescriptor {
private final DeclarationDescriptor containingDeclaration;
protected volatile JetType defaultType;
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return this;
}
protected abstract JetScope getScopeForMemberLookup();
@NotNull
@Override
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Illegal number of type arguments: expected "
+ getTypeConstructor().getParameters().size() + " but was " + typeArguments.size()
+ " for " + getTypeConstructor() + " " + getTypeConstructor().getParameters();
if (typeArguments.isEmpty()) return getScopeForMemberLookup();
List<TypeParameterDescriptor> typeParameters = getTypeConstructor().getParameters();
Map<TypeConstructor, TypeProjection> 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);
protected ClassDescriptorBase(@NotNull DeclarationDescriptor containingDeclaration, @NotNull Name name) {
super(name);
this.containingDeclaration = containingDeclaration;
}
@NotNull
@Override
public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
if (substitutor.isEmpty()) {
return this;
}
return new LazySubstitutingClassDescriptor(this, substitutor);
}
@NotNull
@Override
public JetType getDefaultType() {
if (defaultType == null) {
defaultType = TypeUtils.makeUnsubstitutedType(this, getScopeForMemberLookup());
}
return defaultType;
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
visitor.visitClassDescriptor(this, null);
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitClassDescriptor(this, data);
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
}
@@ -43,7 +43,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
public MutableClassDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetScope outerScope, ClassKind kind, boolean isInner, Name name) {
super(containingDeclaration, kind, isInner);
super(containingDeclaration, name, kind, isInner);
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
@@ -57,7 +57,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
setUpScopeForInitializers(this);
}
setName(name);
scopeForMemberResolution.addLabeledDeclaration(this);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -128,12 +128,6 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setName(@NotNull Name name) {
super.setName(name);
scopeForMemberResolution.addLabeledDeclaration(this);
}
@Override
public void createTypeConstructor() {
super.createTypeConstructor();
@@ -60,35 +60,16 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
private ReceiverParameterDescriptor implicitReceiver;
private Name name;
private final DeclarationDescriptor containingDeclaration;
public MutableClassDescriptorLite(@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Name name,
@NotNull ClassKind kind,
boolean isInner
) {
this.containingDeclaration = containingDeclaration;
super(containingDeclaration, name);
this.kind = kind;
this.isInner = isInner;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
@NotNull
@Override
public Name getName() {
return name;
}
public void setName(@NotNull Name name) {
assert this.name == null : this.name;
this.name = name;
}
@NotNull
@Override
public TypeConstructor getTypeConstructor() {