• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang types.Basic函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/timob/gojvm/types.Basic函数的典型用法代码示例。如果您正苦于以下问题:Golang Basic函数的具体用法?Golang Basic怎么用?Golang Basic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Basic函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ReflectedSignature

func ReflectedSignature(ctx *Environment, f interface{}) (sig types.MethodSignature, err error) {
	sig.Return = types.Basic(types.UnspecKind)

	ftype := reflect.TypeOf(f)
	sig.Params = make([]types.Typed, 0)
	if ftype.Kind() != reflect.Func {
		err = errors.New("ReflectedSignature: f is not a function")
	}
	if err == nil && ftype.NumIn() < 2 {
		err = errors.New("ReflectedSignature: f is not a callback (insufficient args)")
	}
	if err == nil && ftype.NumOut() > 1 {
		err = errors.New("ReflectedSignature: f is not a callback (too many returns)")
	}
	if err == nil && ftype.In(0) != reflect.TypeOf(&Environment{}) {
		err = errors.New("bad first-arg Type: must be *Environment")
	}
	if err == nil && ftype.In(1) != reflect.TypeOf(&Object{}) {
		err = errors.New("bad second-arg Type: must be *Object")
	}
	if err != nil {
		return
	}
	for i := 2; i < ftype.NumIn(); i++ {
		var k types.Typed
		if ftype.In(i).Kind() == reflect.Ptr {
			if ftype.In(i) == reflect.TypeOf(&Object{}) {
				k = types.Class{types.JavaLangObject}
			} else {
				itype := ftype.In(i).Elem()
				pobj := reflect.New(itype).Interface()
				k, err = TypeOf(ctx, pobj)
			}
		} else {
			k, err = TypeOf(ctx, reflect.New(ftype.In(i)).Interface())
		}
		if err != nil {
			break
		}
		sig.Params = append(sig.Params, k)
	}
	if ftype.NumOut() == 1 {
		var k types.Typed
		k, err = reflectedType(ctx, reflect.New(ftype.Out(0)).Interface())
		if err == nil {
			sig.Return = k
		}
	} else {
		sig.Return = types.Basic(types.VoidKind)
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:52,代码来源:method_sig_helpers.c.go


示例2: RegisterNative

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)
}
开发者ID:skanjo,项目名称:javabind,代码行数:29,代码来源:runtime.go


示例3: reflectedType

