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