MCPcopy Create free account
hub / github.com/golang/mobile / javaType

Method javaType

bind/genjava.go:687–729  ·  view source on GitHub ↗

javaType returns a string that can be used as a Java type.

(T types.Type)

Source from the content-addressed store, hash-verified

685
686// javaType returns a string that can be used as a Java type.
687func (g *JavaGen) javaType(T types.Type) string {
688 if isErrorType(T) {
689 // The error type is usually translated into an exception in
690 // Java, however the type can be exposed in other ways, such
691 // as an exported field.
692 return "java.lang.Exception"
693 } else if isJavaType(T) {
694 return classNameFor(T)
695 }
696 switch T := types.Unalias(T).(type) {
697 case *types.Basic:
698 return g.javaBasicType(T)
699 case *types.Slice:
700 elem := g.javaType(T.Elem())
701 return elem + "[]"
702
703 case *types.Pointer:
704 if _, ok := types.Unalias(T.Elem()).(*types.Named); ok {
705 return g.javaType(T.Elem())
706 }
707 g.errorf("unsupported pointer to type: %s", T)
708 case *types.Named:
709 n := T.Obj()
710 nPkg := n.Pkg()
711 if !isErrorType(T) && !g.validPkg(nPkg) {
712 g.errorf("type %s is in %s, which is not bound", n.Name(), nPkg)
713 break
714 }
715 // TODO(crawshaw): more checking here
716 clsName := n.Name()
717 if nPkg != g.Pkg {
718 if clsName == JavaClassName(nPkg) {
719 clsName += "_"
720 }
721 return fmt.Sprintf("%s.%s", g.javaPkgName(nPkg), clsName)
722 } else {
723 return g.javaTypeName(clsName)
724 }
725 default:
726 g.errorf("unsupported javaType: %#+v, %s\n", T, T)
727 }
728 return "TODO"
729}
730
731func (g *JavaGen) genJNIFuncSignature(o *types.Func, sName string, jm *java.Func, proxy, isjava bool) {
732 sig := o.Type().(*types.Signature)

Callers 6

genStructMethod · 0.95
genFuncArgsMethod · 0.95
genObjectMethodsMethod · 0.95
genFuncSignatureMethod · 0.95
genVarMethod · 0.95
genConstMethod · 0.95

Calls 9

javaBasicTypeMethod · 0.95
javaPkgNameMethod · 0.95
javaTypeNameMethod · 0.95
isErrorTypeFunction · 0.85
isJavaTypeFunction · 0.85
classNameForFunction · 0.85
JavaClassNameFunction · 0.85
validPkgMethod · 0.80
errorfMethod · 0.45

Tested by

no test coverage detected