Kapt3: Replace "my/package/Class$Inner" to "my/package/Class/Inner" in kapt3 class builder mode
This commit is contained in:
committed by
Yan Zhulanow
parent
65a9d9e8d2
commit
fc0b17c453
@@ -62,4 +62,12 @@ public class ClassBuilderMode {
|
||||
/* bodies = */ false,
|
||||
/* metadata = */ true,
|
||||
/* sourceRetention = */ true);
|
||||
|
||||
/**
|
||||
* Function signatures + metadata (to support incremental compilation with kapt)
|
||||
*/
|
||||
public final static ClassBuilderMode KAPT3 = new ClassBuilderMode(
|
||||
/* bodies = */ false,
|
||||
/* metadata = */ true,
|
||||
/* sourceRetention = */ true);
|
||||
}
|
||||
|
||||
+9
-2
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.fileClasses.FileClasses;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingConfiguration;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
@@ -81,6 +82,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
private final GenerationState.GenerateClassFilter filter;
|
||||
private final JvmRuntimeTypes runtimeTypes;
|
||||
private final JvmFileClassesProvider fileClassesProvider;
|
||||
private final TypeMappingConfiguration<Type> typeMappingConfiguration;
|
||||
|
||||
public CodegenAnnotatingVisitor(@NotNull GenerationState state) {
|
||||
this.bindingTrace = state.getBindingTrace();
|
||||
@@ -88,6 +90,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
this.filter = state.getGenerateDeclaredClassFilter();
|
||||
this.runtimeTypes = state.getJvmRuntimeTypes();
|
||||
this.fileClassesProvider = state.getFileClassesProvider();
|
||||
this.typeMappingConfiguration = state.getTypeMapper().getTypeMappingConfiguration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -232,8 +235,12 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
private String getName(ClassDescriptor classDescriptor) {
|
||||
String base = peekFromStack(nameStack);
|
||||
Name descriptorName = safeIdentifier(classDescriptor.getName());
|
||||
return DescriptorUtils.isTopLevelDeclaration(classDescriptor) ? base.isEmpty() ? descriptorName
|
||||
.asString() : base + '/' + descriptorName : base + '$' + descriptorName;
|
||||
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
|
||||
return base.isEmpty() ? descriptorName.asString() : base + '/' + descriptorName;
|
||||
}
|
||||
else {
|
||||
return typeMappingConfiguration.getInnerClassNameFactory().invoke(base, descriptorName.asString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -325,7 +325,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
assert callableDescriptor instanceof DeserializedCallableMemberDescriptor : "Not a deserialized function or proper: " + callableDescriptor;
|
||||
|
||||
KotlinTypeMapper.ContainingClassesInfo containingClasses =
|
||||
KotlinTypeMapper.getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) callableDescriptor);
|
||||
state.getTypeMapper().getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) callableDescriptor);
|
||||
|
||||
final ClassId containerId = containingClasses.getImplClassId();
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
|
||||
import kotlin.Pair;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -103,12 +104,32 @@ public class KotlinTypeMapper {
|
||||
private final boolean isJvm8Target;
|
||||
|
||||
private final TypeMappingConfiguration<Type> typeMappingConfiguration = new TypeMappingConfiguration<Type>() {
|
||||
private final Function2<String, String, String> defaultClassNameFactory
|
||||
= TypeMappingConfiguration.Companion.getDEFAULT_INNER_CLASS_NAME_FACTORY();
|
||||
|
||||
private final Function2<String, String, String> innerClassNameFactory = new Function2<String, String, String>() {
|
||||
@Override
|
||||
public String invoke(String outer, String inner) {
|
||||
if (classBuilderMode == ClassBuilderMode.KAPT3) {
|
||||
return outer + '/' + inner;
|
||||
}
|
||||
|
||||
return defaultClassNameFactory.invoke(outer, inner);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinType commonSupertype(@NotNull Collection<KotlinType> types) {
|
||||
return CommonSupertypes.commonSupertype(types);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Function2<String, String, String> getInnerClassNameFactory() {
|
||||
return innerClassNameFactory;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Type getPredefinedTypeForClass(@NotNull ClassDescriptor classDescriptor) {
|
||||
@@ -139,6 +160,11 @@ public class KotlinTypeMapper {
|
||||
this.isJvm8Target = isJvm8Target;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TypeMappingConfiguration<Type> getTypeMappingConfiguration() {
|
||||
return typeMappingConfiguration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BindingContext getBindingContext() {
|
||||
return bindingContext;
|
||||
@@ -250,7 +276,7 @@ public class KotlinTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ContainingClassesInfo getContainingClassesForDeserializedCallable(
|
||||
public ContainingClassesInfo getContainingClassesForDeserializedCallable(
|
||||
@NotNull DeserializedCallableMemberDescriptor deserializedDescriptor
|
||||
) {
|
||||
DeclarationDescriptor parentDeclaration = deserializedDescriptor.getContainingDeclaration();
|
||||
@@ -269,14 +295,16 @@ public class KotlinTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassId getContainerClassIdForClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
private 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
|
||||
return new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||
String defaultImplsClassName = typeMappingConfiguration.getInnerClassNameFactory()
|
||||
.invoke(relativeClassName.shortName().asString(), JvmAbi.DEFAULT_IMPLS_CLASS_NAME);
|
||||
return new ClassId(classId.getPackageFqName(), Name.identifier(defaultImplsClassName));
|
||||
}
|
||||
|
||||
return classId;
|
||||
@@ -437,7 +465,9 @@ public class KotlinTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public Type mapDefaultImpls(@NotNull ClassDescriptor descriptor) {
|
||||
return Type.getObjectType(mapType(descriptor).getInternalName() + JvmAbi.DEFAULT_IMPLS_SUFFIX);
|
||||
String defaultImplsClassName = typeMappingConfiguration.getInnerClassNameFactory().invoke(
|
||||
mapType(descriptor).getInternalName(), JvmAbi.DEFAULT_IMPLS_CLASS_NAME);
|
||||
return Type.getObjectType(defaultImplsClassName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user