Simplify TypeConstructorImpl, extend it from AbstractClassTypeConstructor
This commit is contained in:
@@ -151,13 +151,8 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
public void createTypeConstructor() {
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = TypeConstructorImpl.createForClass(
|
||||
this,
|
||||
Annotations.Companion.getEMPTY(),
|
||||
ModalityKt.isFinalClass(this),
|
||||
getName().asString(),
|
||||
typeParameters,
|
||||
supertypes
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this, Annotations.Companion.getEMPTY(), ModalityKt.isFinalClass(this), typeParameters, supertypes
|
||||
);
|
||||
for (FunctionDescriptor functionDescriptor : getConstructors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
|
||||
+2
-2
@@ -2,10 +2,10 @@ package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
@[Missing annotation class: missing.Ann]() public open class A {
|
||||
@missing.Ann() public open class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@[Missing annotation class: missing.Ann]() public open fun foo(): kotlin.String!
|
||||
@missing.Ann() public open fun foo(): kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ public fun test(): kotlin.Unit
|
||||
|
||||
public interface A</*0*/ T : kotlin.Any!> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ @[Missing annotation class: javax.annotation.Nullable]() y: T?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ @javax.annotation.Nullable() y: T?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@@ -293,10 +293,10 @@ package test {
|
||||
invisible_fake final override /*1*/ /*fake_override*/ fun getFocusTraversalKeys_NoIDCheck(/*0*/ p0: kotlin.Int): kotlin.collections.(Mutable)Set<(raw) kotlin.Any?>!
|
||||
public open override /*1*/ /*fake_override*/ fun getFocusTraversalPolicy(): [ERROR : Unresolved java classifier: FocusTraversalPolicy]!
|
||||
public open override /*1*/ /*fake_override*/ fun getFocusableWindowState(): kotlin.Boolean
|
||||
@[Missing annotation class: java.beans.Transient]() public open override /*1*/ /*fake_override*/ fun getFont(): [ERROR : Unresolved java classifier: Font]!
|
||||
@java.beans.Transient() public open override /*1*/ /*fake_override*/ fun getFont(): [ERROR : Unresolved java classifier: Font]!
|
||||
public open override /*1*/ /*fake_override*/ fun getFontMetrics(/*0*/ p0: [ERROR : Unresolved java classifier: Font]!): [ERROR : Unresolved java classifier: FontMetrics]!
|
||||
invisible_fake final override /*1*/ /*fake_override*/ fun getFont_NoClientCode(): [ERROR : Unresolved java classifier: Font]!
|
||||
@[Missing annotation class: java.beans.Transient]() public open override /*1*/ /*fake_override*/ fun getForeground(): [ERROR : Unresolved java classifier: Color]!
|
||||
@java.beans.Transient() public open override /*1*/ /*fake_override*/ fun getForeground(): [ERROR : Unresolved java classifier: Color]!
|
||||
public open override /*1*/ /*fake_override*/ fun getGlassPane(): java.awt.Component!
|
||||
public open override /*1*/ /*fake_override*/ fun getGraphics(): [ERROR : Unresolved java classifier: Graphics]!
|
||||
public open override /*1*/ /*fake_override*/ fun getGraphicsConfiguration(): [ERROR : Unresolved java classifier: GraphicsConfiguration]!
|
||||
@@ -450,7 +450,7 @@ package test {
|
||||
public open override /*1*/ /*fake_override*/ fun isUndecorated(): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun isValid(): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun isValidateRoot(): kotlin.Boolean
|
||||
@[Missing annotation class: java.beans.Transient]() public open override /*1*/ /*fake_override*/ fun isVisible(): kotlin.Boolean
|
||||
@java.beans.Transient() public open override /*1*/ /*fake_override*/ fun isVisible(): kotlin.Boolean
|
||||
invisible_fake final override /*1*/ /*fake_override*/ fun isVisible_NoClientCode(): kotlin.Boolean
|
||||
@kotlin.Deprecated(message = "Deprecated in Java") public open override /*1*/ /*fake_override*/ fun keyDown(/*0*/ p0: [ERROR : Unresolved java classifier: Event]!, /*1*/ p1: kotlin.Int): kotlin.Boolean
|
||||
@kotlin.Deprecated(message = "Deprecated in Java") public open override /*1*/ /*fake_override*/ fun keyUp(/*0*/ p0: [ERROR : Unresolved java classifier: Event]!, /*1*/ p1: kotlin.Int): kotlin.Boolean
|
||||
|
||||
+9
-10
@@ -151,14 +151,13 @@ class LazyJavaAnnotationDescriptor(
|
||||
}
|
||||
|
||||
private fun createTypeForMissingDependencies(fqName: FqName) =
|
||||
ErrorUtils.createErrorTypeWithCustomConstructor(
|
||||
"[Missing annotation class: $fqName]",
|
||||
ClassDescriptorImpl(
|
||||
EmptyPackageFragmentDescriptor(c.module, fqName.parent()), fqName.shortName(), Modality.FINAL,
|
||||
ClassKind.ANNOTATION_CLASS, listOf(c.module.builtIns.anyType), SourceElement.NO_SOURCE,
|
||||
"[Missing annotation class: $fqName]"
|
||||
).apply {
|
||||
initialize(MemberScope.Empty, emptySet(), null)
|
||||
}.typeConstructor
|
||||
)
|
||||
ErrorUtils.createErrorTypeWithCustomConstructor(
|
||||
"[Missing annotation class: $fqName]",
|
||||
ClassDescriptorImpl(
|
||||
EmptyPackageFragmentDescriptor(c.module, fqName.parent()), fqName.shortName(), Modality.FINAL,
|
||||
ClassKind.ANNOTATION_CLASS, listOf(c.module.builtIns.anyType), SourceElement.NO_SOURCE
|
||||
).apply {
|
||||
initialize(MemberScope.Empty, emptySet(), null)
|
||||
}.typeConstructor
|
||||
)
|
||||
}
|
||||
|
||||
+3
-14
@@ -48,25 +48,14 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
@NotNull ClassKind kind,
|
||||
@NotNull Collection<KotlinType> supertypes,
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
this(containingDeclaration, name, modality, kind, supertypes, source, name.asString());
|
||||
}
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull Modality modality,
|
||||
@NotNull ClassKind kind,
|
||||
@NotNull Collection<KotlinType> supertypes,
|
||||
@NotNull SourceElement source,
|
||||
@NotNull String debugName
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
|
||||
this.modality = modality;
|
||||
this.kind = kind;
|
||||
|
||||
this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.Companion.getEMPTY(), false, debugName,
|
||||
Collections.<TypeParameterDescriptor>emptyList(), supertypes);
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this, Annotations.Companion.getEMPTY(), false, Collections.<TypeParameterDescriptor>emptyList(), supertypes
|
||||
);
|
||||
}
|
||||
|
||||
public final void initialize(
|
||||
|
||||
+3
-3
@@ -79,9 +79,9 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
assert containingClass.getKind() == ClassKind.ENUM_CLASS;
|
||||
|
||||
this.annotations = annotations;
|
||||
this.typeConstructor =
|
||||
TypeConstructorImpl.createForClass(this, getAnnotations(), true, "enum entry", Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singleton(supertype));
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this, getAnnotations(), true, Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(supertype)
|
||||
);
|
||||
|
||||
this.scope = new EnumEntryScope(storageManager);
|
||||
this.enumMemberNames = enumMemberNames;
|
||||
|
||||
+2
-7
@@ -84,13 +84,8 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
supertypes.add(substitutor.substitute(supertype, Variance.INVARIANT));
|
||||
}
|
||||
|
||||
typeConstructor = TypeConstructorImpl.createForClass(
|
||||
this,
|
||||
originalTypeConstructor.getAnnotations(),
|
||||
originalTypeConstructor.isFinal(),
|
||||
originalTypeConstructor.toString(),
|
||||
typeConstructorParameters,
|
||||
supertypes
|
||||
typeConstructor = new TypeConstructorImpl(
|
||||
this, originalTypeConstructor.getAnnotations(), originalTypeConstructor.isFinal(), typeConstructorParameters, supertypes
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
@@ -42,7 +41,13 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
|
||||
public final int hashCode() {
|
||||
if (!hashCodeComputed) {
|
||||
hashCodeComputed = true;
|
||||
hashCode = hashCode(this);
|
||||
ClassifierDescriptor descriptor = getDeclarationDescriptor();
|
||||
if (descriptor instanceof ClassDescriptor && hasMeaningfulFqName(descriptor)) {
|
||||
hashCode = DescriptorUtils.getFqName(descriptor).hashCode();
|
||||
}
|
||||
else {
|
||||
hashCode = System.identityHashCode(this);
|
||||
}
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
@@ -58,27 +63,22 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object obj) {
|
||||
return equals(this, obj);
|
||||
}
|
||||
|
||||
public static boolean equals(@NotNull TypeConstructor me, Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof TypeConstructor)) return false;
|
||||
|
||||
// performance optimization: getFqName is slow method
|
||||
if (other.hashCode() != me.hashCode()) return false;
|
||||
if (other.hashCode() != hashCode()) return false;
|
||||
|
||||
ClassifierDescriptor myDescriptor = me.getDeclarationDescriptor();
|
||||
ClassifierDescriptor myDescriptor = getDeclarationDescriptor();
|
||||
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
|
||||
|
||||
// descriptor for type is created once per module
|
||||
if (myDescriptor == otherDescriptor) return true;
|
||||
|
||||
// All error types have the same descriptor
|
||||
if (myDescriptor != null && !hasMeaningfulFqName(myDescriptor) ||
|
||||
if (!hasMeaningfulFqName(myDescriptor) ||
|
||||
otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
|
||||
return me == other;
|
||||
return this == other;
|
||||
}
|
||||
|
||||
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
|
||||
@@ -90,14 +90,6 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int hashCode(@NotNull TypeConstructor me) {
|
||||
ClassifierDescriptor descriptor = me.getDeclarationDescriptor();
|
||||
if (descriptor instanceof ClassDescriptor && hasMeaningfulFqName(descriptor)) {
|
||||
return DescriptorUtils.getFqName(descriptor).hashCode();
|
||||
}
|
||||
return System.identityHashCode(me);
|
||||
}
|
||||
|
||||
private static boolean hasMeaningfulFqName(@NotNull ClassifierDescriptor descriptor) {
|
||||
return !ErrorUtils.isError(descriptor) &&
|
||||
!DescriptorUtils.isLocal(descriptor);
|
||||
|
||||
@@ -17,63 +17,36 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotatedImpl;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructor {
|
||||
public class TypeConstructorImpl extends AbstractClassTypeConstructor implements TypeConstructor {
|
||||
private final ClassDescriptor classDescriptor;
|
||||
private final Annotations annotations;
|
||||
private final List<TypeParameterDescriptor> parameters;
|
||||
private final Collection<KotlinType> supertypes;
|
||||
private final boolean isFinal;
|
||||
|
||||
@NotNull
|
||||
public static TypeConstructorImpl createForClass(
|
||||
public TypeConstructorImpl(
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isFinal,
|
||||
@NotNull String debugName,
|
||||
@NotNull List<? extends TypeParameterDescriptor> parameters,
|
||||
@NotNull Collection<KotlinType> supertypes
|
||||
) {
|
||||
return new TypeConstructorImpl(classDescriptor, annotations, isFinal, debugName, parameters, supertypes) {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return AbstractClassTypeConstructor.hashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object obj) {
|
||||
return AbstractClassTypeConstructor.equals(this, obj);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final List<TypeParameterDescriptor> parameters;
|
||||
private final Collection<KotlinType> supertypes;
|
||||
private final String debugName;
|
||||
private final boolean isFinal;
|
||||
|
||||
private final ClassifierDescriptor classifierDescriptor;
|
||||
|
||||
private TypeConstructorImpl(
|
||||
@NotNull ClassifierDescriptor classifierDescriptor,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isFinal,
|
||||
@NotNull String debugName,
|
||||
@NotNull List<? extends TypeParameterDescriptor> parameters,
|
||||
@NotNull Collection<KotlinType> supertypes) {
|
||||
super(annotations);
|
||||
this.classifierDescriptor = classifierDescriptor;
|
||||
super(LockBasedStorageManager.NO_LOCKS);
|
||||
this.classDescriptor = classDescriptor;
|
||||
this.annotations = annotations;
|
||||
this.isFinal = isFinal;
|
||||
this.debugName = debugName;
|
||||
this.parameters = Collections.unmodifiableList(new ArrayList<TypeParameterDescriptor>(parameters));
|
||||
this.supertypes = Collections.unmodifiableCollection(supertypes);
|
||||
}
|
||||
@@ -84,15 +57,9 @@ public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeC
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<KotlinType> getSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return debugName;
|
||||
return DescriptorUtils.getFqName(classDescriptor).asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,20 +73,26 @@ public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeC
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return classifierDescriptor;
|
||||
@NotNull
|
||||
public ClassDescriptor getDeclarationDescriptor() {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinBuiltIns getBuiltIns() {
|
||||
return DescriptorUtilsKt.getBuiltIns(classifierDescriptor);
|
||||
protected Collection<KotlinType> computeSupertypes() {
|
||||
return supertypes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
protected SupertypeLoopChecker getSupertypeLoopChecker() {
|
||||
return SupertypeLoopChecker.EMPTY.INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract boolean equals(Object obj);
|
||||
public Annotations getAnnotations() {
|
||||
return annotations;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user