Handle TypeAliasDescriptor in AdaptiveClassifierNamePolicy
(as ClassDescriptor)
This commit is contained in:
+11
-8
@@ -16,18 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.diagnostics.rendering
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.getAbbreviation
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import java.util.*
|
||||
|
||||
@@ -40,7 +36,9 @@ private class AdaptiveClassifierNamePolicy(private val ambiguousNames: List<Name
|
||||
override fun renderClassifier(classifier: ClassifierDescriptor, renderer: DescriptorRenderer): String {
|
||||
return when {
|
||||
hasUniqueName(classifier) -> ClassifierNamePolicy.SHORT.renderClassifier(classifier, renderer)
|
||||
classifier is ClassDescriptor -> ClassifierNamePolicy.FULLY_QUALIFIED.renderClassifier(classifier, renderer)
|
||||
classifier is ClassDescriptor ||
|
||||
classifier is TypeAliasDescriptor ->
|
||||
ClassifierNamePolicy.FULLY_QUALIFIED.renderClassifier(classifier, renderer)
|
||||
classifier is TypeParameterDescriptor -> {
|
||||
val name = classifier.name
|
||||
val typeParametersWithSameName = renderedParameters.getOrPut(name) { LinkedHashSet() }
|
||||
@@ -80,10 +78,15 @@ private fun collectClassifiersFqNames(objectsToRender: Collection<Any?>): Set<Fq
|
||||
}
|
||||
|
||||
private fun collectMentionedClassifiersFqNames(contextObjects: Collection<Any?>, result: MutableSet<FqNameUnsafe>) {
|
||||
fun KotlinType.addMentionedTypeConstructor() {
|
||||
constructor.declarationDescriptor?.let { result.add(it.fqNameUnsafe) }
|
||||
}
|
||||
|
||||
contextObjects.filterIsInstance<KotlinType>().forEach { diagnosticType ->
|
||||
diagnosticType.contains {
|
||||
innerType ->
|
||||
innerType.constructor.declarationDescriptor?.let { result.add(it.fqNameUnsafe) }
|
||||
innerType.addMentionedTypeConstructor()
|
||||
innerType.getAbbreviation()?.addMentionedTypeConstructor()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !DIAGNOSTICS_NUMBER: 1
|
||||
// !DIAGNOSTICS: TYPE_MISMATCH
|
||||
// !MESSAGE_TYPE: HTML
|
||||
|
||||
package a.b.c
|
||||
|
||||
class G
|
||||
|
||||
typealias A = G
|
||||
|
||||
class D<T, A> {
|
||||
fun g(t: Map<T, a.b.c.A>) {
|
||||
}
|
||||
|
||||
fun <T> g(t1: Map<T, A>, t2: Int) {
|
||||
g(t1)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<!-- complexTypeMismatchWithTypeParametersAndTypeAlias1 -->
|
||||
<html>
|
||||
Type mismatch.
|
||||
<table>
|
||||
<tr>
|
||||
<td>Required:</td>
|
||||
<td>Map<`T#1<i> (type parameter of a.b.c.D)</i>, a.b.c.A<font color="808080"><i> /* = G */</i></font>></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Found:</td>
|
||||
<td>Map<`T#2<i> (type parameter of a.b.c.D.g)</i>, A#1<i> (type parameter of a.b.c.D)</i>></td>
|
||||
</tr>
|
||||
</table>
|
||||
</html>
|
||||
@@ -72,6 +72,12 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("complexTypeMismatchWithTypeParametersAndTypeAlias.kt")
|
||||
public void testComplexTypeMismatchWithTypeParametersAndTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/complexTypeMismatchWithTypeParametersAndTypeAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingOverloadsClass.kt")
|
||||
public void testConflictingOverloadsClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/conflictingOverloadsClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user