Optimization: no need to build a set of all supertypes, if we only need to check whether there's a nullable one
This commit is contained in:
@@ -374,7 +374,9 @@ public class TypeUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Set<JetType> getAllSupertypes(@NotNull JetType type) {
|
public static Set<JetType> getAllSupertypes(@NotNull JetType type) {
|
||||||
Set<JetType> result = Sets.newLinkedHashSet();
|
// 15 is obtained by experimentation: JDK classes like ArrayList tend to have so many supertypes,
|
||||||
|
// the average number is lower
|
||||||
|
Set<JetType> result = new LinkedHashSet<JetType>(15);
|
||||||
collectAllSupertypes(type, result);
|
collectAllSupertypes(type, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -389,11 +391,16 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasNullableSuperType(@NotNull JetType type) {
|
public static boolean hasNullableSuperType(@NotNull JetType type) {
|
||||||
for (JetType supertype : getAllSupertypes(type)) {
|
if (type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) {
|
||||||
if (supertype.isNullable()) {
|
// A class/trait cannot have a nullable supertype
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (JetType supertype : getImmediateSupertypes(type)) {
|
||||||
|
if (supertype.isNullable()) return true;
|
||||||
|
if (hasNullableSuperType(supertype)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user