mobile: golang.org/x/mobile/internal/importers Index | Files | Directories

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

Package Files

ast.go

type PkgRef Uses

type PkgRef struct {
    Name string
    Pkg  string
}

PkgRef is a reference to an identifier in a package.

type References Uses

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 Uses

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 Uses

func AnalyzePackages(pkgs []*build.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 Uses

type Struct struct {
    Name    string
    Pkg     string
    PkgPath string
    Refs    []PkgRef
}

Struct is a representation of a struct type with embedded types.

Directories

PathSynopsis
javaThe 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.
objcThe 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.

Package importers imports 10 packages (graph) and is imported by 5 packages. Updated 2017-10-22. Refresh now. Tools for package owners.