annotators

package
v0.0.0-...-43c8ab9 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

README

Package cloudeng.io/go/cmd/goannotate/annotators

CircleCI Go Report Card

import cloudeng.io/go/cmd/goannotate/annotators

Constants

AddLogCallDescription
AddLogCallDescription = `
AddLogCall is an annotator to add function calls that are intended to log entry and exit from functions. The calls will be added as the first statement in the specified function.
`

AddLogCallDescription documents AddLogCall.

Variables

Verbose
// Verbose controls verbose logging.
Verbose = false

Functions

Func Available
func Available() []string

Available lists all available annotations.

Func Description
func Description(name string) string

Description returns the description for the annotator or annotation.

Func Register
func Register(annotator Annotator)

Register registers a new annotator.

Func Registered
func Registered() []string

Registered lists all registered annotatators.

Func Verbosef
func Verbosef(format string, args ...interface{})

Verbosef is like fmt.Printf but will produce output if the Verbose variable is true.

Types

Type AddLogCall
type AddLogCall struct {
	EssentialOptions `yaml:",inline"`
	LocateOptions    `yaml:",inline"`

	AtLeastStatements   int            `yaml:"atLeastStatements" annotator:"the number of statements that must be present in a function in order for it to be annotated."`
	NoAnnotationComment string         `yaml:"noAnnotationComment" annotator:"do not annotate functions that contain this comment"`
	CallGenerator       functions.Spec `yaml:"callGenerator" annotator:"the spec for the function call to be generated"`
}

AddLogCall represents an annotator for adding a function call that logs the entry and exit to every function and method that is matched by the locator.

Methods
func (lc *AddLogCall) Describe() string

Describe implements annotators.Annotation.

func (lc *AddLogCall) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotation.

func (lc *AddLogCall) New(name string) Annotation

New implements annotators.Annotator.

