annotations

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractReceiverType

func ExtractReceiverType(expr ast.Expr) string

ExtractReceiverType extracts the receiver type name from a receiver type expression Examples: *MyStruct -> MyStruct, MyStruct -> MyStruct

Types

type AnnotationReaderFact

type AnnotationReaderFact PackageAnnotations

AnnotationReaderFact is used by AnnotationReader analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*AnnotationReaderFact) AFact

func (*AnnotationReaderFact) AFact()

func (*AnnotationReaderFact) CreateEmpty

func (*AnnotationReaderFact) CreateEmpty() AnnotationWrapper

func (*AnnotationReaderFact) GetAnnotations

func (f *AnnotationReaderFact) GetAnnotations() *PackageAnnotations

type AnnotationWrapper

type AnnotationWrapper interface {
	analysis.Fact
	GetAnnotations() *PackageAnnotations
	CreateEmpty() AnnotationWrapper
}

AnnotationWrapper is an interface for all fact types that wrap PackageAnnotations This allows generic access to annotations while maintaining unique fact types per analyzer

type ConstructorAnnotation

type ConstructorAnnotation struct {
	// Type on which annotation is placed
	OnType    string // "MyStruct"
	OnTypePos token.Pos

	ConstructorNames []string // ["New", "Create"]
}

ConstructorAnnotation @constructor parseConstructorAnnotation @immutable

type ConstructorCheckerFact

type ConstructorCheckerFact PackageAnnotations

ConstructorCheckerFact is used by ConstructorChecker analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*ConstructorCheckerFact) AFact

func (*ConstructorCheckerFact) AFact()

func (*ConstructorCheckerFact) CreateEmpty

func (*ConstructorCheckerFact) GetAnnotations

func (f *ConstructorCheckerFact) GetAnnotations() *PackageAnnotations

type ImmutableAnnotation

type ImmutableAnnotation struct {
	// Type on which annotation is placed
	OnType    string // "MyStruct"
	OnTypePos token.Pos
}

ImmutableAnnotation @immutable @constructor parseImmutableAnnotation

type ImmutableCheckerFact

type ImmutableCheckerFact PackageAnnotations

ImmutableCheckerFact is used by ImmutableChecker analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*ImmutableCheckerFact) AFact

func (*ImmutableCheckerFact) AFact()

func (*ImmutableCheckerFact) CreateEmpty

func (*ImmutableCheckerFact) CreateEmpty() AnnotationWrapper

func (*ImmutableCheckerFact) GetAnnotations

func (f *ImmutableCheckerFact) GetAnnotations() *PackageAnnotations

type ImplementsAnnotation

type ImplementsAnnotation struct {
	// Type on which annotation is placed
	OnType    string // "MyStruct"
	OnTypePos token.Pos

	// Interface that should be implemented
	InterfaceName string // "MyInterface"
	PackageName   string // "" for the current package, "io" for imported (short name from annotation)
	IsPointer     bool   // true if "@implements &Interface"

	// Resolved package information (only available after ReadAllAnnotations)
	// NOTE: This is the only place where we have access to both AST (for comments)
	// and package imports (for resolution). Other loaders are file-agnostic.
	PackageFullPath string // Full import path: "io", "github.com/user/pkg"
	PackageNotFound bool   // true if package was referenced but not found in imports
}

ImplementsAnnotation parse result of "@implements MyStruct" annotation @constructor parseImplementsAnnotation @immutable

type ImplementsCheckerFact

type ImplementsCheckerFact PackageAnnotations

ImplementsCheckerFact is used by ImplementsChecker analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*ImplementsCheckerFact) AFact

func (*ImplementsCheckerFact) AFact()

func (*ImplementsCheckerFact) CreateEmpty

func (*ImplementsCheckerFact) GetAnnotations

func (f *ImplementsCheckerFact) GetAnnotations() *PackageAnnotations

type InterfaceQuery

type InterfaceQuery struct {
	InterfaceName string
	PackageName   string // empty string means current package
}

InterfaceQuery represents what interface we're looking for @immutable

