-
Notifications
You must be signed in to change notification settings - Fork 2
/
Class.go
68 lines (54 loc) · 1.83 KB
/
Class.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
package lang
import "../../../native"
import "../../../rtda"
import "../../../rtda/heap"
const jlClass = "java/lang/Class"
func init() {
native.Register(jlClass, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;", getPrimitiveClass)
native.Register(jlClass, "getName0", "()Ljava/lang/String;", getName0)
native.Register(jlClass, "desiredAssertionStatus0", "(Ljava/lang/Class;)Z", desiredAssertionStatus0)
//native.Register(jlClass, "isInterface", "()Z", isInterface)
//native.Register(jlClass, "isPrimitive", "()Z", isPrimitive)
}
// static native Class<?> getPrimitiveClass(String name);
// (Ljava/lang/String;)Ljava/lang/Class;
func getPrimitiveClass(frame *rtda.Frame) {
nameObj := frame.LocalVars().GetRef(0)
name := heap.GoString(nameObj)
loader := frame.Method().Class().Loader()
class := loader.LoadClass(name).JClass()
frame.OperandStack().PushRef(class)
}
// private native String getName0();
// ()Ljava/lang/String;
func getName0(frame *rtda.Frame) {
this := frame.LocalVars().GetThis()
class := this.Extra().(*heap.Class)
name := class.JavaName()
nameObj := heap.JString(class.Loader(), name)
frame.OperandStack().PushRef(nameObj)
}
// private static native boolean desiredAssertionStatus0(Class<?> clazz);
// (Ljava/lang/Class;)Z
func desiredAssertionStatus0(frame *rtda.Frame) {
// todo
frame.OperandStack().PushBoolean(false)
}
// public native boolean isInterface();
// ()Z
func isInterface(frame *rtda.Frame) {
vars := frame.LocalVars()
this := vars.GetThis()
class := this.Extra().(*heap.Class)
stack := frame.OperandStack()
stack.PushBoolean(class.IsInterface())
}
// public native boolean isPrimitive();
// ()Z
func isPrimitive(frame *rtda.Frame) {
vars := frame.LocalVars()
this := vars.GetThis()
class := this.Extra().(*heap.Class)
stack := frame.OperandStack()
stack.PushBoolean(class.IsPrimitive())
}