Remove reference to KotlinBuiltIns from CompanionObjectMapping

Make it a class
This commit is contained in:
Pavel V. Talanov
2015-09-16 15:56:42 +03:00
parent d2a4235dd8
commit 424d71e964
4 changed files with 13 additions and 8 deletions
@@ -69,7 +69,8 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
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();
assert companion != null : "No companion object found for " + descriptor;
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.resolve.DescriptorUtils
import java.util.Collections
import java.util.*
public object CompanionObjectMapping {
public class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
private val classes = linkedSetOf<ClassDescriptor>()
init {
val builtIns = KotlinBuiltIns.getInstance()
for (type in PrimitiveType.NUMBER_TYPES) {
classes.add(builtIns.getPrimitiveClassDescriptor(type))
}
@@ -32,11 +31,9 @@ public object CompanionObjectMapping {
classes.add(builtIns.getEnum())
}
@JvmStatic
public fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
Collections.unmodifiableSet(classes)
@JvmStatic
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
return DescriptorUtils.isCompanionObject(classDescriptor) &&
classDescriptor.getContainingDeclaration() in classes