importers

package
v0.0.0-...-93c80e8 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PkgRef

type PkgRef struct {
	Name string
	Pkg  string
}

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

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

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

Directories

Path Synopsis
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.
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.
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.
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.

Jump to

Keyboard shortcuts

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