diff options
| author | 2016-10-19 02:35:51 +0200 | |
|---|---|---|
| committer | 2016-10-19 02:35:51 +0200 | |
| commit | f32bae39be570e3363971947dcd79e2809de851b (patch) | |
| tree | ac843b82d117f738b0865823be70f565bb56d6ef | |
| parent | Fix #48 (diff) | |
| download | enigma-f32bae39be570e3363971947dcd79e2809de851b.tar.gz enigma-f32bae39be570e3363971947dcd79e2809de851b.tar.xz enigma-f32bae39be570e3363971947dcd79e2809de851b.zip | |
LocalVariableRenamer: Support correctly Nested Class constructors (Fix #49)
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java | 18 |
1 files changed, 17 insertions, 1 deletions
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 { | |||
| 76 | int numArgs = 0; | 76 | int numArgs = 0; |
| 77 | if (behaviorEntry.getSignature() != null) { | 77 | if (behaviorEntry.getSignature() != null) { |
| 78 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); | 78 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); |
| 79 | |||
| 80 | boolean isNestedClassConstructor = false; | ||
| 81 | |||
| 82 | // If the behavior is a constructor and if it have more than one arg, it's probably from a nested! | ||
| 83 | if (behaviorEntry instanceof ConstructorEntry && behaviorEntry.getClassEntry() != null && behaviorEntry.getClassEntry().isInnerClass() && numArgs >= 1) | ||
| 84 | { | ||
| 85 | // Get the first arg type | ||
| 86 | Type firstArg = behaviorEntry.getSignature().getArgumentTypes().get(0); | ||
| 87 | |||
| 88 | // 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 | ||
| 89 | if (firstArg.isClass() && firstArg.getClassEntry().equals(behaviorEntry.getClassEntry().getOuterClassEntry())) { | ||
| 90 | isNestedClassConstructor = true; | ||
| 91 | numArgs--; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 79 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { | 95 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { |
| 80 | int argi = i - starti; | 96 | int argi = i - starti; |
| 81 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); | 97 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); |
| 82 | if (argName == null) { | 98 | if (argName == null) { |
| 83 | Type argType = behaviorEntry.getSignature().getArgumentTypes().get(argi); | 99 | Type argType = behaviorEntry.getSignature().getArgumentTypes().get(isNestedClassConstructor ? argi + 1 : argi); |
| 84 | // Unfortunately each of these have different name getters, so they have different code paths | 100 | // Unfortunately each of these have different name getters, so they have different code paths |
| 85 | if (argType.isPrimitive()) { | 101 | if (argType.isPrimitive()) { |
| 86 | Type.Primitive argCls = argType.getPrimitive(); | 102 | Type.Primitive argCls = argType.getPrimitive(); |