Rewrite TowerLevels.
This commit is contained in:
@@ -258,19 +258,31 @@ public class TypeUtils {
|
||||
|
||||
@NotNull
|
||||
public static List<KotlinType> getImmediateSupertypes(@NotNull KotlinType type) {
|
||||
boolean isNullable = type.isMarkedNullable();
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
|
||||
Collection<KotlinType> originalSupertypes = type.getConstructor().getSupertypes();
|
||||
List<KotlinType> result = new ArrayList<KotlinType>(originalSupertypes.size());
|
||||
for (KotlinType supertype : originalSupertypes) {
|
||||
KotlinType substitutedType = substitutor.substitute(supertype, Variance.INVARIANT);
|
||||
KotlinType substitutedType = createSubstitutedSupertype(type, supertype, substitutor);
|
||||
if (substitutedType != null) {
|
||||
result.add(makeNullableIfNeeded(substitutedType, isNullable));
|
||||
result.add(substitutedType);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static KotlinType createSubstitutedSupertype(
|
||||
@NotNull KotlinType subType,
|
||||
@NotNull KotlinType superType,
|
||||
@NotNull TypeSubstitutor substitutor
|
||||
) {
|
||||
KotlinType substitutedType = substitutor.substitute(superType, Variance.INVARIANT);
|
||||
if (substitutedType != null) {
|
||||
return makeNullableIfNeeded(substitutedType, subType.isMarkedNullable());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void collectAllSupertypes(@NotNull KotlinType type, @NotNull Set<KotlinType> result) {
|
||||
List<KotlinType> immediateSupertypes = getImmediateSupertypes(type);
|
||||
result.addAll(immediateSupertypes);
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
package org.jetbrains.kotlin.types.typeUtil
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
@@ -162,3 +160,14 @@ private fun constituentTypes(result: MutableSet<KotlinType>, types: Collection<K
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun KotlinType.getImmediateSuperclassNotAny(): KotlinType? {
|
||||
val superclasses = constructor.supertypes.filter {
|
||||
val descriptor = it.constructor.declarationDescriptor
|
||||
(DescriptorUtils.isClass(descriptor) || DescriptorUtils.isEnumClass(descriptor)) &&
|
||||
!KotlinBuiltIns.isAnyOrNullableAny(it)
|
||||
}
|
||||
return superclasses.singleOrNull()?.let {
|
||||
TypeUtils.createSubstitutedSupertype(this, it, TypeSubstitutor.create(this))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user