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