Somewhat improve 'incomplete hierarchy' diagnostic message

This commit is contained in:
Alexander Udalov
2015-08-07 16:21:28 +03:00
parent 9095fa2844
commit df76695e72
2 changed files with 9 additions and 5 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics; import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
import org.jetbrains.kotlin.resolve.jvm.JvmClassName; import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
import org.jetbrains.kotlin.utils.UtilsPackage;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -97,13 +98,16 @@ public final class AnalyzerWithCompilerReport {
BindingContext bindingContext = analysisResult.getBindingContext(); BindingContext bindingContext = analysisResult.getBindingContext();
Collection<ClassDescriptor> classes = bindingContext.getKeys(TraceBasedErrorReporter.INCOMPLETE_HIERARCHY); Collection<ClassDescriptor> classes = bindingContext.getKeys(TraceBasedErrorReporter.INCOMPLETE_HIERARCHY);
if (!classes.isEmpty()) { if (!classes.isEmpty()) {
StringBuilder message = new StringBuilder("The following classes have incomplete hierarchies:\n"); StringBuilder message = new StringBuilder("Supertypes of the following classes cannot be resolved. " +
"Please make sure you have the required dependencies in the classpath:\n");
for (ClassDescriptor descriptor : classes) { for (ClassDescriptor descriptor : classes) {
String fqName = DescriptorUtils.getFqName(descriptor).asString(); String fqName = DescriptorUtils.getFqName(descriptor).asString();
List<String> unresolved = bindingContext.get(TraceBasedErrorReporter.INCOMPLETE_HIERARCHY, descriptor); List<String> unresolved = bindingContext.get(TraceBasedErrorReporter.INCOMPLETE_HIERARCHY, descriptor);
assert unresolved != null && !unresolved.isEmpty() : assert unresolved != null && !unresolved.isEmpty() :
"Incomplete hierarchy should be reported with names of unresolved superclasses: " + fqName; "Incomplete hierarchy should be reported with names of unresolved superclasses: " + fqName;
message.append(" ").append(fqName).append(", unresolved: ").append(unresolved).append("\n"); message.append(" class ").append(fqName)
.append(", unresolved supertypes: ").append(UtilsPackage.join(unresolved, ", "))
.append("\n");
} }
messageCollector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION); messageCollector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION);
} }
@@ -1,7 +1,7 @@
error: the following classes have incomplete hierarchies: error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
test.Sub, unresolved: [Super] class test.Sub, unresolved supertypes: Super
compiler/testData/compileKotlinAgainstCustomBinaries/incompleteHierarchyInJava/source.kt:5:22: error: unresolved reference: foo compiler/testData/compileKotlinAgainstCustomBinaries/incompleteHierarchyInJava/source.kt:5:22: error: unresolved reference: foo
fun bar() = SubSub().foo() fun bar() = SubSub().foo()
^ ^
COMPILATION_ERROR COMPILATION_ERROR