Documentation
¶
Index ¶
- func BytesToAST(data []byte) (ast.Node, *token.FileSet, error)
- func CastNode[T ast.Node](n Node) (T, bool)
- func FindAnnotations[T any](a []Annotation) []T
- func Process(projectRoot, logLv string)
- func Register[T Annotation](processor AnnotationProcessor)
- func RegisterNoop[T Annotation]()
- type Annotation
- type AnnotationProcessor
- type Lookup
- type Meta
- type Node
- type Rerunable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToAST ¶
BytesToAST conversion some bytes to ast.Node
func FindAnnotations ¶
func FindAnnotations[T any](a []Annotation) []T
FindAnnotations returns all annotation with particular type
func Process ¶
func Process(projectRoot, logLv string)
Process is entry point for parsing project annotations
func Register ¶
func Register[T Annotation](processor AnnotationProcessor)
func RegisterNoop ¶
func RegisterNoop[T Annotation]()
Types ¶
type Annotation ¶
type Annotation any
type AnnotationProcessor ¶
type Lookup ¶
type Lookup interface {
// FindImportByAlias returns related import for alias in current ast.File.
// For example:
// import "github.com/bincooo/go-annotation/internal/tag"
// ...
// tag.Parse(...)
// FindImportByAlias("tag") returns "github.com/bincooo/go-annotation/internal/tag", true
FindImportByAlias(alias string) (string, bool)
// FindNodeByAlias returns related Node by alias, related import if any and a type/function name from related module
// if alias is empty, then the search will go in current directory of ast.File
FindNodeByAlias(alias, nodeName string) (Node, string, error)
GetFSet() *token.FileSet
}
Lookup provides API to retrieve related AST entities by dependency for a node at processing time
type Meta ¶
type Meta interface {
// Root returns related module root (absolut path)
Root() string
// Dir returns absolut path to the file directory
Dir() string
// FileName returns file name with extension
FileName() string
// PackageName returns current package name
PackageName() string
// LocalPackageOf returns the file package
LocalPackage() string
}
Meta contains node metadata. At any point of processing the framework works with an AST node that is located in some file/package/module The interface provides meta information about current node
type Node ¶
type Node interface {
// Annotations returns all annotations declared for ast.Node
Annotations() []Annotation
// ASTNode returns ast.Node that currently is in processing
ASTNode() ast.Node
// AnnotatedNode returns annotation.Node by ast.Node that declared as a sub ast.Node for ASTNode()
AnnotatedNode(ast.Node) Node
// ParentNode returns parent annotation.Node by current. false is returned if there is no parents for ast.Node
ParentNode() (Node, bool)
// Imports returns all file imports ([]*ast.ImportSpec)
Imports() []*ast.ImportSpec
// IsSamePackage compares nodes by module root, file location and package name
IsSamePackage(v Node) bool
// Lookup returns a lookup module
Lookup() Lookup
// Meta returns node metadata
Meta() Meta
}
Click to show internal directories.
Click to hide internal directories.