Documentation ¶
Overview ¶
Package code is used to analyse Go code packages. It can find out all the implementation relations between package-level type.
Index ¶
- Constants
- func ComparePackagePaths(pa, pb string, sep byte) bool
- func ComparePackagePaths_ThreeWay(pa, pb string, sep byte) int
- func EmbededFieldsPath(embedding *EmbeddedField, b *strings.Builder, selName string, isField bool) (r string)
- func Kind(tt types.Type) reflect.Kind
- func PrintSelectors(title string, selectors []*Selector)
- type AstValueSpecOwner
- type Attribute
- type CodeAnalyzer
- func (d *CodeAnalyzer) AnalyzePackages(onSubTaskDone func(int, time.Duration, ...int32))
- func (d *CodeAnalyzer) BuildMethodSignatureFromFunctionSignature(funcSig *types.Signature, methodName string, pkgImportPath string) MethodSignature
- func (d *CodeAnalyzer) BuiltinPackge() *Package
- func (d *CodeAnalyzer) CheckTypeMethodContributingToTypeImplementations(pkg, typ, methodPkg, method string) bool
- func (d *CodeAnalyzer) CleanImplements(self *TypeInfo, includingUnnamed bool) []Implementation
- func (d *CodeAnalyzer) ExampleFileSet() *token.FileSet
- func (d *CodeAnalyzer) Id1(p *types.Package, name string) string
- func (d *CodeAnalyzer) Id1b(pkg *Package, name string) string
- func (d *CodeAnalyzer) Id2(p *types.Package, name string) string
- func (d *CodeAnalyzer) Id2b(pkg *Package, name string) string
- func (d *CodeAnalyzer) IsStandardPackage(pkg *Package) bool
- func (d *CodeAnalyzer) IsStandardPackageByPath(path string) bool
- func (d *CodeAnalyzer) IterateModule(f func(*Module))
- func (d *CodeAnalyzer) LookForType(t types.Type) *TypeInfo
- func (d *CodeAnalyzer) ModuleByPath(path string) *Module
- func (d *CodeAnalyzer) NumPackages() int
- func (d *CodeAnalyzer) NumSourceFiles() int
- func (d *CodeAnalyzer) ObjectReferences(obj types.Object) []Identifier
- func (d *CodeAnalyzer) PackageAt(i int) *Package
- func (d *CodeAnalyzer) PackageByPath(path string) *Package
- func (d *CodeAnalyzer) ParsePackages(onSubTaskDone func(int, time.Duration, ...int32), ...) error
- func (d *CodeAnalyzer) RegisterType(t types.Type) *TypeInfo
- func (d *CodeAnalyzer) RegisterTypeName(tn *TypeName)
- func (d *CodeAnalyzer) RetrieveNamedType(t *TypeInfo) (*TypeInfo, bool)
- func (d *CodeAnalyzer) RoughExportedIdentifierCount() int32
- func (d *CodeAnalyzer) RoughTypeNameCount() int32
- func (d *CodeAnalyzer) RuntimeFunctionCodePosition(f string) token.Position
- func (d *CodeAnalyzer) RuntimePackage() *Package
- func (d *CodeAnalyzer) SourceFile(pkgFile string) *SourceFileInfo
- func (d *CodeAnalyzer) StandardPackage(path string) *Package
- func (d *CodeAnalyzer) Statistics() Stats
- func (d *CodeAnalyzer) WorkingDirectoryModule() *Module
- type Constant
- func (c *Constant) AstValueSpec() *ast.ValueSpec
- func (c *Constant) Comment() string
- func (c *Constant) Documentation() string
- func (c *Constant) Exported() bool
- func (c *Constant) Package() *Package
- func (c *Constant) Position() token.Position
- func (c *Constant) TType() types.Type
- func (c *Constant) TypeInfo(d *CodeAnalyzer) *TypeInfo
- type EmbedMode
- type EmbeddedField
- type Example
- type Field
- type Function
- func (f *Function) AstFuncType() *ast.FuncType
- func (f *Function) AstPackage() *Package
- func (f *Function) Comment() string
- func (f *Function) Documentation() string
- func (f *Function) Exported() bool
- func (f *Function) IsMethod() bool
- func (f *Function) Name() string
- func (f *Function) Package() *Package
- func (f *Function) Position() token.Position
- func (f *Function) ReceiverTypeName() (paramField *ast.Field, typename *TypeName, isStar bool)
- func (f *Function) String() string
- func (f *Function) TType() types.Type
- func (f *Function) TypeInfo(d *CodeAnalyzer) *TypeInfo
- type FunctionResource
- type Identifier
- type Implementation
- type Import
- type InstantiatedInfo
- type InterfaceMethod
- func (im *InterfaceMethod) AstFuncType() *ast.FuncType
- func (im *InterfaceMethod) AstPackage() *Package
- func (im *InterfaceMethod) Comment() string
- func (im *InterfaceMethod) Documentation() string
- func (im *InterfaceMethod) Exported() bool
- func (im *InterfaceMethod) IsMethod() bool
- func (im *InterfaceMethod) Name() string
- func (im *InterfaceMethod) Package() *Package
- func (im *InterfaceMethod) Position() token.Position
- func (im *InterfaceMethod) ReceiverTypeName() (paramField *ast.Field, typename *TypeName, isStar bool)
- func (im *InterfaceMethod) String() string
- func (im *InterfaceMethod) TType() types.Type
- func (im *InterfaceMethod) TypeInfo(d *CodeAnalyzer) *TypeInfo
- type LoadError
- type Method
- type MethodSignature
- type Module
- type Package
- func (pkg *Package) BuildResourceLookupTable()
- func (p *Package) ChildByPath(path string) *Package
- func (p *Package) IsFake() bool
- func (p *Package) Module() *Module
- func (p *Package) ModulePath() string
- func (p *Package) ParentPackage() *Package
- func (p *Package) RelPathInModule() string
- func (pkg *Package) SearchResourceByName(name string) Resource
- func (pkg *Package) SourceFileInfoByBareFilename(bareFilename string) *SourceFileInfo
- func (pkg *Package) SourceFileInfoByFilePath(srcPath string) *SourceFileInfo
- type PackageAnalyzeResult
- type Resource
- type Selector
- func (s *Selector) Name() string
- func (s *Selector) Object() types.Object
- func (s *Selector) Package() *Package
- func (s *Selector) PointerReceiverOnly() bool
- func (s *Selector) Position() token.Position
- func (s *Selector) Reset()
- func (s *Selector) String() string
- func (s *Selector) Type() *TypeInfo
- type SelectorCond
- type SeleterMapManager
- type SourceFileInfo
- type Stats
- type ToolchainInfo
- type TopList
- type TypeExpr
- type TypeInfo
- type TypeName
- type ValueResource
- type Variable
- func (v *Variable) AstValueSpec() *ast.ValueSpec
- func (v *Variable) Comment() string
- func (v *Variable) Documentation() string
- func (v *Variable) Exported() bool
- func (v *Variable) Package() *Package
- func (v *Variable) Position() token.Position
- func (v *Variable) TType() types.Type
- func (v *Variable) TypeInfo(d *CodeAnalyzer) *TypeInfo
Constants ¶
const ( SubTask_PreparationDone = iota SubTask_NFilesParsed SubTask_ParsePackagesDone SubTask_CollectPackages SubTask_CollectModules SubTask_CollectExamples SubTask_SortPackagesByDependencies SubTask_CollectDeclarations SubTask_CollectRuntimeFunctionPositions //SubTask_ConfirmTypeSources SubTask_CollectMoreTypes SubTask_CollectSelectors SubTask_CheckCollectedSelectors SubTask_FindImplementations SubTask_RegisterInterfaceMethodsForTypes SubTask_MakeStatistics SubTask_CollectSourceFiles SubTask_CollectObjectReferences SubTask_CacheSourceFiles )
The analysis steps.
const KindCount = reflect.UnsafePointer + 1
Variables ¶
This section is empty.
Functions ¶
func ComparePackagePaths ¶ added in v0.5.4
Should be faster than using strings.Split or Strings.Tokens Return true for pa <= pb.
func ComparePackagePaths_ThreeWay ¶ added in v0.5.4
func EmbededFieldsPath ¶
func EmbededFieldsPath(embedding *EmbeddedField, b *strings.Builder, selName string, isField bool) (r string)
EmbededFieldsPath returns the string representation the middle embedding chain of a Selector.
func PrintSelectors ¶
PrintSelectors prints a lists of Selectors.
Types ¶
type AstValueSpecOwner ¶
AstValueSpecOwneris an interface for Variable/Constant.
type Attribute ¶
type Attribute uint32
A Attribute records some imformations by using bits.
const ( // Higher bits are for runtime-only flags. AtributesPersistentMask Attribute = (1 << 25) - 1 // For functions, type aliases and named types. Builtin Attribute = 1 << 0 // For type aliases and named types. Embeddable Attribute = 1 << 1 PtrEmbeddable Attribute = 1 << 2 // For unnamed struct and interface types. HasUnexporteds Attribute = 1 << 3 // For all types. Defined Attribute = 1 << 4 Comparable Attribute = 1 << 5 // For channel types. Sendable Attribute = 1 << 6 Receivable Attribute = 1 << 7 // For functions. Variadic Attribute = 1 << 8 // For methods. StarReceiver Attribute = 1 << 9 // For type names. Alias Attribute = 1 << 10 )
type CodeAnalyzer ¶
type CodeAnalyzer struct {
// contains filtered or unexported fields
}
CodeAnalyzer holds all the analysis results and functionalities.
func (*CodeAnalyzer) AnalyzePackages ¶
func (d *CodeAnalyzer) AnalyzePackages(onSubTaskDone func(int, time.Duration, ...int32))
AnalyzePackages analyzes the input packages.
func (*CodeAnalyzer) BuildMethodSignatureFromFunctionSignature ¶
func (d *CodeAnalyzer) BuildMethodSignatureFromFunctionSignature(funcSig *types.Signature, methodName string, pkgImportPath string) MethodSignature
BuildMethodSignatureFromFunctionSignature builds the signature for method function object. pkgImportPath should be only passed for unexported method names.
func (*CodeAnalyzer) BuiltinPackge ¶
func (d *CodeAnalyzer) BuiltinPackge() *Package
BuiltinPackge returns the builtin package.
func (*CodeAnalyzer) CheckTypeMethodContributingToTypeImplementations ¶
func (d *CodeAnalyzer) CheckTypeMethodContributingToTypeImplementations(pkg, typ, methodPkg, method string) bool
CheckTypeMethodContributingToTypeImplementations checks whether or not a method implements some interface methods.
func (*CodeAnalyzer) CleanImplements ¶
func (d *CodeAnalyzer) CleanImplements(self *TypeInfo, includingUnnamed bool) []Implementation
CleanImplements returns a clean list of the implementions for a TypeInfo.
func (*CodeAnalyzer) ExampleFileSet ¶ added in v0.2.8
func (d *CodeAnalyzer) ExampleFileSet() *token.FileSet
func (*CodeAnalyzer) Id1 ¶
func (d *CodeAnalyzer) Id1(p *types.Package, name string) string
Id1 builds an id from the specified package and identifier name. The result is the same as go/types.Id.
func (*CodeAnalyzer) Id1b ¶
func (d *CodeAnalyzer) Id1b(pkg *Package, name string) string
Id1b builds an id from the specified package and identifier name. The result is almost the same as go/types.Id.
func (*CodeAnalyzer) Id2 ¶
func (d *CodeAnalyzer) Id2(p *types.Package, name string) string
Id2 builds an id from the specified package and identifier name.
func (*CodeAnalyzer) Id2b ¶
func (d *CodeAnalyzer) Id2b(pkg *Package, name string) string
Id2b builds an id from the specified package and identifier name.
func (*CodeAnalyzer) IsStandardPackage ¶
func (d *CodeAnalyzer) IsStandardPackage(pkg *Package) bool
IsStandardPackage returns whether or not the given package is a standard package.
func (*CodeAnalyzer) IsStandardPackageByPath ¶
func (d *CodeAnalyzer) IsStandardPackageByPath(path string) bool
IsStandardPackageByPath returns whether or not the package specified by the path is a standard package.
func (*CodeAnalyzer) IterateModule ¶ added in v0.2.7
func (d *CodeAnalyzer) IterateModule(f func(*Module))
IterateModule iterates all modules and passes them to the specified callback f.
func (*CodeAnalyzer) LookForType ¶ added in v0.2.7
func (d *CodeAnalyzer) LookForType(t types.Type) *TypeInfo
LookForType trys to find out the TypeInfo registered for the spefified types.Type.
func (*CodeAnalyzer) ModuleByPath ¶ added in v0.2.7
func (d *CodeAnalyzer) ModuleByPath(path string) *Module
ModuleByPath returns the module corresponding the specified path.
func (*CodeAnalyzer) NumPackages ¶
func (d *CodeAnalyzer) NumPackages() int
NumPackages returns packages count.
func (*CodeAnalyzer) NumSourceFiles ¶
func (d *CodeAnalyzer) NumSourceFiles() int
NumSourceFiles returns the source files count.
func (*CodeAnalyzer) ObjectReferences ¶
func (d *CodeAnalyzer) ObjectReferences(obj types.Object) []Identifier
ObjectReferences returns all the references to the given object.
func (*CodeAnalyzer) PackageAt ¶
func (d *CodeAnalyzer) PackageAt(i int) *Package
PackageAt returns the packages at specified index i.
func (*CodeAnalyzer) PackageByPath ¶
func (d *CodeAnalyzer) PackageByPath(path string) *Package
PackageByPath returns the packages corresponding the specified path.
func (*CodeAnalyzer) ParsePackages ¶
func (d *CodeAnalyzer) ParsePackages(onSubTaskDone func(int, time.Duration, ...int32), completeModuleInfo func(*Module), toolchain ToolchainInfo, args ...string) error
ParsePackages parses input packages.
func (*CodeAnalyzer) RegisterType ¶
func (d *CodeAnalyzer) RegisterType(t types.Type) *TypeInfo
RegisterType registers a go/types.Type as TypeInfo.
func (*CodeAnalyzer) RegisterTypeName ¶
func (d *CodeAnalyzer) RegisterTypeName(tn *TypeName)
RegisterTypeName registers a TypeName. Only origin ones should be registered.
func (*CodeAnalyzer) RetrieveNamedType ¶ added in v0.5.4
func (d *CodeAnalyzer) RetrieveNamedType(t *TypeInfo) (*TypeInfo, bool)
RetrieveTypeName trys to retrieve the TypeName from a TypeInfo.
func (*CodeAnalyzer) RoughExportedIdentifierCount ¶
func (d *CodeAnalyzer) RoughExportedIdentifierCount() int32
RoughExportedIdentifierCount returns a rough number of exported identifiers.
func (*CodeAnalyzer) RoughTypeNameCount ¶
func (d *CodeAnalyzer) RoughTypeNameCount() int32
RoughTypeNameCount returns a rough number of all type names.
func (*CodeAnalyzer) RuntimeFunctionCodePosition ¶
func (d *CodeAnalyzer) RuntimeFunctionCodePosition(f string) token.Position
RuntimeFunctionCodePosition returns the position of the specified runtime function f.
func (*CodeAnalyzer) RuntimePackage ¶
func (d *CodeAnalyzer) RuntimePackage() *Package
RuntimePackage returns the runtime package.
func (*CodeAnalyzer) SourceFile ¶ added in v0.2.7
func (d *CodeAnalyzer) SourceFile(pkgFile string) *SourceFileInfo
SourceFile returns the source file coresponding the specified file name. pkgFile: pkg.Path + "/" + file.BareFilename
func (*CodeAnalyzer) StandardPackage ¶ added in v0.5.4
func (d *CodeAnalyzer) StandardPackage(path string) *Package
func (*CodeAnalyzer) Statistics ¶
func (d *CodeAnalyzer) Statistics() Stats
Statistics returns the analysis statistics data.
func (*CodeAnalyzer) WorkingDirectoryModule ¶ added in v0.2.7
func (d *CodeAnalyzer) WorkingDirectoryModule() *Module
WorkingDirectoryModule returns the module at the working directory. It might be nil.
type Constant ¶
type Constant struct { *types.Const Type *TypeInfo Pkg *Package // some duplicated with types.Const.Pkg() AstDecl *ast.GenDecl AstSpec *ast.ValueSpec }
Constant represents a constant.
func (*Constant) AstValueSpec ¶
AstValueSpec returns the go/ast.ValueSpec for a Constant.
func (*Constant) Documentation ¶
Documentation returns the document of a Constant.
func (*Constant) TypeInfo ¶
func (c *Constant) TypeInfo(d *CodeAnalyzer) *TypeInfo
TypeInfo returns the type of a Constant.
type EmbeddedField ¶
type EmbeddedField struct { *Field Prev *EmbeddedField }
EmbeddedField represengts am embedded field.
type Field ¶
type Field struct { AstField *ast.Field Pkg *Package // (nil for exported. ??? Seems not true.) Name string Type *TypeInfo Tag string Mode EmbedMode // contains filtered or unexported fields }
Field represents a struct field.
func (*Field) Documentation ¶ added in v0.1.7
Documentation returns the documents of a Field.
type Function ¶
type Function struct { *types.Func *types.Builtin // for builtin functions Type *TypeInfo Pkg *Package // some duplicated with types.Func.Pkg(), except builtin functions AstDecl *ast.FuncDecl // contains filtered or unexported fields }
Function represents a function, including non-interface methods.
func (*Function) AstFuncType ¶
AstFuncType returns the go/ast.FuncType for a Function.
func (*Function) AstPackage ¶
AstPackage returns the same as Package().
func (*Function) Documentation ¶
Documentation return document of a Function.
func (*Function) ReceiverTypeName ¶
ReceiverTypeName returns the TypeName and whether or not the receiver is a pointer for a method function.
func (*Function) TypeInfo ¶
func (f *Function) TypeInfo(d *CodeAnalyzer) *TypeInfo
TypeInfo returns the tyoe of a Function.
type FunctionResource ¶
type FunctionResource interface { ValueResource IsMethod() bool //ReceiverTypeName() (paramField *ast.Field, typeIdent *ast.Ident, isStar bool) ReceiverTypeName() (paramField *ast.Field, typename *TypeName, isStar bool) AstFuncType() *ast.FuncType // For *Function, the result is the same as ValueResource.Package(). // For *InterfaceMethod, this might be different (caused by embedding, or other reasons). AstPackage() *Package }
FunctionResource is an interface for Function/InterfaceMethod.
type Identifier ¶
type Identifier struct { FileInfo *SourceFileInfo AstIdent *ast.Ident }
Identifier represents an identifier occurrence in code.
type Implementation ¶
type Implementation struct { Impler *TypeInfo // a struct or named type (same as the owner), or a pointer to such a type Interface *TypeInfo // an interface type }
Implementation represents an implementation relation.
type Import ¶
type Import struct { *types.PkgName Pkg *Package // some duplicated with types.PkgName.Pkg() AstDecl *ast.GenDecl AstSpec *ast.ImportSpec }
Import represents an import.
type InstantiatedInfo ¶ added in v0.5.4
type InstantiatedInfo struct {
TypeArgs []TypeExpr
}
type InterfaceMethod ¶
type InterfaceMethod struct { InterfaceTypeName *TypeName //Method *Method // .AstFunc == nil, .AstField != nil Selector *Selector // .Method.AstFunc == nil,.Method .AstField != nil }
InterfaceMethod represents an interface function.
func (*InterfaceMethod) AstFuncType ¶
func (im *InterfaceMethod) AstFuncType() *ast.FuncType
AstFuncType returns the go/ast.FuncType for a InterfaceMethod.
func (*InterfaceMethod) AstPackage ¶
func (im *InterfaceMethod) AstPackage() *Package
AstPackage returns the Package where a InterfaceMethodis is specified. For embedding reason. The result might be different from the owner package.
func (*InterfaceMethod) Comment ¶
func (im *InterfaceMethod) Comment() string
Name returns the comment of a InterfaceMethod.
func (*InterfaceMethod) Documentation ¶
func (im *InterfaceMethod) Documentation() string
Name returns the document of a InterfaceMethod.
func (*InterfaceMethod) Exported ¶
func (im *InterfaceMethod) Exported() bool
Name returns whether or not a InterfaceMethod is exported.
func (*InterfaceMethod) IsMethod ¶
func (im *InterfaceMethod) IsMethod() bool
Name always returns true.
func (*InterfaceMethod) Name ¶
func (im *InterfaceMethod) Name() string
Name returns the name of a InterfaceMethod.
func (*InterfaceMethod) Package ¶
func (im *InterfaceMethod) Package() *Package
Name returns the owner Package of a InterfaceMethod.
func (*InterfaceMethod) Position ¶
func (im *InterfaceMethod) Position() token.Position
Name returns the code position of a InterfaceMethod.
func (*InterfaceMethod) ReceiverTypeName ¶
func (im *InterfaceMethod) ReceiverTypeName() (paramField *ast.Field, typename *TypeName, isStar bool)
ReceiverTypeName returns the TypeName and whether or not the receiver is a pointer for a method function.
func (*InterfaceMethod) String ¶
func (im *InterfaceMethod) String() string
Name returns the string representation of a InterfaceMethod.
func (*InterfaceMethod) TType ¶
func (im *InterfaceMethod) TType() types.Type
Name returns the go/types.Type for a InterfaceMethod.
func (*InterfaceMethod) TypeInfo ¶
func (im *InterfaceMethod) TypeInfo(d *CodeAnalyzer) *TypeInfo
Name returns the type of a InterfaceMethod.
type Method ¶
type Method struct { AstFunc *ast.FuncDecl // for concrete methods //AstInterface *ast.InterfaceType // for interface methods (the owner interface) AstField *ast.Field // for interface methods Pkg *Package // (nil for exported. ??? Seems not true.) Name string Type *TypeInfo // ToDo: use custom struct including PointerRecv instead. PointerRecv bool // duplicated info, for faster access ImplementsSomething bool // false if the method is unimportant for its reveiver to implement some interface type //>> 1.18, ToDo Parameterized bool // Containing parameter types which are parameterized. // contains filtered or unexported fields }
Method represent a method.
func (*Method) Documentation ¶ added in v0.1.7
Documentation returns the document of a Method.
type MethodSignature ¶
type MethodSignature struct { Name string // must be an identifier other than "_" Pkg string // the import path, for unepxorted method names only //InOutTypes []int32 // global type indexes InOutTypes string NumInOutAndVariadic int }
MethodSignature represents a hashable struct for a method.
type Module ¶
type Module struct { Index int // users might make some optimizations by using the index Dir string // might be blank for vendored modules Path string Version string // ... Replace moduleReplacement RepositoryCommit string // might be the same as Version, or not. RepositoryURL string RepositoryDir string // no much useful // Generally blank. But // 1. "/src" for std and "/src/cmd" for toolchain. // 2. Some modules are not at the root of their repositories. // (Often, such a repository contains multiple modules. // ex., for github.com/aws/aws-sdk-go-v2/service/{ec2,s3}, // they are service/s3, service/ec2) ExtraPathInRepository string Pkgs []*Package // seen packages // contains filtered or unexported fields }
A Module holds the information for a Go module.
func (*Module) ActualPath ¶ added in v0.2.8
func (*Module) ActualVersion ¶ added in v0.2.8
func (*Module) PackageByPath ¶ added in v0.5.4
ToDo: build a trie to run faster?
type Package ¶
type Package struct { Index int // ToDo: use this to do some optimizations PPkg *packages.Package // ToDo: renamed to PP to be consistent with TypeInfo.TT? Path string Deps []*Package DepedBys []*Package DepHeight int32 // 0 means the height is not determined yet. The order determines the parse order. DepDepth int32 // 0 means the depth is not determined yet. The value mains how close to main pacakges. (Moved to user space). // This field might be shared with PackageForDisplay // for concurrent reads. *PackageAnalyzeResult // ToDo: not as pointer? AllResources map[string]Resource // ToDo: use a slice to save memory SourceFiles []SourceFileInfo ExampleFiles []*ast.File Examples []*doc.Example OneLineDoc string Directory string // contains filtered or unexported fields }
Package holds the information and the analysis result of a Go package.
func (*Package) BuildResourceLookupTable ¶ added in v0.5.4
func (pkg *Package) BuildResourceLookupTable()
ToDo: build a trie to run faster
func (*Package) ChildByPath ¶ added in v0.5.4
func (*Package) ModulePath ¶ added in v0.5.2
ModulePath returns the module path of a Package.
func (*Package) ParentPackage ¶ added in v0.5.4
func (*Package) RelPathInModule ¶ added in v0.5.4
func (*Package) SearchResourceByName ¶ added in v0.5.4
func (*Package) SourceFileInfoByBareFilename ¶ added in v0.2.8
func (pkg *Package) SourceFileInfoByBareFilename(bareFilename string) *SourceFileInfo
SourceFileInfoByBareFilename returns the SourceFileInfo corresponding the specified bare filename.
func (*Package) SourceFileInfoByFilePath ¶ added in v0.2.8
func (pkg *Package) SourceFileInfoByFilePath(srcPath string) *SourceFileInfo
SourceFileInfoByFilePath return the SourceFileInfo corresponding the specified file path.
type PackageAnalyzeResult ¶
type PackageAnalyzeResult struct { AllTypeNames []*TypeName // not including instantiated ones AllFunctions []*Function // not including instantiated ones AllVariables []*Variable AllConstants []*Constant AllImports []*Import CodeLinesWithBlankLines int32 // contains filtered or unexported fields }
PackageAnalyzeResult holds the analysis result of a Go package.
func NewPackageAnalyzeResult ¶
func NewPackageAnalyzeResult() *PackageAnalyzeResult
NewPackageAnalyzeResult returns a new initialized PackageAnalyzeResult.
func (*PackageAnalyzeResult) TypeNameByName ¶ added in v0.5.4
func (pr *PackageAnalyzeResult) TypeNameByName(name string) *TypeName
type Resource ¶
type Resource interface { Name() string Exported() bool //IndexString() string Documentation() string Comment() string Position() token.Position Package() *Package }
Resource is an interface for Variable/Constant/TypeName/Function/InterfaceMethod.
type Selector ¶
type Selector struct { Id string // One and only one of the two is nil. *Field *Method //>> 1.18 Instantiated *InstantiatedInfo RealType *TypeInfo EmbeddingChain *EmbeddedField // in the inverse order Depth uint16 // the chain length Indirect bool // whether the chain contains indirects or not // contains filtered or unexported fields }
Selector represents a selector, either a field or a method.
func (*Selector) PointerReceiverOnly ¶
PointerReceiverOnly returns whether or not a method selector is declared for a pointer type.
type SelectorCond ¶
type SelectorCond uint8
const ( SelectorCond_Normal SelectorCond = iota SelectorCond_Hidden )
type SeleterMapManager ¶
type SeleterMapManager struct {
// contains filtered or unexported fields
}
type SourceFileInfo ¶
type SourceFileInfo struct { Pkg *Package // to remove one field in Identifier. Also good to external source line generation. // Filename only. BareFilename string BareGeneratedFilename string // The full path of a (Go or others) source file. // It might be blank for some cgo generated files. OriginalFile string // The followings are blank for most files. GeneratedFile string // Non-nil for Go files. // If an original Go file has a corresponding generated file, // then the ast file is for that generated file. AstFile *ast.File // ... Content []byte }
func (*SourceFileInfo) AstBareFileName ¶
func (info *SourceFileInfo) AstBareFileName() string
type Stats ¶
type Stats struct { Packages int32 StdPackages int32 AllPackageDeps int32 PackagesByDeps [100]int32 PackagesDepsTopList TopList FilesWithoutGenerateds int32 // without generated ones FilesWithGenerateds int32 // with generated ones // To calculate imports per file. // Deps per packages are available in other ways. AstFiles int32 Imports int32 FilesByImportCount [100]int32 FilesImportCountTopList TopList CodeLinesWithBlankLines int32 FilesByCodeLinesWithBlankLines [100]int32 FilesCodeLineTopList TopList PackagesByCodeLinesWithBlankLines [100]int32 PackagesCodeLineTopList TopList // Types ExportedTypeNamesByKind [KindCount]int32 ExportedTypeNames int32 ExportedTypeAliases int32 ExportedCompositeTypeNames int32 ExportedBasicTypeNames int32 ExportedNumericTypeNames int32 ExportedIntergerTypeNames int32 ExportedUnsignedTypeNames int32 //ExportedNamedStructTypeNames int32 // should be equal to ExportedTypeNamesByKind[reflect.Struct] ExportedNamedStructTypesWithEmbeddingFields int32 ExportedNamedStructTypesWithPromotedFields int32 ExportedNamedStructTypeFields int32 ExportedNamedStructTypeExplicitFields int32 ExportedNamedStructTypeExportedFields int32 ExportedNamedStructTypeExportedExplicitFields int32 ExportedNamedStructsByEmbeddingFieldCount [100]int32 ExportedNamedStructsEmbeddingFieldCountTopList TopList ExportedNamedStructsByFieldCount [100]int32 // including promoteds and non-exporteds ExportedNamedStructsFieldCountTopList TopList ExportedNamedStructsByExplicitFieldCount [100]int32 // including non-exporteds but not including promoted ExportedNamedStructsExplicitFieldCountTopList TopList ExportedNamedStructsByExportedFieldCount [100]int32 // including promoteds ExportedNamedStructsExportedFieldCountTopList TopList ExportedNamedStructsByExportedExplicitFieldCount [100]int32 // not including promoteds ExportedNamedStructsExportedExplicitFieldCount TopList ExportedNamedStructsByExportedPromotedFieldCount [100]int32 ExportedNamedStructsExportedPromotedFieldCount TopList ExportedNamedNonInterfaceTypesByMethodCount [100]int32 // T and *T combined ExportedNamedNonInterfaceTypesByExportedMethodCount [100]int32 // T and *T combined ExportedNamedNonInterfaceTypesExportedMethodCountTopList TopList ExportedNamedNonInterfacesExportedMethods int32 ExportedNamedNonInterfacesWithExportedMethods int32 ExportedNamedInterfacesByMethodCount [100]int32 ExportedNamedInterfacesByExportedMethodCount [100]int32 // the last element means (N-1)+ ExportedNamedInterfacesExportedMethodCountTopList TopList ExportedNamedInterfacesExportedMethods int32 // Values ExportedVariables int32 ExportedConstants int32 ExportedFunctions int32 ExportedMethods int32 // non-interface methods ExportedVariablesByTypeKind [KindCount]int32 ExportedConstantsByTypeKind [KindCount]int32 // ToDo: Methods corresponding the same interface method should be viewed as one method in counting. ExportedFunctionParameters int32 // including methods ExportedFunctionResults int32 // including methods ExportedFunctionWithLastErrorResult int32 // including methods ExportedFunctionsByParameterCount [100]int32 // including methods ExportedFunctionsParameterCountTopList TopList ExportedFunctionsByResultCount [100]int32 // including methods ExportedFunctionsResultCountTopList TopList // Others. ExportedIdentifers int32 ExportedIdentifersSumLength int32 ExportedIdentifiersByLength [100]int32 ExportedIdentiferLengthTopList TopList // contains filtered or unexported fields }
A Stats hold all the analysis statistics data.
type ToolchainInfo ¶ added in v0.3.2
type TopList ¶ added in v0.2.0
type TopList struct { Criteria int Items []interface{} }
A TopList specifies the minimu criteria for a top list and hold the top list items.
type TypeInfo ¶
type TypeInfo struct { TT types.Type // ToDo: Exprs []ast.Expr Underlying *TypeInfo //>> 1.18 // For named types only. // For an origin named type, Instantiated is always nil, and this == TypeName.Denoting. // For an instantiated type, Instantiated should not be nil, and this != TypeName.Denoting. // But for some diffcualies, the Instantiated field if an instantiated type is nil, // in which case, the selectors of the instantiated type is incomplete. // // ToDo: the Origin field might be useless. It is this if TypeName is nil, otherwise, it is TypeName.Denoting. //Origin *TypeInfo TypeName *TypeName Instantiated *InstantiatedInfo //Implements []*TypeInfo //StarImplements []*TypeInfo // if TT is neither pointer nor interface. Implements []Implementation // For interface types. ImplementedBys []*TypeInfo // Aliases []*TypeName // ToDo: For unnamed and builtin basic types. Underlieds []*TypeName // Explicit fields and methods. // * For named types, only explicitly declared methods are included. // The field is only built for T. (*T).DirectSelectors is always nil. // * For named interface types, all explicitly specified methods and embedded types (as fields). // * For unnamed struct types, only direct fields. Only built for strct{...}, not for *struct{...}. // ToDo: note, for a type may have many alias, the ast.Expr (for types) // recorded in a Selector is just one of many possibilities. DirectSelectors []*Selector EmbeddingFields int32 // for struct types only now. ToDo: also for interface types. // All methods, including extended/promoted ones. AllMethods []*Selector // All fields, including promoted ones. AllFields []*Selector // Ror rendering links in doc comments. // Built as neede. AllSelectors map[string]*Selector // For .TypeName != nil AsTypesOf []ValueResource // variables and constants AsInputsOf []ValueResource // variables and functions AsOutputsOf []ValueResource // variables and functions // contains filtered or unexported fields }
TypeInfo represents a type and records its analysis result.
func (*TypeInfo) SelectorByName ¶ added in v0.5.4
type TypeName ¶
type TypeName struct { Pkg *Package // some duplicated with types.TypeName.Pkg(), except builtin types AstDecl *ast.GenDecl AstSpec *ast.TypeSpec // For alias TypeName, Source.Type is the denoting type. Source TypeExpr TypeParams []TypeExpr // It this is an alias, then Denoting is also the Source type. Denoting *TypeInfo *types.TypeName // contains filtered or unexported fields }
func (*TypeName) Documentation ¶
Documentation returns the documents of a TypeName.
type ValueResource ¶
type ValueResource interface { Resource TType() types.Type // The result should not be used in comparisons. TypeInfo(d *CodeAnalyzer) *TypeInfo }
ValueResource is an interface for Variable/Constant/Function/InterfaceMethod..
type Variable ¶
type Variable struct { *types.Var Type *TypeInfo Pkg *Package // some duplicated with types.Var.Pkg() AstDecl *ast.GenDecl AstSpec *ast.ValueSpec }
Variable represents a variable.
func (*Variable) AstValueSpec ¶
AstValueSpec returns the go/ast.ValueSpec for a Variable.
func (*Variable) Documentation ¶
Documentation returns the document of a Variable.
func (*Variable) TypeInfo ¶
func (v *Variable) TypeInfo(d *CodeAnalyzer) *TypeInfo
TypeInfo returns the type of a Variable.