Documentation
¶
Index ¶
- func BuildCallbackDispatch(cb *MergedCallback) string
- func BuildCallbackType(cb *MergedCallback) string
- func Generate(specPath, overlayPath, templatesDir, outputDir, goModule string) error
- func GoImportToRelDir(goImport, goModule string) string
- func IsManager(cls *MergedClass) bool
- func JNISignature(params []Param, returnType string) string
- func JNITypeSignature(javaType string) string
- func JavaClassToSlash(className string) string
- func ParamConversionCode(p MergedParam) string
- func ReturnConversionCode(javaType, goType string) string
- type Callback
- type CallbackMethod
- type Class
- type Constant
- type ConversionOverride
- type Field
- type IntentExtra
- type ManagerData
- type MergedCallback
- type MergedCallbackMethod
- type MergedClass
- type MergedConstant
- type MergedConstantGroup
- type MergedDataClass
- type MergedField
- type MergedMethod
- type MergedParam
- type MergedSpec
- type Method
- type Overlay
- type Param
- type ReturnKind
- type Spec
- type StaticField
- type TypeConv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCallbackDispatch ¶
func BuildCallbackDispatch(cb *MergedCallback) string
BuildCallbackDispatch generates the Go code for a callback's switch/case dispatch inside a jni.NewProxy handler.
func BuildCallbackType ¶
func BuildCallbackType(cb *MergedCallback) string
BuildCallbackType generates the Go struct type definition with function fields for a callback interface.
func Generate ¶
Generate is the main entry point. It loads spec + overlay, merges them, renders templates, and writes output files.
The goModule parameter is the Go module path (e.g. "github.com/AndroidGoLab/jni"). Output directories and Go package names are derived from the spec's go_import field by stripping the module prefix.
func GoImportToRelDir ¶
GoImportToRelDir strips the Go module prefix from a go_import path to produce the relative output directory. e.g. GoImportToRelDir("github.com/foo/bar/hw/cam", "github.com/foo/bar") → "hw/cam"
func IsManager ¶
func IsManager(cls *MergedClass) bool
IsManager returns true if the class is obtained via system service.
func JNISignature ¶
JNISignature computes the JNI method signature from parameter types and return type.
func JNITypeSignature ¶
JNITypeSignature converts a single Java type to its JNI type signature. Generic type parameters are stripped because JNI uses erased types.
func JavaClassToSlash ¶
JavaClassToSlash converts a dotted Java class name to slash-separated JNI format. Handles inner classes: "android.app.AlarmManager.AlarmClockInfo" becomes "android/app/AlarmManager$AlarmClockInfo".
func ParamConversionCode ¶
func ParamConversionCode(p MergedParam) string
ParamConversionCode generates Go code to convert a Go parameter to its JNI representation before a JNI call.
func ReturnConversionCode ¶
ReturnConversionCode generates Go code to convert a JNI return value to Go.
Types ¶
type Callback ¶
type Callback struct {
JavaInterface string `yaml:"java_interface"`
GoType string `yaml:"go_type"`
Methods []CallbackMethod `yaml:"methods"`
}
Callback describes a Java callback interface to bridge to Go.
type CallbackMethod ¶
type CallbackMethod struct {
JavaMethod string `yaml:"java_method"`
Params []string `yaml:"params"`
GoField string `yaml:"go_field"`
}
CallbackMethod describes a single method in a callback interface.
type Class ¶
type Class struct {
JavaClass string `yaml:"java_class"`
GoType string `yaml:"go_type"`
Obtain string `yaml:"obtain"`
ServiceName string `yaml:"service_name"`
Kind string `yaml:"kind"`
Close bool `yaml:"close"`
Methods []Method `yaml:"methods"`
StaticMethods []Method `yaml:"static_methods"`
Fields []Field `yaml:"fields"`
StaticFields []StaticField `yaml:"static_fields"`
IntentExtras []IntentExtra `yaml:"intent_extras"`
}
Class describes a Java class to wrap.
func (Class) AllMethods ¶
AllMethods returns both instance and static methods. Static methods have their Static field set to true.
type Constant ¶
type Constant struct {
GoName string `yaml:"go_name"`
Value string `yaml:"value"`
GoType string `yaml:"go_type"`
GoUnderlying string `yaml:"go_underlying"`
}
Constant describes a named constant value.
type ConversionOverride ¶
ConversionOverride specifies custom type conversion expressions.
type Field ¶
type Field struct {
JavaMethod string `yaml:"java_method"`
JavaField string `yaml:"java_field"`
Returns string `yaml:"returns"`
GoName string `yaml:"go_name"`
GoType string `yaml:"go_type"`
}
Field describes a getter method on a data class. Supports both java_method (getter) and java_field (direct field access).
func (Field) GetterName ¶
GetterName returns the Java getter method name for this field. If java_method is set, it is used directly. If java_field is set, it is converted to a getter name (e.g., "packageName" → "getPackageName").
type IntentExtra ¶
type IntentExtra struct {
JavaExtra string `yaml:"java_extra"`
JavaType string `yaml:"java_type"`
GoName string `yaml:"go_name"`
GoType string `yaml:"go_type"`
}
IntentExtra describes a value extracted from a sticky broadcast intent.
type ManagerData ¶
ManagerData holds template data for generating a system service manager constructor.
func ManagerConstructorData ¶
func ManagerConstructorData(cls *MergedClass) ManagerData
ManagerConstructorData returns template data for the NewManager constructor.
type MergedCallback ¶
type MergedCallback struct {
JavaInterface string
GoType string
Methods []MergedCallbackMethod
}
MergedCallback is a resolved callback interface.
type MergedCallbackMethod ¶
type MergedCallbackMethod struct {
JavaMethod string
GoField string
Params []MergedParam
GoParams string
}
MergedCallbackMethod is a resolved callback method.
type MergedClass ¶
type MergedClass struct {
JavaClass string
JavaClassSlash string
GoType string
Obtain string
ServiceName string
Kind string
Close bool
Methods []MergedMethod
}
MergedClass is a resolved Java class wrapper.
type MergedConstant ¶
MergedConstant is a resolved constant value.
type MergedConstantGroup ¶
type MergedConstantGroup struct {
GoType string
BaseType string
Values []MergedConstant
}
MergedConstantGroup groups constants by their Go type.
type MergedDataClass ¶
type MergedDataClass struct {
JavaClass string
JavaClassSlash string
GoType string
Fields []MergedField
}
MergedDataClass is a resolved data class (getter extraction).
type MergedField ¶
type MergedField struct {
JavaMethod string // getter method name (for java_method fields)
JavaName string // raw field name (for java_field direct access)
GoName string
GoType string
JNISig string
CallSuffix string
IsField bool // true = use GetFieldID/Get*Field, false = use GetMethodID/Call*Method
}
MergedField is a resolved field getter on a data class.
type MergedMethod ¶
type MergedMethod struct {
JavaMethod string
GoName string
Static bool
Params []MergedParam
Returns string
GoReturn string
Error bool
JNISig string
CallSuffix string
ReturnKind ReturnKind
GoParamList string
GoReturnList string
GoReturnVars string
GoReturnValues string
JNIArgs string
HasError bool
}
MergedMethod is a resolved method with all computed helpers.
type MergedParam ¶
type MergedParam struct {
JavaType string
GoName string
GoType string
ConversionCode string
IsString bool
IsBool bool
IsObject bool
}
MergedParam is a resolved parameter.
type MergedSpec ¶
type MergedSpec struct {
Package string
GoImport string
JavaPackageDesc string
Classes []MergedClass
DataClasses []MergedDataClass
Callbacks []MergedCallback
ConstantGroups []MergedConstantGroup
}
MergedSpec is the fully resolved specification ready for template rendering.
type Method ¶
type Method struct {
JavaMethod string `yaml:"java_method"`
GoName string `yaml:"go_name"`
Static bool `yaml:"static"`
Params []Param `yaml:"params"`
Returns string `yaml:"returns"`
Error bool `yaml:"error"`
}
Method describes a Java method to generate a Go wrapper for.
type Overlay ¶
type Overlay struct {
GoNameOverrides map[string]string `yaml:"go_name_overrides"`
MethodGrouping map[string][]string `yaml:"method_grouping"`
ExtraMethods []Method `yaml:"extra_methods"`
TypeOverrides map[string]string `yaml:"type_overrides"`
ConversionFuncs map[string]ConversionOverride `yaml:"conversion_funcs"`
}
Overlay provides per-package customization applied on top of a Spec.
func LoadOverlay ¶
LoadOverlay reads an overlay YAML file. If the file does not exist, an empty Overlay is returned without error.
type Param ¶
type Param struct {
JavaType string `yaml:"java_type"`
GoName string `yaml:"go_name"`
GoType string `yaml:"go_type"`
}
Param describes a method parameter.
type ReturnKind ¶
type ReturnKind string
ReturnKind classifies how a method's return value should be handled in the generated code.
const ( ReturnVoid ReturnKind = "void" ReturnString ReturnKind = "string" ReturnBool ReturnKind = "bool" ReturnObject ReturnKind = "object" ReturnPrimitive ReturnKind = "primitive" )
type Spec ¶
type Spec struct {
Package string `yaml:"package"`
GoImport string `yaml:"go_import"`
Classes []Class `yaml:"classes"`
Callbacks []Callback `yaml:"callbacks"`
Constants []Constant `yaml:"constants"`
IntentExtras []IntentExtra `yaml:"intent_extras"`
}
Spec represents a per-package Java API specification loaded from YAML.
type StaticField ¶
type StaticField struct {
JavaField string `yaml:"java_field"`
Returns string `yaml:"returns"`
GoName string `yaml:"go_name"`
GoType string `yaml:"go_type"`
}
StaticField describes a Java static field to read.
type TypeConv ¶
TypeConv holds the Go and JNI type information for a Java type.
func ResolveType ¶
ResolveType maps a Java type string to its TypeConv. Generic type parameters are stripped because JNI uses erased types.