annotation

package
v0.0.0-...-3ce278f Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FuncAnnotation     = "// mutator-disable-func"
	RegexpAnnotation   = "// mutator-disable-regexp"
	NextLineAnnotation = "// mutator-disable-next-line"
)

Annotation constants define the comment patterns used to disable mutations

Variables

This section is empty.

Functions

func DecoratorFilter

func DecoratorFilter(m mutator.Mutator, name string, filters ...filter.NodeFilter) mutator.Mutator

DecoratorFilter creates a mutator that applies one or more filters before executing the provided mutator.

func HandleBlockStmt

func HandleBlockStmt(node ast.Stmt) bool

HandleBlockStmt is a temporary workaround specifically for handling BlockStmt nodes in AST. It performs cleanup and transfers collected annotation data to statement nodes within blocks. This is a tactical solution to handle edge cases where mutators only look at nodes inside block statements. A more robust architectural solution should be implemented in future versions.

Types

type BaseCollector

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

BaseCollector provides default chain handling behavior

func (*BaseCollector) Handle

func (h *BaseCollector) Handle(name string, comment *ast.Comment, fset *token.FileSet, file *ast.File, fileAbs string)

Handle implements the default chain behavior by delegating to the next handler.

func (*BaseCollector) SetNext

func (h *BaseCollector) SetNext(next ChainCollector)

SetNext sets the next handler in the chain of responsibility.

type ChainCollector

type ChainCollector interface {
	// Handle processes an annotation if it matches the handler's type,
	// otherwise delegates to the next handler in the chain.
	Handle(name string, comment *ast.Comment, fset *token.FileSet, file *ast.File, fileAbs string)
	// SetNext establishes the next handler in the chain of responsibility.
	SetNext(next ChainCollector)
}

ChainCollector defines the interface for handlers in the annotation processing chain. Implementations should handle specific annotation types and pass unhandled cases to the next handler in the chain.

type FunctionAnnotation

type FunctionAnnotation struct {
	Exclusions map[token.Pos]struct{}
	Name       string
}

FunctionAnnotation represents a collection of exclusions of function declarations.

type LineAnnotation

type LineAnnotation struct {
	Exclusions map[int]map[token.Pos]mutatorInfo
	Name       string
}

LineAnnotation represents a collection of exclusions based on lines in the file.

type NextLineAnnotationCollector

type NextLineAnnotationCollector struct {
	BaseCollector
	Processor LineAnnotation
}

NextLineAnnotationCollector implements the ChainCollector interface for "mutator-disable-next-line" annotations.

func (*NextLineAnnotationCollector) Handle

func (n *NextLineAnnotationCollector) Handle(name string, comment *ast.Comment, fset *token.FileSet, file *ast.File, fileAbs string)

Handle processes regex pattern annotations, delegating other types to the next handler.

type Processor

type Processor struct {
	FunctionAnnotation FunctionAnnotation
	RegexAnnotation    RegexAnnotation
	LineAnnotation     LineAnnotation
}

Processor handles mutation exclusion logic based on source code annotations.

func NewProcessor

func NewProcessor() *Processor

NewProcessor creates and returns a new initialized Processor.

func (*Processor) Collect

func (p *Processor) Collect(file *ast.File, fset *token.FileSet, fileAbs string)

Collect processes an AST file to gather all mutation exclusions based on annotations.

func (*Processor) ShouldSkip

func (p *Processor) ShouldSkip(node ast.Node, mutatorName string) bool

ShouldSkip determines if a given node should be excluded from mutation.

type RegexAnnotation

type RegexAnnotation struct {
	Exclusions map[int]map[token.Pos]mutatorInfo
	Name       string
}

RegexAnnotation represents a collection of exclusions based on regex pattern matches.

type RegexAnnotationCollector

type RegexAnnotationCollector struct {
	BaseCollector
	Processor RegexAnnotation
}

RegexAnnotationCollector implements the ChainCollector interface for "mutator-disable-regexp" annotations.

func (*RegexAnnotationCollector) Handle

func (r *RegexAnnotationCollector) Handle(name string, comment *ast.Comment, fset *token.FileSet, file *ast.File, fileAbs string)

Handle processes regex pattern annotations, delegating other types to the next handler.

Jump to

Keyboard shortcuts

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