當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Type.FullName方法代碼示例

本文整理匯總了Golang中github.com/gsrpc/gslang/ast.Type.FullName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.FullName方法的具體用法?Golang Type.FullName怎麽用?Golang Type.FullName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gsrpc/gslang/ast.Type的用法示例。


在下文中一共展示了Type.FullName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: typeName

func (codegen *_CodeGen) typeName(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		return builtin[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.typeName(typeRef.Ref)

	case *ast.Enum, *ast.Table:
		_, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if gslang.IsException(typeDecl) {
			return exception(name)
		}

		return name

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
開發者ID:gsrpc,項目名稱:gsrpc,代碼行數:30,代碼來源:codegen.go

示例2: defaultVal

func (codegen *_CodeGen) defaultVal(typeDecl ast.Type) string {

	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)
		return defaultval[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.defaultVal(typeRef.Ref)

	case *ast.Enum:

		enum := typeDecl.(*ast.Enum)

		_, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())
		//
		// if prefix != "" {
		// 	return prefix + "." + name + "." + enum.Constants[0].Name()
		// }

		return name + "." + enum.Constants[0].Name()

	case *ast.Table:

		return "new " + codegen.typeName(typeDecl) + "()"

	case *ast.Seq:
		return fmt.Sprintf("new %s", codegen.arrayDefaultVal(typeDecl))
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
開發者ID:gsrpc,項目名稱:gsrpc,代碼行數:35,代碼來源:codegen.go

示例3: objTypeName

func (codegen *_CodeGen) objTypeName(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		return builtinObj[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.typeName(typeRef.Ref)

	case *ast.Enum, *ast.Table:
		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return prefix + "." + name
		}

		return name

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
開發者ID:gsrpc,項目名稱:gsrpc,代碼行數:30,代碼來源:codegen.go

示例4: readType

func (codegen *_CodeGen) readType(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)
		return readMapping[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.readType(typeRef.Ref)

	case *ast.Enum:
		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return prefix + ".Read" + name
		}

		return "Read" + name

	case *ast.Table:

		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return "" + prefix + ".Read" + name
		}

		return "Read" + name

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		var buff bytes.Buffer

		isbytes := false

		builtinType, ok := seq.Component.(*ast.BuiltinType)

		if ok && builtinType.Type == lexer.KeyByte {
			isbytes = true
		}

		if seq.Size != -1 {

			if isbytes {
				if err := codegen.tpl.ExecuteTemplate(&buff, "readByteArray", seq); err != nil {
					gserrors.Panicf(err, "exec template(readByteArray) for %s errir", seq)
				}
			} else {
				if err := codegen.tpl.ExecuteTemplate(&buff, "readArray", seq); err != nil {
					gserrors.Panicf(err, "exec template(readArray) for %s errir", seq)
				}
			}

		} else {

			if isbytes {
				if err := codegen.tpl.ExecuteTemplate(&buff, "readByteList", seq); err != nil {
					gserrors.Panicf(err, "exec template(readByteList) for %s errir", seq)
				}
			} else {
				if err := codegen.tpl.ExecuteTemplate(&buff, "readList", seq); err != nil {
					gserrors.Panicf(err, "exec template(readList) for %s errir", seq)
				}
			}

		}

		return buff.String()
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
開發者ID:gsrpc,項目名稱:gsrpc,代碼行數:75,代碼來源:codegen.go


注:本文中的github.com/gsrpc/gslang/ast.Type.FullName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。