[SLC] Support generics and ignore whitespace in KtSuperTypeList.findEntry

This commit is contained in:
Pavel Mikhailovskii
2023-02-13 14:47:45 +00:00
committed by Space Team
parent a9cae3fe87
commit e77f5c7764
5 changed files with 32 additions and 17 deletions
@@ -13,24 +13,11 @@ import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService
import org.jetbrains.kotlin.psi.*
fun KtSuperTypeList.findEntry(fqNameToFind: String): KtSuperTypeListEntry? {
val name = fqNameToFind.substringAfterLast(delimiter = '.', missingDelimiterValue = "")
if (name.isEmpty()) {
return entries.find { it.typeAsUserType?.textMatches(fqNameToFind) == true }
}
fun KtSuperTypeList.findEntry(fqNameToFind: String): KtSuperTypeListEntry? =
entries.find { it.typeAsUserType?.simpleName == fqNameToFind }
val qualifier = fqNameToFind.substringBeforeLast('.')
val entries = entries.mapNotNull { entry -> entry.typeAsUserType?.let { entry to it } }
.filter { (_, type) -> type.referencedName == name && (type.qualifier?.textMatches(qualifier) != false) }
.ifEmpty { return null }
return if (entries.size == 1) {
entries.first().first
} else {
val entry = entries.firstOrNull { it.second.qualifier != null } ?: entries.firstOrNull()
entry?.first
}
}
private val KtUserType.simpleName: String?
get() = qualifier?.let { "${it.simpleName}.$referencedName" } ?: referencedName
// NOTE: avoid using blocking lazy in light classes, it leads to deadlocks
fun <T> lazyPub(initializer: () -> T) = lazy(LazyThreadSafetyMode.PUBLICATION, initializer)
@@ -300,6 +300,12 @@ public class SymbolLightClassesByPsiForLibraryTestGenerated extends AbstractSymb
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("unresolvedGenericSupertypes.kt")
public void testUnresolvedGenericSupertypes() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/unresolvedGenericSupertypes.kt");
}
@Test
@TestMetadata("unresolvedWithAliasedImport.kt")
public void testUnresolvedWithAliasedImport() throws Exception {
@@ -300,6 +300,12 @@ public class SymbolLightClassesByPsiForSourceTestGenerated extends AbstractSymbo
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("unresolvedGenericSupertypes.kt")
public void testUnresolvedGenericSupertypes() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByPsi/unresolvedGenericSupertypes.kt");
}
@Test
@TestMetadata("unresolvedWithAliasedImport.kt")
public void testUnresolvedWithAliasedImport() throws Exception {
@@ -0,0 +1,7 @@
public final class C1 /* C1*/ extends Super<T, U> implements Intf1<A, B>, Intf2<X, Y<Z>> {
public C1();// .ctor()
}
public final class C2 /* C2*/ extends com.example.Super<T, U> implements com.example.Intf1<A, B>, com.example.Intf2<X, Y<Z>> {
public C2();// .ctor()
}
@@ -0,0 +1,9 @@
public class C1: Intf1 < A , B >, Super < T , U >(42),
Intf2 < X ,
Y < Z >>
public class C2: com . example . Intf1 < A , B >, com . example . Super < T , U >(42),
com . example . Intf2 < X ,
Y < Z >>
// COMPILATION_ERRORS