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:
+4
-4
@@ -154,11 +154,11 @@ class JavaTypeResolver(
|
||||
attr.flexibility == FLEXIBLE_LOWER_BOUND -> MEMBER_SIGNATURE_COVARIANT
|
||||
attr.flexibility == FLEXIBLE_UPPER_BOUND -> MEMBER_SIGNATURE_CONTRAVARIANT
|
||||
|
||||
// This case has to be checked before isMarkedReadOnly/isMarkedMutable, because those two are slow
|
||||
// not mapped, we don't care about being marked mutable/read-only
|
||||
javaToKotlin.mapPlatformClass(fqName, c.module.builtIns).isEmpty() -> attr.howThisTypeIsUsed
|
||||
// This case has to be checked before isMarkedReadOnly/isMarkedMutable, because those two are slow
|
||||
// not mapped, we don't care about being marked mutable/read-only
|
||||
!javaToKotlin.isJavaPlatformClass(fqName) -> attr.howThisTypeIsUsed
|
||||
|
||||
// Read (possibly external) annotations
|
||||
// Read (possibly external) annotations
|
||||
else -> attr.howThisTypeIsUsedAccordingToAnnotations
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -172,6 +172,10 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
||||
: classId(outer).createNestedClassId(Name.identifier(clazz.getSimpleName()));
|
||||
}
|
||||
|
||||
public boolean isJavaPlatformClass(@NotNull FqName fqName) {
|
||||
return mapJavaToKotlin(fqName) != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<ClassDescriptor> mapPlatformClass(@NotNull FqName fqName, @NotNull KotlinBuiltIns builtIns) {
|
||||
ClassDescriptor kotlinAnalog = mapJavaToKotlin(fqName, builtIns);
|
||||
|
||||
Reference in New Issue
Block a user