diff options
author | Stiver <stiver.mail@gmail.com> | 2014-03-27 16:14:29 +0100 |
---|---|---|
committer | Stiver <stiver.mail@gmail.com> | 2014-03-27 16:14:29 +0100 |
commit | 988a7b935a26f05fd59b452840932f543fbb2643 (patch) | |
tree | 85f6f4159ef92e2ce3e1052688e38be17dda24dd /src/de/fernflower | |
parent | bd99d3eb2f6ba60d7d2f9c81199708ca68db837c (diff) | |
download | fernflower-988a7b935a26f05fd59b452840932f543fbb2643.tar fernflower-988a7b935a26f05fd59b452840932f543fbb2643.tar.gz fernflower-988a7b935a26f05fd59b452840932f543fbb2643.tar.lz fernflower-988a7b935a26f05fd59b452840932f543fbb2643.tar.xz fernflower-988a7b935a26f05fd59b452840932f543fbb2643.zip |
resolving naming conflicts with local variables used in lambda
expressions
Diffstat (limited to 'src/de/fernflower')
-rw-r--r-- | src/de/fernflower/main/ClassWriter.java | 71 | ||||
-rw-r--r-- | src/de/fernflower/main/rels/NestedClassProcessor.java | 32 |
2 files changed, 66 insertions, 37 deletions
diff --git a/src/de/fernflower/main/ClassWriter.java b/src/de/fernflower/main/ClassWriter.java index 7e1266a..8c79fa1 100644 --- a/src/de/fernflower/main/ClassWriter.java +++ b/src/de/fernflower/main/ClassWriter.java @@ -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(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 - if(!firstpar) { - buff.append(", "); + 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++) { - - if(!firstpar) { - bufstrwriter.write(", "); - } + int start_index = md_content.params.length - md_lambda.params.length; + + for(int i=0;i<md_content.params.length;i++) { - VarType partype = md.params[i].copy(); + if(i >= start_index) { - 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); + 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; } - - 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(")"); diff --git a/src/de/fernflower/main/rels/NestedClassProcessor.java b/src/de/fernflower/main/rels/NestedClassProcessor.java index 8358f63..751ee58 100644 --- a/src/de/fernflower/main/rels/NestedClassProcessor.java +++ b/src/de/fernflower/main/rels/NestedClassProcessor.java @@ -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) { |