diff options
| author | 2014-09-24 20:32:19 -0400 | |
|---|---|---|
| committer | 2014-09-24 20:32:19 -0400 | |
| commit | 064fe6a628f23f21eb2c8f584215f439e54cfaec (patch) | |
| tree | 733f840aca8dca170e9403de51be256b24ed00b2 /src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | |
| parent | HOW DO I WRITE SO MANY BUGS?!? (diff) | |
| download | enigma-fork-064fe6a628f23f21eb2c8f584215f439e54cfaec.tar.gz enigma-fork-064fe6a628f23f21eb2c8f584215f439e54cfaec.tar.xz enigma-fork-064fe6a628f23f21eb2c8f584215f439e54cfaec.zip | |
fixed in-jar detection for bridge-related methods
Diffstat (limited to 'src/cuchaz/enigma/mapping/BehaviorEntryFactory.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | 76 |
1 files changed, 76 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..d3cfb93 --- /dev/null +++ b/src/cuchaz/enigma/mapping/BehaviorEntryFactory.java | |||
| @@ -0,0 +1,76 @@ | |||
| 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 | |||
| 19 | public class BehaviorEntryFactory | ||
| 20 | { | ||
| 21 | public static BehaviorEntry create( String className, String name, String signature ) | ||
| 22 | { | ||
| 23 | return create( new ClassEntry( className ), name, signature ); | ||
| 24 | } | ||
| 25 | |||
| 26 | public static BehaviorEntry create( ClassEntry classEntry, String name, String signature ) | ||
| 27 | { | ||
| 28 | if( name.equals( "<init>" ) ) | ||
| 29 | { | ||
| 30 | return new ConstructorEntry( classEntry, signature ); | ||
| 31 | } | ||
| 32 | else if( name.equals( "<clinit>" ) ) | ||
| 33 | { | ||
| 34 | return new ConstructorEntry( classEntry ); | ||
| 35 | } | ||
| 36 | else | ||
| 37 | { | ||
| 38 | return new MethodEntry( classEntry, name, signature ); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | public static BehaviorEntry create( CtBehavior behavior ) | ||
| 43 | { | ||
| 44 | String className = Descriptor.toJvmName( behavior.getDeclaringClass().getName() ); | ||
| 45 | if( behavior instanceof CtMethod ) | ||
| 46 | { | ||
| 47 | return create( className, behavior.getName(), behavior.getSignature() ); | ||
| 48 | } | ||
| 49 | else if( behavior instanceof CtConstructor ) | ||
| 50 | { | ||
| 51 | CtConstructor constructor = (CtConstructor)behavior; | ||
| 52 | if( constructor.isClassInitializer() ) | ||
| 53 | { | ||
| 54 | return create( className, "<clinit>", null ); | ||
| 55 | } | ||
| 56 | else | ||
| 57 | { | ||
| 58 | return create( className, "<init>", constructor.getSignature() ); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | throw new IllegalArgumentException( "Unable to create BehaviorEntry from " + behavior ); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public static BehaviorEntry createObf( ClassEntry classEntry, MethodMapping methodMapping ) | ||
| 68 | { | ||
| 69 | return create( classEntry, methodMapping.getObfName(), methodMapping.getObfSignature() ); | ||
| 70 | } | ||
| 71 | |||
| 72 | public static BehaviorEntry createDeobf( ClassEntry classEntry, MethodMapping methodMapping ) | ||
| 73 | { | ||
| 74 | return create( classEntry, methodMapping.getDeobfName(), methodMapping.getObfSignature() ); | ||
| 75 | } | ||
| 76 | } | ||