blob: b011e0bea74878a20f6bd9439d8558550b8ef0de (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package cuchaz.enigma.mapping;
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtField;
import javassist.CtMethod;
import javassist.bytecode.Descriptor;
import cuchaz.enigma.mapping.BehaviorEntry;
import cuchaz.enigma.mapping.ClassEntry;
import cuchaz.enigma.mapping.ConstructorEntry;
import cuchaz.enigma.mapping.FieldEntry;
import cuchaz.enigma.mapping.MethodEntry;
public class JavassistUtil {
public static ClassEntry getClassEntry(CtClass c) {
return new ClassEntry(Descriptor.toJvmName(c.getName()));
}
public static ClassEntry getSuperclassEntry(CtClass c) {
return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass()));
}
public static MethodEntry getMethodEntry(CtMethod method) {
return new MethodEntry(
getClassEntry(method.getDeclaringClass()),
method.getName(),
method.getMethodInfo().getDescriptor()
);
}
public static ConstructorEntry getConstructorEntry(CtConstructor constructor) {
return new ConstructorEntry(
getClassEntry(constructor.getDeclaringClass()),
constructor.getMethodInfo().getDescriptor()
);
}
public static BehaviorEntry getBehaviorEntry(CtBehavior behavior) {
if (behavior instanceof CtMethod) {
return getMethodEntry((CtMethod)behavior);
} else if (behavior instanceof CtConstructor) {
return getConstructorEntry((CtConstructor)behavior);
}
throw new Error("behavior is neither Method nor Constructor!");
}
public static FieldEntry getFieldEntry(CtField field) {
return new FieldEntry(
getClassEntry(field.getDeclaringClass()),
field.getName()
);
}
}
|