func (j *JavaToGoSet) Convert(obj *gojvm.Object) (err error) { iter, err := obj.CallObj(j.env, false, "iterator", types.Class{types.NewName("java.util.Iterator")}) if err != nil { return } return j.JavaToGoIterator.Convert(iter) }
func RegisterNative(className string, method string, paramTypes []string, returnType string, fn interface{}) { f := func(t string) types.Typed { switch t { case "void": return types.Basic(types.VoidKind) case "int": return types.Basic(types.IntKind) case "long": return types.Basic(types.LongKind) case "float": return types.Basic(types.FloatKind) case "double": return types.Basic(types.DoubleKind) case "boolean": return types.Basic(types.BoolKind) default: return types.Class{types.NewName(t)} } return types.Basic(types.VoidKind) } var msig types.MethodSignature for _, v := range paramTypes { msig.Params = append(msig.Params, f(v)) } msig.Return = f(returnType) GetEnv().RegisterNative(className, method, msig, fn) }
/* returns a new *Object of the class named by 'klass' (Wrapper around NewInstance(types.NewName(...))) */ func (self *Environment) NewInstanceStr(klass string, params ...interface{}) (obj *Object, err error) { class, err := self.GetClass(types.NewName(klass)) if err != nil { return } return self.NewInstance(class, params...) }
/* returns the (potentially cached) types.Name of the class. */ func (self *Class) GetName(env *Environment) (name types.Name, err error) { //log.Printf("Name(miss)") var cstr string cstr, _, err = self.CallString(env, false, "getName") if err == nil { name = types.NewName(cstr) } return }
func CallStaticObj(class string, method string, retType interface{}, args ...interface{}) (*gojvm.Object, error) { var t types.Typed switch v := retType.(type) { case string: t = types.Class{types.NewName(v)} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return nil, err } return cls.CallObj(env, true, method, t, args...) }
func CallStaticIntArray(class string, method string, args ...interface{}) ([]int, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return nil, err } return cls.CallIntArray(env, true, method, args...) }
func GetFieldStaticBoolean(class string, fieldName string) (bool, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return false, err } return cls.GetBooleanField(env, true, fieldName) }
func CallStaticDouble(class string, method string, args ...interface{}) (float64, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return 0, err } return cls.CallDouble(env, true, method, args...) }
func GetFieldStaticDouble(class string, fieldName string) (float64, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return 0, err } return cls.GetDoubleField(env, true, fieldName) }
func CallStaticBoolean(class string, method string, args ...interface{}) (bool, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return false, err } return cls.CallBoolean(env, true, method, args...) }
func GetFieldStaticInt(class string, fieldName string) (int, error) { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return 0, err } return cls.GetIntField(env, true, fieldName) }
func CallStaticVoid(class string, method string, args ...interface{}) error { env := GetEnv() cls, err := env.GetClass(types.NewName(class)) if err != nil { return err } return cls.CallVoid(env, true, method, args...) }
func GetFieldStaticObj(class string, fieldName string, retType interface{}) (*gojvm.Object, error) { env := GetEnv() var t types.Typed switch v := retType.(type) { case string: t = types.Class{types.NewName(v)} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } cls, err := env.GetClass(types.NewName(class)) if err != nil { return nil, err } return cls.GetObjField(env, true, fieldName, t) }
func CallStaticObjArray(class string, method string, retType interface{}, args ...interface{}) (*gojvm.Object, error) { var t types.Typed switch v := retType.(type) { case string: t = types.Array{types.Class{types.NewName(v)}} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } return CallStaticObj(class, method, t, args...) }
func (c *Callable) CallObjArray(method string, retType interface{}, args ...interface{}) (*gojvm.Object, error) { var t types.Typed switch v := retType.(type) { case string: t = types.Array{types.Class{types.NewName(v)}} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } return c.Obj.CallObj(GetEnv(), false, method, t, args...) }
func (c *Callable) SetFieldObj(fieldName string, retType interface{}, val interface{}) error { var t types.Typed switch v := retType.(type) { case string: t = types.Class{types.NewName(v)} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } return c.Obj.SetObjField(GetEnv(), false, fieldName, t, val.(CallableContainer).getCallable().Obj) }
func (c *Callable) GetFieldObjArray(fieldName string, retType interface{}) (*gojvm.Object, error) { var t types.Typed switch v := retType.(type) { case string: t = types.Array{types.Class{types.NewName(v)}} case types.Typed: t = v default: panic("Callable.callObj unknown retType type") } return c.Obj.GetObjField(GetEnv(), false, fieldName, t) }
func (self *Environment) RegisterNative(className string, method string, sig types.MethodSignature, fptr interface{}) error { class, err := self.GetClass(types.NewName(className)) if err != nil { return err } cname := C.CString(method) defer C.free(unsafe.Pointer(cname)) csig := C.CString(sig.String()) defer C.free(unsafe.Pointer(csig)) C.envRegisterNative(self.env, class.class, cname, csig, fptr.(unsafe.Pointer)) return nil }
/* Returns the (potentially cached) name of the ObjectClass of the named object. */ func (self *Object) Name(env *Environment) (name types.Name, err error) { clsObj, err := self.CallObj(env, false, "getClass", types.Class{ClassClass}) if err != nil { return } nameStr, _, err := clsObj.CallString(env, false, "getName") if err != nil { return } return types.NewName(nameStr), nil /* var c *Class c, err = clsObj.ObjectClass(env) if err == nil { defer env.DeleteLocalClassRef(c) name, err = c.GetName(env) } else { log.Printf("Couldn't get object class!") } return */ }
func (j *JavaToGoMap) Convert(obj *gojvm.Object) (err error) { r_value := reflect.ValueOf(j.mapval) if r_value.Type().Kind() != reflect.Ptr { return errors.New("JavaToGoMap.Convert: dest not ptr") } r_map := reflect.Indirect(r_value) if r_map.Type().Kind() != reflect.Map { return errors.New("JavaToGoMap.Convert: dest ptr , does not point to map") } if r_map.IsNil() { r_map.Set(reflect.MakeMap(r_map.Type())) } keySet, err := obj.CallObj(j.env, false, "keySet", types.Class{types.NewName("java/util/Set")}) if err != nil { return } keyList, err := j.env.NewInstanceStr("java/util/ArrayList", &gojvm.CastObject{keySet, types.NewName("java/util/Collection")}) if err != nil { return } len, err := size(j.env, obj) if err != nil { return } for i := 0; i < len; i++ { keyobj, err := keyList.CallObj(j.env, false, "get", types.Class{types.JavaLangObject}, i) if err != nil { return err } valobj, err := obj.CallObj( j.env, false, "get", types.Class{types.JavaLangObject}, &gojvm.CastObject{keyobj, types.JavaLangObject}, ) if err != nil { return err } r_newKey := reflect.Indirect(reflect.New(r_map.Type().Key())) j.key.Dest(r_newKey.Addr().Interface()) r_newVal := reflect.Indirect(reflect.New(r_map.Type().Elem())) if r_newVal.Type().Kind() == reflect.Ptr { r_elemVal := reflect.New(r_newVal.Type().Elem()) r_newVal.Set(r_elemVal) c := &Callable{} reflect.Indirect(r_elemVal).FieldByName("Callable").Set(reflect.ValueOf(c)) j.value.Dest(c) } else { j.value.Dest(r_newVal.Addr().Interface()) } // j.value.Dest(r_newVal.Addr().Interface()) if err = j.key.Convert(keyobj); err != nil { return err } if err = j.value.Convert(valobj); err != nil { return err } if err = j.key.CleanUp(); err != nil { return err } if err = j.value.CleanUp(); err != nil { return err } r_map.SetMapIndex(r_newKey, r_newVal) } return }
// Wrapper around GetClass(types.NewName(...)) func (self *Environment) GetClassStr(klass string) (c *Class, err error) { class := types.NewName(klass) return self.GetClass(class) }
func ObjectArray(objects []*gojvm.Object, name string) *gojvm.ObjectArray { return &gojvm.ObjectArray{objects, types.NewName(name)} }
func CastObject(obj *gojvm.Object, name string) *gojvm.CastObject { return &gojvm.CastObject{obj, types.NewName(name)} }