summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
diff options
context:
space:
mode:
authorGravatar Thog2017-03-08 08:17:04 +0100
committerGravatar Thog2017-03-08 08:17:04 +0100
commit6e464ea251cab63c776ece0b2a356f1498ffa294 (patch)
tree5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
parentDrop unix case style and implement hashCode when equals is overrided (diff)
downloadenigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java')
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java75
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 ******************************************************************************/
11package cuchaz.enigma.bytecode;
12 11
13import java.util.ArrayList; 12package cuchaz.enigma.bytecode;
14import java.util.List;
15 13
16import cuchaz.enigma.mapping.*; 14import cuchaz.enigma.mapping.*;
17import javassist.CtBehavior; 15import javassist.CtBehavior;
@@ -19,48 +17,51 @@ import javassist.CtClass;
19import javassist.bytecode.CodeAttribute; 17import javassist.bytecode.CodeAttribute;
20import javassist.bytecode.LocalVariableAttribute; 18import javassist.bytecode.LocalVariableAttribute;
21 19
20import java.util.ArrayList;
21import java.util.List;
22
22public class MethodParameterWriter { 23public 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}