From 60f30732ed5f73c91260da8c43abbb2f28288d77 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 19 Nov 2012 21:38:01 +0400 Subject: [PATCH] Supported several load from Java errors per declaration. --- .../messages/AnalyzerWithCompilerReport.java | 15 ++++++++++----- .../java/resolver/JavaConstructorResolver.java | 4 ++-- .../java/resolver/JavaFunctionResolver.java | 12 ++++++++---- .../java/resolver/JavaPropertyResolver.java | 3 ++- .../jet/lang/resolve/BindingContext.java | 5 +++-- .../jvm/compiler/JdkAnnotationsSanityTest.java | 15 ++++++++------- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java index 5da85566a1e..2b422efcf83 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java @@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import java.util.Collection; +import java.util.List; import static org.jetbrains.jet.lang.diagnostics.DiagnosticUtils.sortedDiagnostics; @@ -118,17 +119,21 @@ public final class AnalyzerWithCompilerReport { private void reportAlternativeSignatureErrors() { assert analyzeExhaust != null; BindingContext bc = analyzeExhaust.getBindingContext(); - Collection descriptorsWithErrors = bc.getKeys(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR); + Collection descriptorsWithErrors = bc.getKeys(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS); if (!descriptorsWithErrors.isEmpty()) { - StringBuilder message = new StringBuilder("The following Java entities have annotations wrong Kotlin signatures:\n"); + StringBuilder messageStart = new StringBuilder("The following Java entities have annotations wrong Kotlin signatures:\n"); for (DeclarationDescriptor descriptor : descriptorsWithErrors) { PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, descriptor); assert declaration instanceof PsiModifierListOwner; String externalName = PsiFormatUtil.getExternalName((PsiModifierListOwner) declaration); - message.append(externalName).append(": "); - message.append(bc.get(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, descriptor)).append("\n"); + messageStart.append(externalName).append(": "); + List errors = bc.get(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, descriptor); + assert errors != null; + for (String error : errors) { + messageCollectorWrapper.report(CompilerMessageSeverity.ERROR, + messageStart + error + "\n", CompilerMessageLocation.NO_LOCATION); + } } - messageCollectorWrapper.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION); } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java index f9e60a7cb2d..9e63f50d8cc 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java @@ -198,8 +198,8 @@ public final class JavaConstructorResolver { valueParameterDescriptors = alternativeMethodSignatureData.getValueParameters(); } else if (alternativeMethodSignatureData.hasErrors()) { - trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, constructorDescriptor, - alternativeMethodSignatureData.getError()); + trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, constructorDescriptor, + Collections.singletonList(alternativeMethodSignatureData.getError())); } constructorDescriptor.initialize(classDescriptor.getTypeConstructor().getParameters(), diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java index 912df59bfa7..95b8148fcb8 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaFunctionResolver.java @@ -140,10 +140,12 @@ public final class JavaFunctionResolver { .resolveParameterDescriptors(functionDescriptorImpl, method.getParameters(), methodTypeVariableResolver); JetType returnType = makeReturnType(returnPsiType, method, methodTypeVariableResolver); + final List signatureErrors = Lists.newArrayList(); + returnType = SignaturesPropagation.modifyReturnTypeAccordingToSuperMethods(returnType, method, trace, new Function1() { @Override public Void invoke(String error) { - trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, functionDescriptorImpl, error); + signatureErrors.add(error); return null; } }); @@ -157,8 +159,7 @@ public final class JavaFunctionResolver { methodTypeParameters = alternativeMethodSignatureData.getTypeParameters(); } else if (alternativeMethodSignatureData.hasErrors()) { - trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, functionDescriptorImpl, - alternativeMethodSignatureData.getError()); + signatureErrors.add(alternativeMethodSignatureData.getError()); } functionDescriptorImpl.initialize( @@ -184,7 +185,10 @@ public final class JavaFunctionResolver { throw new IllegalStateException("non-static method in subclass"); } - if (trace.get(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, functionDescriptorImpl) == null) { + if (!signatureErrors.isEmpty()) { + trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, functionDescriptorImpl, signatureErrors); + } + if (signatureErrors.isEmpty()) { List superFunctions = SignaturesPropagation.getSuperFunctionsForMethod(method, trace); for (FunctionDescriptor superFunction : superFunctions) { TypeSubstitutor substitutor = SubstitutionUtils.buildDeepSubstitutor(((ClassDescriptor) ownerDescriptor).getDefaultType()); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java index 41de9c25927..914110bc207 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java @@ -269,7 +269,8 @@ public final class JavaPropertyResolver { } } else { - trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, propertyDescriptor, signatureData.getError()); + trace.record(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, propertyDescriptor, + Collections.singletonList(signatureData.getError())); } return propertyType; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java index 273d5d4266c..4d6e56af9ec 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -38,6 +38,7 @@ import org.jetbrains.jet.util.slicedmap.*; import java.util.Collection; import java.util.Collections; +import java.util.List; import static org.jetbrains.jet.util.slicedmap.RewritePolicy.DO_NOTHING; @@ -256,8 +257,8 @@ public interface BindingContext { WritableSlice INCOMPLETE_HIERARCHY = Slices.createCollectiveSetSlice(); - WritableSlice LOAD_FROM_JAVA_SIGNATURE_ERROR = - new BasicWritableSlice(Slices.ONLY_REWRITE_TO_EQUAL, true); + WritableSlice> LOAD_FROM_JAVA_SIGNATURE_ERRORS = + new BasicWritableSlice>(Slices.ONLY_REWRITE_TO_EQUAL, true); WritableSlice IS_DECLARED_IN_JAVA = Slices.createSimpleSlice(); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/JdkAnnotationsSanityTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/JdkAnnotationsSanityTest.java index c57ef92d506..f00d775798d 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/JdkAnnotationsSanityTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/JdkAnnotationsSanityTest.java @@ -48,6 +48,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.resolve.DescriptorRenderer; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -76,7 +77,7 @@ public class JdkAnnotationsSanityTest extends KotlinTestWithEnvironment { final BindingContext bindingContext = injector.getBindingTrace().getBindingContext(); JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver(); - final Map errors = Maps.newHashMap(); + final Map> errors = Maps.newHashMap(); Iterable affectedClasses = getAffectedClasses(kotlinAnnotationsRoot); AlternativeSignatureErrorFindingVisitor visitor = new AlternativeSignatureErrorFindingVisitor(bindingContext, errors); @@ -94,7 +95,7 @@ public class JdkAnnotationsSanityTest extends KotlinTestWithEnvironment { if (!errors.isEmpty()) { StringBuilder sb = new StringBuilder("Error(s) in JDK alternative signatures: \n"); - for (Map.Entry entry : errors.entrySet()) { + for (Map.Entry> entry : errors.entrySet()) { sb.append(DescriptorRenderer.TEXT.render(entry.getKey())).append(" : ").append(entry.getValue()).append("\n"); } fail(sb.toString()); @@ -206,9 +207,9 @@ public class JdkAnnotationsSanityTest extends KotlinTestWithEnvironment { private static class AlternativeSignatureErrorFindingVisitor extends DeclarationDescriptorVisitorEmptyBodies { private final BindingContext bindingContext; - private final Map errors; + private final Map> errors; - public AlternativeSignatureErrorFindingVisitor(BindingContext bindingContext, Map errors) { + public AlternativeSignatureErrorFindingVisitor(BindingContext bindingContext, Map> errors) { this.bindingContext = bindingContext; this.errors = errors; } @@ -239,9 +240,9 @@ public class JdkAnnotationsSanityTest extends KotlinTestWithEnvironment { } private Void visitDeclaration(@NotNull DeclarationDescriptor descriptor) { - String error = bindingContext.get(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERROR, descriptor); - if (error != null) { - errors.put(descriptor, error); + List errors = bindingContext.get(BindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, descriptor); + if (errors != null) { + this.errors.put(descriptor, errors); } return null; }