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:
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.j2k.ast.Import
|
||||
import org.jetbrains.kotlin.j2k.ast.ImportList
|
||||
@@ -60,7 +59,7 @@ private fun Converter.convertImport(fqName: FqName, ref: PsiJavaCodeReferenceEle
|
||||
if (annotationConverter.isImportNotRequired(fqName)) return emptyList()
|
||||
|
||||
// If imported class has a kotlin analog, drop the import
|
||||
if (!JavaToKotlinClassMap.INSTANCE.mapPlatformClass(fqName, DefaultBuiltIns.Instance).isEmpty()) return emptyList()
|
||||
if (JavaToKotlinClassMap.INSTANCE.isJavaPlatformClass(fqName)) return emptyList()
|
||||
}
|
||||
|
||||
//TODO: how to detect compiled Kotlin here?
|
||||
|
||||
Reference in New Issue
Block a user