Documentation
¶
Overview ¶
Package importer provides a function to parse a directory and returns the package information
Index ¶
- Variables
- func FileFilter(fileInfo os.FileInfo) bool
- func GetImportSpecForIdentifierAndFile(identifier string, file *ast.File) (*ast.ImportSpec, error)
- func ImportPathToFilePath(i *ast.ImportSpec) (string, error)
- func TryToFindIdentifier(identifier string, file *ast.File) (*ast.ImportSpec, error)
- type PackageInfo
- func (p *PackageInfo) FileForPointer(pointer *PkgResolverPointer) *ast.File
- func (p *PackageInfo) FindImport(pointer *PkgResolverPointer, selector, identifier string) (bool, ast.Expr, *PkgResolverPointer)
- func (p *PackageInfo) FindInCurrent(pointer *PkgResolverPointer, identifier string) (bool, ast.Expr, *PkgResolverPointer)
- func (p *PackageInfo) GetRootPkg() map[string]*ast.File
- func (p *PackageInfo) IsRoot(pointer *PkgResolverPointer) bool
- func (p *PackageInfo) PkgForPointer(pointer *PkgResolverPointer) *ast.Package
- func (p *PackageInfo) PkgsForDir(dir string) map[string]*ast.Package
- func (p *PackageInfo) RootPointerForFileName(fileName string) *PkgResolverPointer
- type PkgResolverPointer
Constants ¶
This section is empty.
Variables ¶
var ( ErrAtleastOnePackageRequired error = fmt.Errorf("expected atleast one package") ErrIncorrectPackageAmount error = fmt.Errorf("unexpected amount of packages") ErrUnableToFindIdentifier error = fmt.Errorf("unable to find identifier") )
error definitions
Functions ¶
func FileFilter ¶
FileFilter filter files which should not be included in this case all files which end with _test.go
func GetImportSpecForIdentifierAndFile ¶
GetImportSpecForIdentifierAndFile Find an import spec for given identifier in given file
func ImportPathToFilePath ¶
func ImportPathToFilePath(i *ast.ImportSpec) (string, error)
ImportPathToFilePath converts an import path to file path
func TryToFindIdentifier ¶
TryToFindIdentifier in case this is hit, we got unresolved imports an example could be "somepkg/v2"
Types ¶
type PackageInfo ¶
type PackageInfo struct { RootDir string RootPkg string // map[dir][packagename]package: []Files PkgInfo map[string]map[string]*ast.Package }
PackageInfo package info contains information about a package defined in a directory
func (*PackageInfo) FileForPointer ¶
func (p *PackageInfo) FileForPointer(pointer *PkgResolverPointer) *ast.File
FileForPointer retrieve ast file for pointer
func (*PackageInfo) FindImport ¶
func (p *PackageInfo) FindImport(pointer *PkgResolverPointer, selector, identifier string) (bool, ast.Expr, *PkgResolverPointer)
FindImport finds a imported object on selector and identifier
func (*PackageInfo) FindInCurrent ¶
func (p *PackageInfo) FindInCurrent(pointer *PkgResolverPointer, identifier string) (bool, ast.Expr, *PkgResolverPointer)
FindInCurrent tries to find an indentifier in current package
func (*PackageInfo) GetRootPkg ¶
func (p *PackageInfo) GetRootPkg() map[string]*ast.File
GetRootPkg retrieve the root package
func (*PackageInfo) IsRoot ¶
func (p *PackageInfo) IsRoot(pointer *PkgResolverPointer) bool
IsRoot check if pointer is in root some decisions need to be based on this
func (*PackageInfo) PkgForPointer ¶
func (p *PackageInfo) PkgForPointer(pointer *PkgResolverPointer) *ast.Package
PkgForPointer retrieve ast package for pointer
func (*PackageInfo) PkgsForDir ¶
func (p *PackageInfo) PkgsForDir(dir string) map[string]*ast.Package
PkgsForDir resolve directory
func (*PackageInfo) RootPointerForFileName ¶
func (p *PackageInfo) RootPointerForFileName(fileName string) *PkgResolverPointer
RootPointerForFileName get root pointer for given filename
type PkgResolverPointer ¶
PkgResolverPointer pointer of a the package resolver used to identify where to look for specific values