name and containingDeclaration pulled up
This commit is contained in:
+3
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-4
@@ -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());
|
||||
|
||||
+83
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
-59
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -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();
|
||||
|
||||
+2
-21
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user