From b7ea590e23799ba816ecd06366b07da65cc4cbb1 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 18 Mar 2020 19:28:43 +0300 Subject: [PATCH] [IDEA] Add HTML render for ambiguous callable references diagnostic ^KT-36125 Fixed --- .../idea/highlighter/IdeErrorMessages.java | 3 +++ .../kotlin/idea/highlighter/IdeRenderers.kt | 18 +++++++++++---- ...allableReferenceResolutionAmbiguityHtml.kt | 23 +++++++++++++++++++ ...ableReferenceResolutionAmbiguityHtml1.html | 9 ++++++++ ...callableReferenceResolutionAmbiguityTxt.kt | 23 +++++++++++++++++++ ...llableReferenceResolutionAmbiguityTxt1.txt | 5 ++++ .../DiagnosticMessageTestGenerated.java | 10 ++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml.kt create mode 100644 idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml1.html create mode 100644 idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt.kt create mode 100644 idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt1.txt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java index a54c5f5c48a..7209d13623f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java @@ -147,6 +147,9 @@ public class IdeErrorMessages { MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, KotlinIdeaAnalysisBundle.htmlMessage("html.overload.resolution.ambiguity.all.these.functions.match.ul.0.ul.html"), HTML_AMBIGUOUS_CALLS); + MAP.put(CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY, + KotlinIdeaAnalysisBundle.htmlMessage("html.overload.resolution.ambiguity.all.these.functions.match.ul.0.ul.html"), + HTML_AMBIGUOUS_REFERENCES); MAP.put(NONE_APPLICABLE, KotlinIdeaAnalysisBundle.htmlMessage("html.none.of.the.following.functions.can.be.called.with.the.arguments.supplied.ul.0.ul.html"), HTML_NONE_APPLICABLE_CALLS); MAP.put(CANNOT_COMPLETE_RESOLVE, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeRenderers.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeRenderers.kt index 5eb2dc717df..ff535df431f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeRenderers.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeRenderers.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.highlighter +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.diagnostics.rendering.* import org.jetbrains.kotlin.idea.KotlinIdeaAnalysisBundle @@ -20,11 +21,18 @@ object IdeRenderers { @JvmField val HTML_AMBIGUOUS_CALLS = Renderer { calls: Collection> -> - val descriptors = calls - .map { it.resultingDescriptor } - .sortedWith(MemberComparator.INSTANCE) - val context = RenderingContext.Impl(descriptors) - descriptors.joinToString("") { "
  • ${HTML.render(it, context)}
  • " } + renderAmbiguousDescriptors(calls.map { it.resultingDescriptor }) + } + + @JvmField + val HTML_AMBIGUOUS_REFERENCES = Renderer { descriptors: Collection -> + renderAmbiguousDescriptors(descriptors) + } + + private fun renderAmbiguousDescriptors(descriptors: Collection): String { + val sortedDescriptors = descriptors.sortedWith(MemberComparator.INSTANCE) + val context = RenderingContext.Impl(sortedDescriptors) + return sortedDescriptors.joinToString("") { "
  • ${HTML.render(it, context)}
  • " } } @JvmField diff --git a/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml.kt b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml.kt new file mode 100644 index 00000000000..0f0134cab33 --- /dev/null +++ b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY +// !MESSAGE_TYPE: HTML + +package a.b + +val ref1 = take(::foo) + +fun take(arg: Any) {} + +fun foo(a: kotlin.String, t: T) { + +} + +fun foo(b: String, t : T) { + +} + +fun foo(i: Int) { + +} + +class String \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml1.html b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml1.html new file mode 100644 index 00000000000..3532149ff24 --- /dev/null +++ b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml1.html @@ -0,0 +1,9 @@ + + +Overload resolution ambiguity. All these functions match. +
      +
    • public fun <`T> foo(b: a.b.String, t: T): Unit defined in a.b in file callableReferenceResolutionAmbiguityHtml.kt
    • +
    • public fun foo(i: Int): Unit defined in a.b in file callableReferenceResolutionAmbiguityHtml.kt
    • +
    • public fun <`T> foo(a: kotlin.String, t: T): Unit defined in a.b in file callableReferenceResolutionAmbiguityHtml.kt
    • +
    + \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt.kt b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt.kt new file mode 100644 index 00000000000..93b917b9b55 --- /dev/null +++ b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY +// !MESSAGE_TYPE: TEXT + +package a.b + +val ref1 = take(::foo) + +fun take(arg: Any) {} + +fun foo(a: kotlin.String, t: T) { + +} + +fun foo(b: String, t : T) { + +} + +fun foo(i: Int) { + +} + +class String \ No newline at end of file diff --git a/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt1.txt b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt1.txt new file mode 100644 index 00000000000..c20c03af69f --- /dev/null +++ b/idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt1.txt @@ -0,0 +1,5 @@ + +Callable reference resolution ambiguity: +public fun foo(b: a.b.String, t: T): Unit defined in a.b in file callableReferenceResolutionAmbiguityTxt.kt +public fun foo(i: Int): Unit defined in a.b in file callableReferenceResolutionAmbiguityTxt.kt +public fun foo(a: kotlin.String, t: T): Unit defined in a.b in file callableReferenceResolutionAmbiguityTxt.kt \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java index 55bc936e88b..3c3e60ba209 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/DiagnosticMessageTestGenerated.java @@ -43,6 +43,16 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes runTest("idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt"); } + @TestMetadata("callableReferenceResolutionAmbiguityHtml.kt") + public void testCallableReferenceResolutionAmbiguityHtml() throws Exception { + runTest("idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityHtml.kt"); + } + + @TestMetadata("callableReferenceResolutionAmbiguityTxt.kt") + public void testCallableReferenceResolutionAmbiguityTxt() throws Exception { + runTest("idea/testData/diagnosticMessage/callableReferenceResolutionAmbiguityTxt.kt"); + } + @TestMetadata("cannotInferVisibility.kt") public void testCannotInferVisibility() throws Exception { runTest("idea/testData/diagnosticMessage/cannotInferVisibility.kt");