java

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp16696

TODO: Support unicode characters

Types

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 {
	FuncSig
	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
	CommonSig
}

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 "System.java"

public final class java.lang.System {
  public static final java.io.InputStream in;
    descriptor: Ljava/io/InputStream;
  public static final java.io.PrintStream out;
    descriptor: Ljava/io/PrintStream;
  public static final java.io.PrintStream err;
    descriptor: Ljava/io/PrintStream;
  public static void setIn(java.io.InputStream);
    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
	Boolean
	Short
	Char
	Byte
	Long
	Float
	Double
	String
	Array
	Object
)

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

Jump to

Keyboard shortcuts

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