Documentation
¶
Index ¶
- Variables
- func AnalyzeForeach(program *Program, initialPkg, initialObj string)
- func ExecCheck(fset *token.FileSet, pkg *Package)
- func FindFilePaths(path string) (paths []string)
- func Main(config *Config) error
- func NextPackagePaths(p *Package) (paths []string)
- func ParseAll(program *Program, initialPackage string, initialFilePaths []string)
- func ParseAst(fset *token.FileSet, p *Package, paths ...string)
- func Write(w io.Writer, program *Program) error
- type Annotation
- type CommonDecl
- func (d *CommonDecl) GetUses() DeclSet
- func (d *CommonDecl) ID() string
- func (d *CommonDecl) IsInitOrUnderScore() bool
- func (d *CommonDecl) IsUsed() bool
- func (d *CommonDecl) Node() ast.Node
- func (d *CommonDecl) Pkg() *Package
- func (d *CommonDecl) SetNode(n ast.Node)
- func (d *CommonDecl) String() string
- func (d *CommonDecl) Use()
- func (d *CommonDecl) Uses(decl Decl)
- type Config
- type Decl
- type DeclFinder
- type DeclSet
- type DeclType
- type DependencyResolver
- type Filter
- type Import
- type ImportSet
- type MethodDecl
- type Package
- type PackageSet
- type Program
- type TypeDecl
- func (d *TypeDecl) EachMethod(f func(m *MethodDecl))
- func (d *TypeDecl) GetMethod(m *MethodDecl) (*MethodDecl, bool)
- func (d *TypeDecl) GetMethodByName(name string) (*MethodDecl, bool)
- func (d *TypeDecl) KeepMethod()
- func (d *TypeDecl) Methods() []*MethodDecl
- func (d *TypeDecl) SetMethod(m *MethodDecl)
- func (d *TypeDecl) ShouldKeepMethods() bool
Constants ¶
This section is empty.
Variables ¶
var (
WarnOutput = os.Stderr
)
Functions ¶
func AnalyzeForeach ¶
AnalyzeForeach executes analyzing dependency for each packages.
func FindFilePaths ¶
FindFilePaths finds filepaths from package path. https://pkg.go.dev/golang.org/x/tools/go/packages?tab=doc#example-package
func NextPackagePaths ¶
NextPackagePaths returns list of imported package paths.
func ParseAll ¶
ParseAll parses all ast files and sets to Program's map. This also parses external imported package's ast.
Types ¶
type Annotation ¶
type Annotation string
Annotation is an annotation for doc text.
func (Annotation) String ¶
func (a Annotation) String() string
type CommonDecl ¶
type CommonDecl struct {
// contains filtered or unexported fields
}
CommonDecl represents one of Var, Const, Func declaration.
func NewCommonDecl ¶
func NewCommonDecl(pkg *Package, ids ...string) *CommonDecl
NewCommonDecl returns new CommonDecl. The length of ids must be one, and the value must be its name.
func (*CommonDecl) GetUses ¶ added in v1.4.0
func (d *CommonDecl) GetUses() DeclSet
func (*CommonDecl) ID ¶
func (d *CommonDecl) ID() string
ID returns id made by makeID(package-path, declName).
func (*CommonDecl) IsInitOrUnderScore ¶ added in v1.3.0
func (d *CommonDecl) IsInitOrUnderScore() bool
IsInitOrUnderScore return true if the Desc is init func or var declared with underscore.
func (*CommonDecl) IsUsed ¶
func (d *CommonDecl) IsUsed() bool
IsUsed returns true if it is used from main package.
func (*CommonDecl) Node ¶
func (d *CommonDecl) Node() ast.Node
Node returns ast.Node. Its field is initialized lazily.
func (*CommonDecl) String ¶
func (d *CommonDecl) String() string
func (*CommonDecl) Use ¶
func (d *CommonDecl) Use()
Use change this and its dependencies' used field to true.
func (*CommonDecl) Uses ¶
func (d *CommonDecl) Uses(decl Decl)
Uses sets given decl to dependency map.
type Config ¶
type Config struct { // path to main.go or glob of main package files InputFile string `yaml:"inputFile"` // list of output paths // filepath, 'stdout' or 'clipboard' are available OutputPaths []string `yaml:"outputPaths"` // package path prefixes treat as same as builtin packages. ThirdPartyPackagePathPrefixes []string `yaml:"thirdPartyPackagePathPrefixes"` // contains filtered or unexported fields }
Config is a configuration.
func DefaultConfig ¶ added in v1.4.0
func DefaultConfig() *Config
func UnmarshalConfig ¶ added in v1.4.0
type Decl ¶
type Decl interface { ID() string Node() ast.Node SetNode(ast.Node) Pkg() *Package IsUsed() bool Use() Uses(Decl) GetUses() DeclSet fmt.Stringer }
Decl represents a declaration.
type DeclFinder ¶
type DeclFinder struct {
// contains filtered or unexported fields
}
DeclFinder find package-level declarations and set it to DeclSet.
func NewDeclFinder ¶
func NewDeclFinder(dset DeclSet, iset *ImportSet, pkg *Package) *DeclFinder
NewDeclFinder returns new DeclFinder
func (*DeclFinder) Decl ¶
func (f *DeclFinder) Decl(decl ast.Decl)
Decl finds package-level declarations from ast.Decl.
func (*DeclFinder) Files ¶
func (f *DeclFinder) Files()
Files finds package-level declarations foreach file.decls concurrently.
func (*DeclFinder) FuncDecl ¶
func (f *DeclFinder) FuncDecl(decl *ast.FuncDecl)
FuncDecl finds package-level declarations from ast.FuncDecl.
func (*DeclFinder) GenDecl ¶
func (f *DeclFinder) GenDecl(decl *ast.GenDecl)
GenDecl finds package-level declarations from ast.GenDecl.
type DeclSet ¶
DeclSet is a set of Decl
func (DeclSet) GetOrCreate ¶
GetOrCreate gets Decl from set if exists, otherwise create new one and add to set then returns it.
func (DeclSet) ListInitOrUnderscore ¶ added in v1.3.0
ListInitOrUnderscore returns Decl list of init func or vars declared with underscore.
type DeclType ¶
type DeclType int
DeclType represents declaration type.
const ( // DecCommon represents common declaration type. // e.g, Var, Const, Func DecCommon DeclType // DecType represents type declaration type. // e.g, Struct, Interface DecType // DecMethod represents method declaration. DecMethod )
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
DependencyResolver provides a method for checking dependency.
func NewDependencyResolver ¶
func NewDependencyResolver(dset DeclSet, iset *ImportSet, pset PackageSet) *DependencyResolver
NewDependencyResolver returns new DependencyResolver
func (*DependencyResolver) Check ¶
func (r *DependencyResolver) Check(decl Decl)
Check checks on which given decl depending on.
func (*DependencyResolver) CheckEach ¶ added in v1.4.0
func (r *DependencyResolver) CheckEach(initial Decl)
func (*DependencyResolver) CheckEmbedded ¶
func (r *DependencyResolver) CheckEmbedded(decl Decl)
CheckEmbedded checks set a method inherit from to dependency set when the decl is embedded method.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter provides a method for filtering slice of ast.Decl.
func (*Filter) Decls ¶
Decls returns new slice that consists of used declarations. All unused declaration will be removed. Be careful this method manipulates decls directly.
func (*Filter) PackageSelectorExpr ¶
PackageSelectorExpr removes external package's selectors.
fmt.Println() → fmt.Println() // keep builtin packages mypkg.SomeFunc() → SomeFunc() // remove package selector
type Import ¶
type Import struct {
// contains filtered or unexported fields
}
Import represents import.
func (*Import) ToSpec ¶
func (i *Import) ToSpec() *ast.ImportSpec
ToSpec creates and returns ast.ImportSpec.
type ImportSet ¶
type ImportSet struct {
// contains filtered or unexported fields
}
ImportSet is a set of Import.
func (*ImportSet) AddAndGet ¶ added in v1.0.1
AddAndGet gets an Import form set if exists, otherwise creates new one and returns it.
func (*ImportSet) GetOrCreate ¶
GetOrCreate gets an Import form set if exists, otherwise creates new one and returns it.
type MethodDecl ¶
type MethodDecl struct { *CommonDecl // contains filtered or unexported fields }
MethodDecl represents method declaration.
func NewMethodDecl ¶
func NewMethodDecl(pkg *Package, ids ...string) *MethodDecl
NewMethodDecl returns new MethodDecl. Length of ids must be two, the head value is its receiver's type name and second value is func name.
func (*MethodDecl) IsEmbedded ¶
func (d *MethodDecl) IsEmbedded() bool
IsEmbedded returns true if it is embedded method.
func (*MethodDecl) SetEmbedded ¶
func (d *MethodDecl) SetEmbedded(b bool)
SetEmbedded change its embedded field to true.
func (*MethodDecl) SetType ¶
func (d *MethodDecl) SetType(t *TypeDecl)
SetType sets given TypeDecl to field.
func (*MethodDecl) Type ¶
func (d *MethodDecl) Type() *TypeDecl
Type returns TypeDecl this method belongs to. The field is initialized lazily.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents analyzing information.
func (*Package) InitObjects ¶
func (pkg *Package) InitObjects()
InitObjects compiles all files' objects into one map. This is called after parsing all ast files and before start analyzing dependencies.
func (*Package) PushAstFile ¶
PushAstFile push ast.File to files.
type PackageSet ¶
PackageSet is a map of Package.
func (PackageSet) Add ¶
func (p PackageSet) Add(path string, pkg *Package)
Add sets the Package to set.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a container of information that is necessary across packages.
type TypeDecl ¶
type TypeDecl struct { *CommonDecl // contains filtered or unexported fields }
TypeDecl represents Type declaration.
func NewTypeDecl ¶
NewTypeDecl returns new TypeDecl. The length of ids must be one, and the value must be the type name.
func (*TypeDecl) EachMethod ¶ added in v1.4.0
func (d *TypeDecl) EachMethod(f func(m *MethodDecl))
func (*TypeDecl) GetMethod ¶ added in v1.4.0
func (d *TypeDecl) GetMethod(m *MethodDecl) (*MethodDecl, bool)
func (*TypeDecl) GetMethodByName ¶ added in v1.4.0
func (d *TypeDecl) GetMethodByName(name string) (*MethodDecl, bool)
func (*TypeDecl) KeepMethod ¶
func (d *TypeDecl) KeepMethod()
KeepMethod set true its keep method option. When the field is true, all methods will not removed even the method is not used from main.
func (*TypeDecl) Methods ¶
func (d *TypeDecl) Methods() []*MethodDecl
Methods returns methods as a slice.
func (*TypeDecl) SetMethod ¶
func (d *TypeDecl) SetMethod(m *MethodDecl)
SetMethod sets given method to methods set.