join

package
v0.0.0-...-f4f425e Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package join provides implementations of the InjectionPoint interface for common injection points.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllOf

func AllOf(requirements ...Point) allOf

func Configuration

func Configuration(requirements map[string]string) configuration

func DeclarationOf

func DeclarationOf(importPath string, name string) *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 FunctionCall(importPath string, name string) *functionCall

func ImportPath

func ImportPath(name string) importPath

func Not

func Not(jp Point) not

func OneOf

func OneOf(candidates ...Point) oneOf

func PackageFilter

func PackageFilter(root bool, pattern string) 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

func StructDefinition(typeName typed.TypeName) *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

func StructLiteralField(typeName typed.TypeName, field string) *structLiteral

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

func ValueDeclaration(typeName typed.TypeName) *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.

func FromYAML

func FromYAML(ctx context.Context, node ast.Node) (Point, error)

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 (StructLiteralMatch) String

func (s StructLiteralMatch) String() string

func (*StructLiteralMatch) UnmarshalYAML

func (s *StructLiteralMatch) UnmarshalYAML(ctx gocontext.Context, node ast.Node) error

Jump to

Keyboard shortcuts

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