[SLC] Support generics and ignore whitespace in KtSuperTypeList.findEntry
This commit is contained in:
committed by
Space Team
parent
a9cae3fe87
commit
e77f5c7764
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user