Add JavaToKotlinClassMap#isJavaPlatformClass
Use it instead of mapPlatformClass where we only need to check emptiness because mapPlatformClass requires built-ins and it's not always easy to come up with the correct instance of built-ins. In KotlinEvaluationBuilder, use the nullable function findClassAcrossModuleDependencies instead of mapPlatformClass which uses the throwing resolveClassByFqName. This is necessary because DefaultBuiltIns, which are used there, are not always able to find classes mapped by a _Java_ to Kotlin class map. (The correct solution would be not to use DefaultBuiltIns at all, instead obtaining the correct instance of built-ins, which are almost certainly going to be JvmBuiltIns, from the project configuration.)
This commit is contained in:
@@ -93,4 +93,4 @@ class ImportableFqNameClassifier(private val file: KtFile) {
|
||||
}
|
||||
|
||||
fun isJavaClassNotToBeUsedInKotlin(fqName: FqName): Boolean
|
||||
= JavaToKotlinClassMap.INSTANCE.mapPlatformClass(fqName, DefaultBuiltIns.Instance).isNotEmpty() || JavaAnnotationMapper.javaToKotlinNameMap[fqName] != null
|
||||
= JavaToKotlinClassMap.INSTANCE.isJavaPlatformClass(fqName) || JavaAnnotationMapper.javaToKotlinNameMap[fqName] != null
|
||||
|
||||
@@ -20,11 +20,13 @@ import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import java.util.*
|
||||
|
||||
data class DataForConversion private constructor(
|
||||
val elementsAndTexts: Collection<Any> /* list consisting of PsiElement's to convert and plain String's */,
|
||||
@@ -243,9 +245,7 @@ data class DataForConversion private constructor(
|
||||
else {
|
||||
val fqName = FqNameUnsafe(qualifiedName)
|
||||
// skip explicit imports of platform classes mapped into Kotlin classes
|
||||
if (fqName.isSafe
|
||||
&& JavaToKotlinClassMap.INSTANCE.mapPlatformClass(
|
||||
fqName.toSafe(), DefaultBuiltIns.Instance).isNotEmpty()) continue
|
||||
if (fqName.isSafe && JavaToKotlinClassMap.INSTANCE.isJavaPlatformClass(fqName.toSafe())) continue
|
||||
append("import $qualifiedName\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.resolve.AnalyzingUtils
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ASM5
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -549,8 +550,10 @@ fun Type.getClassDescriptor(scope: GlobalSearchScope): ClassDescriptor? {
|
||||
|
||||
val jvmName = JvmClassName.byInternalName(internalName).fqNameForClassNameWithoutDollars
|
||||
|
||||
val platformClasses = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(jvmName, DefaultBuiltIns.Instance)
|
||||
if (platformClasses.isNotEmpty()) return platformClasses.first()
|
||||
// TODO: use the correct built-ins from the module instead of DefaultBuiltIns here
|
||||
JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(jvmName)?.let(
|
||||
DefaultBuiltIns.Instance.builtInsModule::findClassAcrossModuleDependencies
|
||||
)?.let { return it }
|
||||
|
||||
return runReadAction {
|
||||
val classes = JavaPsiFacade.getInstance(scope.project).findClasses(jvmName.asString(), scope)
|
||||
|
||||
Reference in New Issue
Block a user