From 22c250778e2371cad1ea9a7db4fe30f7b44056c0 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Wed, 16 Sep 2015 13:17:56 +0300 Subject: [PATCH] Introduce TypeConstructor#getBuiltIns --- .../lazy/descriptors/LazyClassDescriptor.java | 1 + .../impl/AbstractLazyTypeParameterDescriptor.java | 8 ++++++++ .../calls/inference/CapturedTypeConstructor.kt | 2 ++ .../constants/IntegerValueTypeConstructor.kt | 9 +++++---- .../kotlin/types/AbstractClassTypeConstructor.java | 13 +++++++++++++ .../src/org/jetbrains/kotlin/types/ErrorUtils.java | 13 +++++++++++++ .../kotlin/types/IntersectionTypeConstructor.java | 7 +++++++ .../org/jetbrains/kotlin/types/TypeConstructor.java | 4 ++++ .../jetbrains/kotlin/types/TypeConstructorImpl.java | 10 +++++++++- 9 files changed, 62 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java index f9afb4f3860..614427ed8fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -664,6 +664,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes } @Override + @NotNull public ClassifierDescriptor getDeclarationDescriptor() { return LazyClassDescriptor.this; } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractLazyTypeParameterDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractLazyTypeParameterDescriptor.java index 936791b347e..6103f5001d1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractLazyTypeParameterDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractLazyTypeParameterDescriptor.java @@ -17,12 +17,14 @@ package org.jetbrains.kotlin.descriptors.impl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.name.Name; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.TypeConstructor; @@ -82,6 +84,12 @@ public abstract class AbstractLazyTypeParameterDescriptor extends AbstractTypePa return AbstractLazyTypeParameterDescriptor.this.getAnnotations(); } + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return DescriptorUtilsKt.getBuiltIns(AbstractLazyTypeParameterDescriptor.this); + } + @Override public String toString() { return getName().toString(); diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt index 0fcbf021329..c5dd16c6455 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/CapturedTypeConstructor.kt @@ -51,6 +51,8 @@ public class CapturedTypeConstructor( override fun getAnnotations() = Annotations.EMPTY override fun toString() = "CapturedTypeConstructor($typeProjection)" + + override fun getBuiltIns(): KotlinBuiltIns = typeProjection.type.constructor.builtIns } public class CapturedType( diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt index d1b4fb2db17..56f58b81682 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt @@ -17,14 +17,11 @@ package org.jetbrains.kotlin.resolve.constants import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeConstructor - -import java.util.ArrayList -import java.util.Collections +import java.util.* public class IntegerValueTypeConstructor( private val value: Long, @@ -62,5 +59,9 @@ public class IntegerValueTypeConstructor( public fun getValue(): Long = value + override fun getBuiltIns(): KotlinBuiltIns { + return builtIns + } + override fun toString() = "IntegerValueType(" + value + ")" } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java index ceedab43fc9..39f6b680a48 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/AbstractClassTypeConstructor.java @@ -17,10 +17,13 @@ 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.name.FqNameUnsafe; import org.jetbrains.kotlin.resolve.DescriptorUtils; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; public abstract class AbstractClassTypeConstructor implements TypeConstructor { private boolean hashCodeComputed; @@ -35,6 +38,16 @@ public abstract class AbstractClassTypeConstructor implements TypeConstructor { return hashCode; } + @NotNull + @Override + public abstract ClassifierDescriptor getDeclarationDescriptor(); + + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return DescriptorUtilsKt.getBuiltIns(getDeclarationDescriptor()); + } + @Override @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") public boolean equals(Object obj) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 48245d0b4b1..ac53e7b77a2 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.impl.*; import org.jetbrains.kotlin.incremental.components.LookupLocation; import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.name.Name; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter; import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.storage.LockBasedStorageManager; @@ -635,6 +636,12 @@ public class ErrorUtils { public Annotations getAnnotations() { return errorTypeConstructor.getAnnotations(); } + + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return DescriptorUtilsKt.getBuiltIns(typeParameterDescriptor); + } } public static boolean isFunctionPlaceholder(@Nullable JetType type) { @@ -706,6 +713,12 @@ public class ErrorUtils { public String toString() { return errorTypeConstructor.toString(); } + + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return errorTypeConstructor.getBuiltIns(); + } } private ErrorUtils() {} diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/IntersectionTypeConstructor.java b/core/descriptors/src/org/jetbrains/kotlin/types/IntersectionTypeConstructor.java index 823ecc6f741..fa15d1a8a96 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/IntersectionTypeConstructor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/IntersectionTypeConstructor.java @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.types; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.AnnotatedImpl; @@ -63,6 +64,12 @@ public class IntersectionTypeConstructor extends AnnotatedImpl implements TypeCo return null; } + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return intersectedTypes.iterator().next().getConstructor().getBuiltIns(); + } + @Override public String toString() { return makeDebugNameForIntersectionType(intersectedTypes); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java index 9e200f2a314..fc693f8c576 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructor.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.types; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.ReadOnly; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.Annotated; @@ -48,4 +49,7 @@ public interface TypeConstructor extends Annotated { @Nullable ClassifierDescriptor getDeclarationDescriptor(); + + @NotNull + KotlinBuiltIns getBuiltIns(); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java index c3671c5d702..8ff07de633a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeConstructorImpl.java @@ -18,11 +18,13 @@ 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.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.AnnotatedImpl; import org.jetbrains.kotlin.descriptors.annotations.Annotations; +import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import java.util.ArrayList; import java.util.Collection; @@ -84,7 +86,7 @@ public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeC private final ClassifierDescriptor classifierDescriptor; private TypeConstructorImpl( - @Nullable ClassifierDescriptor classifierDescriptor, + @NotNull ClassifierDescriptor classifierDescriptor, @NotNull Annotations annotations, boolean isFinal, @NotNull String debugName, @@ -131,6 +133,12 @@ public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeC return classifierDescriptor; } + @NotNull + @Override + public KotlinBuiltIns getBuiltIns() { + return DescriptorUtilsKt.getBuiltIns(classifierDescriptor); + } + @Override public abstract int hashCode();