Enable kotlin.collections support for UL classes
Removed restriction for classes derived from Kotlin collections Added type erasure for java collection overrided methods
This commit is contained in:
+4
-56
@@ -20,8 +20,6 @@ import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.CachedValue
|
||||
@@ -40,11 +38,10 @@ import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.extensions.LightClassApplicabilityType
|
||||
import org.jetbrains.kotlin.extensions.LightClassApplicabilityCheckExtension
|
||||
import org.jetbrains.kotlin.extensions.LightClassApplicabilityType
|
||||
import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassContexts
|
||||
import org.jetbrains.kotlin.idea.caches.lightClasses.LazyLightClassDataHolder
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
@@ -57,8 +54,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
@@ -69,12 +64,6 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
|
||||
private inner class KtUltraLightSupportImpl(private val element: KtElement, private val module: Module) : KtUltraLightSupport {
|
||||
|
||||
private fun KtDeclaration.forLogString(): String? = when (this) {
|
||||
is KtClassOrObject -> this.fqName?.asString()
|
||||
is KtFile -> this.packageFqNameByTree.asString()
|
||||
else -> this.text
|
||||
}
|
||||
|
||||
override val isReleasedCoroutine
|
||||
get() = module.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||
|
||||
@@ -103,14 +92,6 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
LOG.debug { "Using heavy light classes because of compiler plugins" }
|
||||
return true
|
||||
}
|
||||
|
||||
val problem = findTooComplexDeclaration(element)
|
||||
if (problem != null) {
|
||||
LOG.debug {
|
||||
"Using heavy light classes for ${element.forLogString()} because of ${StringUtil.trimLog(problem.text, 100)}"
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -164,31 +145,6 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
namePreprocessor = ::tryGetPredefinedName
|
||||
)
|
||||
}
|
||||
|
||||
private fun findTooComplexDeclaration(declaration: KtDeclaration): PsiElement? {
|
||||
|
||||
if (declaration is KtClassOrObject) {
|
||||
declaration.primaryConstructor?.let { findTooComplexDeclaration(it) }?.let { return it }
|
||||
|
||||
for (d in declaration.declarations) {
|
||||
if (d is KtClassOrObject && !(d is KtObjectDeclaration && d.isCompanion())) continue
|
||||
|
||||
findTooComplexDeclaration(d)?.let { return it }
|
||||
}
|
||||
|
||||
if (implementsKotlinCollection(declaration)) {
|
||||
return declaration.getSuperTypeList()
|
||||
}
|
||||
}
|
||||
if (declaration is KtCallableDeclaration) {
|
||||
declaration.valueParameters.mapNotNull { findTooComplexDeclaration(it) }.firstOrNull()?.let { return it }
|
||||
}
|
||||
if (declaration is KtProperty) {
|
||||
declaration.accessors.mapNotNull { findTooComplexDeclaration(it) }.firstOrNull()?.let { return it }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createUltraLightClassForFacade(
|
||||
@@ -240,14 +196,6 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
}
|
||||
}
|
||||
|
||||
private fun implementsKotlinCollection(classOrObject: KtClassOrObject): Boolean {
|
||||
if (classOrObject.superTypeListEntries.isEmpty()) return false
|
||||
|
||||
return (resolveToDescriptor(classOrObject) as? ClassifierDescriptor)?.getAllSuperClassifiers()?.any {
|
||||
it.fqNameSafe.asString().startsWith("kotlin.collections.")
|
||||
} == true
|
||||
}
|
||||
|
||||
private fun KtFile.hasAlias(shortName: Name?): Boolean {
|
||||
if (shortName == null) return false
|
||||
return allAliases(this)[shortName.asString()] == true
|
||||
@@ -307,10 +255,10 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
getResolutionFacade().frontendService<LazyLightClassDataHolder.DiagnosticsHolder>()
|
||||
|
||||
override fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor? {
|
||||
try {
|
||||
return declaration.resolveToDescriptorIfAny(BodyResolveMode.FULL)
|
||||
return try {
|
||||
declaration.resolveToDescriptorIfAny(BodyResolveMode.FULL)
|
||||
} catch (e: NoDescriptorForDeclarationException) {
|
||||
return null
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user