join

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 12 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 added in v0.9.4

func DeclarationOf(importPath string, name string) *declarationOf

DeclarationOf matches the (top-level) declaration of the specified symbol.

func Directive

func Directive(name string) directive

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 PackageName

func PackageName(name string) packageName

func StructDefinition

func StructDefinition(typeName TypeName) *structDefinition

StructDefinition matches the definition of a particular struct given its fully qualified name.

func StructLiteral

func StructLiteral(typeName TypeName, match StructLiteralMatch) *structLiteral

StructLiteral matches struct literal expressions of the designated type, filtered by the specified match type.

func StructLiteralField

func StructLiteralField(typeName TypeName, field string) *structLiteral

StructLiteralField matches a specific field in struct literals of the designated type.

func TestMain added in v1.0.2

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 TypeName) *valueDeclaration

Types

type FunctionOption

type FunctionOption interface {
	fingerprint.Hashable
	// contains filtered or unexported methods
}

func Name

func Name(name string) FunctionOption

func Receiver

func Receiver(typeName TypeName) FunctionOption

func Signature

func Signature(args []TypeName, ret []TypeName) FunctionOption

Signature matches function declarations based on their arguments and return value types.

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

	// 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(node *yaml.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 added in v1.0.0

func (StructLiteralMatch) String

func (s StructLiteralMatch) String() string

func (*StructLiteralMatch) UnmarshalYAML

func (s *StructLiteralMatch) UnmarshalYAML(node *yaml.Node) error

type TypeName

type TypeName struct {
	// contains filtered or unexported fields
}

func MustTypeName

func MustTypeName(n string) (tn TypeName)

MustTypeName is the same as NewTypeName, except it panics in case of an error.

func NewTypeName

func NewTypeName(n string) (tn TypeName, err error)

func (*TypeName) AsNode

func (n *TypeName) AsNode() dst.Expr

func (TypeName) Hash added in v1.0.0

func (n TypeName) Hash(h *fingerprint.Hasher) error

func (TypeName) ImportPath

func (n TypeName) ImportPath() string

ImportPath returns the import path for this type name, or a blank string if this refers to a local or built-in type.

func (TypeName) Matches

func (n TypeName) Matches(node dst.Expr) bool

Matches determines whether the provided node represents the same type as this TypeName.

func (TypeName) MatchesDefinition

func (n TypeName) MatchesDefinition(node dst.Expr, importPath string) bool

MacthesDefinition determines whether the provided node matches the definition of this TypeName. The `importPath` argument determines the context in which the assertion is made.

func (TypeName) Name

func (n TypeName) Name() string

Name returns the unqualified name of this type.

func (TypeName) Pointer

func (n TypeName) Pointer() bool

Pointer returns whether this is a pointer type.

Jump to

Keyboard shortcuts

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