func reflectedType(env *Environment, v interface{}) (k types.Typed, err error) {
	vtype := reflect.TypeOf(v)
	vkind := vtype.Kind()
	switch vkind {
	case reflect.Ptr:
		k, err = TypeOf(env, reflect.Indirect(reflect.ValueOf(v)).Interface())
	case reflect.Bool:
		k = types.Basic(types.BoolKind)
	case reflect.Uint8, reflect.Int8:
		k = types.Basic(types.ByteKind)
	case reflect.Int16, reflect.Uint16:
		k = types.Basic(types.ShortKind)
	case reflect.Int32, reflect.Uint32:
		k = types.Basic(types.IntKind)
	case reflect.Uint64, reflect.Int64:
		k = types.Basic(types.LongKind)
	case reflect.Int, reflect.Uint:
		k = types.Basic(types.IntKind)
	case reflect.Float32:
		k = types.Basic(types.FloatKind)
	case reflect.Float64:
		k = types.Basic(types.DoubleKind)
	case reflect.Struct:
		k = types.Class{[]string{"golang", vkind.String()}}
	case reflect.String:
		k = types.Class{types.JavaLangString}
	case reflect.Slice, reflect.Array:
		sltype := vtype.Elem()
		switch sltype.Kind() {
		case reflect.Uint8:
			k = types.Array{types.Basic(types.ByteKind)}
		case reflect.String:
			k = types.Array{types.Class{types.JavaLangString}}
		default:
			err = errors.New("Unhandled slice type " + sltype.String())
		}
	default:
		switch T := v.(type) {
		default:
			err = errors.New(fmt.Sprintf("Unsure how to TypeOf '%s'/%T", vkind.String(), T))
		}
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:44,代码来源:method_sig_helpers.c.go


示例4: TestJVMTrivialClass

func TestJVMTrivialClass(t *testing.T) {
	env := setupJVM(t)
	for i, test := range trivialClassTests {
		form, err := FormFor(env, types.Basic(types.VoidKind), test.ConstArgs...)
		fatalIf(t, err != nil, "[%d] Error generating formFor: %v", i, err)
		fatalIf(t, form == "", "Got nil form")
		klass, err := env.NewInstanceStr(TrivialClass, test.ConstArgs...)
		fatalIf(t, err != nil, "[%d] Error generating formFor: %v", i, err)
		kused, _, err := klass.CallString(env, false, "getConstructorUsed")
		fatalIf(t, err != nil, "[%d] Error getting constructor used: %v", i, err)
		fatalIf(t, kused != form, "[%d] Constructor called was wrong (Exp: %s, got: %s)", form, kused)

	}
}
开发者ID:timob,项目名称:gojvm,代码行数:14,代码来源:jvm_xclass_test.go


示例5: setDoubleField

func (self *Environment) setDoubleField(z interface{}, static bool, name string, val float64) (err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.IntKind))
	if err != nil {
		return
	}
	if static {
		C.envSetStaticDoubleField(self.env, C.valObject(jval), field.field, C.jdouble(val))
	} else {
		C.envSetDoubleField(self.env, C.valObject(jval), field.field, C.jdouble(val))
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:15,代码来源:environ.c.go


示例6: callVoid

func (self *Environment) callVoid(z interface{}, static bool, name string, params ...interface{}) (err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.VoidKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	if static {
		C.envCallStaticVoidMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		C.envCallVoidMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:16,代码来源:environ.c.go


示例7: NewInstance

/*
	returns a new *Object of type *Class, using the constructor identified by []params
*/
func (self *Environment) NewInstance(c *Class, params ...interface{}) (o *Object, err error) {
	meth, alp, localStack, err := self.getClassMethod(c, false, "<init>", types.Basic(types.VoidKind), params...)
	//	meth, alp, err := self.getObjectMethod(newObject(self, c, C.jobject( c.class)), "<init>", BasicType(JavaVoidKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	obj := C.envNewObjectA(self.env, c.class, meth.method, alp.Ptr())
	if obj != nil {
		obj = C.envNewGlobalRef(self.env, obj)
		o = newObject(obj)
	} else {
		err = self.ExceptionOccurred()
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:19,代码来源:environ.c.go


示例8: callFloat

func (self *Environment) callFloat(z interface{}, static bool, name string, params ...interface{}) (v float32, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.FloatKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var ji C.jfloat
	if static {
		ji = C.envCallStaticFloatMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		ji = C.envCallFloatMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	v = float32(ji)
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:18,代码来源:environ.c.go


示例9: getShortField

func (self *Environment) getShortField(z interface{}, static bool, name string) (v int16, err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.ShortKind))
	if err != nil {
		return
	}
	var oval C.jshort
	if static {
		oval = C.envGetStaticShortField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetShortField(self.env, C.valObject(jval), field.field)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = int16(oval)
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:19,代码来源:environ.c.go


示例10: setBoolField

func (self *Environment) setBoolField(z interface{}, static bool, name string, gval bool) (err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.BoolKind))
	if err != nil {
		return
	}
	val := C.jboolean(C.JNI_FALSE)
	if gval {
		val = C.JNI_TRUE
	}
	if static {
		C.envSetStaticBooleanField(self.env, C.valObject(jval), field.field, val)
	} else {
		C.envSetBooleanField(self.env, C.valObject(jval), field.field, val)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:19,代码来源:environ.c.go


示例11: getDobuleField

func (self *Environment) getDobuleField(z interface{}, static bool, name string) (v float64, err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.IntKind))
	if err != nil {
		return
	}
	var oval C.jdouble
	if static {
		oval = C.envGetStaticDoubleField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetDoubleField(self.env, C.valObject(jval), field.field)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = float64(oval)
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:19,代码来源:environ.c.go


示例12: callIntArray

func (self *Environment) callIntArray(z interface{}, static bool, name string, params ...interface{}) (v []int, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Array{types.Basic(types.IntKind)}, params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var oval C.jobject
	if static {
		oval = C.envCallStaticObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		oval = C.envCallObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if oval == nil {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = self.ToIntArray(newObject(oval))
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:20,代码来源:environ.c.go


示例13: callShort

func (self *Environment) callShort(z interface{}, static bool, name string, params ...interface{}) (v int16, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.ShortKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var oval C.jshort
	if static {
		oval = C.envCallStaticShortMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		oval = C.envCallShortMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = int16(oval)
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:20,代码来源:environ.c.go


示例14: getIntArrayField

func (self *Environment) getIntArrayField(z interface{}, static bool, name string) (v []int, err error) {
	jval, field, err := self.getField(z, static, name, types.Array{types.Basic(types.IntKind)})
	if err != nil {
		return
	}
	var oval C.jobject
	if static {
		oval = C.envGetStaticObjectField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetObjectField(self.env, C.valObject(jval), field.field)
	}
	if oval == nil {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = self.ToIntArray(newObject(oval))
	}

	return
}
开发者ID:timob,项目名称:gojvm,代码行数:20,代码来源:environ.c.go


示例15: ToString

func (self *Environment) ToString(strobj *Object) (str string, isNull bool, err error) {
	if strobj.object == nil {
		isNull = true
		return
	}
	var bytesObj *Object
	bytesObj, err = self.CallObjectObj(strobj, false, "getBytes", types.Array{types.Basic(types.ByteKind)}, self.utf8())
	if err == nil && bytesObj == nil {
		isNull = true
		return
	}
	if err == nil {
		defer self.DeleteLocalRef(bytesObj)
		alen := C.envGetArrayLength(self.env, bytesObj.object)
		_false := C.jboolean(C.JNI_FALSE)
		ptr := C.envGetByteArrayElements(self.env, bytesObj.object, &_false)
		defer C.envReleaseByteArrayElements(self.env, bytesObj.object, ptr, 0)
		str = string(C.GoBytes(unsafe.Pointer(ptr), C.int(alen)))
	}
	return
}
开发者ID:timob,项目名称:gojvm,代码行数:21,代码来源:environ.c.go


示例16: TestTrivialFormFor

package gojvm

import (
	"github.com/timob/gojvm/types"
	"testing"
)

type formForTest struct {
	rtype  types.Typed
	params []interface{}
	eform  string
	eerror error
}

var formOfTests = []formForTest{
	formForTest{types.Basic(types.VoidKind), []interface{}{}, "()V", nil},
	formForTest{types.Basic(types.VoidKind), []interface{}{int(5)}, "(I)V", nil},
	formForTest{types.Basic(types.VoidKind), []interface{}{int16(5)}, "(S)V", nil},
	formForTest{types.Basic(types.VoidKind), []interface{}{int64(5)}, "(J)V", nil},
	formForTest{types.Basic(types.VoidKind), []interface{}{"5"}, "(Ljava/lang/String;)V", nil},
	formForTest{types.Basic(types.VoidKind), []interface{}{"5", &Object{}}, "(Ljava/lang/String;Ljava/lang/Object;)V", nil},
	formForTest{types.Basic(types.ShortKind), []interface{}{int64(5)}, "(J)S", nil},
	formForTest{types.Basic(types.BoolKind), []interface{}{int(0)}, "(I)Z", nil},
	formForTest{types.Class{types.JavaLangObject}, []interface{}{int(0)}, "(I)Ljava/lang/Object;", nil},
	formForTest{types.Array{types.Basic(types.ByteKind)}, []interface{}{[]byte{1, 2, 3}}, "([B)[B", nil},
}

func TestTrivialFormFor(t *testing.T) {
	env := setupJVM(t)
	for i, test := range formOfTests {
		form, err := FormFor(env, test.rtype, test.params...)
开发者ID:timob,项目名称:gojvm,代码行数:31,代码来源:param_reflection_test.go



注:本文中的github.com/timob/gojvm/types.Basic函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.NewName函数代码示例发布时间:2022-05-28
下一篇:
Golang gojvm.Object类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap