diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExpectedLoadErrorsUtil.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExpectedLoadErrorsUtil.java index adf36ffb900..c0b212a7336 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExpectedLoadErrorsUtil.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/ExpectedLoadErrorsUtil.java @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies; import org.jetbrains.kotlin.load.java.JavaBindingContext; import org.jetbrains.kotlin.name.FqName; -import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.constants.ConstantValue; @@ -41,23 +40,22 @@ public class ExpectedLoadErrorsUtil { @NotNull PackageViewDescriptor packageFromJava, @NotNull BindingContext bindingContext ) { - Map> expectedErrors = getExpectedLoadErrors(packageFromJava); - Map> actualErrors = getActualLoadErrors(bindingContext); + Map> expectedErrors = getExpectedLoadErrors(packageFromJava); + Map> actualErrors = getActualLoadErrors(bindingContext); - for (DeclarationDescriptor descriptor : ContainerUtil.union(expectedErrors.keySet(), actualErrors.keySet())) { - List actual = actualErrors.get(descriptor); - List expected = expectedErrors.get(descriptor); - String rendered = DescriptorRenderer.FQ_NAMES_IN_TYPES.render(descriptor); + for (SourceElement source : ContainerUtil.union(expectedErrors.keySet(), actualErrors.keySet())) { + List actual = actualErrors.get(source); + List expected = expectedErrors.get(source); - assertNotNull("Unexpected load error(s):\n" + actual + "\ncontainer:" + rendered, expected); - assertNotNull("Missing load error(s):\n" + expected + "\ncontainer:" + rendered, actual); + assertNotNull("Unexpected load error(s):\n" + actual + "\ncontainer:" + source, expected); + assertNotNull("Missing load error(s):\n" + expected + "\ncontainer:" + source, actual); - assertSameElements("Unexpected/missing load error(s)\ncontainer:" + rendered, actual, expected); + assertSameElements("Unexpected/missing load error(s)\ncontainer:" + source, actual, expected); } } - private static Map> getExpectedLoadErrors(@NotNull PackageViewDescriptor packageFromJava) { - final Map> map = new HashMap>(); + private static Map> getExpectedLoadErrors(@NotNull PackageViewDescriptor packageFromJava) { + final Map> map = new HashMap>(); packageFromJava.acceptVoid(new DeclarationDescriptorVisitorEmptyBodies() { @Override @@ -91,7 +89,7 @@ public class ExpectedLoadErrorsUtil { //noinspection ConstantConditions List errors = Arrays.asList(error.split("\\|")); - map.put(descriptor.getOriginal(), errors); + putError(map, descriptor, errors); return null; } @@ -108,18 +106,30 @@ public class ExpectedLoadErrorsUtil { return map; } - private static Map> getActualLoadErrors(@NotNull BindingContext bindingContext) { - Map> result = new HashMap>(); + private static Map> getActualLoadErrors(@NotNull BindingContext bindingContext) { + Map> result = new HashMap>(); Collection descriptors = bindingContext.getKeys(JavaBindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS); for (DeclarationDescriptor descriptor : descriptors) { List errors = bindingContext.get(JavaBindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, descriptor); - result.put(descriptor.getOriginal(), errors); + if (errors == null) continue; + + putError(result, descriptor, errors); } return result; } + private static void putError( + @NotNull Map> result, + @NotNull DeclarationDescriptor descriptor, + @NotNull List errors + ) { + assert descriptor.getOriginal() instanceof DeclarationDescriptorWithSource + : "Signature errors should be reported only on declarations with source, but " + descriptor + " found"; + result.put(((DeclarationDescriptorWithSource) descriptor.getOriginal()).getSource(), errors); + } + private ExpectedLoadErrorsUtil() { } }