summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cuchaz/enigma/bytecode/MethodParameterWriter.java53
1 files changed, 53 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..5d4ca1a
--- /dev/null
+++ b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
@@ -0,0 +1,53 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.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 cuchaz.enigma.mapping.ArgumentEntry;
19import cuchaz.enigma.mapping.BehaviorEntry;
20import cuchaz.enigma.mapping.BehaviorEntryFactory;
21import cuchaz.enigma.mapping.Translator;
22
23public class MethodParameterWriter {
24
25 private Translator m_translator;
26
27 public MethodParameterWriter(Translator translator) {
28 m_translator = translator;
29 }
30
31 public void writeMethodArguments(CtClass c) {
32
33 // Procyon will read method arguments from the "MethodParameters" attribute, so write those
34 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
35 BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(behavior);
36
37 // get the number of arguments
38 int numParams = behaviorEntry.getSignature().getArgumentTypes().size();
39 if (numParams <= 0) {
40 continue;
41 }
42
43 // get the list of argument names
44 List<String> names = new ArrayList<String>(numParams);
45 for (int i = 0; i < numParams; i++) {
46 names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, "")));
47 }
48
49 // save the mappings to the class
50 MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names);
51 }
52 }
53}