Version: v0.0.0-...-45e4d75 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0



The java package takes the result of an AST traversal by the importers package and queries the java command for the type information for the referenced Java classes and interfaces.

It is the of go/types for Java types and is used by the bind package to generate Go wrappers for Java API on Android.



This section is empty.


This section is empty.


func IsAvailable

func IsAvailable() bool

IsAvailable reports whether the required tools are available for Import to work. In particular, IsAvailable checks the existence of the javap binary.

func JNIMangle

func JNIMangle(s string) string

Mangle a name according to

TODO: Support unicode characters


type Class

type Class struct {
	// "java.pkg.Class.Inner"
	Name string
	// "java.pkg.Class$Inner"
	FindName string
	// JNI mangled name
	JNIName string
	// "Inner"
	PkgName string
	Funcs   []*FuncSet
	Methods []*FuncSet

	// All methods, including methods from
	// supers.
	AllMethods []*FuncSet
	Vars       []*Var
	Supers     []string
	Final      bool
	Abstract   bool
	Interface  bool
	Throwable  bool
	// Whether the class has a no-arg constructor
	HasNoArgCon bool
	// contains filtered or unexported fields

Class is the bind representation of a Java class or interface. Use Import to convert class references to Class.

type CommonSig

type CommonSig struct {
	// Variadic is set if the signature covers variants
	// with varying number of parameters.
	Variadic bool
	// HasRet is true if at least one variant returns a
	// value.
	HasRet bool
	Throws bool
	Params []*Type
	Ret    *Type

CommonSig is a signature compatible with every overloaded variant of a FuncSet.

type Func

type Func struct {
	ArgDesc string
	// Mangled JNI name
	JNIName     string
	Static      bool
	Abstract    bool
	Final       bool
	Public      bool
	Constructor bool
	Params      []*Type
	Ret         *Type
	Decl        string
	Throws      string

Func is a Java static function or method or constructor.

type FuncSet

type FuncSet struct {
	Name   string
	GoName string
	Funcs  []*Func

FuncSet is the set of overloaded variants of a function. If the function is not overloaded, its FuncSet contains one entry.

type FuncSig

type FuncSig struct {
	Name string
	// The method descriptor, in JNI format.
	Desc string

FuncSig uniquely identifies a Java Func.

type Importer

type Importer struct {
	Bootclasspath string
	Classpath     string
	// JavaPkg is java package name for generated classes.
	JavaPkg string
	// contains filtered or unexported fields

func (*Importer) Import

func (j *Importer) Import(refs *importers.References) ([]*Class, error)

Import returns Java Class descriptors for a list of references.

The javap command from the Java SDK is used to dump class information. Its output looks like this:

Compiled from "" public final class java.lang.System {

public static final in;
  descriptor: Ljava/io/InputStream;
public static final out;
  descriptor: Ljava/io/PrintStream;
public static final err;
  descriptor: Ljava/io/PrintStream;
public static void setIn(;
  descriptor: (Ljava/io/InputStream;)V



type Type

type Type struct {
	Kind  TypeKind
	Class string
	Elem  *Type

Type is a Java type.

func (*Type) CType

func (t *Type) CType() string

func (*Type) JNICallType

func (t *Type) JNICallType() string

func (*Type) JNIType

func (t *Type) JNIType() string

func (*Type) Type

func (t *Type) Type() string

type TypeKind

type TypeKind int
const (
	Int TypeKind = iota

type Var

type Var struct {
	Name   string
	Static bool
	Final  bool
	Val    string
	Type   *Type

Var is a Java member variable.

func (*Var) Constant

func (v *Var) Constant() bool

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL