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
@@ -47,7 +47,7 @@ public class JvmRuntimeTypes {
this.reflectionTypes = reflectionTypes;
ModuleDescriptor fakeModule = new ModuleDescriptorImpl(Name.special("<fake module for functions impl>"),
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.getInstance());
Collections.<ImportPath>emptyList(), JavaToKotlinClassMap.INSTANCE);
PackageFragmentDescriptor kotlinJvmInternal =
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 platformToKotlinClassMap = JavaToKotlinClassMap.getInstance()
override val platformToKotlinClassMap = JavaToKotlinClassMap.INSTANCE
}
@@ -148,7 +148,7 @@ public enum TopDownAnalyzerFacadeForJVM {
public static ModuleDescriptorImpl createJavaModule(@NotNull String name) {
return new ModuleDescriptorImpl(Name.special(name),
DEFAULT_IMPORTS,
JavaToKotlinClassMap.getInstance());
JavaToKotlinClassMap.INSTANCE);
}
@NotNull
@@ -219,7 +219,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
FqName javaFqName = KotlinToJavaTypesMap.getInstance().getKotlinToJavaFqName(originalClassFqName);
if (javaFqName == null) return null;
Collection<ClassDescriptor> descriptors = JavaToKotlinClassMap.getInstance().mapPlatformClass(javaFqName);
Collection<ClassDescriptor> descriptors = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(javaFqName);
for (ClassDescriptor descriptor : descriptors) {
String fqName = DescriptorUtils.getFqName(descriptor).asString();
if (isSameName(qualifiedName, fqName)) {
@@ -125,7 +125,7 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
@Override
public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
// skip java.util.Collection, etc.
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(DescriptorUtils.getFqNameSafe(descriptor)).isEmpty()) {
if (!JavaToKotlinClassMap.INSTANCE.mapPlatformClass(DescriptorUtils.getFqNameSafe(descriptor)).isEmpty()) {
return null;
}
@@ -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>();
@@ -482,7 +482,7 @@ fun Type.getClassDescriptor(project: Project): ClassDescriptor? {
val jvmName = JvmClassName.byInternalName(getInternalName()).getFqNameForClassNameWithoutDollars()
val platformClasses = JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmName)
val platformClasses = JavaToKotlinClassMap.INSTANCE.mapPlatformClass(jvmName)
if (platformClasses.notEmpty) return platformClasses.first()
return runReadAction {
+1 -1
View File
@@ -68,7 +68,7 @@ private fun Converter.filterImport(name: String, ref: PsiJavaCodeReferenceElemen
if (name in annotationConverter.annotationsToRemove) return null
// 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()
if (target is KotlinLightClassForPackage) {