Do not compare local classes by FqNames

This commit is contained in:
Andrey Breslav
2014-05-30 12:45:05 +04:00
parent 93031c1245
commit e50a17e668
9 changed files with 142 additions and 2 deletions
@@ -101,6 +101,20 @@ public class DescriptorUtils {
return false;
}
/**
* descriptor may be local itself or have a local ancestor
*/
public static boolean isLocal(@NotNull DeclarationDescriptor descriptor) {
DeclarationDescriptor current = descriptor;
while (current instanceof MemberDescriptor) {
if (isAnonymousObject(current) || ((DeclarationDescriptorWithVisibility) current).getVisibility() == Visibilities.LOCAL) {
return true;
}
current = current.getContainingDeclaration();
}
return false;
}
@NotNull
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
FqName safe = getFqNameSafeIfPossible(descriptor);
@@ -41,8 +41,8 @@ public abstract class AbstractClassTypeConstructor implements TypeConstructor {
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
// All error types have the same descriptor
if (myDescriptor != null && ErrorUtils.isError(myDescriptor)
|| otherDescriptor != null && ErrorUtils.isError(otherDescriptor)) {
if (myDescriptor != null && !hasMeaningfulFqName(myDescriptor) ||
otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
return me == other;
}
@@ -65,4 +65,9 @@ public abstract class AbstractClassTypeConstructor implements TypeConstructor {
}
return System.identityHashCode(me);
}
private static boolean hasMeaningfulFqName(@NotNull ClassifierDescriptor descriptor) {
return !ErrorUtils.isError(descriptor) &&
!DescriptorUtils.isLocal(descriptor);
}
}