mirror of
https://github.com/moparisthebest/fernflower
synced 2024-11-26 19:22:15 -05:00
resolving naming conflicts with local variables used in lambda
expressions
This commit is contained in:
parent
bd99d3eb2f
commit
988a7b935a
@ -137,7 +137,9 @@ public class ClassWriter {
|
||||
// lambda method
|
||||
StructMethod mt = cl.getMethod(node.lambda_information.content_method_key);
|
||||
MethodWrapper meth = wrapper.getMethodWrapper(mt.getName(), mt.getDescriptor());
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(node.lambda_information.method_descriptor);
|
||||
|
||||
MethodDescriptor md_content = MethodDescriptor.parseDescriptor(node.lambda_information.content_method_descriptor);
|
||||
MethodDescriptor md_lambda = MethodDescriptor.parseDescriptor(node.lambda_information.method_descriptor);
|
||||
|
||||
if(!lambda_to_anonymous) { // lambda parameters '() ->'
|
||||
|
||||
@ -146,18 +148,23 @@ public class ClassWriter {
|
||||
boolean firstpar = true;
|
||||
int index = 1;
|
||||
|
||||
for(int i=0;i<md.params.length;i++) {
|
||||
int start_index = md_content.params.length - md_lambda.params.length;
|
||||
|
||||
for(int i=0;i<md_content.params.length;i++) {
|
||||
|
||||
if(!firstpar) {
|
||||
buff.append(", ");
|
||||
if(i >= start_index) {
|
||||
|
||||
if(!firstpar) {
|
||||
buff.append(", ");
|
||||
}
|
||||
|
||||
String parname = meth.varproc.getVarName(new VarVersionPaar(index, 0));
|
||||
buff.append(parname==null ? "param"+index : parname); // null iff decompiled with errors
|
||||
|
||||
firstpar = false;
|
||||
}
|
||||
|
||||
String parname = meth.varproc.getVarName(new VarVersionPaar(index, 0));
|
||||
buff.append(parname==null ? "param"+index : parname); // null iff decompiled with errors
|
||||
|
||||
firstpar = false;
|
||||
|
||||
index+=md.params[i].stack_size;
|
||||
index+=md_content.params[i].stack_size;
|
||||
}
|
||||
buff.append(") ->");
|
||||
|
||||
@ -588,7 +595,8 @@ public class ClassWriter {
|
||||
String indstr = InterpreterUtil.getIndentString(indent);
|
||||
|
||||
String method_name = node_lambda.lambda_information.method_name;
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(node_lambda.lambda_information.method_descriptor);
|
||||
MethodDescriptor md_content = MethodDescriptor.parseDescriptor(node_lambda.lambda_information.content_method_descriptor);
|
||||
MethodDescriptor md_lambda = MethodDescriptor.parseDescriptor(node_lambda.lambda_information.method_descriptor);
|
||||
|
||||
StringWriter strwriter = new StringWriter();
|
||||
BufferedWriter bufstrwriter = new BufferedWriter(strwriter);
|
||||
@ -602,28 +610,33 @@ public class ClassWriter {
|
||||
boolean firstpar = true;
|
||||
int index = 1;
|
||||
|
||||
for(int i=0;i<md.params.length;i++) {
|
||||
int start_index = md_content.params.length - md_lambda.params.length;
|
||||
|
||||
for(int i=0;i<md_content.params.length;i++) {
|
||||
|
||||
if(i >= start_index) {
|
||||
|
||||
if(!firstpar) {
|
||||
bufstrwriter.write(", ");
|
||||
}
|
||||
|
||||
if(!firstpar) {
|
||||
bufstrwriter.write(", ");
|
||||
VarType partype = md_content.params[i].copy();
|
||||
|
||||
String strpartype = ExprProcessor.getCastTypeName(partype);
|
||||
if(ExprProcessor.UNDEFINED_TYPE_STRING.equals(strpartype) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
|
||||
strpartype = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
|
||||
}
|
||||
|
||||
bufstrwriter.write(strpartype);
|
||||
bufstrwriter.write(" ");
|
||||
|
||||
String parname = meth.varproc.getVarName(new VarVersionPaar(index, 0));
|
||||
bufstrwriter.write(parname==null?"param"+index:parname); // null iff decompiled with errors
|
||||
|
||||
firstpar = false;
|
||||
}
|
||||
|
||||
VarType partype = md.params[i].copy();
|
||||
|
||||
String strpartype = ExprProcessor.getCastTypeName(partype);
|
||||
if(ExprProcessor.UNDEFINED_TYPE_STRING.equals(strpartype) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
|
||||
strpartype = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT);
|
||||
}
|
||||
|
||||
bufstrwriter.write(strpartype);
|
||||
bufstrwriter.write(" ");
|
||||
|
||||
String parname = meth.varproc.getVarName(new VarVersionPaar(index, 0));
|
||||
bufstrwriter.write(parname==null?"param"+index:parname); // null iff decompiled with errors
|
||||
|
||||
firstpar = false;
|
||||
|
||||
index+=md.params[i].stack_size;
|
||||
index+=md_content.params[i].stack_size;
|
||||
}
|
||||
|
||||
bufstrwriter.write(")");
|
||||
|
@ -120,19 +120,22 @@ public class NestedClassProcessor {
|
||||
|
||||
final boolean is_static_lambda_content = child.lambda_information.is_content_method_static;
|
||||
|
||||
if(!is_static_lambda_content) { // this pointer
|
||||
if(DecompilerContext.getOption(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS)) {
|
||||
//meth.varproc.getThisvars().put(newvar, parent.classStruct.qualifiedName);
|
||||
}
|
||||
}
|
||||
|
||||
final String parent_class_name = parent.wrapper.getClassStruct().qualifiedName;
|
||||
final String lambda_class_name = child.simpleName;
|
||||
|
||||
final VarType lambda_class_type = new VarType(lambda_class_name, true);
|
||||
|
||||
|
||||
// this pointer
|
||||
if(!is_static_lambda_content && DecompilerContext.getOption(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS)) {
|
||||
meth.varproc.getThisvars().put(new VarVersionPaar(0, 0), parent_class_name);
|
||||
meth.varproc.setVarName(new VarVersionPaar(0, 0), parent.simpleName + ".this");
|
||||
}
|
||||
|
||||
// local variables
|
||||
DirectGraph graph = encmeth.getOrBuildGraph();
|
||||
|
||||
final HashMap<VarVersionPaar, String> mapNewNames = new HashMap<VarVersionPaar, String>();
|
||||
|
||||
graph.iterateExprents(new DirectGraph.ExprentIterator() {
|
||||
public int processExprent(Exprent exprent) {
|
||||
|
||||
@ -158,7 +161,8 @@ public class NestedClassProcessor {
|
||||
VarVersionPaar enc_varpaar = new VarVersionPaar((VarExprent)param);
|
||||
String enc_varname = encmeth.varproc.getVarName(enc_varpaar);
|
||||
|
||||
meth.varproc.setVarName(new VarVersionPaar(varindex, 0), enc_varname);
|
||||
//meth.varproc.setVarName(new VarVersionPaar(varindex, 0), enc_varname);
|
||||
mapNewNames.put(new VarVersionPaar(varindex, 0), enc_varname);
|
||||
}
|
||||
|
||||
varindex+=md_content.params[i].stack_size;
|
||||
@ -171,6 +175,18 @@ public class NestedClassProcessor {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// update names of local variables
|
||||
HashSet<String> setNewOuterNames = new HashSet<String>(mapNewNames.values());
|
||||
setNewOuterNames.removeAll(meth.setOuterVarNames);
|
||||
|
||||
meth.varproc.refreshVarNames(new VarNamesCollector(setNewOuterNames));
|
||||
meth.setOuterVarNames.addAll(setNewOuterNames);
|
||||
|
||||
for(Entry<VarVersionPaar, String> entr : mapNewNames.entrySet()) {
|
||||
meth.varproc.setVarName(entr.getKey(), entr.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkNotFoundClasses(ClassNode root, ClassNode node) {
|
||||
|
Loading…
Reference in New Issue
Block a user