AnonymousObjectGeneration refactoring
This commit is contained in:
+4
-8
@@ -32,8 +32,6 @@ public class AnonymousObjectGeneration {
|
|||||||
|
|
||||||
private final Map<Integer, LambdaInfo> lambdasToInline;
|
private final Map<Integer, LambdaInfo> lambdasToInline;
|
||||||
|
|
||||||
private final boolean isSameModule;
|
|
||||||
|
|
||||||
private Type newLambdaType;
|
private Type newLambdaType;
|
||||||
|
|
||||||
private String newConstructorDescriptor;
|
private String newConstructorDescriptor;
|
||||||
@@ -50,7 +48,6 @@ public class AnonymousObjectGeneration {
|
|||||||
AnonymousObjectGeneration(
|
AnonymousObjectGeneration(
|
||||||
@NotNull String ownerInternalName,
|
@NotNull String ownerInternalName,
|
||||||
boolean needReification,
|
boolean needReification,
|
||||||
boolean isSameModule,
|
|
||||||
@NotNull Map<Integer, LambdaInfo> lambdasToInline,
|
@NotNull Map<Integer, LambdaInfo> lambdasToInline,
|
||||||
boolean capturedOuterRegenerated,
|
boolean capturedOuterRegenerated,
|
||||||
boolean alreadyRegenerated,
|
boolean alreadyRegenerated,
|
||||||
@@ -60,7 +57,6 @@ public class AnonymousObjectGeneration {
|
|||||||
this.ownerInternalName = ownerInternalName;
|
this.ownerInternalName = ownerInternalName;
|
||||||
this.constructorDesc = constructorDesc;
|
this.constructorDesc = constructorDesc;
|
||||||
this.lambdasToInline = lambdasToInline;
|
this.lambdasToInline = lambdasToInline;
|
||||||
this.isSameModule = isSameModule;
|
|
||||||
this.capturedOuterRegenerated = capturedOuterRegenerated;
|
this.capturedOuterRegenerated = capturedOuterRegenerated;
|
||||||
this.needReification = needReification;
|
this.needReification = needReification;
|
||||||
this.alreadyRegenerated = alreadyRegenerated;
|
this.alreadyRegenerated = alreadyRegenerated;
|
||||||
@@ -68,21 +64,21 @@ public class AnonymousObjectGeneration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AnonymousObjectGeneration(
|
public AnonymousObjectGeneration(
|
||||||
@NotNull String ownerInternalName, boolean isSameModule, boolean needReification,
|
@NotNull String ownerInternalName, boolean needReification,
|
||||||
boolean alreadyRegenerated,
|
boolean alreadyRegenerated,
|
||||||
boolean isStaticOrigin
|
boolean isStaticOrigin
|
||||||
) {
|
) {
|
||||||
this(
|
this(
|
||||||
ownerInternalName, needReification, isSameModule,
|
ownerInternalName, needReification,
|
||||||
new HashMap<Integer, LambdaInfo>(), false, alreadyRegenerated, null, isStaticOrigin
|
new HashMap<Integer, LambdaInfo>(), false, alreadyRegenerated, null, isStaticOrigin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwnerInternalName() {
|
public String getOldClassName() {
|
||||||
return ownerInternalName;
|
return ownerInternalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldRegenerate() {
|
public boolean shouldRegenerate(boolean isSameModule) {
|
||||||
return !alreadyRegenerated && (
|
return !alreadyRegenerated && (
|
||||||
!lambdasToInline.isEmpty() || !isSameModule || capturedOuterRegenerated || needReification
|
!lambdasToInline.isEmpty() || !isSameModule || capturedOuterRegenerated || needReification
|
||||||
);
|
);
|
||||||
|
|||||||
+3
-3
@@ -244,10 +244,10 @@ public class AnonymousObjectTransformer {
|
|||||||
inliningContext.subInline(inliningContext.nameGenerator.subGenerator("lambda")),
|
inliningContext.subInline(inliningContext.nameGenerator.subGenerator("lambda")),
|
||||||
remapper,
|
remapper,
|
||||||
isSameModule,
|
isSameModule,
|
||||||
"Transformer for " + anonymousObjectGen.getOwnerInternalName(),
|
"Transformer for " + anonymousObjectGen.getOldClassName(),
|
||||||
sourceMapper,
|
sourceMapper,
|
||||||
new InlineCallSiteInfo(
|
new InlineCallSiteInfo(
|
||||||
anonymousObjectGen.getOwnerInternalName(),
|
anonymousObjectGen.getOldClassName(),
|
||||||
sourceNode.name,
|
sourceNode.name,
|
||||||
isConstructor ? anonymousObjectGen.getNewConstructorDescriptor() : sourceNode.desc),
|
isConstructor ? anonymousObjectGen.getNewConstructorDescriptor() : sourceNode.desc),
|
||||||
null
|
null
|
||||||
@@ -390,7 +390,7 @@ public class AnonymousObjectTransformer {
|
|||||||
CapturedParamOwner owner = new CapturedParamOwner() {
|
CapturedParamOwner owner = new CapturedParamOwner() {
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.getObjectType(anonymousObjectGen.getOwnerInternalName());
|
return Type.getObjectType(anonymousObjectGen.getOldClassName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -177,9 +177,9 @@ public class MethodInliner {
|
|||||||
private void handleAnonymousObjectGeneration() {
|
private void handleAnonymousObjectGeneration() {
|
||||||
anonymousObjectGen = iterator.next();
|
anonymousObjectGen = iterator.next();
|
||||||
|
|
||||||
if (anonymousObjectGen.shouldRegenerate()) {
|
if (anonymousObjectGen.shouldRegenerate(isSameModule)) {
|
||||||
//TODO: need poping of type but what to do with local funs???
|
//TODO: need poping of type but what to do with local funs???
|
||||||
String oldClassName = anonymousObjectGen.getOwnerInternalName();
|
String oldClassName = anonymousObjectGen.getOldClassName();
|
||||||
String newClassName = inliningContext.nameGenerator.genLambdaClassName();
|
String newClassName = inliningContext.nameGenerator.genLambdaClassName();
|
||||||
remapper.addMapping(oldClassName, newClassName);
|
remapper.addMapping(oldClassName, newClassName);
|
||||||
AnonymousObjectTransformer transformer =
|
AnonymousObjectTransformer transformer =
|
||||||
@@ -272,7 +272,7 @@ public class MethodInliner {
|
|||||||
}
|
}
|
||||||
else if (isAnonymousConstructorCall(owner, name)) { //TODO add method
|
else if (isAnonymousConstructorCall(owner, name)) { //TODO add method
|
||||||
assert anonymousObjectGen != null : "<init> call not corresponds to new call" + owner + " " + name;
|
assert anonymousObjectGen != null : "<init> call not corresponds to new call" + owner + " " + name;
|
||||||
if (anonymousObjectGen.shouldRegenerate()) {
|
if (anonymousObjectGen.shouldRegenerate(isSameModule)) {
|
||||||
//put additional captured parameters on stack
|
//put additional captured parameters on stack
|
||||||
for (CapturedParamDesc capturedParamDesc : anonymousObjectGen.getAllRecapturedParameters()) {
|
for (CapturedParamDesc capturedParamDesc : anonymousObjectGen.getAllRecapturedParameters()) {
|
||||||
visitFieldInsn(Opcodes.GETSTATIC, capturedParamDesc.getContainingLambdaName(),
|
visitFieldInsn(Opcodes.GETSTATIC, capturedParamDesc.getContainingLambdaName(),
|
||||||
@@ -283,7 +283,7 @@ public class MethodInliner {
|
|||||||
|
|
||||||
//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) {
|
||||||
inliningContext.getParent().typeRemapper.addAdditionalMappings(anonymousObjectGen.getOwnerInternalName(), newInternalName);
|
inliningContext.getParent().typeRemapper.addAdditionalMappings(anonymousObjectGen.getOldClassName(), newInternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
anonymousObjectGen = null;
|
anonymousObjectGen = null;
|
||||||
@@ -502,7 +502,7 @@ public class MethodInliner {
|
|||||||
if (isAnonymousSingletonLoad(owner, fieldInsnNode.name)) {
|
if (isAnonymousSingletonLoad(owner, fieldInsnNode.name)) {
|
||||||
anonymousObjectGenerations.add(
|
anonymousObjectGenerations.add(
|
||||||
new AnonymousObjectGeneration(
|
new AnonymousObjectGeneration(
|
||||||
owner, isSameModule, awaitClassReification, isAlreadyRegenerated(owner), true
|
owner, awaitClassReification, isAlreadyRegenerated(owner), true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
awaitClassReification = false;
|
awaitClassReification = false;
|
||||||
@@ -552,15 +552,15 @@ public class MethodInliner {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private AnonymousObjectGeneration buildConstructorInvocation(
|
private AnonymousObjectGeneration buildConstructorInvocation(
|
||||||
@NotNull String owner,
|
@NotNull String anonymousType,
|
||||||
@NotNull String desc,
|
@NotNull String desc,
|
||||||
@NotNull Map<Integer, LambdaInfo> lambdaMapping,
|
@NotNull Map<Integer, LambdaInfo> lambdaMapping,
|
||||||
boolean needReification
|
boolean needReification
|
||||||
) {
|
) {
|
||||||
return new AnonymousObjectGeneration(
|
return new AnonymousObjectGeneration(
|
||||||
owner, needReification, isSameModule, lambdaMapping,
|
anonymousType, needReification, lambdaMapping,
|
||||||
inliningContext.classRegeneration,
|
inliningContext.classRegeneration,
|
||||||
isAlreadyRegenerated(owner),
|
isAlreadyRegenerated(anonymousType),
|
||||||
desc,
|
desc,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user