Remove reference to KotlinBuiltIns from CompanionObjectMapping
Make it a class
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping;
|
import org.jetbrains.kotlin.builtins.CompanionObjectMapping;
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
@@ -27,13 +28,16 @@ import org.jetbrains.org.objectweb.asm.Type;
|
|||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||||
|
|
||||||
public class FieldInfo {
|
public class FieldInfo {
|
||||||
|
|
||||||
|
private static final CompanionObjectMapping COMPANION_OBJECT_MAPPING = new CompanionObjectMapping(KotlinBuiltIns.getInstance());
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper) {
|
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper) {
|
||||||
if (!classDescriptor.getKind().isSingleton()) {
|
if (!classDescriptor.getKind().isSingleton()) {
|
||||||
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonCompanionObject(classDescriptor) || CompanionObjectMapping.hasMappingToObject(classDescriptor)) {
|
if (isNonCompanionObject(classDescriptor) || COMPANION_OBJECT_MAPPING.hasMappingToObject(classDescriptor)) {
|
||||||
Type type = typeMapper.mapType(classDescriptor);
|
Type type = typeMapper.mapType(classDescriptor);
|
||||||
return new FieldInfo(type, type, JvmAbi.INSTANCE_FIELD, true);
|
return new FieldInfo(type, type, JvmAbi.INSTANCE_FIELD, true);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -69,7 +69,8 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
|||||||
add(ClassId.topLevel(jvmType.getWrapperFqName()), builtIns.getPrimitiveClassDescriptor(jvmType.getPrimitiveType()));
|
add(ClassId.topLevel(jvmType.getWrapperFqName()), builtIns.getPrimitiveClassDescriptor(jvmType.getPrimitiveType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ClassDescriptor descriptor : CompanionObjectMapping.allClassesWithIntrinsicCompanions()) {
|
CompanionObjectMapping companionObjectMapping = new CompanionObjectMapping(builtIns);
|
||||||
|
for (ClassDescriptor descriptor : companionObjectMapping.allClassesWithIntrinsicCompanions()) {
|
||||||
ClassDescriptor companion = descriptor.getCompanionObjectDescriptor();
|
ClassDescriptor companion = descriptor.getCompanionObjectDescriptor();
|
||||||
assert companion != null : "No companion object found for " + descriptor;
|
assert companion != null : "No companion object found for " + descriptor;
|
||||||
add(ClassId.topLevel(new FqName("kotlin.jvm.internal." + descriptor.getName().asString() + "CompanionObject")), companion);
|
add(ClassId.topLevel(new FqName("kotlin.jvm.internal." + descriptor.getName().asString() + "CompanionObject")), companion);
|
||||||
|
|||||||
@@ -18,13 +18,12 @@ package org.jetbrains.kotlin.builtins
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import java.util.Collections
|
import java.util.*
|
||||||
|
|
||||||
public object CompanionObjectMapping {
|
public class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
|
||||||
private val classes = linkedSetOf<ClassDescriptor>()
|
private val classes = linkedSetOf<ClassDescriptor>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val builtIns = KotlinBuiltIns.getInstance()
|
|
||||||
for (type in PrimitiveType.NUMBER_TYPES) {
|
for (type in PrimitiveType.NUMBER_TYPES) {
|
||||||
classes.add(builtIns.getPrimitiveClassDescriptor(type))
|
classes.add(builtIns.getPrimitiveClassDescriptor(type))
|
||||||
}
|
}
|
||||||
@@ -32,11 +31,9 @@ public object CompanionObjectMapping {
|
|||||||
classes.add(builtIns.getEnum())
|
classes.add(builtIns.getEnum())
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
public fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
public fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
||||||
Collections.unmodifiableSet(classes)
|
Collections.unmodifiableSet(classes)
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
||||||
return DescriptorUtils.isCompanionObject(classDescriptor) &&
|
return DescriptorUtils.isCompanionObject(classDescriptor) &&
|
||||||
classDescriptor.getContainingDeclaration() in classes
|
classDescriptor.getContainingDeclaration() in classes
|
||||||
|
|||||||
+4
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.js.translate.intrinsic.objects
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsArrayAccess
|
import com.google.dart.compiler.backend.js.ast.JsArrayAccess
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping
|
import org.jetbrains.kotlin.builtins.CompanionObjectMapping
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig
|
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig
|
||||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||||
@@ -36,8 +37,10 @@ class DefaultClassObjectIntrinsic(val fqName: FqName, val moduleName: String): O
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class ObjectIntrinsics {
|
public class ObjectIntrinsics {
|
||||||
|
private val companionObjectMapping = CompanionObjectMapping(KotlinBuiltIns.getInstance())
|
||||||
|
|
||||||
public fun getIntrinsic(classDescriptor: ClassDescriptor): ObjectIntrinsic {
|
public fun getIntrinsic(classDescriptor: ClassDescriptor): ObjectIntrinsic {
|
||||||
if (!CompanionObjectMapping.hasMappingToObject(classDescriptor)) return NO_OBJECT_INTRINSIC
|
if (!companionObjectMapping.hasMappingToObject(classDescriptor)) return NO_OBJECT_INTRINSIC
|
||||||
|
|
||||||
val containingDeclaration = classDescriptor.getContainingDeclaration()
|
val containingDeclaration = classDescriptor.getContainingDeclaration()
|
||||||
val name = Name.identifier(containingDeclaration.getName().asString() + "CompanionObject")
|
val name = Name.identifier(containingDeclaration.getName().asString() + "CompanionObject")
|
||||||
|
|||||||
Reference in New Issue
Block a user