summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/bytecode/MethodParameterWriter.java')
-rw-r--r--src/cuchaz/enigma/bytecode/MethodParameterWriter.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
new file mode 100644
index 0000000..0bdf47a
--- /dev/null
+++ b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
@@ -0,0 +1,70 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.bytecode;
12
13import java.util.ArrayList;
14import java.util.List;
15
16import javassist.CtBehavior;
17import javassist.CtClass;
18import javassist.bytecode.CodeAttribute;
19import javassist.bytecode.LocalVariableAttribute;
20import cuchaz.enigma.mapping.ArgumentEntry;
21import cuchaz.enigma.mapping.BehaviorEntry;
22import cuchaz.enigma.mapping.EntryFactory;
23import cuchaz.enigma.mapping.Signature;
24import cuchaz.enigma.mapping.Translator;
25
26public class MethodParameterWriter {
27
28 private Translator m_translator;
29
30 public MethodParameterWriter(Translator translator) {
31 m_translator = translator;
32 }
33
34 public void writeMethodArguments(CtClass c) {
35
36 // Procyon will read method arguments from the "MethodParameters" attribute, so write those
37 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
38
39 // if there's a local variable table here, don't write a MethodParameters attribute
40 // let the local variable writer deal with it instead
41 // procyon starts doing really weird things if we give it both attributes
42 CodeAttribute codeAttribute = behavior.getMethodInfo().getCodeAttribute();
43 if (codeAttribute != null && codeAttribute.getAttribute(LocalVariableAttribute.tag) != null) {
44 continue;
45 }
46
47 BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior);
48
49 // get the number of arguments
50 Signature signature = behaviorEntry.getSignature();
51 if (signature == null) {
52 // static initializers have no signatures, or arguments
53 continue;
54 }
55 int numParams = signature.getArgumentTypes().size();
56 if (numParams <= 0) {
57 continue;
58 }
59
60 // get the list of argument names
61 List<String> names = new ArrayList<String>(numParams);
62 for (int i = 0; i < numParams; i++) {
63 names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, "")));
64 }
65
66 // save the mappings to the class
67 MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names);
68 }
69 }
70}