-
Notifications
You must be signed in to change notification settings - Fork 45
/
convert.go
53 lines (45 loc) · 1.12 KB
/
convert.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
package jnigi
// Types that can covert to Go values from object reference
type ToGoConverter interface {
// Method should delete reference if it is not needed anymore
ConvertToGo(obj *ObjectRef) error
}
// ArrayRef just disables auto conversion of Java arrays to Go slices
type ArrayRef struct {
*ObjectRef
Type
}
func NewArrayRef(t Type) *ArrayRef {
a := &ArrayRef{nil, t}
return a
}
// Just hold on to the reference to the array jobject
func (a *ArrayRef) ConvertToGo(obj *ObjectRef) error {
a.ObjectRef = obj
return nil
}
func (a *ArrayRef) GetType() Type {
return a.Type
}
// Types that can convert to Java Object
type ToJavaConverter interface {
// Returned reference will be deleted
ConvertToJava() (*ObjectRef, error)
}
// Type used to represent arg that has been converted using ConvertToJava
type convertedArg struct {
*ObjectRef
}
func replaceConvertedArgs(args []interface{}) (err error) {
for i, arg := range args {
if v, ok := arg.(ToJavaConverter); ok {
var convArg convertedArg
convArg.ObjectRef, err = v.ConvertToJava()
if err != nil {
break
}
args[i] = &convArg
}
}
return err
}