summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
diff options
context:
space:
mode:
authorGravatar lclc982016-06-30 00:49:21 +1000
committerGravatar GitHub2016-06-30 00:49:21 +1000
commit4be005617b3b8c3578cca07c5d085d12916f0d1d (patch)
treedb163431f38703e26da417ef05eaea2b27a498b9 /src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
parentSome small changes to fix idea importing (diff)
downloadenigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz
enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz
enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip
Json format (#2)
* Added new format * Fixed bug * Updated Version
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java')
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
new file mode 100644
index 0000000..e53e8e7
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java
@@ -0,0 +1,66 @@
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 * <p>
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 cuchaz.enigma.mapping.*;
17import javassist.CtBehavior;
18import javassist.CtClass;
19import javassist.bytecode.CodeAttribute;
20import javassist.bytecode.LocalVariableAttribute;
21
22public class MethodParameterWriter {
23
24 private Translator m_translator;
25
26 public MethodParameterWriter(Translator translator) {
27 m_translator = translator;
28 }
29
30 public void writeMethodArguments(CtClass c) {
31
32 // Procyon will read method arguments from the "MethodParameters" attribute, so write those
33 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
34
35 // 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 // procyon starts doing really weird things if we give it both attributes
38 CodeAttribute codeAttribute = behavior.getMethodInfo().getCodeAttribute();
39 if (codeAttribute != null && codeAttribute.getAttribute(LocalVariableAttribute.tag) != null) {
40 continue;
41 }
42
43 BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior);
44
45 // get the number of arguments
46 Signature signature = behaviorEntry.getSignature();
47 if (signature == null) {
48 // static initializers have no signatures, or arguments
49 continue;
50 }
51 int numParams = signature.getArgumentTypes().size();
52 if (numParams <= 0) {
53 continue;
54 }
55
56 // get the list of argument 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}