Documentation
¶
Overview ¶
Package join provides implementations of the InjectionPoint interface for common injection points.
Index ¶
- func AllOf(requirements ...Point) allOf
- func Configuration(requirements map[string]string) configuration
- func DeclarationOf(importPath string, name string) *declarationOf
- func Directive(name string) directive
- func Function(opts ...FunctionOption) *functionDeclaration
- func FunctionBody(up Point) *functionBody
- func FunctionCall(importPath string, name string) *functionCall
- func ImportPath(name string) importPath
- func Not(jp Point) not
- func OneOf(candidates ...Point) oneOf
- func PackageFilter(root bool, pattern string) packageFilter
- func PackageName(name string) packageName
- func StructDefinition(typeName typed.TypeName) *structDefinition
- func StructLiteral(typeName typed.TypeName, match StructLiteralMatch) *structLiteral
- func StructLiteralField(typeName typed.TypeName, field string) *structLiteral
- func TestMain(v bool) testMain
- func ValueDeclaration(typeName typed.TypeName) *valueDeclaration
- type FunctionOption
- func ArgumentImplements(interfaceName string) FunctionOption
- func FinalResultImplements(interfaceName string) FunctionOption
- func Name(name string) FunctionOption
- func Receiver(typeName typed.TypeName) FunctionOption
- func ResultImplements(interfaceName string) FunctionOption
- func Signature(args []typed.TypeName, ret []typed.TypeName) FunctionOption
- func SignatureContains(args []typed.TypeName, ret []typed.TypeName) FunctionOption
- type Point
- type StructLiteralMatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configuration ¶
func DeclarationOf ¶
DeclarationOf matches the (top-level) declaration of the specified symbol.
func Directive ¶
func Directive(name string) directive
Directive matches nodes that are prefaced by a special pragma comment, which is a single-line style comment without any blanks between the leading // and the directive name. Directives apply to the node they are directly attached to, but also to certain nested nodes:
- For assignments, it applies to the RHS only; unless it's a declaration assignment (the := token), in which case it also applies to the LHS,
- For call expressions, it applies only to the function part (not the arguments)n
- For channel send operations, it only applies to the value being sent,
- For defer, go, and return statements, it applies to the value side.
func Function ¶
func Function(opts ...FunctionOption) *functionDeclaration
Function matches function declaration nodes based on properties of their signature.
func FunctionBody ¶
func FunctionBody(up Point) *functionBody
FunctionBody returns the *dst.BlockStmt of the matched *dst.FuncDecl body.
func FunctionCall ¶
func ImportPath ¶
func ImportPath(name string) importPath
func PackageFilter ¶
PackageFilter creates a package filter join point that matches import paths using glob patterns.
If root is true, only matches packages within the current Go module and applies the pattern to relative paths within the module. If root is false, matches packages from any module using the full import path.
Supports standard glob patterns plus ** (globstar) for recursive matching:
- * matches any sequence within a path segment
- ** matches any sequence across multiple path segments
- ? matches any single character except path separator
- [class] matches any character in the character class
Examples:
PackageFilter(true, "internal/*") - matches internal packages in root module only PackageFilter(false, "**/internal/*") - matches internal packages at any depth PackageFilter(false, "github.com/myorg/**") - matches any package under myorg
func PackageName ¶
func PackageName(name string) packageName
func StructDefinition ¶
StructDefinition matches the definition of a particular struct given its fully qualified name.
func StructLiteral ¶
func StructLiteral(typeName typed.TypeName, match StructLiteralMatch) *structLiteral
StructLiteral matches struct literal expressions of the designated type, filtered by the specified match type.
func StructLiteralField ¶
StructLiteralField matches a specific field in struct literals of the designated type.
func TestMain ¶
func TestMain(v bool) testMain
TestMain matches only nodes in ASTs in files that either are (if true), or are not (if false) part of a synthetic test main package.
func ValueDeclaration ¶
Types ¶
type FunctionOption ¶
type FunctionOption interface {
fingerprint.Hashable
// contains filtered or unexported methods
}
func ArgumentImplements ¶
func ArgumentImplements(interfaceName string) FunctionOption
ArgumentImplements creates a FunctionOption that matches functions where at least one argument implements the named interface.
func FinalResultImplements ¶
func FinalResultImplements(interfaceName string) FunctionOption
FinalResultImplements creates a FunctionOption that matches functions where the final return value implements the named interface.
func Name ¶
func Name(name string) FunctionOption
func Receiver ¶
func Receiver(typeName typed.TypeName) FunctionOption
func ResultImplements ¶
func ResultImplements(interfaceName string) FunctionOption
ResultImplements creates a FunctionOption that matches functions where at least one return value implements the named interface.
func Signature ¶
func Signature(args []typed.TypeName, ret []typed.TypeName) FunctionOption
Signature matches function declarations based on their arguments and return value types.
func SignatureContains ¶
func SignatureContains(args []typed.TypeName, ret []typed.TypeName) FunctionOption
SignatureContains matches function declarations based on their arguments and return value types in any order and does not require all arguments or return values to be present.
type Point ¶
type Point interface {
// ImpliesImported returns a list of import paths that are known to already be
// imported if the join point matches.
ImpliesImported() []string
// PackageMayMatch determines whether the join point may match the given package data from the importcfg file.
PackageMayMatch(ctx *may.PackageContext) may.MatchType
// FileMayMatch determines whether the join point may match the given file raw content
FileMayMatch(ctx *may.FileContext) may.MatchType
// Matches determines whether the injection should be performed on the given
// node or not. The node's ancestry is also provided to allow Point to make
// decisions based on parent nodes.
Matches(ctx context.AspectContext) bool
fingerprint.Hashable
}
Point is the interface that abstracts selection of nodes where to inject code.
type StructLiteralMatch ¶
type StructLiteralMatch int
const ( // StructLiteralMatchAny matches struct literals regardless of whether they are pointer or value. // [StructLiteral] join points specified with this match type may match [*dst.CompositeLit] or // [*dst.UnaryExpr] nodes. StructLiteralMatchAny StructLiteralMatch = iota // StructLiteralMatchValueOnly matches struct literals that are not pointers. [StructLiteral] join // points specified with this match type only ever match [*dst.CompositeLit] nodes. StructLiteralMatchValueOnly // StructLiteralMatchPointerOnly matches struct literals that are pointers. [StructLiteral] join // points specified with this match type only ever match [*dst.UnaryExpr] nodes. StructLiteralMatchPointerOnly )
func (StructLiteralMatch) Hash ¶
func (s StructLiteralMatch) Hash(h *fingerprint.Hasher) error
func (StructLiteralMatch) String ¶
func (s StructLiteralMatch) String() string