From 93b2c6d59bd82283cf2f7221e02481ba2fd7f5c2 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Apr 2017 19:58:55 +0300 Subject: [PATCH] fixed lambda parameter names already used in the context # Conflicts: # src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java # src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java # src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java # test/org/jetbrains/java/decompiler/SingleClassesTest.java --- .../main/collectors/VarNamesCollector.java | 3 ++- .../main/rels/NestedClassProcessor.java | 20 ++++++++++--------- .../modules/decompiler/vars/VarProcessor.java | 4 ++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java b/src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java index dfde971..8d9d5c0 100644 --- a/src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java +++ b/src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java @@ -15,6 +15,7 @@ */ package org.jetbrains.java.decompiler.main.collectors; +import java.util.Collection; import java.util.HashSet; public class VarNamesCollector { @@ -24,7 +25,7 @@ public class VarNamesCollector { public VarNamesCollector() { } - public VarNamesCollector(HashSet setNames) { + public VarNamesCollector(Collection setNames) { usedNames.addAll(setNames); } diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java index 6e40fcb..c4a4ff5 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java @@ -44,6 +44,7 @@ import org.jetbrains.java.decompiler.util.InterpreterUtil; import java.util.*; import java.util.Map.Entry; +import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; public class NestedClassProcessor { @@ -277,6 +278,7 @@ public class NestedClassProcessor { if (expr.type == Exprent.EXPRENT_NEW) { NewExprent new_expr = (NewExprent)expr; + VarNamesCollector enclosingCollector = new VarNamesCollector(encmeth.varproc.getVarNames()); if (new_expr.isLambda() && lambda_class_type.equals(new_expr.getNewtype())) { InvocationExprent inv_dynamic = new_expr.getConstructor(); @@ -284,16 +286,16 @@ public class NestedClassProcessor { int param_index = is_static_lambda_content ? 0 : 1; int varindex = is_static_lambda_content ? 0 : 1; - for (int i = 0; i < vars_count; ++i) { + for (int i = 0; i < md_content.params.length; ++i) { + VarVersionPaar varVersion = new VarVersionPaar(varindex, 0, ExprProcessor.getCastTypeName(md_content.params[i].copy()), false); + if (i < vars_count) { + Exprent param = inv_dynamic.getLstParameters().get(param_index + i); - Exprent param = inv_dynamic.getLstParameters().get(param_index + i); - - if (param.type == Exprent.EXPRENT_VAR) { - VarVersionPaar enc_varpaar = new VarVersionPaar((VarExprent)param); - String enc_varname = encmeth.varproc.getVarName(enc_varpaar); - - //meth.varproc.setVarName(new VarVersionPaar(varindex, 0), enc_varname); - mapNewNames.put(new VarVersionPaar(varindex, 0), enc_varname); + if (param.type == Exprent.EXPRENT_VAR) { + mapNewNames.put(varVersion, encmeth.varproc.getVarName(new VarVersionPaar((VarExprent) param))); + } + } else { + mapNewNames.put(varVersion, enclosingCollector.getFreeName(meth.varproc.getVarName(varVersion))); } varindex += md_content.params[i].stack_size; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java index 4d4dabb..18314d8 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java @@ -120,6 +120,10 @@ public class VarProcessor { mapVarNames.put(varpaar, name); } + public Collection getVarNames() { + return mapVarNames != null ? mapVarNames.values() : Collections.EMPTY_SET; + } + public int getVarFinal(VarVersionPaar varpaar) { return varvers == null ? VarTypeProcessor.VAR_FINAL : varvers.getVarFinal(varpaar); }