Simplify detecting loops in classes supertypes

This commit is contained in:
Denis Zharkov
2015-10-28 17:52:23 +03:00
parent 33d67a3bf4
commit 8ba2dc5530
@@ -490,20 +490,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@Mutable @Mutable
public final Collection<KotlinType> trueSupertypes; public final Collection<KotlinType> trueSupertypes;
@Mutable @Mutable
public final Collection<KotlinType> cyclicSupertypes; public final Collection<KotlinType> allSuperTypes;
private Supertypes(@Mutable @NotNull Collection<KotlinType> trueSupertypes) { private Supertypes(@Mutable @NotNull Collection<KotlinType> allSuperTypes) {
this(trueSupertypes, new ArrayList<KotlinType>(0)); this.trueSupertypes = allSuperTypes;
} this.allSuperTypes = new ArrayList<KotlinType>(allSuperTypes);
private Supertypes(@Mutable @NotNull Collection<KotlinType> trueSupertypes, @Mutable @NotNull Collection<KotlinType> cyclicSupertypes) {
this.trueSupertypes = trueSupertypes;
this.cyclicSupertypes = cyclicSupertypes;
} }
@NotNull @NotNull
public Collection<KotlinType> getAllSupertypes() { public Collection<KotlinType> getAllSupertypes() {
return CollectionsKt.plus(trueSupertypes, cyclicSupertypes); return allSuperTypes;
} }
} }
@@ -537,7 +533,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
new Function1<Supertypes, Unit>() { new Function1<Supertypes, Unit>() {
@Override @Override
public Unit invoke(@NotNull Supertypes supertypes) { public Unit invoke(@NotNull Supertypes supertypes) {
findAndDisconnectLoopsInTypeHierarchy(supertypes); findAndDisconnectLoopsInTypeHierarchy(supertypes.trueSupertypes);
return Unit.INSTANCE$; return Unit.INSTANCE$;
} }
} }
@@ -585,12 +581,11 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
return supertypes.invoke().trueSupertypes; return supertypes.invoke().trueSupertypes;
} }
private void findAndDisconnectLoopsInTypeHierarchy(Supertypes supertypes) { private void findAndDisconnectLoopsInTypeHierarchy(@Mutable Collection<KotlinType> supertypes) {
for (Iterator<KotlinType> iterator = supertypes.trueSupertypes.iterator(); iterator.hasNext(); ) { for (Iterator<KotlinType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
KotlinType supertype = iterator.next(); KotlinType supertype = iterator.next();
if (isReachable(supertype.getConstructor(), this, new HashSet<TypeConstructor>())) { if (isReachable(supertype.getConstructor(), this, new HashSet<TypeConstructor>())) {
iterator.remove(); iterator.remove();
supertypes.cyclicSupertypes.add(supertype);
ClassifierDescriptor supertypeDescriptor = supertype.getConstructor().getDeclarationDescriptor(); ClassifierDescriptor supertypeDescriptor = supertype.getConstructor().getDeclarationDescriptor();
if (supertypeDescriptor instanceof ClassDescriptor) { if (supertypeDescriptor instanceof ClassDescriptor) {