util

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompliesGetter

func CompliesGetter(m *types.Func) bool

CompliesGetter checks whether the given function complies with the requirements of a getter function. A getter function must have no input parameters and must return exactly one non-error value.

func CompliesStringer

func CompliesStringer(src types.Type) bool

CompliesStringer checks if the given type is a Stringer compliant type, which has a method "String()" that takes no arguments and returns a string.

func Deref

func Deref(typ types.Type) (types.Type, bool)

Deref dereferences a type if it is a *Pointer type and returns its base type and true. Otherwise, it returns (typ, false).

func DerefPtr

func DerefPtr(typ types.Type) types.Type

DerefPtr dereferences a *Pointer type and returns its base type.

func ExtractMatchComments

func ExtractMatchComments(commentGroup *ast.CommentGroup, pattern *regexp.Regexp) []*ast.Comment

ExtractMatchComments removes pattern matched comments from commentGroup and returns them.

func FindField

func FindField(t types.Type, name string, exactCase bool) (field *types.Var)

FindField returns the field with the given name from the given type.

func FindMethod

func FindMethod(t types.Type, name string, exactCase bool) (method *types.Func)

FindMethod returns the method with the given name in the given type.

func GetDocCommentOn

func GetDocCommentOn(file *ast.File, obj types.Object) (cg *ast.CommentGroup, cleanUp func())

GetDocCommentOn retrieves doc comments that relate to nodes.

func GetMethodReturnTypes

func GetMethodReturnTypes(m *types.Func) (*types.Tuple, bool)

GetMethodReturnTypes returns the return types of the given method.

func InsertComment

func InsertComment(file *ast.File, text string, pos token.Pos)

InsertComment inserts a comment with the specified text at the specified position in file.Comments.

func IsBasicType

func IsBasicType(t types.Type) bool

IsBasicType returns true if the given type is a basic type.

func IsErrorType

func IsErrorType(t types.Type) bool

IsErrorType returns true if the given type is an error type.

func IsFunc

func IsFunc(obj types.Object) bool

IsFunc returns true if the given type is a func type.

func IsInvalidType

func IsInvalidType(t types.Type) bool

IsInvalidType returns true if the given type is an invalid type.

func IsNamedType

func IsNamedType(t types.Type) bool

IsNamedType returns true if the given type is a named type.

func IsPtr

func IsPtr(t types.Type) bool

IsPtr returns true if the given type is a pointer type.

func IsSliceType

func IsSliceType(t types.Type) bool

IsSliceType returns true if the given type is a slice type.

func IsStructType

func IsStructType(t types.Type) bool

IsStructType returns true if the given type is a struct type.

func IterateFields

func IterateFields(t types.Type, cb func(*types.Var) (done bool))

IterateFields iterates over the fields of the given type and calls the callback for each one.

func IterateMethods

func IterateMethods(t types.Type, cb func(*types.Func) (done bool))

IterateMethods iterates over the methods of the given type and calls the callback for each one.

func MatchComments

func MatchComments(commentGroup *ast.CommentGroup, pattern *regexp.Regexp) bool

MatchComments reports whether any comment line in commentGroup contains any match of the regular expression pattern.

func ParseGetterReturnTypes

func ParseGetterReturnTypes(m *types.Func) (ret types.Type, retError, ok bool)

ParseGetterReturnTypes returns the return types of the given method.

func PathMatch

func PathMatch(pattern, name string, exactCase bool) (bool, error)

PathMatch returns true if the name matches the pattern.

func PkgOf

func PkgOf(t types.Type) *types.Package

PkgOf returns the package of the given type.

func RemoveDecl

func RemoveDecl(file *ast.File, name string)

RemoveDecl removes a declaration named name from file.Decls.

func RemoveMatchComments

func RemoveMatchComments(file *ast.File, pattern *regexp.Regexp)

RemoveMatchComments removes pattern matched comments from file.Comments.

func SliceElement

func SliceElement(t types.Type) types.Type

SliceElement returns the type of the element in a slice type.

func StringType

func StringType() types.Type

StringType returns the string type in the universe scope.

func ToAstNode

func ToAstNode(file *ast.File, obj types.Object) (path []ast.Node, exact bool)

ToAstNode converts types.Object to []ast.Node.

func ToTextList

func ToTextList(doc *ast.CommentGroup) []string

ToTextList returns a list of strings representing the comments in a CommentGroup.

Types

type ImportNames

type ImportNames map[string]string

ImportNames is a map of a package path to a package name in a convergen setup file.

func NewImportNames

func NewImportNames(specs []*ast.ImportSpec) ImportNames

NewImportNames creates a new ImportNames instance.

func (ImportNames) IsExternal

func (i ImportNames) IsExternal(t types.Type) bool

IsExternal returns true if the given type is defined in a different package than the conversion setup file.

func (ImportNames) LookupName

func (i ImportNames) LookupName(pkgPath string) (name string, ok bool)

LookupName looks up the map with the pkgPath and returns its corresponding name in the conversion setup file.

func (ImportNames) LookupPath

func (i ImportNames) LookupPath(pkgName string) (path string, ok bool)

LookupPath looks up the map with the pkgName and returns its corresponding path in the conversion setup file.

func (ImportNames) TypeName

func (i ImportNames) TypeName(t types.Type) string

TypeName returns a string representation of the given type with its package name.

type LookupFieldOpt

type LookupFieldOpt struct {
	ExactCase     bool
	SupportsError bool
	Pattern       string
}

Jump to

Keyboard shortcuts

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