Use more deterministic local variable names

This commit bases local variable names on the original instruction
index, which produces much more consistent results than the variable
slot/version.
master
Graham 4 years ago
parent 964f7292a8
commit 4d46ef6312
  1. 18
      src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java

@ -139,13 +139,19 @@ public class ClassWrapper {
VarNamesCollector namesCollector = new VarNamesCollector(); VarNamesCollector namesCollector = new VarNamesCollector();
classStruct.getFields().forEach(f -> namesCollector.addName(f.getName())); classStruct.getFields().forEach(f -> namesCollector.addName(f.getName()));
int index = mt.hasModifier(CodeConstants.ACC_STATIC) ? 0 : 1;
for (int i = 0; i < md.params.length; i++) {
varProc.setVarName(new VarVersionPair(index, 0), "arg" + i);
index += md.params[i].stackSize;
}
Map<Integer, String> paramNames = new HashMap<>(); Map<Integer, String> paramNames = new HashMap<>();
if (DecompilerContext.getOption(IFernflowerPreferences.USE_METHOD_PARAMETERS)) { if (DecompilerContext.getOption(IFernflowerPreferences.USE_METHOD_PARAMETERS)) {
StructMethodParametersAttribute attr = mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS); StructMethodParametersAttribute attr = mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS);
if (attr != null) { if (attr != null) {
List<StructMethodParametersAttribute.Entry> entries = attr.getEntries(); List<StructMethodParametersAttribute.Entry> entries = attr.getEntries();
int index = mt.hasModifier(CodeConstants.ACC_STATIC) ? 0 : 1; index = mt.hasModifier(CodeConstants.ACC_STATIC) ? 0 : 1;
for (int i = 0; i < md.params.length && i < entries.size(); i++) { for (int i = 0; i < md.params.length && i < entries.size(); i++) {
String myName = entries.get(i).myName; String myName = entries.get(i).myName;
if (myName != null) { if (myName != null) {
@ -210,11 +216,13 @@ public class ClassWrapper {
} }
int pc = originalPcTable.getOriginalPc(bytecodeOffset); int pc = originalPcTable.getOriginalPc(bytecodeOffset);
if (!originalPcTable.hasName(pc)) {
continue;
}
String name = originalPcTable.getName(pc); String name;
if (originalPcTable.hasName(pc)) {
name = originalPcTable.getName(pc);
} else {
name = "local" + pc;
}
varProc.setVarName(varExpr.getVarVersionPair(), name); varProc.setVarName(varExpr.getVarVersionPair(), name);
} }

Loading…
Cancel
Save