Singleton made thread-safe in JavaToKotlinClassMap

This commit is contained in:
Andrey Breslav
2014-12-02 18:40:39 +03:00
parent 80a32ee875
commit 99ac9e1c2f
10 changed files with 12 additions and 20 deletions
@@ -63,7 +63,7 @@ class LazyJavaAnnotationDescriptor(
private val type = c.storageManager.createLazyValue {(): JetType ->
val fqName = fqName()
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) }
annotationClass?.getDefaultType() ?: ErrorUtils.createErrorType(fqName.asString())
}
@@ -46,7 +46,7 @@ class LazyJavaTypeResolver(
return when (javaType) {
is JavaPrimitiveType -> {
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)
jetType!!
}
@@ -65,7 +65,7 @@ class LazyJavaTypeResolver(
public fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): JetType {
val javaComponentType = arrayType.getComponentType()
if (javaComponentType is JavaPrimitiveType) {
val jetType = JavaToKotlinClassMap.getInstance().mapPrimitiveKotlinClass("[" + javaComponentType.getCanonicalText())
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass("[" + javaComponentType.getCanonicalText())
if (jetType != null) {
return if (PLATFORM_TYPES && attr.allowFlexible)
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
@@ -117,7 +117,7 @@ class LazyJavaTypeResolver(
val fqName = classifier.getFqName()
.sure("Class type should have a FQ name: " + classifier)
val javaToKotlinClassMap = JavaToKotlinClassMap.getInstance()
val javaToKotlinClassMap = JavaToKotlinClassMap.INSTANCE
val howThisTypeIsUsedEffectively = when {
attr.flexibility == FLEXIBLE_LOWER_BOUND -> MEMBER_SIGNATURE_COVARIANT
attr.flexibility == FLEXIBLE_UPPER_BOUND -> MEMBER_SIGNATURE_CONTRAVARIANT
@@ -33,15 +33,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.*;
public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap {
private static JavaToKotlinClassMap instance = null;
@NotNull
public static JavaToKotlinClassMap getInstance() {
if (instance == null) {
instance = new JavaToKotlinClassMap();
}
return instance;
}
public static final JavaToKotlinClassMap INSTANCE = new JavaToKotlinClassMap();
private final Map<FqName, ClassDescriptor> classDescriptorMap = new HashMap<FqName, ClassDescriptor>();
private final Map<FqName, ClassDescriptor> classDescriptorMapForCovariantPositions = new HashMap<FqName, ClassDescriptor>();