From f32bae39be570e3363971947dcd79e2809de851b Mon Sep 17 00:00:00 2001 From: Thog Date: Wed, 19 Oct 2016 02:35:51 +0200 Subject: LocalVariableRenamer: Support correctly Nested Class constructors (Fix #49) --- .../cuchaz/enigma/bytecode/LocalVariableRenamer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java index 3f4b96f9..24b5f363 100644 --- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java @@ -76,11 +76,27 @@ public class LocalVariableRenamer { int numArgs = 0; if (behaviorEntry.getSignature() != null) { numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); + + boolean isNestedClassConstructor = false; + + // If the behavior is a constructor and if it have more than one arg, it's probably from a nested! + if (behaviorEntry instanceof ConstructorEntry && behaviorEntry.getClassEntry() != null && behaviorEntry.getClassEntry().isInnerClass() && numArgs >= 1) + { + // Get the first arg type + Type firstArg = behaviorEntry.getSignature().getArgumentTypes().get(0); + + // If the arg is a class and if the class name match the outer class name of the constructor, it's definitely a constructor of a nested class + if (firstArg.isClass() && firstArg.getClassEntry().equals(behaviorEntry.getClassEntry().getOuterClassEntry())) { + isNestedClassConstructor = true; + numArgs--; + } + } + for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { int argi = i - starti; String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); if (argName == null) { - Type argType = behaviorEntry.getSignature().getArgumentTypes().get(argi); + Type argType = behaviorEntry.getSignature().getArgumentTypes().get(isNestedClassConstructor ? argi + 1 : argi); // Unfortunately each of these have different name getters, so they have different code paths if (argType.isPrimitive()) { Type.Primitive argCls = argType.getPrimitive(); -- cgit v1.2.3