Minor, extract methods in TImpl codegen
This commit is contained in:
@@ -1364,27 +1364,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
int flags = ACC_PUBLIC; // TODO.
|
int flags = ACC_PUBLIC; // TODO.
|
||||||
|
|
||||||
Method function;
|
TraitImplDelegateInfo delegateInfo = getTraitImplDelegateInfo(fun);
|
||||||
Method functionOriginal;
|
Method function = delegateInfo.delegate;
|
||||||
if (fun instanceof PropertyAccessorDescriptor) {
|
Method functionOriginal = delegateInfo.original;
|
||||||
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
|
||||||
PropertyDescriptor original = property.getOriginal();
|
|
||||||
if (fun instanceof PropertyGetterDescriptor) {
|
|
||||||
function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
|
||||||
functionOriginal = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
|
||||||
}
|
|
||||||
else if (fun instanceof PropertySetterDescriptor) {
|
|
||||||
function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
|
||||||
functionOriginal = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it? " + fun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
function = typeMapper.mapSignature(fun.getName(), fun).getAsmMethod();
|
|
||||||
functionOriginal = typeMapper.mapSignature(fun.getName(), fun.getOriginal()).getAsmMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
MethodVisitor mv = v.newMethod(myClass, flags, function.getName(), function.getDescriptor(), null, null);
|
||||||
AnnotationCodegen.forMethod(mv, state.getTypeMapper()).genAnnotations(fun);
|
AnnotationCodegen.forMethod(mv, state.getTypeMapper()).genAnnotations(fun);
|
||||||
@@ -1396,20 +1378,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
isCallInsideSameModuleAsDeclared(inheritedFun, context),
|
isCallInsideSameModuleAsDeclared(inheritedFun, context),
|
||||||
OwnerKind.IMPLEMENTATION).getSignature();
|
OwnerKind.IMPLEMENTATION).getSignature();
|
||||||
|
|
||||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
writeAnnotationForDelegateToTraitImpl(fun, inheritedFun, mv, jvmSignature);
|
||||||
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
|
||||||
if (fun instanceof PropertyAccessorDescriptor) {
|
|
||||||
kotlinFlags |= JvmStdlibNames.FLAG_PROPERTY_BIT;
|
|
||||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
|
||||||
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
|
||||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
|
||||||
}
|
|
||||||
kotlinFlags |= DescriptorKindUtils.kindToFlags(inheritedFun.getKind());
|
|
||||||
aw.writeFlags(kotlinFlags);
|
|
||||||
aw.visitEnd();
|
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
genStubCode(mv);
|
genStubCode(mv);
|
||||||
@@ -1446,6 +1415,66 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
FunctionCodegen.generateBridgeIfNeeded(context, state, v, function, fun);
|
FunctionCodegen.generateBridgeIfNeeded(context, state, v, function, fun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class TraitImplDelegateInfo {
|
||||||
|
private final Method delegate;
|
||||||
|
private final Method original;
|
||||||
|
|
||||||
|
private TraitImplDelegateInfo(@NotNull Method delegate, @NotNull Method original) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.original = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private TraitImplDelegateInfo getTraitImplDelegateInfo(@NotNull FunctionDescriptor fun) {
|
||||||
|
if (fun instanceof PropertyAccessorDescriptor) {
|
||||||
|
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
||||||
|
PropertyDescriptor original = property.getOriginal();
|
||||||
|
if (fun instanceof PropertyGetterDescriptor) {
|
||||||
|
JvmPropertyAccessorSignature function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||||
|
JvmPropertyAccessorSignature functionOriginal = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||||
|
return new TraitImplDelegateInfo(
|
||||||
|
function.getJvmMethodSignature().getAsmMethod(), functionOriginal.getJvmMethodSignature().getAsmMethod());
|
||||||
|
}
|
||||||
|
else if (fun instanceof PropertySetterDescriptor) {
|
||||||
|
JvmPropertyAccessorSignature function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION);
|
||||||
|
JvmPropertyAccessorSignature functionOriginal = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||||
|
return new TraitImplDelegateInfo(
|
||||||
|
function.getJvmMethodSignature().getAsmMethod(), functionOriginal.getJvmMethodSignature().getAsmMethod());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it? " + fun);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Method function = typeMapper.mapSignature(fun.getName(), fun).getAsmMethod();
|
||||||
|
Method functionOriginal = typeMapper.mapSignature(fun.getName(), fun.getOriginal()).getAsmMethod();
|
||||||
|
return new TraitImplDelegateInfo(function, functionOriginal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeAnnotationForDelegateToTraitImpl(
|
||||||
|
@NotNull FunctionDescriptor fun,
|
||||||
|
@NotNull FunctionDescriptor inheritedFun,
|
||||||
|
@NotNull MethodVisitor mv,
|
||||||
|
@NotNull JvmMethodSignature jvmSignature
|
||||||
|
) {
|
||||||
|
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||||
|
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
||||||
|
if (fun instanceof PropertyAccessorDescriptor) {
|
||||||
|
kotlinFlags |= JvmStdlibNames.FLAG_PROPERTY_BIT;
|
||||||
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
|
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||||
|
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||||
|
}
|
||||||
|
kotlinFlags |= DescriptorKindUtils.kindToFlags(inheritedFun.getKind());
|
||||||
|
aw.writeFlags(kotlinFlags);
|
||||||
|
aw.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
private void generateDelegatorToConstructorCall(
|
private void generateDelegatorToConstructorCall(
|
||||||
InstructionAdapter iv, ExpressionCodegen codegen,
|
InstructionAdapter iv, ExpressionCodegen codegen,
|
||||||
ConstructorDescriptor constructorDescriptor,
|
ConstructorDescriptor constructorDescriptor,
|
||||||
|
|||||||
Reference in New Issue
Block a user