Drop TypeMappingConfiguration.innerClassNameFactory, use default implementation

After 57d209f599, non-default behavior is no longer used.

 #KT-21453 Fixed
This commit is contained in:
Alexander Udalov
2017-11-27 17:12:57 +01:00
parent 79e399942d
commit f80c9a4692
6 changed files with 32 additions and 92 deletions
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor;
import org.jetbrains.kotlin.load.kotlin.TypeMappingConfiguration;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
@@ -87,7 +86,6 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
private final BindingContext bindingContext;
private final GenerationState.GenerateClassFilter filter;
private final JvmRuntimeTypes runtimeTypes;
private final TypeMappingConfiguration<Type> typeMappingConfiguration;
private final SwitchCodegenProvider switchCodegenProvider;
private final LanguageVersionSettings languageVersionSettings;
private final ClassBuilderMode classBuilderMode;
@@ -97,7 +95,6 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
this.bindingContext = state.getBindingContext();
this.filter = state.getGenerateDeclaredClassFilter();
this.runtimeTypes = state.getJvmRuntimeTypes();
this.typeMappingConfiguration = state.getTypeMapper().getTypeMappingConfiguration();
this.switchCodegenProvider = new SwitchCodegenProvider(state);
this.languageVersionSettings = state.getLanguageVersionSettings();
this.classBuilderMode = state.getClassBuilderMode();
@@ -269,7 +266,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
return base.isEmpty() ? descriptorName.asString() : base + '/' + descriptorName;
}
else {
return typeMappingConfiguration.getInnerClassNameFactory().invoke(base, descriptorName.asString());
return base + "$" + descriptorName.asString();
}
}
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.codegen.coroutines.*
import org.jetbrains.kotlin.codegen.intrinsics.bytecode
import org.jetbrains.kotlin.codegen.intrinsics.classId
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.isInlineOnly
import org.jetbrains.kotlin.name.Name
@@ -557,7 +558,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
assert(callableDescriptor is DeserializedCallableMemberDescriptor) { "Not a deserialized function or proper: " + callableDescriptor }
val containingClasses = state.typeMapper.getContainingClassesForDeserializedCallable(callableDescriptor as DeserializedCallableMemberDescriptor)
val containingClasses = KotlinTypeMapper.getContainingClassesForDeserializedCallable(callableDescriptor as DeserializedCallableMemberDescriptor)
val containerId = containingClasses.implClassId
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiElement;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment;
@@ -104,12 +103,6 @@ public class KotlinTypeMapper {
return CommonSupertypes.commonSupertype(types);
}
@NotNull
@Override
public Function2<String, String, String> getInnerClassNameFactory() {
return TypeMappingConfiguration.DefaultImpls.getInnerClassNameFactory(this);
}
@Nullable
@Override
public Type getPredefinedTypeForClass(@NotNull ClassDescriptor classDescriptor) {
@@ -147,11 +140,6 @@ public class KotlinTypeMapper {
this.isJvm8TargetWithDefaults = isJvm8TargetWithDefaults;
}
@NotNull
public TypeMappingConfiguration<Type> getTypeMappingConfiguration() {
return typeMappingConfiguration;
}
@NotNull
public BindingContext getBindingContext() {
return bindingContext;
@@ -190,7 +178,7 @@ public class KotlinTypeMapper {
}
@NotNull
private String internalNameForPackageMemberOwner(@NotNull CallableMemberDescriptor descriptor, boolean publicFacade) {
private static String internalNameForPackageMemberOwner(@NotNull CallableMemberDescriptor descriptor, boolean publicFacade) {
boolean isAccessor = descriptor instanceof AccessorForCallableDescriptor;
if (isAccessor) {
descriptor = ((AccessorForCallableDescriptor) descriptor).getCalleeDescriptor();
@@ -269,7 +257,7 @@ public class KotlinTypeMapper {
}
@NotNull
public ContainingClassesInfo getContainingClassesForDeserializedCallable(
public static ContainingClassesInfo getContainingClassesForDeserializedCallable(
@NotNull DeserializedCallableMemberDescriptor deserializedDescriptor
) {
DeclarationDescriptor parentDeclaration = deserializedDescriptor.getContainingDeclaration();
@@ -288,15 +276,14 @@ public class KotlinTypeMapper {
}
@NotNull
private ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
private static ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
ClassId classId = DescriptorUtilsKt.getClassId(classDescriptor);
assert classId != null : "Deserialized class should have a ClassId: " + classDescriptor;
if (isInterface(classDescriptor)) {
FqName relativeClassName = classId.getRelativeClassName();
//TODO test nested trait fun inlining
String defaultImplsClassName = typeMappingConfiguration.getInnerClassNameFactory()
.invoke(relativeClassName.shortName().asString(), JvmAbi.DEFAULT_IMPLS_CLASS_NAME);
String defaultImplsClassName = relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX;
return new ClassId(classId.getPackageFqName(), Name.identifier(defaultImplsClassName));
}
@@ -304,7 +291,7 @@ public class KotlinTypeMapper {
}
@Nullable
private String getPackageMemberOwnerInternalName(@NotNull DeserializedCallableMemberDescriptor descriptor, boolean publicFacade) {
private static String getPackageMemberOwnerInternalName(@NotNull DeserializedCallableMemberDescriptor descriptor, boolean publicFacade) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
assert containingDeclaration instanceof PackageFragmentDescriptor : "Not a top-level member: " + descriptor;
@@ -315,7 +302,7 @@ public class KotlinTypeMapper {
ClassId ownerClassId = publicFacade ? containingClasses.getFacadeClassId()
: containingClasses.getImplClassId();
return JvmClassName.byClassId(ownerClassId, typeMappingConfiguration).getInternalName();
return JvmClassName.byClassId(ownerClassId).getInternalName();
}
private static final ClassId FAKE_CLASS_ID_FOR_BUILTINS = ClassId.topLevel(new FqName("kotlin.KotlinPackage"));
@@ -457,9 +444,7 @@ public class KotlinTypeMapper {
@NotNull
public Type mapDefaultImpls(@NotNull ClassDescriptor descriptor) {
String defaultImplsClassName = typeMappingConfiguration.getInnerClassNameFactory().invoke(
mapType(descriptor).getInternalName(), JvmAbi.DEFAULT_IMPLS_CLASS_NAME);
return Type.getObjectType(defaultImplsClassName);
return Type.getObjectType(mapType(descriptor).getInternalName() + JvmAbi.DEFAULT_IMPLS_SUFFIX);
}
@NotNull
@@ -957,7 +942,7 @@ public class KotlinTypeMapper {
}
@Nullable
private String getPartSimpleNameForMangling(@NotNull CallableMemberDescriptor descriptor) {
private static String getPartSimpleNameForMangling(@NotNull CallableMemberDescriptor descriptor) {
KtFile containingFile = DescriptorToSourceUtils.getContainingFile(descriptor);
if (containingFile != null) {
JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile);
@@ -1058,7 +1043,7 @@ public class KotlinTypeMapper {
}
@NotNull
public JvmMethodGenericSignature mapSignatureWithCustomParameters(
private JvmMethodGenericSignature mapSignatureWithCustomParameters(
@NotNull FunctionDescriptor f,
@NotNull OwnerKind kind,
@NotNull List<ValueParameterDescriptor> valueParameters,
@@ -47,13 +47,6 @@ private fun <T : Any> JvmTypeFactory<T>.boxTypeIfNeeded(possiblyPrimitiveType: T
if (needBoxedType) boxType(possiblyPrimitiveType) else possiblyPrimitiveType
interface TypeMappingConfiguration<out T : Any> {
private companion object {
private val DEFAULT_INNER_CLASS_NAME_FACTORY = fun(outer: String, inner: String) = outer + "$" + inner
}
val innerClassNameFactory: (outer: String, inner: String) -> String
get() = DEFAULT_INNER_CLASS_NAME_FACTORY
fun commonSupertype(types: Collection<@JvmSuppressWildcards KotlinType>): KotlinType
fun getPredefinedTypeForClass(classDescriptor: ClassDescriptor): T?
fun getPredefinedInternalNameForClass(classDescriptor: ClassDescriptor): String?
@@ -81,7 +74,7 @@ fun <T : Any> mapType(
)
}
mapBuiltInType(kotlinType, factory, mode, typeMappingConfiguration)?.let { builtInType ->
mapBuiltInType(kotlinType, factory, mode)?.let { builtInType ->
val jvmType = factory.boxTypeIfNeeded(builtInType, mode.needPrimitiveBoxing)
writeGenericType(kotlinType, jvmType, mode)
return jvmType
@@ -183,12 +176,7 @@ fun hasVoidReturnType(descriptor: CallableDescriptor): Boolean {
&& descriptor !is PropertyGetterDescriptor
}
private fun <T : Any> mapBuiltInType(
type: KotlinType,
typeFactory: JvmTypeFactory<T>,
mode: TypeMappingMode,
typeMappingConfiguration: TypeMappingConfiguration<T>
): T? {
private fun <T : Any> mapBuiltInType(type: KotlinType, typeFactory: JvmTypeFactory<T>, mode: TypeMappingMode): T? {
val descriptor = type.constructor.declarationDescriptor as? ClassDescriptor ?: return null
if (descriptor === FAKE_CONTINUATION_CLASS_DESCRIPTOR) {
@@ -214,7 +202,7 @@ private fun <T : Any> mapBuiltInType(
if (!mode.kotlinCollectionsToJavaCollections &&
JavaToKotlinClassMap.mutabilityMappings.any { it.javaClass == classId }) return null
return typeFactory.createObjectType(JvmClassName.byClassId(classId, typeMappingConfiguration).internalName)
return typeFactory.createObjectType(JvmClassName.byClassId(classId).internalName)
}
}
@@ -233,13 +221,13 @@ fun computeInternalName(
return if (fqName.isRoot) name else fqName.asString().replace('.', '/') + '/' + name
}
val containerClass = container as? ClassDescriptor ?:
throw IllegalArgumentException("Unexpected container: $container for $klass")
val containerClass = container as? ClassDescriptor
?: throw IllegalArgumentException("Unexpected container: $container for $klass")
val containerInternalName =
typeMappingConfiguration.getPredefinedInternalNameForClass(containerClass) ?:
computeInternalName(containerClass, typeMappingConfiguration)
return typeMappingConfiguration.innerClassNameFactory(containerInternalName, name)
return containerInternalName + "$" + name
}
private fun getRepresentativeUpperBound(descriptor: TypeParameterDescriptor): KotlinType {
@@ -271,8 +259,7 @@ open class JvmDescriptorTypeWriter<T : Any>(private val jvmTypeFactory: JvmTypeF
open fun writeArrayEnd() {
}
open public fun writeClass(objectType: T) {
open fun writeClass(objectType: T) {
writeJvmTypeAsIs(objectType)
}
@@ -16,15 +16,10 @@
package org.jetbrains.kotlin.resolve.jvm;
import kotlin.jvm.functions.Function2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.load.kotlin.TypeMappingConfiguration;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
import java.util.regex.Pattern;
public class JvmClassName {
@NotNull
public static JvmClassName byInternalName(@NotNull String internalName) {
@@ -33,31 +28,8 @@ public class JvmClassName {
@NotNull
public static JvmClassName byClassId(@NotNull ClassId classId) {
return byClassId(classId, null);
}
@NotNull
public static JvmClassName byClassId(@NotNull ClassId classId, @Nullable TypeMappingConfiguration<?> typeMappingConfiguration) {
FqName packageFqName = classId.getPackageFqName();
String[] relativeClassNameSegments = classId.getRelativeClassName().asString().split(Pattern.quote("."));
String relativeClassName;
if (relativeClassNameSegments.length == 1) {
relativeClassName = relativeClassNameSegments[0];
}
else if (relativeClassNameSegments.length > 1 && typeMappingConfiguration != null) {
Function2<String, String, String> innerClassNameFactory = typeMappingConfiguration.getInnerClassNameFactory();
relativeClassName = innerClassNameFactory.invoke(relativeClassNameSegments[0], relativeClassNameSegments[1]);
for (int i = 2; i < relativeClassNameSegments.length; ++i) {
relativeClassName = innerClassNameFactory.invoke(relativeClassName, relativeClassNameSegments[i]);
}
}
else {
// Default behavior if we don't have an inner class name factory
relativeClassName = classId.getRelativeClassName().asString().replace('.', '$');
}
String relativeClassName = classId.getRelativeClassName().asString().replace('.', '$');
return packageFqName.isRoot()
? new JvmClassName(relativeClassName)
: new JvmClassName(packageFqName.asString().replace('.', '/') + "/" + relativeClassName);
@@ -17,37 +17,37 @@
package org.jetbrains.kotlin.android.parcel
import kotlinx.android.parcel.TypeParceler
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.*
import org.jetbrains.kotlin.android.parcel.ParcelableResolveExtension.Companion.createMethod
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.*
import org.jetbrains.kotlin.android.parcel.serializers.PARCEL_TYPE
import org.jetbrains.kotlin.android.parcel.serializers.ParcelSerializer
import org.jetbrains.kotlin.android.parcel.serializers.TypeParcelerMapping
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
import org.jetbrains.kotlin.codegen.FunctionGenerationStrategy.CodegenBased
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.context.ClassContext
import org.jetbrains.kotlin.codegen.coroutines.UninitializedStoresProcessor
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
import org.jetbrains.kotlin.codegen.writeSyntheticClassMetadata
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation.*
import org.jetbrains.kotlin.incremental.components.NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
@@ -224,8 +224,7 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
private fun writeCreatorAccessField(codegen: ImplementationBodyCodegen, parcelableClass: ClassDescriptor) {
val parcelableAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType)
val creatorAsmType = Type.getObjectType(
codegen.typeMapper.typeMappingConfiguration.innerClassNameFactory(parcelableAsmType.internalName, "Creator"))
val creatorAsmType = Type.getObjectType(parcelableAsmType.internalName + "\$Creator")
codegen.v.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_STATIC or ACC_PUBLIC or ACC_FINAL, "CREATOR",
creatorAsmType.descriptor, null, null)
@@ -240,8 +239,7 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
properties: List<PropertyToSerialize>
) {
val containerAsmType = codegen.typeMapper.mapType(parcelableClass.defaultType)
val creatorAsmType = Type.getObjectType(
codegen.typeMapper.typeMappingConfiguration.innerClassNameFactory(containerAsmType.internalName, "Creator"))
val creatorAsmType = Type.getObjectType(containerAsmType.internalName + "\$Creator")
val creatorClass = ClassDescriptorImpl(
parcelableClass, Name.identifier("Creator"), Modality.FINAL, ClassKind.CLASS, emptyList(),