imports

package
v0.0.0-...-786a137 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

imports defines an import manager that manages ident-to-imports relation. It is supposed to be used to add imports to existent files while keeping their existent imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Import

type Import struct {
	Path string
	Name string
}

type ImportMap

type ImportMap struct {
	// contains filtered or unexported fields
}

func (ImportMap) AddMissingImports

func (im ImportMap) AddMissingImports(df *dst.File)

AddMissingImports adds missing imports from imports to df, both *dst.File.Imports and the first import decl in *dst.File.Decls.

func (ImportMap) AstExpr

func (im ImportMap) AstExpr(ty TargetType) *ast.SelectorExpr

func (ImportMap) DstExpr

func (im ImportMap) DstExpr(ty TargetType) *dst.SelectorExpr

func (*ImportMap) Ident

func (im *ImportMap) Ident(path string) (string, bool)

func (ImportMap) MissingImports

func (im ImportMap) MissingImports() iter.Seq2[string, string]

func (ImportMap) Qualifier

func (im ImportMap) Qualifier(currentPkgPath string) types.Qualifier

Qualifier returns types.Qualifier that fully qualifies members of all packages other than currentPkgPath.

type ImportParser

type ImportParser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(pkg *types.Package) *ImportParser

func NewParserPackages

func NewParserPackages(pkgs []*packages.Package) *ImportParser

func (*ImportParser) AppendExtra

func (p *ImportParser) AppendExtra(imports ...TargetImport)

func (*ImportParser) Parse

func (p *ImportParser) Parse(importSpecs []*ast.ImportSpec) (ImportMap, error)

type TargetImport

type TargetImport struct {
	Import Import
	// may be empty
	Ident string
	Types []string
}

type TargetImports

type TargetImports map[string]TargetImport

func (TargetImports) Append

func (ti TargetImports) Append(imports ...TargetImport)

type TargetType

type TargetType struct {
	ImportPath string
	Name       string
}

func (TargetType) Is

func (t TargetType) Is(ty types.Type) bool

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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