extracted method 'isSameName' + rename

This commit is contained in:
Svetlana Isakova
2012-09-13 16:11:01 +04:00
parent a4694f767a
commit b7b15f8379
@@ -336,14 +336,14 @@ class AlternativeSignatureData {
return visitCommonType(DescriptorUtils.getFQName(classDescriptor).toSafe().getFqName(), type); return visitCommonType(DescriptorUtils.getFQName(classDescriptor).toSafe().getFqName(), type);
} }
private JetType visitCommonType(@NotNull String expectedFqNamePostfix, @NotNull JetTypeElement type) { private JetType visitCommonType(@NotNull String qualifiedName, @NotNull JetTypeElement type) {
TypeConstructor originalTypeConstructor = autoType.getConstructor(); TypeConstructor originalTypeConstructor = autoType.getConstructor();
ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor(); ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor();
assert declarationDescriptor != null; assert declarationDescriptor != null;
String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName(); String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName();
ClassDescriptor classFromLibrary = getExpectedFromLibrary(expectedFqNamePostfix); ClassDescriptor classFromLibrary = getAutoTypeAnalogWithinBuiltins(qualifiedName);
if (!fqName.equals(expectedFqNamePostfix) && !fqName.endsWith("." + expectedFqNamePostfix) && classFromLibrary == null) { if (!isSameName(qualifiedName, fqName) && classFromLibrary == null) {
fail("Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName); fail("Alternative signature type mismatch, expected: %s, actual: %s", qualifiedName, fqName);
} }
List<TypeProjection> arguments = autoType.getArguments(); List<TypeProjection> arguments = autoType.getArguments();
@@ -410,14 +410,14 @@ class AlternativeSignatureData {
} }
@Nullable @Nullable
private ClassDescriptor getExpectedFromLibrary(String expectedFqNamePostfix) { private ClassDescriptor getAutoTypeAnalogWithinBuiltins(String qualifiedName) {
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(autoType); Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(autoType);
if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null; if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null;
Collection<ClassDescriptor> descriptors = Collection<ClassDescriptor> descriptors =
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byType(javaAnalog).getFqName()); JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byType(javaAnalog).getFqName());
for (ClassDescriptor descriptor : descriptors) { for (ClassDescriptor descriptor : descriptors) {
String fqName = DescriptorUtils.getFQName(descriptor).getFqName(); String fqName = DescriptorUtils.getFQName(descriptor).getFqName();
if (fqName.endsWith("." + expectedFqNamePostfix)) { if (isSameName(qualifiedName, fqName)) {
return descriptor; return descriptor;
} }
} }
@@ -429,4 +429,8 @@ class AlternativeSignatureData {
throw new UnsupportedOperationException("Self-types are not supported yet"); throw new UnsupportedOperationException("Self-types are not supported yet");
} }
} }
private static boolean isSameName(String qualifiedName, String fullyQualifiedName) {
return fullyQualifiedName.equals(qualifiedName) || fullyQualifiedName.endsWith("." + qualifiedName);
}
} }