jniType returns a string that can be used as a JNI type.
(T types.Type)
| 606 | |
| 607 | // jniType returns a string that can be used as a JNI type. |
| 608 | func (g *JavaGen) jniType(T types.Type) string { |
| 609 | switch T := types.Unalias(T).(type) { |
| 610 | case *types.Basic: |
| 611 | switch T.Kind() { |
| 612 | case types.Bool, types.UntypedBool: |
| 613 | return "jboolean" |
| 614 | case types.Int: |
| 615 | return "jlong" |
| 616 | case types.Int8: |
| 617 | return "jbyte" |
| 618 | case types.Int16: |
| 619 | return "jshort" |
| 620 | case types.Int32, types.UntypedRune: // types.Rune |
| 621 | return "jint" |
| 622 | case types.Int64, types.UntypedInt: |
| 623 | return "jlong" |
| 624 | case types.Uint8: // types.Byte |
| 625 | // TODO(crawshaw): Java bytes are signed, so this is |
| 626 | // questionable, but vital. |
| 627 | return "jbyte" |
| 628 | // TODO(crawshaw): case types.Uint, types.Uint16, types.Uint32, types.Uint64: |
| 629 | case types.Float32: |
| 630 | return "jfloat" |
| 631 | case types.Float64, types.UntypedFloat: |
| 632 | return "jdouble" |
| 633 | case types.String, types.UntypedString: |
| 634 | return "jstring" |
| 635 | default: |
| 636 | g.errorf("unsupported basic type: %s", T) |
| 637 | return "TODO" |
| 638 | } |
| 639 | case *types.Slice: |
| 640 | return "jbyteArray" |
| 641 | |
| 642 | case *types.Pointer: |
| 643 | if _, ok := types.Unalias(T.Elem()).(*types.Named); ok { |
| 644 | return g.jniType(T.Elem()) |
| 645 | } |
| 646 | g.errorf("unsupported pointer to type: %s", T) |
| 647 | case *types.Named: |
| 648 | return "jobject" |
| 649 | default: |
| 650 | g.errorf("unsupported jniType: %#+v, %s\n", T, T) |
| 651 | } |
| 652 | return "TODO" |
| 653 | } |
| 654 | |
| 655 | func (g *JavaGen) javaBasicType(T *types.Basic) string { |
| 656 | switch T.Kind() { |
no test coverage detected