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.java66
1 files changed, 66 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..5a11cd8
--- /dev/null
+++ b/src/cuchaz/enigma/bytecode/MethodParameterWriter.java
@@ -0,0 +1,66 @@
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 javassist.CtConstructor;
19import javassist.CtMethod;
20import javassist.bytecode.Descriptor;
21import cuchaz.enigma.mapping.ArgumentEntry;
22import cuchaz.enigma.mapping.BehaviorEntry;
23import cuchaz.enigma.mapping.ClassEntry;
24import cuchaz.enigma.mapping.ConstructorEntry;
25import cuchaz.enigma.mapping.MethodEntry;
26import cuchaz.enigma.mapping.Translator;
27
28public class MethodParameterWriter {
29
30 private Translator m_translator;
31
32 public MethodParameterWriter(Translator translator) {
33 m_translator = translator;
34 }
35
36 public void writeMethodArguments(CtClass c) {
37
38 // Procyon will read method arguments from the "MethodParameters" attribute, so write those
39 ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName()));
40 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
41 int numParams = Descriptor.numOfParameters(behavior.getMethodInfo().getDescriptor());
42 if (numParams <= 0) {
43 continue;
44 }
45
46 // get the behavior entry
47 BehaviorEntry behaviorEntry;
48 if (behavior instanceof CtMethod) {
49 behaviorEntry = new MethodEntry(classEntry, behavior.getMethodInfo().getName(), behavior.getSignature());
50 } else if (behavior instanceof CtConstructor) {
51 behaviorEntry = new ConstructorEntry(classEntry, behavior.getSignature());
52 } else {
53 throw new Error("Unsupported behavior type: " + behavior.getClass().getName());
54 }
55
56 // get the list of parameter names
57 List<String> names = new ArrayList<String>(numParams);
58 for (int i = 0; i < numParams; i++) {
59 names.add(m_translator.translate(new ArgumentEntry(behaviorEntry, i, "")));
60 }
61
62 // save the mappings to the class
63 MethodParametersAttribute.updateClass(behavior.getMethodInfo(), names);
64 }
65 }
66}