diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MutableClassDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MutableClassDescriptor.java index 67d6e212f16..71380808717 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MutableClassDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MutableClassDescriptor.java @@ -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()); diff --git a/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.txt b/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.txt index fa432313f28..7e9b5d313ff 100644 --- a/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.txt +++ b/compiler/testData/diagnostics/tests/j+k/annotationWithArgumentsMissingDependencies.txt @@ -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 } diff --git a/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.txt b/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.txt index f02304cbe6a..e5bb47b5c19 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.txt +++ b/compiler/testData/diagnostics/tests/platformTypes/noAnnotationInClassPath.txt @@ -5,7 +5,7 @@ public fun test(): kotlin.Unit public interface A { 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 } diff --git a/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.txt b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.txt index 1cf2b924d51..98a45956172 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.txt +++ b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.txt @@ -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 diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt index f4c18258ec4..e62c424589a 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt @@ -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 + ) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ClassDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ClassDescriptorImpl.java index 99b6307f831..007bb9bc71f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ClassDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ClassDescriptorImpl.java @@ -48,25 +48,14 @@ public class ClassDescriptorImpl extends ClassDescriptorBase { @NotNull ClassKind kind, @NotNull Collection 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 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.emptyList(), supertypes); + this.typeConstructor = new TypeConstructorImpl( + this, Annotations.Companion.getEMPTY(), false, Collections.emptyList(), supertypes + ); } public final void initialize( diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/EnumEntrySyntheticClassDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/EnumEntrySyntheticClassDescriptor.java index e511bc8bc86..177fddd7ffa 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/EnumEntrySyntheticClassDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/EnumEntrySyntheticClassDescriptor.java @@ -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.emptyList(), - Collections.singleton(supertype)); + this.typeConstructor = new TypeConstructorImpl( + this, getAnnotations(), true, Collections.emptyList(), Collections.singleton(supertype) + ); this.scope = new EnumEntryScope(storageManager); this.enumMemberNames = enumMemberNames; diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java index d63c268e91b..25470de4c9b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java @@ -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 ); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java index 888326cdfd1..674f053e503 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java @@ -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); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java index 65e50d66238..46515cd01d3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java @@ -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 parameters; + private final Collection 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 parameters, @NotNull Collection 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 parameters; - private final Collection 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 parameters, - @NotNull Collection 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(parameters)); this.supertypes = Collections.unmodifiableCollection(supertypes); } @@ -84,15 +57,9 @@ public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeC return parameters; } - @Override - @NotNull - public Collection 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 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; + } }