helpers

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnexpectedTypeError = fmt.Errorf("the given types.Type interface underlying type is not recognizable")

Functions

func CallbackOnNamedType

func CallbackOnNamedType(fieldType types.Type, callback func(obj *types.Named)) error

CallbackOnNamedType will iterate over a types.Type, trying to find some NamedType to pass as argument to the callback function

If the Type is an anonymous struct, for example, it will recursively iterate over the fields until it finds some Named type, or a basic type (in which case, the callback is not called). Note that the callback can be called more than just once (maybe not even called)

func GetCharReplacement

func GetCharReplacement(a rune) (rune, bool)

GetCharReplacement will return the valid non-ASCII equivalent of an invalid GO typename symbol

func IdentifierToAsciiTypeName

func IdentifierToAsciiTypeName(typeIdentifier string) string

IdentifierToAsciiTypeName will transform a type identifier into an ASCII-only, valid GO typename

Example: "*int" (invalid typename) turns into "Ptr_int"

func IdentifierToTypeName

func IdentifierToTypeName(typeIdentifier string) string

IdentifierToTypeName will transform a type identifier into a valid GO typename. Note that it will use non-ASCII symbols as a trick to stay as close as possible to the original identifier representation

Example: "*int" turns into "ᕽint"

func ObjectIsAccessible

func ObjectIsAccessible(obj types.Object, fromPackagePath string, logger goParser.LoggerCLI) bool

ObjectIsAccessible will recursively check an object to see if it is accessible from the given package path (is it public? Private? Builtin?...)

func ResolveTypeIdentifier

func ResolveTypeIdentifier(t types.Type, pkgImports GoImports) (string, error)

ResolveTypeIdentifier will take some type and return a string that represents it

Example: the type "pointer to integer" will return the string "*int"

func TypeIsAccessible

func TypeIsAccessible(t types.Type, fromPackagePath string) (bool, error)

TypeIsAccessible will check to see if some type is fully accessible from the given package (is it public? Private? Builtin? All struct fields exported?...)

Types

type GoImports

type GoImports interface {
	NeedImport(string) bool
	AliasFromPath(string) string
}

GoImports just to ease tests

Jump to

Keyboard shortcuts

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