diff options
| author | 2015-02-08 21:29:25 -0500 | |
|---|---|---|
| committer | 2015-02-08 21:29:25 -0500 | |
| commit | ed9b5cdfc648e86fd463bfa8d86b94c41671e14c (patch) | |
| tree | 2619bbc7e04dfa3b82f8dfd3b1d31f529766cd4b /src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | |
| download | enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.tar.gz enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.tar.xz enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.zip | |
switch all classes to new signature/type system
Diffstat (limited to 'src/cuchaz/enigma/mapping/BehaviorEntryFactory.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/mapping/BehaviorEntryFactory.java b/src/cuchaz/enigma/mapping/BehaviorEntryFactory.java new file mode 100644 index 0000000..61e501b --- /dev/null +++ b/src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | |||
| @@ -0,0 +1,57 @@ | |||
| 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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import javassist.CtBehavior; | ||
| 14 | import javassist.CtConstructor; | ||
| 15 | import javassist.CtMethod; | ||
| 16 | import javassist.bytecode.Descriptor; | ||
| 17 | |||
| 18 | public class BehaviorEntryFactory { | ||
| 19 | |||
| 20 | public static BehaviorEntry create(String className, String name, String signature) { | ||
| 21 | return create(new ClassEntry(className), name, signature); | ||
| 22 | } | ||
| 23 | |||
| 24 | public static BehaviorEntry create(ClassEntry classEntry, String name, String signature) { | ||
| 25 | if (name.equals("<init>")) { | ||
| 26 | return new ConstructorEntry(classEntry, new Signature(signature)); | ||
| 27 | } else if (name.equals("<clinit>")) { | ||
| 28 | return new ConstructorEntry(classEntry); | ||
| 29 | } else { | ||
| 30 | return new MethodEntry(classEntry, name, new Signature(signature)); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static BehaviorEntry create(CtBehavior behavior) { | ||
| 35 | String className = Descriptor.toJvmName(behavior.getDeclaringClass().getName()); | ||
| 36 | if (behavior instanceof CtMethod) { | ||
| 37 | return create(className, behavior.getName(), behavior.getSignature()); | ||
| 38 | } else if (behavior instanceof CtConstructor) { | ||
| 39 | CtConstructor constructor = (CtConstructor)behavior; | ||
| 40 | if (constructor.isClassInitializer()) { | ||
| 41 | return create(className, "<clinit>", null); | ||
| 42 | } else { | ||
| 43 | return create(className, "<init>", constructor.getSignature()); | ||
| 44 | } | ||
| 45 | } else { | ||
| 46 | throw new IllegalArgumentException("Unable to create BehaviorEntry from " + behavior); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | public static BehaviorEntry createObf(ClassEntry classEntry, MethodMapping methodMapping) { | ||
| 51 | return create(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature().toString()); | ||
| 52 | } | ||
| 53 | |||
| 54 | public static BehaviorEntry createDeobf(ClassEntry classEntry, MethodMapping methodMapping) { | ||
| 55 | return create(classEntry, methodMapping.getDeobfName(), methodMapping.getObfSignature().toString()); | ||
| 56 | } | ||
| 57 | } | ||