Improve JvmConflictingDeclarations diagnostics rendering
This commit is contained in:
+8
-6
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.diagnostics;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.*;
|
import org.jetbrains.kotlin.diagnostics.rendering.*;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -31,17 +31,19 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String render(@NotNull ConflictingJvmDeclarationsData data, @NotNull RenderingContext context) {
|
public String render(@NotNull ConflictingJvmDeclarationsData data, @NotNull RenderingContext context) {
|
||||||
List<String> renderedDescriptors = new ArrayList<String>();
|
List<DeclarationDescriptor> renderedDescriptors = new ArrayList<DeclarationDescriptor>();
|
||||||
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
|
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
|
||||||
DeclarationDescriptor descriptor = origin.getDescriptor();
|
DeclarationDescriptor descriptor = origin.getDescriptor();
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
renderedDescriptors.add(DescriptorRenderer.COMPACT.render(descriptor));
|
renderedDescriptors.add(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(renderedDescriptors);
|
Collections.sort(renderedDescriptors, MemberComparator.INSTANCE);
|
||||||
|
RenderingContext.Impl renderingContext = new RenderingContext.Impl(renderedDescriptors);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String renderedDescriptor : renderedDescriptors) {
|
for (DeclarationDescriptor descriptor : renderedDescriptors) {
|
||||||
sb.append(" ").append(renderedDescriptor).append("\n");
|
sb.append(" ").append(Renderers.COMPACT.render(descriptor, renderingContext)).append("\n");
|
||||||
}
|
}
|
||||||
return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
|
return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,13 +71,14 @@ object IdeRenderers {
|
|||||||
withDefinedIn = false
|
withDefinedIn = false
|
||||||
}.asRenderer()
|
}.asRenderer()
|
||||||
|
|
||||||
@JvmField val HTML_CONFLICTING_JVM_DECLARATIONS_DATA = ContextDependentRenderer {
|
@JvmField val HTML_CONFLICTING_JVM_DECLARATIONS_DATA = Renderer {
|
||||||
data: ConflictingJvmDeclarationsData, renderingContext ->
|
data: ConflictingJvmDeclarationsData ->
|
||||||
|
|
||||||
val conflicts = data.signatureOrigins
|
val descriptors = data.signatureOrigins
|
||||||
.mapNotNull { it.descriptor }
|
.mapNotNull { it.descriptor }
|
||||||
.sortedWith(MemberComparator.INSTANCE)
|
.sortedWith(MemberComparator.INSTANCE)
|
||||||
.joinToString("") { "<li>" + HTML_COMPACT_WITH_MODIFIERS.render(it, renderingContext) + "</li>\n" }
|
val context = RenderingContext.of(descriptors)
|
||||||
|
val conflicts = descriptors.joinToString("") { "<li>" + HTML_COMPACT_WITH_MODIFIERS.render(it, context) + "</li>\n" }
|
||||||
|
|
||||||
"The following declarations have the same JVM signature (<code>${data.signature.name}${data.signature.desc}</code>):<br/>\n<ul>\n$conflicts</ul>"
|
"The following declarations have the same JVM signature (<code>${data.signature.name}${data.signature.desc}</code>):<br/>\n<ul>\n$conflicts</ul>"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package a.b
|
||||||
|
|
||||||
|
class String
|
||||||
|
|
||||||
|
interface I {
|
||||||
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||||
|
fun foo(l: List<a.b.String>): Unit
|
||||||
|
fun foo(l: List<kotlin.String>): Unit">fun foo(l: List<String>)</error>
|
||||||
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||||
|
fun foo(l: List<a.b.String>): Unit
|
||||||
|
fun foo(l: List<kotlin.String>): Unit">fun foo(l: List<kotlin.String>)</error>
|
||||||
|
}
|
||||||
Vendored
+4
-4
@@ -6,8 +6,8 @@ import kotlin.jvm.JvmName
|
|||||||
import kotlin.jvm.JvmMultifileClass
|
import kotlin.jvm.JvmMultifileClass
|
||||||
|
|
||||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
fun <get-x>(): kotlin.Int
|
fun <get-x>(): Int
|
||||||
fun getX(): kotlin.Int">val x</error> = 1
|
fun getX(): Int">val x</error> = 1
|
||||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (getX()I):
|
||||||
fun <get-x>(): kotlin.Int
|
fun <get-x>(): Int
|
||||||
fun getX(): kotlin.Int">fun getX()</error> = 1
|
fun getX(): Int">fun getX()</error> = 1
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
interface T {
|
interface T {
|
||||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||||
fun foo(l: kotlin.collections.List<kotlin.Int>): kotlin.Unit
|
fun foo(l: List<Int>): Unit
|
||||||
fun foo(l: kotlin.collections.List<kotlin.String>): kotlin.Unit">fun foo(l: List<String>)</error> {}
|
fun foo(l: List<String>): Unit">fun foo(l: List<String>)</error> {}
|
||||||
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
<error descr="[CONFLICTING_JVM_DECLARATIONS] Platform declaration clash: The following declarations have the same JVM signature (foo(Ljava/util/List;)V):
|
||||||
fun foo(l: kotlin.collections.List<kotlin.Int>): kotlin.Unit
|
fun foo(l: List<Int>): Unit
|
||||||
fun foo(l: kotlin.collections.List<kotlin.String>): kotlin.Unit">fun foo(l: List<Int>)</error> {}
|
fun foo(l: List<String>): Unit">fun foo(l: List<Int>)</error> {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -729,6 +729,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/checker/duplicateJvmSignature/functionAndProperty"), Pattern.compile("^(.+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/checker/duplicateJvmSignature/functionAndProperty"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ambiguous.kt")
|
||||||
|
public void testAmbiguous() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/duplicateJvmSignature/functionAndProperty/ambiguous.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("class.kt")
|
@TestMetadata("class.kt")
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/duplicateJvmSignature/functionAndProperty/class.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/duplicateJvmSignature/functionAndProperty/class.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user