diff options
| author | 2015-05-21 23:30:00 +0100 | |
|---|---|---|
| committer | 2015-05-21 23:30:00 +0100 | |
| commit | e3f452250e51b7271f3989c7dfd12e4422934942 (patch) | |
| tree | 5aa482f9a6e21eb318a3e23e7d8274d77c73faf6 /src/cuchaz/enigma/bytecode/MethodParameterWriter.java | |
| download | enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.gz enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.xz enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.zip | |
Support Gradle alongside SSJB
This makes builds faster, simpler and better automated but still keeps
Cuchaz happy. :)
Diffstat (limited to 'src/cuchaz/enigma/bytecode/MethodParameterWriter.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/MethodParameterWriter.java | 70 |
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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode; | ||
| 12 | |||
| 13 | import java.util.ArrayList; | ||
| 14 | import java.util.List; | ||
| 15 | |||
| 16 | import javassist.CtBehavior; | ||
| 17 | import javassist.CtClass; | ||
| 18 | import javassist.bytecode.CodeAttribute; | ||
| 19 | import javassist.bytecode.LocalVariableAttribute; | ||
| 20 | import cuchaz.enigma.mapping.ArgumentEntry; | ||
| 21 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 22 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 23 | import cuchaz.enigma.mapping.Signature; | ||
| 24 | import cuchaz.enigma.mapping.Translator; | ||
| 25 | |||
| 26 | public 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 | } | ||