More informative diagnostic messages for ACCIDENTAL_OVERRIDES and CONFLICTING_JVM_DECLARATIONS

#KT-1 In Progress
This commit is contained in:
Andrey Breslav
2014-06-06 14:38:26 +04:00
parent 622b7e3740
commit f229301a0f
4 changed files with 59 additions and 10 deletions
@@ -17,8 +17,10 @@
package org.jetbrains.jet.lang.resolve.java.diagnostics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.renderer.Renderer;
public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
@@ -26,15 +28,22 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
private static final Renderer<ConflictingJvmDeclarationsData> CONFLICTING_JVM_DECLARATIONS_DATA = new Renderer<ConflictingJvmDeclarationsData>() {
@NotNull
@Override
public String render(@NotNull ConflictingJvmDeclarationsData element) {
return element.getSignature().getName() + element.getSignature().getDesc();
public String render(@NotNull ConflictingJvmDeclarationsData data) {
StringBuilder sb = new StringBuilder();
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
DeclarationDescriptor descriptor = origin.getDescriptor();
if (descriptor != null) {
sb.append(" ").append(DescriptorRenderer.COMPACT.render(descriptor)).append("\n");
}
}
return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
}
};
public static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap();
static {
MAP.put(ErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: ''{0}''", CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: ''{0}''", CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
}
+21 -5
View File
@@ -1,6 +1,22 @@
ERROR: $TESTDATA_DIR$/signatureClash.kt: (6, 5) Accidental override: 'getX()I'
ERROR: $TESTDATA_DIR$/signatureClash.kt: (8, 5) Platform declaration clash: 'getA()I'
ERROR: $TESTDATA_DIR$/signatureClash.kt: (9, 5) Platform declaration clash: 'getA()I'
ERROR: $TESTDATA_DIR$/signatureClash.kt: (12, 1) Platform declaration clash: 'getB()I'
ERROR: $TESTDATA_DIR$/signatureClash.kt: (13, 1) Platform declaration clash: 'getB()I'
ERROR: $TESTDATA_DIR$/signatureClash.kt: (6, 5) Accidental override: The following declarations have the same JVM signature (getX()I):
fun getX(): kotlin.Int
fun <get-x>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (8, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
fun getA(): kotlin.Int
fun <get-a>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (9, 5) Platform declaration clash: The following declarations have the same JVM signature (getA()I):
fun getA(): kotlin.Int
fun <get-a>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (12, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun getB(): kotlin.Int
fun <get-b>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (12, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun <get-b>(): kotlin.Int
fun getB(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (13, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun getB(): kotlin.Int
fun <get-b>(): kotlin.Int
ERROR: $TESTDATA_DIR$/signatureClash.kt: (13, 1) Platform declaration clash: The following declarations have the same JVM signature (getB()I):
fun <get-b>(): kotlin.Int
fun getB(): kotlin.Int
COMPILATION_ERROR
@@ -28,6 +28,8 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.RENDER_CLASS_OR_OBJECT;
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.STRING;
import static org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TextElementType;
import static org.jetbrains.jet.lang.resolve.java.diagnostics.ErrorsJvm.ACCIDENTAL_OVERRIDE;
import static org.jetbrains.jet.lang.resolve.java.diagnostics.ErrorsJvm.CONFLICTING_JVM_DECLARATIONS;
import static org.jetbrains.jet.plugin.highlighter.HtmlTabledDescriptorRenderer.tableForTypes;
import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.*;
@@ -37,7 +39,7 @@ import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.*;
*/
public class IdeErrorMessages {
public static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap();
public static final DiagnosticRenderer<Diagnostic> RENDERER = new DispatchingDiagnosticRenderer(ContainerUtil.concat(true, DefaultErrorMessages.MAPS, MAP));
public static final DiagnosticRenderer<Diagnostic> RENDERER = new DispatchingDiagnosticRenderer(ContainerUtil.concat(false, DefaultErrorMessages.MAPS, MAP));
static {
MAP.put(TYPE_MISMATCH, "<html>Type mismatch.<table><tr><td>Required:</td><td>{0}</td></tr><tr><td>Found:</td><td>{1}</td></tr></table></html>",
@@ -103,6 +105,9 @@ public class IdeErrorMessages {
MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "<html>Property delegate must have a ''{0}'' method. None of the following functions is suitable. <ul>{1}</ul></html>",
STRING, HTML_NONE_APPLICABLE_CALLS);
MAP.put(CONFLICTING_JVM_DECLARATIONS, "<html>Platform declaration clash: {0}</html>", HTML_CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ACCIDENTAL_OVERRIDE, "<html>Accidental override: {0}</html>", HTML_CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.setImmutable();
}
@@ -18,8 +18,11 @@ package org.jetbrains.jet.plugin.highlighter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.java.diagnostics.ConflictingJvmDeclarationsData;
import org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.renderer.Renderer;
@@ -132,4 +135,20 @@ public class IdeRenderers {
return DescriptorRenderer.HTML.renderType(returnType);
}
};
public static final Renderer<ConflictingJvmDeclarationsData> HTML_CONFLICTING_JVM_DECLARATIONS_DATA = new Renderer<ConflictingJvmDeclarationsData>() {
@NotNull
@Override
public String render(@NotNull ConflictingJvmDeclarationsData data) {
StringBuilder sb = new StringBuilder("<ul>");
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
DeclarationDescriptor descriptor = origin.getDescriptor();
if (descriptor != null) {
sb.append("<li>").append(DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS.render(descriptor)).append("</li>\n");
}
}
sb.append("</ul>");
return ("The following declarations have the same JVM signature (<code>" + data.getSignature().getName() + data.getSignature().getDesc() + "</code>):<br/>\n" + sb).trim();
}
};
}