type MutableAnnotation

type MutableAnnotation struct {
	// Type on which the field is defined
	OnType string // "MyStruct"

	// Field name that is marked as mutable
	FieldName string // "MutableField"

	// Position of the field declaration
	Pos token.Pos
}

MutableAnnotation @immutable @constructor parseMutableAnnotation

type PackageAnnotations

type PackageAnnotations struct {
	ImplementsAnnotations  []ImplementsAnnotation
	ConstructorAnnotations []ConstructorAnnotation
	ImmutableAnnotations   []ImmutableAnnotation
	TestonlyAnnotations    []TestOnlyAnnotation
	MutableAnnotations     []MutableAnnotation
	PackageOnlyAnnotations []PackageOnlyAnnotation
}

PackageAnnotations @implements &analysis.Fact @immutable

func ReadAllAnnotations

func ReadAllAnnotations(
	cfg *config.Config,
	pass *analysis.Pass,
) PackageAnnotations

func (*PackageAnnotations) AFact

func (*PackageAnnotations) AFact()

func (*PackageAnnotations) ToInterfaceQuery

func (p *PackageAnnotations) ToInterfaceQuery() []InterfaceQuery

func (*PackageAnnotations) ToTypeQuery

func (p *PackageAnnotations) ToTypeQuery() []TypeQuery

type PackageOnlyAnnotation

type PackageOnlyAnnotation struct {
	// Kind of declaration: type, func, or method
	Kind TestOnlyKind

	// Name of the object: type name, function name, or method name
	// Examples: "MyStruct", "MyFunction", "MyMethod"
	ObjectName string
	Pos        token.Pos

	// Receiver type (only for methods, empty otherwise)
	// Example: "MyStruct" for method receivers
	ReceiverType string

	// Allowed packages for this item (always includes current package)
	// Examples: ["mypackage", "github.com/user/pkg", "io"]
	AllowedPackages []string
}

PackageOnlyAnnotation @immutable

type PackageOnlyCheckerFact

type PackageOnlyCheckerFact PackageAnnotations

PackageOnlyCheckerFact is used by PackageOnlyChecker analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*PackageOnlyCheckerFact) AFact

func (*PackageOnlyCheckerFact) AFact()

func (*PackageOnlyCheckerFact) CreateEmpty

func (*PackageOnlyCheckerFact) GetAnnotations

func (f *PackageOnlyCheckerFact) GetAnnotations() *PackageAnnotations

type TestOnlyAnnotation

type TestOnlyAnnotation struct {
	// Kind of declaration: type, func, or method
	Kind TestOnlyKind

	// Name of the object: type name, function name, or method name
	// Examples: "MyStruct", "MyFunction", "MyMethod"
	ObjectName string
	Pos        token.Pos

	// Receiver type (only for methods, empty otherwise)
	// Example: "MyStruct" for method receivers
	ReceiverType string
}

TestOnlyAnnotation @immutable

type TestOnlyCheckerFact

type TestOnlyCheckerFact PackageAnnotations

TestOnlyCheckerFact is used by TestOnlyChecker analyzer @implements &analysis.Fact @implements &AnnotationWrapper

func (*TestOnlyCheckerFact) AFact

func (*TestOnlyCheckerFact) AFact()

func (*TestOnlyCheckerFact) CreateEmpty

func (*TestOnlyCheckerFact) CreateEmpty() AnnotationWrapper

func (*TestOnlyCheckerFact) GetAnnotations

func (f *TestOnlyCheckerFact) GetAnnotations() *PackageAnnotations

type TestOnlyKind

type TestOnlyKind int

TestOnlyKind represents the kind of declaration @testonly is placed on

const (
	TestOnlyOnType   TestOnlyKind = iota // @testonly on type (struct, interface, etc)
	TestOnlyOnFunc                       // @testonly on function
	TestOnlyOnMethod                     // @testonly on method
)

type TypeQuery

type TypeQuery struct {
	TypeName string
}

TypeQuery represents what type we're looking for @immutable

Jump to

Keyboard shortcuts

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