forked from abneptis/GoJVM
/
param_reflection.go
55 lines (48 loc) · 1.38 KB
/
param_reflection.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
package gojvm
import (
"github.com/timob/gojvm/types"
// "reflect"
// "log"
)
/*
Returns the signature string for the configured environment, return type and parameters
(exported for convenience) ;
Reflection is handled by ParameterString
*/
func FormFor(ctx *Environment, ret types.Typed, params ...interface{}) (s string, err error) {
s, err = ParameterString(ctx, params...)
if err == nil {
s = s + ret.TypeString()
}
return
}
/*
Returns an array of types.Typeds matching the params list (which may be empty, resulting
in a valid empty (nil) list of types.Typeds).
Reflection is done by TypeOf.
* Environment is required in order to interpolate abstract objects into
class names.
*/
func ParameterTypes(ctx *Environment, params ...interface{}) (jtypes []types.Typed, err error) {
for _, param := range params {
var jt types.Typed
jt, err = TypeOf(ctx, param)
//log.Printf("param[%d] '%+v' %v", i, param, reflect.TypeOf(param).String())
if err != nil {
break
}
jtypes = append(jtypes, jt)
}
return
}
/* Helper function for the parameter-side only of a JavaMethodSignature.
the resultant string is () quoted by jms.ParameterString()
*/
func ParameterString(ctx *Environment, params ...interface{}) (s string, err error) {
jms := types.MethodSignature{}
jms.Params, err = ParameterTypes(ctx, params...)
if err == nil {
s = jms.ParameterString()
}
return
}