Documentation
¶
Overview ¶
Package specgen generates Java API YAML specs from .class files using javap.
Index ¶
- Variables
- func GenerateFromRefDir(refDir string, extraClassPath string, outputDir string, goModule string) error
- func LoadServiceNames(classPath string) (map[string]string, error)
- type JavapClass
- type JavapConstant
- type JavapConstructor
- type JavapMethod
- type JavapParam
- type PackageMapping
- type SpecCallback
- type SpecCallbackMethod
- type SpecClass
- type SpecConstant
- type SpecField
- type SpecFile
- type SpecMethod
- type SpecParam
Constants ¶
This section is empty.
Variables ¶
var AndroidServiceName map[string]string
AndroidServiceName maps known manager class names to their Android Context.getSystemService() constant names. Populated at runtime by LoadServiceNames, which reflects on android.jar via the svcgen Java tool.
Functions ¶
func GenerateFromRefDir ¶
func GenerateFromRefDir( refDir string, extraClassPath string, outputDir string, goModule string, ) error
GenerateFromRefDir scans ref/ for .class files and generates one YAML spec per top-level class (inner classes are grouped with their parent). extraClassPath is appended to the javap -cp argument.
func LoadServiceNames ¶ added in v0.0.4
LoadServiceNames runs the Java svcgen program against the given android.jar classpath and returns a map of fully-qualified Java class name to service name string (e.g. "android.app.AlarmManager" -> "alarm").
Types ¶
type JavapClass ¶
type JavapClass struct {
FullName string // e.g. "android.app.KeyguardManager"
IsInterface bool
IsAbstract bool
IsFinal bool
Constants []JavapConstant
Methods []JavapMethod
Constructors []JavapConstructor
Implements []string
}
JavapClass holds the parsed output of javap for one class.
type JavapConstant ¶
type JavapConstant struct {
Name string // e.g. "ERROR_BAD_VALUE"
JavaType string // e.g. "int", "java.lang.String"
Value string // e.g. "1", "gps" -- extracted from ConstantValue attribute
}
JavapConstant is a public static final field.
type JavapConstructor ¶ added in v0.0.7
type JavapConstructor struct {
Params []JavapParam
}
JavapConstructor is a public constructor parsed from javap output.
type JavapMethod ¶
type JavapMethod struct {
Name string
ReturnType string // "void", "int", "boolean", "java.lang.String", etc.
Params []JavapParam
IsStatic bool
Throws bool
}
JavapMethod is a public method parsed from javap output.
type PackageMapping ¶
type PackageMapping struct {
JavaPrefix string // e.g. "android.app.admin"
Package string // e.g. "admin"
GoImport string // e.g. "github.com/AndroidGoLab/jni/app/admin"
}
PackageMapping defines how a Java package maps to a Go package.
type SpecCallback ¶
type SpecCallback struct {
JavaInterface string `yaml:"java_interface"`
GoType string `yaml:"go_type"`
Methods []SpecCallbackMethod `yaml:"methods"`
}
SpecCallback is a callback interface in the YAML spec.
type SpecCallbackMethod ¶
type SpecCallbackMethod struct {
JavaMethod string `yaml:"java_method"`
Params []string `yaml:"params"`
GoField string `yaml:"go_field"`
}
SpecCallbackMethod is a callback method in the YAML spec.
type SpecClass ¶
type SpecClass struct {
JavaClass string `yaml:"java_class"`
GoType string `yaml:"go_type"`
Obtain string `yaml:"obtain,omitempty"`
ServiceName string `yaml:"service_name,omitempty"`
Kind string `yaml:"kind,omitempty"`
Close bool `yaml:"close,omitempty"`
ConstructorParams []SpecParam `yaml:"constructor_params,omitempty"`
Methods []SpecMethod `yaml:"methods,omitempty"`
StaticMethods []SpecMethod `yaml:"static_methods,omitempty"`
Fields []SpecField `yaml:"fields,omitempty"`
}
SpecClass is a class in the YAML spec.
type SpecConstant ¶
type SpecConstant struct {
GoName string `yaml:"go_name"`
Value string `yaml:"value"`
GoType string `yaml:"go_type"`
}
SpecConstant is a constant in the YAML spec.
type SpecField ¶
type SpecField struct {
JavaMethod string `yaml:"java_method"`
Returns string `yaml:"returns"`
GoName string `yaml:"go_name"`
GoType string `yaml:"go_type"`
}
SpecField is a data class field in the YAML spec.
type SpecFile ¶
type SpecFile struct {
Package string `yaml:"package"`
GoImport string `yaml:"go_import"`
Classes []SpecClass `yaml:"classes"`
Callbacks []SpecCallback `yaml:"callbacks,omitempty"`
Constants []SpecConstant `yaml:"constants,omitempty"`
}
SpecFile is the YAML output structure.
func GenerateSpec ¶
func GenerateSpec( classPath string, className string, pkgMapping PackageMapping, goModule string, ) (*SpecFile, error)
GenerateSpec generates a YAML spec from .class files in a directory by running javap on each class.