Singleton made thread-safe in JavaToKotlinClassMap
This commit is contained in:
@@ -47,7 +47,7 @@ public class JvmRuntimeTypes {
|
|||||||
this.reflectionTypes = reflectionTypes;
|
this.reflectionTypes = reflectionTypes;
|
||||||
|
|
||||||
ModuleDescriptor fakeModule = new ModuleDescriptorImpl(Name.special("<fake module for functions impl>"),
|
ModuleDescriptor fakeModule = new ModuleDescriptorImpl(Name.special("<fake module for functions impl>"),
|
||||||
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.getInstance());
|
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.INSTANCE);
|
||||||
|
|
||||||
PackageFragmentDescriptor kotlinJvmInternal =
|
PackageFragmentDescriptor kotlinJvmInternal =
|
||||||
new MutablePackageFragmentDescriptor(fakeModule, new FqName("kotlin.jvm.internal"));
|
new MutablePackageFragmentDescriptor(fakeModule, new FqName("kotlin.jvm.internal"));
|
||||||
|
|||||||
@@ -78,6 +78,6 @@ public object JvmAnalyzerFacade : AnalyzerFacade<JvmResolverForModule, JvmPlatfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val defaultImports = TopDownAnalyzerFacadeForJVM.DEFAULT_IMPORTS
|
override val defaultImports = TopDownAnalyzerFacadeForJVM.DEFAULT_IMPORTS
|
||||||
override val platformToKotlinClassMap = JavaToKotlinClassMap.getInstance()
|
override val platformToKotlinClassMap = JavaToKotlinClassMap.INSTANCE
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -148,7 +148,7 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
public static ModuleDescriptorImpl createJavaModule(@NotNull String name) {
|
public static ModuleDescriptorImpl createJavaModule(@NotNull String name) {
|
||||||
return new ModuleDescriptorImpl(Name.special(name),
|
return new ModuleDescriptorImpl(Name.special(name),
|
||||||
DEFAULT_IMPORTS,
|
DEFAULT_IMPORTS,
|
||||||
JavaToKotlinClassMap.getInstance());
|
JavaToKotlinClassMap.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -219,7 +219,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
|||||||
FqName javaFqName = KotlinToJavaTypesMap.getInstance().getKotlinToJavaFqName(originalClassFqName);
|
FqName javaFqName = KotlinToJavaTypesMap.getInstance().getKotlinToJavaFqName(originalClassFqName);
|
||||||
if (javaFqName == null) return null;
|
if (javaFqName == null) return null;
|
||||||
|
|
||||||
Collection<ClassDescriptor> descriptors = JavaToKotlinClassMap.getInstance().mapPlatformClass(javaFqName);
|
Collection<ClassDescriptor> descriptors = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(javaFqName);
|
||||||
for (ClassDescriptor descriptor : descriptors) {
|
for (ClassDescriptor descriptor : descriptors) {
|
||||||
String fqName = DescriptorUtils.getFqName(descriptor).asString();
|
String fqName = DescriptorUtils.getFqName(descriptor).asString();
|
||||||
if (isSameName(qualifiedName, fqName)) {
|
if (isSameName(qualifiedName, fqName)) {
|
||||||
|
|||||||
+1
-1
@@ -125,7 +125,7 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
|
|||||||
@Override
|
@Override
|
||||||
public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
|
public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
|
||||||
// skip java.util.Collection, etc.
|
// skip java.util.Collection, etc.
|
||||||
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(DescriptorUtils.getFqNameSafe(descriptor)).isEmpty()) {
|
if (!JavaToKotlinClassMap.INSTANCE.mapPlatformClass(DescriptorUtils.getFqNameSafe(descriptor)).isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
private val type = c.storageManager.createLazyValue {(): JetType ->
|
private val type = c.storageManager.createLazyValue {(): JetType ->
|
||||||
val fqName = fqName()
|
val fqName = fqName()
|
||||||
if (fqName == null) return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
|
if (fqName == null) return@createLazyValue ErrorUtils.createErrorType("No fqName: $javaAnnotation")
|
||||||
val annotationClass = JavaToKotlinClassMap.getInstance().mapKotlinClass(fqName, TypeUsage.MEMBER_SIGNATURE_INVARIANT)
|
val annotationClass = JavaToKotlinClassMap.INSTANCE.mapKotlinClass(fqName, TypeUsage.MEMBER_SIGNATURE_INVARIANT)
|
||||||
?: javaAnnotation.resolve()?.let { javaClass -> c.moduleClassResolver.resolveClass(javaClass) }
|
?: javaAnnotation.resolve()?.let { javaClass -> c.moduleClassResolver.resolveClass(javaClass) }
|
||||||
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
|
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -46,7 +46,7 @@ class LazyJavaTypeResolver(
|
|||||||
return when (javaType) {
|
return when (javaType) {
|
||||||
is JavaPrimitiveType -> {
|
is JavaPrimitiveType -> {
|
||||||
val canonicalText = javaType.getCanonicalText()
|
val canonicalText = javaType.getCanonicalText()
|
||||||
val jetType = JavaToKotlinClassMap.getInstance().mapPrimitiveKotlinClass(canonicalText)
|
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass(canonicalText)
|
||||||
assert(jetType != null, "Primitive type is not found: " + canonicalText)
|
assert(jetType != null, "Primitive type is not found: " + canonicalText)
|
||||||
jetType!!
|
jetType!!
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class LazyJavaTypeResolver(
|
|||||||
public fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): JetType {
|
public fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): JetType {
|
||||||
val javaComponentType = arrayType.getComponentType()
|
val javaComponentType = arrayType.getComponentType()
|
||||||
if (javaComponentType is JavaPrimitiveType) {
|
if (javaComponentType is JavaPrimitiveType) {
|
||||||
val jetType = JavaToKotlinClassMap.getInstance().mapPrimitiveKotlinClass("[" + javaComponentType.getCanonicalText())
|
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass("[" + javaComponentType.getCanonicalText())
|
||||||
if (jetType != null) {
|
if (jetType != null) {
|
||||||
return if (PLATFORM_TYPES && attr.allowFlexible)
|
return if (PLATFORM_TYPES && attr.allowFlexible)
|
||||||
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
|
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
|
||||||
@@ -117,7 +117,7 @@ class LazyJavaTypeResolver(
|
|||||||
val fqName = classifier.getFqName()
|
val fqName = classifier.getFqName()
|
||||||
.sure("Class type should have a FQ name: " + classifier)
|
.sure("Class type should have a FQ name: " + classifier)
|
||||||
|
|
||||||
val javaToKotlinClassMap = JavaToKotlinClassMap.getInstance()
|
val javaToKotlinClassMap = JavaToKotlinClassMap.INSTANCE
|
||||||
val howThisTypeIsUsedEffectively = when {
|
val howThisTypeIsUsedEffectively = when {
|
||||||
attr.flexibility == FLEXIBLE_LOWER_BOUND -> MEMBER_SIGNATURE_COVARIANT
|
attr.flexibility == FLEXIBLE_LOWER_BOUND -> MEMBER_SIGNATURE_COVARIANT
|
||||||
attr.flexibility == FLEXIBLE_UPPER_BOUND -> MEMBER_SIGNATURE_CONTRAVARIANT
|
attr.flexibility == FLEXIBLE_UPPER_BOUND -> MEMBER_SIGNATURE_CONTRAVARIANT
|
||||||
|
|||||||
+1
-9
@@ -33,15 +33,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap {
|
public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap {
|
||||||
private static JavaToKotlinClassMap instance = null;
|
public static final JavaToKotlinClassMap INSTANCE = new JavaToKotlinClassMap();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JavaToKotlinClassMap getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new JavaToKotlinClassMap();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<FqName, ClassDescriptor> classDescriptorMap = new HashMap<FqName, ClassDescriptor>();
|
private final Map<FqName, ClassDescriptor> classDescriptorMap = new HashMap<FqName, ClassDescriptor>();
|
||||||
private final Map<FqName, ClassDescriptor> classDescriptorMapForCovariantPositions = new HashMap<FqName, ClassDescriptor>();
|
private final Map<FqName, ClassDescriptor> classDescriptorMapForCovariantPositions = new HashMap<FqName, ClassDescriptor>();
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ fun Type.getClassDescriptor(project: Project): ClassDescriptor? {
|
|||||||
|
|
||||||
val jvmName = JvmClassName.byInternalName(getInternalName()).getFqNameForClassNameWithoutDollars()
|
val jvmName = JvmClassName.byInternalName(getInternalName()).getFqNameForClassNameWithoutDollars()
|
||||||
|
|
||||||
val platformClasses = JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmName)
|
val platformClasses = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(jvmName)
|
||||||
if (platformClasses.notEmpty) return platformClasses.first()
|
if (platformClasses.notEmpty) return platformClasses.first()
|
||||||
|
|
||||||
return runReadAction {
|
return runReadAction {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ private fun Converter.filterImport(name: String, ref: PsiJavaCodeReferenceElemen
|
|||||||
if (name in annotationConverter.annotationsToRemove) return null
|
if (name in annotationConverter.annotationsToRemove) return null
|
||||||
|
|
||||||
// If imported class has a kotlin analog, drop the import
|
// If imported class has a kotlin analog, drop the import
|
||||||
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(FqName(name)).isEmpty()) return null
|
if (!JavaToKotlinClassMap.INSTANCE.mapPlatformClass(FqName(name)).isEmpty()) return null
|
||||||
|
|
||||||
val target = ref.resolve()
|
val target = ref.resolve()
|
||||||
if (target is KotlinLightClassForPackage) {
|
if (target is KotlinLightClassForPackage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user