Ensure stable order is used when rendering list of resolved calls by sorting them with MemberComparator.

This commit is contained in:
Ilya Gorbunov
2015-05-19 22:16:44 +03:00
parent 4de3e3c712
commit fb342de451
10 changed files with 38 additions and 47 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.psi.JetNamedDeclaration
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.Renderer
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.MemberComparator
import org.jetbrains.kotlin.resolve.calls.inference.*
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.BoundKind.LOWER_BOUND
@@ -95,12 +96,11 @@ public object Renderers {
}
public val AMBIGUOUS_CALLS: Renderer<Collection<ResolvedCall<*>>> = Renderer {
argument: Collection<ResolvedCall<*>> ->
val stringBuilder = StringBuilder("\n")
for (call in argument) {
stringBuilder.append(DescriptorRenderer.FQ_NAMES_IN_TYPES.render(call.getResultingDescriptor())).append("\n")
}
stringBuilder.toString()
calls: Collection<ResolvedCall<*>> ->
calls
.map { it.getResultingDescriptor() }
.sortBy(MemberComparator.INSTANCE)
.joinToString(separator = "\n", prefix = "\n") { DescriptorRenderer.FQ_NAMES_IN_TYPES.render(it) }
}
platformStatic
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.Renderers
import org.jetbrains.kotlin.idea.highlighter.renderersUtil.renderResolvedCall
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.Renderer
import org.jetbrains.kotlin.resolve.MemberComparator
import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData
@@ -29,13 +30,10 @@ import org.jetbrains.kotlin.types.JetType
public object IdeRenderers {
public val HTML_AMBIGUOUS_CALLS: Renderer<Collection<ResolvedCall<*>>> = Renderer {
calls: Collection<ResolvedCall<*>> ->
StringBuilder {
for (call in calls) {
append("<li>")
append(DescriptorRenderer.HTML.render(call.getResultingDescriptor()))
append("</li>")
}
}.toString()
calls
.map { it.getResultingDescriptor() }
.sortBy(MemberComparator.INSTANCE)
.joinToString("") { "<li>" + DescriptorRenderer.HTML.render(it) + "</li>" }
}
public val HTML_RENDER_TYPE: Renderer<JetType> = Renderer {
@@ -44,13 +42,11 @@ public object IdeRenderers {
public val HTML_NONE_APPLICABLE_CALLS: Renderer<Collection<ResolvedCall<*>>> = Renderer {
calls: Collection<ResolvedCall<*>> ->
StringBuilder {
for (resolvedCall in calls) {
append("<li>")
append(renderResolvedCall(resolvedCall))
append("</li>")
}
}.toString()
// TODO: compareBy(comparator, selector) in stdlib
val comparator = comparator<ResolvedCall<*>> { c1, c2 -> MemberComparator.INSTANCE.compare(c1.getResultingDescriptor(), c2.getResultingDescriptor()) }
calls
.sortBy(comparator)
.joinToString("") { "<li>" + renderResolvedCall(it) + "</li>" }
}
public val HTML_TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER: Renderer<InferenceErrorData> = Renderer {
@@ -76,19 +72,14 @@ public object IdeRenderers {
public val HTML_CONFLICTING_JVM_DECLARATIONS_DATA: Renderer<ConflictingJvmDeclarationsData> = Renderer<ConflictingJvmDeclarationsData> {
data: ConflictingJvmDeclarationsData ->
val sb = StringBuilder {
append("<ul>")
for (origin in data.signatureOrigins) {
val descriptor = origin.descriptor
if (descriptor != null) {
append("<li>")
append(DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS.render(descriptor))
append("</li>\n")
}
}
append("</ul>")
}
("The following declarations have the same JVM signature (<code>" + data.signature.name + data.signature.desc + "</code>):<br/>\n" + sb).trim()
val conflicts = data.signatureOrigins
.map { it.descriptor }
.filterNotNull()
.sortBy(MemberComparator.INSTANCE)
.joinToString("") { "<li>" + DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS.render(it) + "</li>\n" }
"The following declarations have the same JVM signature (<code>${data.signature.name}${data.signature.desc}</code>):<br/>\n<ul>\n$conflicts</ul>"
}
public val HTML_THROWABLE: Renderer<Throwable> = Renderer {
@@ -2,8 +2,8 @@
<html>
None of the following functions can be called with the arguments supplied.
<ul>
<li>foo(Int, String, <font color=red><b>Boolean</b></font>) <i>defined in</i> root package</li>
<li>foo(<font color=red><b>Boolean</b></font>, String) <i>defined in</i> root package</li>
<li>foo(Int<font color=red><b>)</b></font> <i>defined in</i> root package</li>
<li>foo(Int, String, <font color=red><b>Boolean</b></font>) <i>defined in</i> root package</li>
</ul>
</html>
@@ -2,14 +2,14 @@
<html>
None of the following functions can be called with the arguments supplied.
<ul>
<li>foo(Int, Any, List<`Int><font color=red><b>)</b></font><br/>
<i>where</i> T = Int<i> for </i><br/>
<b>fun</b> <`T> foo(t: T, a: Any, l: List<`T>): Int <i>defined in</i> p</li>
<li>foo(Int, <font color=red><b>R</b></font>, MutableList<`Int>, MutableList<`<font color=red><b>R</b></font>>)<br/>
<i>where</i> <font color=red><b>R</b></font><i> cannot be inferred</i>; T = Int<i> for </i><br/>
<b>fun</b> <`T, R> foo(t: T, r: R, lt: MutableList<`T>, lr: MutableList<`R>): Int <i>defined in</i> p</li>
<li>foo(<font color=red><b>T</b></font>, Any, MutableList<`<font color=red><b>T</b></font>>, MutableList<`<font color=red><b>T</b></font>>)<br/>
<i>where</i> <font color=red><b>T</b></font><i> cannot be inferred</i><i> for </i><br/>
<b>fun</b> <`T> foo(t: T, a: Any, lt: MutableList<`T>, lr: MutableList<`T>): Int <i>defined in</i> p</li>
<li>foo(Int, <font color=red><b>R</b></font>, MutableList<`Int>, MutableList<`<font color=red><b>R</b></font>>)<br/>
<i>where</i> <font color=red><b>R</b></font><i> cannot be inferred</i>; T = Int<i> for </i><br/>
<b>fun</b> <`T, R> foo(t: T, r: R, lt: MutableList<`T>, lr: MutableList<`R>): Int <i>defined in</i> p</li>
<li>foo(Int, Any, List<`Int><font color=red><b>)</b></font><br/>
<i>where</i> T = Int<i> for </i><br/>
<b>fun</b> <`T> foo(t: T, a: Any, l: List<`T>): Int <i>defined in</i> p</li>
</ul>
</html>
@@ -1,5 +1,5 @@
// "Import" "true"
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>internal</b> <b>fun</b> kotlin.String.minus(str: kotlin.String): kotlin.String <i>defined in</i> h</li><li><b>internal</b> <b>fun</b> kotlin.String.minus(i: java.lang.Integer): kotlin.String <i>defined in</i> h</li></ul></html>
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>internal</b> <b>fun</b> kotlin.String.minus(i: java.lang.Integer): kotlin.String <i>defined in</i> h</li><li><b>internal</b> <b>fun</b> kotlin.String.minus(str: kotlin.String): kotlin.String <i>defined in</i> h</li></ul></html>
package h
@@ -1,5 +1,5 @@
// "Import" "true"
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>internal</b> <b>fun</b> kotlin.String.minus(str: kotlin.String): kotlin.String <i>defined in</i> h</li><li><b>internal</b> <b>fun</b> kotlin.String.minus(i: java.lang.Integer): kotlin.String <i>defined in</i> h</li></ul></html>
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>internal</b> <b>fun</b> kotlin.String.minus(i: java.lang.Integer): kotlin.String <i>defined in</i> h</li><li><b>internal</b> <b>fun</b> kotlin.String.minus(str: kotlin.String): kotlin.String <i>defined in</i> h</li></ul></html>
package h
@@ -1,5 +1,5 @@
// "Insert 'this()' call" "true"
// ERROR: <html>None of the following functions can be called with the arguments supplied. <ul><li><init>(<font color=red><b>String</b></font>) <i>defined in</i> A</li><li><init>(<font color=red><b>Int</b></font>) <i>defined in</i> A</li></ul></html>
// ERROR: <html>None of the following functions can be called with the arguments supplied. <ul><li><init>(<font color=red><b>Int</b></font>) <i>defined in</i> A</li><li><init>(<font color=red><b>String</b></font>) <i>defined in</i> A</li></ul></html>
class A(val x: Int) {
constructor(x: String)<caret>
@@ -1,5 +1,5 @@
// "Insert 'this()' call" "true"
// ERROR: <html>None of the following functions can be called with the arguments supplied. <ul><li><init>(<font color=red><b>String</b></font>) <i>defined in</i> A</li><li><init>(<font color=red><b>Int</b></font>) <i>defined in</i> A</li></ul></html>
// ERROR: <html>None of the following functions can be called with the arguments supplied. <ul><li><init>(<font color=red><b>Int</b></font>) <i>defined in</i> A</li><li><init>(<font color=red><b>String</b></font>) <i>defined in</i> A</li></ul></html>
class A(val x: Int) {
constructor(x: String) : this(<caret>)
@@ -1,4 +1,4 @@
// ERROR: None of the following functions can be called with the arguments supplied: public open fun valueOf(p0: kotlin.String!, p1: kotlin.Int): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.Short): kotlin.Short! defined in java.lang.Short
// ERROR: None of the following functions can be called with the arguments supplied: public open fun valueOf(p0: kotlin.Short): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!): kotlin.Short! defined in java.lang.Short public open fun valueOf(p0: kotlin.String!, p1: kotlin.Int): kotlin.Short! defined in java.lang.Short
package demo
class Test {
+2 -2
View File
@@ -1,5 +1,5 @@
// ERROR: None of the following functions can be called with the arguments supplied: public constructor FileInputStream(p0: kotlin.String!) defined in java.io.FileInputStream public constructor FileInputStream(p0: java.io.File!) defined in java.io.FileInputStream public constructor FileInputStream(p0: [ERROR : Unresolved java classifier: FileDescriptor]!) defined in java.io.FileInputStream
// ERROR: None of the following functions can be called with the arguments supplied: public constructor InputStreamReader(p0: java.io.InputStream!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: kotlin.String!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: java.nio.charset.Charset!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: [ERROR : Unresolved java classifier: CharsetDecoder]!) defined in java.io.InputStreamReader
// ERROR: None of the following functions can be called with the arguments supplied: public constructor FileInputStream(p0: [ERROR : Unresolved java classifier: FileDescriptor]!) defined in java.io.FileInputStream public constructor FileInputStream(p0: java.io.File!) defined in java.io.FileInputStream public constructor FileInputStream(p0: kotlin.String!) defined in java.io.FileInputStream
// ERROR: None of the following functions can be called with the arguments supplied: public constructor InputStreamReader(p0: java.io.InputStream!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: [ERROR : Unresolved java classifier: CharsetDecoder]!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: java.nio.charset.Charset!) defined in java.io.InputStreamReader public constructor InputStreamReader(p0: java.io.InputStream!, p1: kotlin.String!) defined in java.io.InputStreamReader
// ERROR: Assignments are not expressions, and only expressions are allowed in this context
// ERROR: Unresolved reference: close
import java.io.*