[IDEA] Add HTML render for ambiguous callable references diagnostic
^KT-36125 Fixed
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<ResolvedCall<*>> ->
|
||||
val descriptors = calls
|
||||
.map { it.resultingDescriptor }
|
||||
.sortedWith(MemberComparator.INSTANCE)
|
||||
val context = RenderingContext.Impl(descriptors)
|
||||
descriptors.joinToString("") { "<li>${HTML.render(it, context)}</li>" }
|
||||
renderAmbiguousDescriptors(calls.map { it.resultingDescriptor })
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val HTML_AMBIGUOUS_REFERENCES = Renderer { descriptors: Collection<CallableDescriptor> ->
|
||||
renderAmbiguousDescriptors(descriptors)
|
||||
}
|
||||
|
||||
private fun renderAmbiguousDescriptors(descriptors: Collection<CallableDescriptor>): String {
|
||||
val sortedDescriptors = descriptors.sortedWith(MemberComparator.INSTANCE)
|
||||
val context = RenderingContext.Impl(sortedDescriptors)
|
||||
return sortedDescriptors.joinToString("") { "<li>${HTML.render(it, context)}</li>" }
|
||||
}
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -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 <T> foo(a: kotlin.String, t: T) {
|
||||
|
||||
}
|
||||
|
||||
fun <T> foo(b: String, t : T) {
|
||||
|
||||
}
|
||||
|
||||
fun foo(i: Int) {
|
||||
|
||||
}
|
||||
|
||||
class String
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<!-- callableReferenceResolutionAmbiguityHtml1 -->
|
||||
<html>
|
||||
Overload resolution ambiguity. All these functions match.
|
||||
<ul>
|
||||
<li><b>public</b> <b>fun</b> <`T> foo(b: a.b.String, t: T): Unit <i>defined in</i> a.b <i>in file</i> callableReferenceResolutionAmbiguityHtml.kt</li>
|
||||
<li><b>public</b> <b>fun</b> foo(i: Int): Unit <i>defined in</i> a.b <i>in file</i> callableReferenceResolutionAmbiguityHtml.kt</li>
|
||||
<li><b>public</b> <b>fun</b> <`T> foo(a: kotlin.String, t: T): Unit <i>defined in</i> a.b <i>in file</i> callableReferenceResolutionAmbiguityHtml.kt</li>
|
||||
</ul>
|
||||
</html>
|
||||
@@ -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 <T> foo(a: kotlin.String, t: T) {
|
||||
|
||||
}
|
||||
|
||||
fun <T> foo(b: String, t : T) {
|
||||
|
||||
}
|
||||
|
||||
fun foo(i: Int) {
|
||||
|
||||
}
|
||||
|
||||
class String
|
||||
@@ -0,0 +1,5 @@
|
||||
<!-- callableReferenceResolutionAmbiguityTxt1 -->
|
||||
Callable reference resolution ambiguity:
|
||||
public fun <T> 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 <T> foo(a: kotlin.String, t: T): Unit defined in a.b in file callableReferenceResolutionAmbiguityTxt.kt
|
||||
+10
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user