Skip to content

Commit 6876f8f

Browse files
committed
Adjust synthetic parameter identification logic to account for multiple constructors
1 parent 303ad8b commit 6876f8f

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -727,31 +727,45 @@ private static Map<String, List<VarFieldPair>> getMaskLocalVars(ClassWrapper wra
727727
StructClass cl = wrapper.getClassStruct();
728728

729729
// iterate over constructors
730-
for (StructMethod mt : cl.getMethods()) {
731-
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
732-
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
733-
MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.INIT_NAME, mt.getDescriptor());
734-
DirectGraph graph = method.getOrBuildGraph();
735-
736-
if (graph != null) { // something gone wrong, should not be null
737-
List<VarFieldPair> fields = new ArrayList<>(md.params.length);
738-
739-
int varIndex = 1;
740-
for (int i = 0; i < md.params.length; i++) { // no static methods allowed
741-
String keyField = getEnclosingVarField(cl, method, graph, varIndex, i);
742-
fields.add(keyField == null ? null : new VarFieldPair(keyField, new VarVersionPair(-1, 0))); // TODO: null?
743-
varIndex += md.params[i].stackSize;
744-
}
730+
for (int p = 0; p < 2; p++) {
731+
boolean found = false;
732+
// Do 2 passes. First pass is the "normal" pass, and try again if we find nothing that way.
733+
734+
for (StructMethod mt : cl.getMethods()) {
735+
if (CodeConstants.INIT_NAME.equals(mt.getName())) {
736+
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
737+
MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.INIT_NAME, mt.getDescriptor());
738+
DirectGraph graph = method.getOrBuildGraph();
739+
740+
if (graph != null) { // something gone wrong, should not be null
741+
List<VarFieldPair> fields = new ArrayList<>(md.params.length);
742+
743+
int varIndex = 1;
744+
for (int i = 0; i < md.params.length; i++) { // no static methods allowed
745+
// Always assume we can use the heuristic if there's only one metho
746+
String keyField = getEnclosingVarField(cl, method, graph, varIndex, i, p == 1 || cl.getMethods().size() == 1);
747+
if (!keyField.isEmpty()) {
748+
found = true;
749+
}
750+
751+
fields.add(keyField == null ? null : new VarFieldPair(keyField, new VarVersionPair(-1, 0))); // TODO: null?
752+
varIndex += md.params[i].stackSize;
753+
}
745754

746-
mapMasks.put(mt.getDescriptor(), fields);
755+
mapMasks.put(mt.getDescriptor(), fields);
756+
}
747757
}
748758
}
759+
760+
if (found) {
761+
break;
762+
}
749763
}
750764

751765
return mapMasks;
752766
}
753767

754-
private static String getEnclosingVarField(StructClass cl, MethodWrapper method, DirectGraph graph, int index, int outerIdx) {
768+
private static String getEnclosingVarField(StructClass cl, MethodWrapper method, DirectGraph graph, int index, int outerIdx, boolean useHeuristic) {
755769
String field = "";
756770

757771
// parameter variable final
@@ -811,7 +825,7 @@ private static String getEnclosingVarField(StructClass cl, MethodWrapper method,
811825

812826
String name = method.varproc.getVarName(var);
813827
VarType type = method.varproc.getVarType(var);
814-
if (hostName.equals(type.value)) {
828+
if (hostName.equals(type.value) && useHeuristic) {
815829
field = InterpreterUtil.makeUniqueKey(name, type.toString());
816830
} else {
817831
// Also check the enclosing class if it's anonymous

0 commit comments

Comments
 (0)