diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java index 28ad04a..d63572e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java | |||
| @@ -8,10 +8,8 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.bytecode; | ||
| 12 | 11 | ||
| 13 | import java.util.ArrayList; | 12 | package cuchaz.enigma.bytecode; |
| 14 | import java.util.List; | ||
| 15 | 13 | ||
| 16 | import cuchaz.enigma.mapping.*; | 14 | import cuchaz.enigma.mapping.*; |
| 17 | import javassist.CtBehavior; | 15 | import javassist.CtBehavior; |
| @@ -19,48 +17,51 @@ import javassist.CtClass; | |||
| 19 | import javassist.bytecode.CodeAttribute; | 17 | import javassist.bytecode.CodeAttribute; |
| 20 | import javassist.bytecode.LocalVariableAttribute; | 18 | import javassist.bytecode.LocalVariableAttribute; |
| 21 | 19 | ||
| 20 | import java.util.ArrayList; | ||
| 21 | import java.util.List; | ||
| 22 | |||
| 22 | public class MethodParameterWriter { | 23 | public class MethodParameterWriter { |
| 23 | 24 | ||
| 24 | private Translator translator; | 25 | private Translator translator; |
| 25 | 26 | ||
| 26 | public MethodParameterWriter(Translator translator) { | 27 | public MethodParameterWriter(Translator translator) { |
| 27 | this.translator = translator; | 28 | this.translator = translator; |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | public void writeMethodArguments(CtClass c) { | 31 | public void writeMethodArguments(CtClass c) { |
| 31 | 32 | ||
| 32 | // Procyon will read method arguments from the "MethodParameters" attribute, so write those | 33 | // Procyon will read method arguments from the "MethodParameters" attribute, so write those |
| 33 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 34 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 34 | 35 | ||
| 35 | // if there's a local variable table here, don't write a MethodParameters attribute | 36 | // if there's a local variable table here, don't write a MethodParameters attribute |
| 36 | // let the local variable writer deal with it instead | 37 | // let the local variable writer deal with it instead |
| 37 | // procyon starts doing really weird things if we give it both attributes | 38 | // procyon starts doing really weird things if we give it both attributes |
| 38 | CodeAttribute codeAttribute = behavior.getMethodInfo().getCodeAttribute(); | 39 | CodeAttribute codeAttribute = behavior.getMethodInfo().getCodeAttribute(); |
| 39 | if (codeAttribute != null && codeAttribute.getAttribute(LocalVariableAttribute.tag) != null) { | 40 | if (codeAttribute != null && codeAttribute.getAttribute(LocalVariableAttribute.tag) != null) { |
| 40 | continue; | 41 | continue; |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); | 44 | BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); |
| 44 | 45 | ||
| 45 | // get the number of arguments | 46 | // get the number of arguments |
| 46 | Signature signature = behaviorEntry.getSignature(); | 47 | Signature signature = behaviorEntry.getSignature(); |
| 47 | if (signature == null) { | 48 | if (signature == null) { |
| 48 | // static initializers have no signatures, or arguments | 49 | // static initializers have no signatures, or arguments |
| 49 | continue; | 50 | continue; |
| 50 | } | 51 | } |
| 51 | int numParams = signature.getArgumentTypes().size(); | 52 | int numParams = signature.getArgumentTypes().size(); |
| 52 | if (numParams <= 0) { | 53 | if (numParams <= 0) { |
| 53 | continue; | 54 | continue; |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | // get the list of argument names | 57 | // get the list of argument names |
| 57 | List<String> names = new ArrayList<>(numParams); | 58 | List<String> names = new ArrayList<>(numParams); |
| 58 | for (int i = 0; i < numParams; i++) { | 59 | for (int i = 0; i < numParams; i++) { |
| 59 | names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); | 60 | names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | // save the mappings to the class | 63 | // save the mappings to the class |
| 63 | MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names); | 64 | MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names); |
| 64 | } | 65 | } |
| 65 | } | 66 | } |
| 66 | } | 67 | } |