Code clean
This commit is contained in:
@@ -270,16 +270,17 @@ public class MethodInliner {
|
||||
}
|
||||
}
|
||||
else if (isAnonymousConstructorCall(owner, name)) { //TODO add method
|
||||
assert transformationInfo != null : "<init> call not corresponds to new call" + owner + " " + name;
|
||||
//TODO add proper message
|
||||
assert transformationInfo instanceof AnonymousObjectTransformationInfo :
|
||||
"<init> call doesn't correspond to object transformation info: " + owner + "." + name + ", info " + transformationInfo;
|
||||
if (transformationInfo.shouldRegenerate(isSameModule)) {
|
||||
if (transformationInfo instanceof AnonymousObjectTransformationInfo) {
|
||||
//put additional captured parameters on stack
|
||||
for (CapturedParamDesc capturedParamDesc : ((AnonymousObjectTransformationInfo) transformationInfo).getAllRecapturedParameters()) {
|
||||
visitFieldInsn(Opcodes.GETSTATIC, capturedParamDesc.getContainingLambdaName(),
|
||||
"$$$" + capturedParamDesc.getFieldName(), capturedParamDesc.getType().getDescriptor());
|
||||
}
|
||||
super.visitMethodInsn(opcode, transformationInfo.getNewClassName(), name, ((AnonymousObjectTransformationInfo) transformationInfo).getNewConstructorDescriptor(), itf);
|
||||
//put additional captured parameters on stack
|
||||
for (CapturedParamDesc capturedParamDesc : ((AnonymousObjectTransformationInfo) transformationInfo).getAllRecapturedParameters()) {
|
||||
visitFieldInsn(Opcodes.GETSTATIC, capturedParamDesc.getContainingLambdaName(),
|
||||
"$$$" + capturedParamDesc.getFieldName(), capturedParamDesc.getType().getDescriptor());
|
||||
}
|
||||
super.visitMethodInsn(opcode, transformationInfo.getNewClassName(), name,
|
||||
((AnonymousObjectTransformationInfo) transformationInfo).getNewConstructorDescriptor(), itf);
|
||||
|
||||
//TODO: add new inner class also for other contexts
|
||||
if (inliningContext.getParent() instanceof RegeneratedClassContext) {
|
||||
|
||||
@@ -25,14 +25,13 @@ import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import java.util.*
|
||||
|
||||
abstract class ObjectTransformer<T : TransformationInfo>(@JvmField val transformationInfo: T, val state: GenerationState) {
|
||||
|
||||
abstract fun doTransform(parentRemapper: FieldRemapper): InlineResult
|
||||
|
||||
@JvmField
|
||||
val transformationResult = InlineResult.create()
|
||||
protected val transformationResult = InlineResult.create()
|
||||
|
||||
protected fun createRemappingClassBuilderViaFactory(inliningContext: InliningContext): ClassBuilder {
|
||||
val classBuilder = state.factory.newVisitor(
|
||||
@@ -89,10 +88,12 @@ class WhenMappingTransformer(
|
||||
}, ClassReader.SKIP_FRAMES)
|
||||
|
||||
assert(methodNodes.size == 1, { "When mapping ${fieldNode.owner} class should contain only one method but: " + methodNodes.joinToString { it.name } })
|
||||
val clinit = methodNodes.first()
|
||||
assert(clinit.name == "<clinit>", { "When mapping should contains only <clinit> method, but contains '${clinit.name}'" })
|
||||
|
||||
var transformedNode = cutOtherMappings(methodNodes.first())
|
||||
val result = classBuilder.visitor.visitMethod(transformedNode.access, transformedNode.name, transformedNode.desc, transformedNode.signature, transformedNode.exceptions.toTypedArray())
|
||||
transformedNode.accept(result)
|
||||
var transformedClinit = cutOtherMappings(clinit)
|
||||
val result = classBuilder.visitor.visitMethod(transformedClinit.access, transformedClinit.name, transformedClinit.desc, transformedClinit.signature, transformedClinit.exceptions.toTypedArray())
|
||||
transformedClinit.accept(result)
|
||||
|
||||
return transformationResult
|
||||
}
|
||||
@@ -107,12 +108,12 @@ class WhenMappingTransformer(
|
||||
isValues(it)
|
||||
}
|
||||
|
||||
val nextValuesOrEnd = generateSequence(myArrayAccess) { it.next }.first {
|
||||
val nextValuesAccessOrEnd = generateSequence(myArrayAccess) { it.next }.first {
|
||||
isValues(it) || it.opcode == Opcodes.RETURN
|
||||
}
|
||||
|
||||
val result = MethodNode(node.access, node.name, node.desc, node.signature, node.exceptions.toTypedArray())
|
||||
InsnSequence(myValuesAccess, nextValuesOrEnd).forEach { it.accept(result) }
|
||||
InsnSequence(myValuesAccess, nextValuesAccessOrEnd).forEach { it.accept(result) }
|
||||
result.visitInsn(Opcodes.RETURN)
|
||||
|
||||
return result
|
||||
|
||||
@@ -55,7 +55,7 @@ class WhenMappingTransformationInfo(
|
||||
}
|
||||
|
||||
override fun createTransformer(inliningContext: InliningContext, sameModule: Boolean): ObjectTransformer<*> {
|
||||
return WhenMappingTransformer(this, inliningContext);
|
||||
return WhenMappingTransformer(this, inliningContext)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user