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/JavassistUtil.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/JavassistUtil.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/JavassistUtil.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/mapping/JavassistUtil.java b/src/cuchaz/enigma/mapping/JavassistUtil.java new file mode 100644 index 0000000..0c446c4 --- /dev/null +++ b/src/cuchaz/enigma/mapping/JavassistUtil.java | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import javassist.CtBehavior; | ||
| 4 | import javassist.CtClass; | ||
| 5 | import javassist.CtConstructor; | ||
| 6 | import javassist.CtField; | ||
| 7 | import javassist.CtMethod; | ||
| 8 | import javassist.bytecode.Descriptor; | ||
| 9 | import javassist.expr.ConstructorCall; | ||
| 10 | import javassist.expr.FieldAccess; | ||
| 11 | import javassist.expr.MethodCall; | ||
| 12 | import javassist.expr.NewExpr; | ||
| 13 | |||
| 14 | public class JavassistUtil { | ||
| 15 | |||
| 16 | public static ClassEntry getClassEntry(CtClass c) { | ||
| 17 | return new ClassEntry(Descriptor.toJvmName(c.getName())); | ||
| 18 | } | ||
| 19 | |||
| 20 | public static ClassEntry getSuperclassEntry(CtClass c) { | ||
| 21 | return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass())); | ||
| 22 | } | ||
| 23 | |||
| 24 | public static MethodEntry getMethodEntry(CtMethod method) { | ||
| 25 | return new MethodEntry( | ||
| 26 | getClassEntry(method.getDeclaringClass()), | ||
| 27 | method.getName(), | ||
| 28 | new Signature(method.getMethodInfo().getDescriptor()) | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static MethodEntry getMethodEntry(MethodCall call) { | ||
| 33 | return new MethodEntry( | ||
| 34 | new ClassEntry(Descriptor.toJvmName(call.getClassName())), | ||
| 35 | call.getMethodName(), | ||
| 36 | new Signature(call.getSignature()) | ||
| 37 | ); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static ConstructorEntry getConstructorEntry(CtConstructor constructor) { | ||
| 41 | return new ConstructorEntry( | ||
| 42 | getClassEntry(constructor.getDeclaringClass()), | ||
| 43 | new Signature(constructor.getMethodInfo().getDescriptor()) | ||
| 44 | ); | ||
| 45 | } | ||
| 46 | |||
| 47 | public static ConstructorEntry getConstructorEntry(ConstructorCall call) { | ||
| 48 | return new ConstructorEntry( | ||
| 49 | new ClassEntry(Descriptor.toJvmName(call.getClassName())), | ||
| 50 | new Signature(call.getSignature()) | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | public static ConstructorEntry getConstructorEntry(NewExpr call) { | ||
| 55 | return new ConstructorEntry( | ||
| 56 | new ClassEntry(Descriptor.toJvmName(call.getClassName())), | ||
| 57 | new Signature(call.getSignature()) | ||
| 58 | ); | ||
| 59 | } | ||
| 60 | |||
| 61 | public static BehaviorEntry getBehaviorEntry(CtBehavior behavior) { | ||
| 62 | if (behavior instanceof CtMethod) { | ||
| 63 | return getMethodEntry((CtMethod)behavior); | ||
| 64 | } else if (behavior instanceof CtConstructor) { | ||
| 65 | return getConstructorEntry((CtConstructor)behavior); | ||
| 66 | } | ||
| 67 | throw new Error("behavior is neither Method nor Constructor!"); | ||
| 68 | } | ||
| 69 | |||
| 70 | public static FieldEntry getFieldEntry(CtField field) { | ||
| 71 | return new FieldEntry( | ||
| 72 | getClassEntry(field.getDeclaringClass()), | ||
| 73 | field.getName() | ||
| 74 | ); | ||
| 75 | } | ||
| 76 | |||
| 77 | public static FieldEntry getFieldEntry(FieldAccess call) { | ||
| 78 | return new FieldEntry( | ||
| 79 | new ClassEntry(Descriptor.toJvmName(call.getClassName())), | ||
| 80 | call.getFieldName() | ||
| 81 | ); | ||
| 82 | } | ||
| 83 | } | ||