Object transformation: store captured field before super constructor call
This commit is contained in:
+11
-18
@@ -199,7 +199,7 @@ public class AnonymousObjectTransformer {
|
|||||||
List<Type> descTypes = new ArrayList<Type>();
|
List<Type> descTypes = new ArrayList<Type>();
|
||||||
|
|
||||||
Parameters constructorParams = constructorInlineBuilder.buildParameters();
|
Parameters constructorParams = constructorInlineBuilder.buildParameters();
|
||||||
final int [] capturedIndexes = new int [constructorParams.totalSize()];
|
int [] capturedIndexes = new int [constructorParams.totalSize()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ public class AnonymousObjectTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Pair<String, Type>> capturedFieldsToGenerate = new ArrayList<Pair<String, Type>>();
|
List<Pair<String, Type>> capturedFieldsToGenerate = new ArrayList<Pair<String, Type>>();
|
||||||
for (CapturedParamInfo capturedParamInfo : allCapturedBuilder.listCaptured()) {
|
for (CapturedParamInfo capturedParamInfo : allCapturedBuilder.listCaptured()) {
|
||||||
if (capturedParamInfo.getLambda() == null) { //not inlined
|
if (capturedParamInfo.getLambda() == null) { //not inlined
|
||||||
capturedFieldsToGenerate.add(new Pair<String, Type>(capturedParamInfo.getNewFieldName(), capturedParamInfo.getType()));
|
capturedFieldsToGenerate.add(new Pair<String, Type>(capturedParamInfo.getNewFieldName(), capturedParamInfo.getType()));
|
||||||
@@ -232,23 +232,16 @@ public class AnonymousObjectTransformer {
|
|||||||
"<init>", constructorDescriptor,
|
"<init>", constructorDescriptor,
|
||||||
null, ArrayUtil.EMPTY_STRING_ARRAY);
|
null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||||
|
|
||||||
MethodVisitor capturedFieldInitializer = new InstructionAdapter(InlineCodegenUtil.API, constructorVisitor) {
|
//initialize captured fields
|
||||||
private boolean superCallProcessed;
|
List<FieldInfo> fields = AsmUtil.transformCapturedParams(capturedFieldsToGenerate, newLambdaType);
|
||||||
@Override
|
int paramIndex = 0;
|
||||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
InstructionAdapter capturedFieldInitializer = new InstructionAdapter(constructorVisitor);
|
||||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
for (FieldInfo fieldInfo : fields) {
|
||||||
if (!superCallProcessed && "<init>".equals(name)) {
|
AsmUtil.genAssignInstanceFieldFromParam(fieldInfo, capturedIndexes[paramIndex], capturedFieldInitializer);
|
||||||
superCallProcessed = true;
|
paramIndex++;
|
||||||
List<FieldInfo> fields = AsmUtil.transformCapturedParams(capturedFieldsToGenerate, newLambdaType);
|
}
|
||||||
int paramIndex = 0;
|
|
||||||
for (FieldInfo fieldInfo : fields) {
|
|
||||||
AsmUtil.genAssignInstanceFieldFromParam(fieldInfo, capturedIndexes[paramIndex], this);
|
|
||||||
paramIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
//then transform constructor
|
||||||
Parameters constructorParameters = constructorInlineBuilder.buildParameters();
|
Parameters constructorParameters = constructorInlineBuilder.buildParameters();
|
||||||
|
|
||||||
RegeneratedLambdaFieldRemapper remapper =
|
RegeneratedLambdaFieldRemapper remapper =
|
||||||
|
|||||||
Reference in New Issue
Block a user