package importers
import "golang.org/x/mobile/internal/importers"
The importers package uses go/ast to analyze Go packages or Go files and collect references to types whose package has a package prefix. It is used by the language specific importers to determine the set of wrapper types to be generated.
For example, in the Go file
package javaprogram
import "Java/java/lang"
func F() {
o := lang.Object.New() ...
}
the java importer uses this package to determine that the "java/lang" package and the wrapper interface, lang.Object, needs to be generated. After calling AnalyzeFile or AnalyzePackages, the References result contains the reference to lang.Object and the names set will contain "New".
Index ¶
- type PkgRef
- type References
- func AnalyzeFile(file *ast.File, pkgPrefix string) (*References, error)
- func AnalyzePackages(pkgs []*packages.Package, pkgPrefix string) (*References, error)
- type Struct
Types ¶
type PkgRef ¶
PkgRef is a reference to an identifier in a package.
type References ¶
type References struct { // The list of references to identifiers in packages that are // identified by a package prefix. Refs []PkgRef // The list of names used in at least one selector expression. // Useful as a conservative upper bound on the set of identifiers // referenced from a set of packages. Names map[string]struct{} // Embedders is a list of struct types with prefixed types // embedded. Embedders []Struct }
References is the result of analyzing a Go file or set of Go packages.
For example, the Go file
package pkg
import "Prefix/some/Package"
var A = Package.Identifier
Will result in a single PkgRef with the "some/Package" package and the Identifier name. The Names set will contain the single name, "Identifier".
func AnalyzeFile ¶
func AnalyzeFile(file *ast.File, pkgPrefix string) (*References, error)
AnalyzeFile scans the provided file for references to packages with the given package prefix. The list of unique (package, identifier) pairs is returned
func AnalyzePackages ¶
func AnalyzePackages(pkgs []*packages.Package, pkgPrefix string) (*References, error)
AnalyzePackages scans the provided packages for references to packages with the given package prefix. The list of unique (package, identifier) pairs is returned
type Struct ¶
Struct is a representation of a struct type with embedded types.
Source Files ¶
ast.go
Directories ¶
Path | Synopsis |
---|---|
internal/importers/java | 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. |
internal/importers/objc | The objc package takes the result of an AST traversal by the importers package and uses the clang command to dump the type information for the referenced ObjC classes and protocols. |
- Version
- v0.0.0-20250408133729-978277e7eaf7 (latest)
- Published
- Apr 8, 2025
- Platform
- windows/amd64
- Imports
- 8 packages
- Last checked
- 3 days ago –
Tools for package owners.