func (lc *AddLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotation.

Type Annotation
type Annotation interface {
	// UnmarshalYAML unmarshals the annotator's yaml configuration.
	UnmarshalYAML(buf []byte) error
	// Do runs the annotator. Root specifies an alternate location for the
	// modified files, if it is empty, files are modified in place. The original
	// directory structure will be mirrored under root.
	// Packages is the set of packages to be annotated as requested on the
	// command line and which overrides any configured ones.
	Do(ctx context.Context, root string, packages []string) error
	// Describe returns a description for the annotation.
	Describe() string
}

Annotation represents a configured instance of an Annotator.

Functions
func Lookup(name string) Annotation

Lookup returns the annotation with the specified typeName, if any.

Type Annotator
type Annotator interface {
	// New creates a new instance of T. It used to create new configurations
	// as specified in config files, namely an 'annotation'
	New(name string) Annotation
	Describe() string
}

Annotator represents the interface that all annotators must implement.

Type EnsureCopyrightAndLicense
type EnsureCopyrightAndLicense struct {
	EssentialOptions `yaml:",inline"`

	Copyright       string   `yaml:"copyright" annotator:"desired copyright notice."`
	Exclusions      []string `yaml:"exclusions" annotator:"regular expressions for files to be excluded."`
	License         string   `yaml:"license" annotator:"desired license notice."`
	UpdateCopyright bool     `yaml:"updateCopyright" annotator:"set to true to update existing copyright notice"`
	UpdateLicense   bool     `yaml:"updateLicense" annotator:"set to true to update existing license notice"`
}

EnsureCopyrightAndLicense represents an annotator that can insert or replace copyright and license headers from go source code files.

Methods
func (ec *EnsureCopyrightAndLicense) Describe() string

Describe implements annotators.Annotations.

func (ec *EnsureCopyrightAndLicense) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotations.

func (ec *EnsureCopyrightAndLicense) New(name string) Annotation

New implements annotators.Annotators.

func (ec *EnsureCopyrightAndLicense) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotations.

Type EssentialOptions
type EssentialOptions struct {
	Type        string   `yaml:"type" annotator:"name of annotator type."`
	Name        string   `yaml:"name" annotator:"name of annotation."`
	Packages    []string `yaml:"packages" annotator:"packages to be annotated"`
	Concurrency int      `yaml:"concurrency" annotator:"the number of goroutines to use, zero for a sensible default."`
}

EssentialOptions represents the configuration options required for all annotations.

Type LocateOptions
type LocateOptions struct {
	Interfaces     []string `yaml:"interfaces" annotator:"list of interfaces whose implementations are to be annoated."`
	Functions      []string `yaml:"functions" annotator:"list of functions that are to be annotated."`
	IncludeMethods bool     `yaml:"includeMethods" annotator:"if set, methods as well as functions that match the function spec are annotated"`
}

LocateOptions represents the configuration options used to locate specific interfaces and/or functions.

Type RmLogCall
type RmLogCall struct {
	EssentialOptions `yaml:",inline"`
	LocateOptions    `yaml:",inline"`

	FunctionNameRE string `yaml:"functionNameRE" annotator:"the function call (regexp) to be removed"`
	Comment        string `yaml:"comment" annotator:"optional comment that must appear in the comments associated with the function call if it is to be removed."`
	Deferred       bool   `yaml:"deferred" annotator:"if set requires that the function to be removed must be defered."`
}

RmLogCall represents an annotor for removing logging calls.

Methods
func (rc *RmLogCall) Describe() string

Describe implements annotators.Annotation.

func (rc *RmLogCall) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotation.

func (rc *RmLogCall) New(name string) Annotation

New implements annotators.Annotator.

func (rc *RmLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotation.

Type Spec
type Spec struct {
	yaml.MapSlice
	Name string `yaml:"name"` // Name identifies a particular configuration of an annotator type.
	Type string `yaml:"type"` // Type identifies the annotation to be performed.
}

Spec represents the yaml configuration for an annotation. It has a common field for the type and name of the annotator but all other fields are delegated to the Unmarshal method of the annotator specuifed by the Type field.

Methods
func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Documentation

Index

Constants

View Source
const AddLogCallDescription = `` /* 180-byte string literal not displayed */

AddLogCallDescription documents AddLogCall.

Variables

View Source
var (
	// Verbose controls verbose logging.
	Verbose = false
)

Functions

func Available

func Available() []string

Available lists all available annotations.

func Description

func Description(name string) string

Description returns the description for the annotator or annotation.

func Register

func Register(annotator Annotator)

Register registers a new annotator.

func Registered

func Registered() []string

Registered lists all registered annotatators.

func Verbosef

func Verbosef(format string, args ...interface{})

Verbosef is like fmt.Printf but will produce output if the Verbose variable is true.

Types

type AddLogCall

type AddLogCall struct {
	EssentialOptions `yaml:",inline"`
	LocateOptions    `yaml:",inline"`

	AtLeastStatements   int            `` /* 129-byte string literal not displayed */
	NoAnnotationComment string         `yaml:"noAnnotationComment" annotator:"do not annotate functions that contain this comment"`
	CallGenerator       functions.Spec `yaml:"callGenerator" annotator:"the spec for the function call to be generated"`
}

AddLogCall represents an annotator for adding a function call that logs the entry and exit to every function and method that is matched by the locator.

func (*AddLogCall) Describe

func (lc *AddLogCall) Describe() string

Describe implements annotators.Annotation.

func (*AddLogCall) Do

func (lc *AddLogCall) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotation.

func (*AddLogCall) New

func (lc *AddLogCall) New(name string) Annotation

New implements annotators.Annotator.

func (*AddLogCall) UnmarshalYAML

func (lc *AddLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotation.

type Annotation

type Annotation interface {
	// UnmarshalYAML unmarshals the annotator's yaml configuration.
	UnmarshalYAML(buf []byte) error
	// Do runs the annotator. Root specifies an alternate location for the
	// modified files, if it is empty, files are modified in place. The original
	// directory structure will be mirrored under root.
	// Packages is the set of packages to be annotated as requested on the
	// command line and which overrides any configured ones.
	Do(ctx context.Context, root string, packages []string) error
	// Describe returns a description for the annotation.
	Describe() string
}

Annotation represents a configured instance of an Annotator.

func Lookup

func Lookup(name string) Annotation

Lookup returns the annotation with the specified typeName, if any.

type Annotator

type Annotator interface {
	// New creates a new instance of T. It used to create new configurations
	// as specified in config files, namely an 'annotation'
	New(name string) Annotation
	Describe() string
}

Annotator represents the interface that all annotators must implement.

type EnsureCopyrightAndLicense

type EnsureCopyrightAndLicense struct {
	EssentialOptions `yaml:",inline"`

	Copyright       string   `yaml:"copyright" annotator:"desired copyright notice."`
	Exclusions      []string `yaml:"exclusions" annotator:"regular expressions for files to be excluded."`
	License         string   `yaml:"license" annotator:"desired license notice."`
	UpdateCopyright bool     `yaml:"updateCopyright" annotator:"set to true to update existing copyright notice"`
	UpdateLicense   bool     `yaml:"updateLicense" annotator:"set to true to update existing license notice"`
}

EnsureCopyrightAndLicense represents an annotator that can insert or replace copyright and license headers from go source code files.

func (*EnsureCopyrightAndLicense) Describe

func (ec *EnsureCopyrightAndLicense) Describe() string

Describe implements annotators.Annotations.

func (*EnsureCopyrightAndLicense) Do

func (ec *EnsureCopyrightAndLicense) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotations.

func (*EnsureCopyrightAndLicense) New

New implements annotators.Annotators.

func (*EnsureCopyrightAndLicense) UnmarshalYAML

func (ec *EnsureCopyrightAndLicense) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotations.

type EssentialOptions

type EssentialOptions struct {
	Type        string   `yaml:"type" annotator:"name of annotator type."`
	Name        string   `yaml:"name" annotator:"name of annotation."`
	Packages    []string `yaml:"packages" annotator:"packages to be annotated"`
	Concurrency int      `yaml:"concurrency" annotator:"the number of goroutines to use, zero for a sensible default."`
}

EssentialOptions represents the configuration options required for all annotations.

type LocateOptions

type LocateOptions struct {
	Interfaces     []string `yaml:"interfaces" annotator:"list of interfaces whose implementations are to be annoated."`
	Functions      []string `yaml:"functions" annotator:"list of functions that are to be annotated."`
	IncludeMethods bool     `yaml:"includeMethods" annotator:"if set, methods as well as functions that match the function spec are annotated"`
}

LocateOptions represents the configuration options used to locate specific interfaces and/or functions.

type RmLogCall

type RmLogCall struct {
	EssentialOptions `yaml:",inline"`
	LocateOptions    `yaml:",inline"`

	FunctionNameRE string `yaml:"functionNameRE" annotator:"the function call (regexp) to be removed"`
	Comment        string `` /* 134-byte string literal not displayed */
	Deferred       bool   `yaml:"deferred" annotator:"if set requires that the function to be removed must be defered."`
}

RmLogCall represents an annotor for removing logging calls.

func (*RmLogCall) Describe

func (rc *RmLogCall) Describe() string

Describe implements annotators.Annotation.

func (*RmLogCall) Do

func (rc *RmLogCall) Do(ctx context.Context, root string, pkgs []string) error

Do implements annotators.Annotation.

func (*RmLogCall) New

func (rc *RmLogCall) New(name string) Annotation

New implements annotators.Annotator.

func (*RmLogCall) UnmarshalYAML

func (rc *RmLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements annotators.Annotation.

type Spec

type Spec struct {
	yaml.MapSlice
	Name string `yaml:"name"` // Name identifies a particular configuration of an annotator type.
	Type string `yaml:"type"` // Type identifies the annotation to be performed.
}

Spec represents the yaml configuration for an annotation. It has a common field for the type and name of the annotator but all other fields are delegated to the Unmarshal method of the annotator specuifed by the Type field.

func (*Spec) UnmarshalYAML

func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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