-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava_class_def.go
126 lines (117 loc) · 2.81 KB
/
java_class_def.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package emulator
import (
"strings"
)
type javaClass struct {
JvmId uint64
JvmName string
JvmFields map[uint64]*javaField
JvmMethods map[uint64]*javaMethod
JvmIgnore bool
JvmSuper *javaClass
Class *jClass
}
func JavaClassDef() *javaClass {
return &javaClass{
JvmId: NextClassId(),
JvmFields: map[uint64]*javaField{},
JvmMethods: map[uint64]*javaMethod{},
}
}
func (jcd *javaClass) GetJniDescription() string {
return jcd.JvmName
}
func (jcd *javaClass) GetJvmId() uint64 {
return jcd.JvmId
}
func (jcd *javaClass) GetJvmName() string {
return jcd.JvmName
}
func (jcd *javaClass) SetJvmSuper(cls *javaClass) {
jcd.JvmSuper = cls
}
func (jcd *javaClass) SetJvmName(s string) {
jcd.JvmName = s
}
func (jcd *javaClass) GetMethodByName() {
}
func (jcd *javaClass) GetJvmIgnore() bool {
return jcd.JvmIgnore
}
func (jcd *javaClass) GetJvmSuper() *javaClass {
return jcd.JvmSuper
}
//
func (jcd *javaClass) AddField(jf *javaField) {
jcd.JvmFields[jf.JvmId] = jf
}
func (jcd *javaClass) AddMethod(jm *javaMethod) {
jcd.JvmMethods[jm.JvmId] = jm
}
//
func (jcd *javaClass) FindMethod(name, signature string) *javaMethod {
for _, met := range jcd.JvmMethods {
if met.Name == name && met.Signature == signature {
return met
}
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindMethod(name, signature)
}
return nil
}
//用于支持java反射,java反射签名都没有返回值
//@param signature_no_ret something like (ILjava/lang/String;) 注意,没有返回值
func (jcd *javaClass) FindMethodSigWithNoRet(name, signature string) *javaMethod {
for _, met := range jcd.JvmMethods {
if met.Name == name && strings.HasPrefix(met.Signature, signature) {
return met
}
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindMethodSigWithNoRet(name, signature)
}
return nil
}
//
func (jcd *javaClass) FindMethodById(jvmId uint64) *javaMethod {
if met, exist := jcd.JvmMethods[jvmId]; exist {
return met
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindMethodById(jvmId)
}
return nil
}
//
func (jcd *javaClass) FindField(name, signature string, isStatic bool) *javaField {
for _, field := range jcd.JvmFields {
if field.Name == name && field.signature == signature && field.isStatic == isStatic {
return field
}
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindField(name, signature, isStatic)
}
return nil
}
func (jcd *javaClass) FindFieldById(jvmId uint64) *javaField {
if field, exist := jcd.JvmFields[jvmId]; exist {
return field
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindFieldById(jvmId)
}
return nil
}
func (jcd *javaClass) FindFieldByNameOnly(name string) *javaField {
for _, field := range jcd.JvmFields {
if field.Name == name {
return field
}
}
if jcd.JvmSuper != nil {
return jcd.JvmSuper.FindFieldByNameOnly(name)
}
return nil
}