Documentation ¶
Overview ¶
Package types provides type information for Go types, methods, and functions.
Index ¶
- Variables
- func FormatDoc(doc, name, label string) string
- func FuncName(f any) string
- func GetDoc(value, parent reflect.Value, field reflect.StructField, label string) (string, bool)
- func StructGoString(str any) string
- func TypeName(typ reflect.Type) string
- func TypeNameValue(v any) string
- type Directive
- type Field
- type Func
- type Method
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // Funcs records all types (i.e., a type registry) // key is long type name: package_url.Func, e.g., cogentcore.org/core/core.Button Funcs = map[string]*Func{} // FuncIDCounter is an atomically incremented uint64 used // for assigning new [Func.ID] numbers FuncIDCounter uint64 )
var ( // Types is a type registry, initialized to contain all builtin types. New types // can be added with [AddType]. The key is the long type name: package/path.Type, // e.g., cogentcore.org/core/core.Button. Types = map[string]*Type{} )
Functions ¶
func FormatDoc ¶
FormatDoc formats the given Go documentation string for an identifier with the given CamelCase name and intended label. It replaces the name with the label and cleans up trailing punctuation.
func FuncName ¶
FuncName returns the fully package-qualified name of given function This is guaranteed to be unique and used for the Funcs registry.
func GetDoc ¶
GetDoc gets the documentation for the given value with the given parent struct, field, and label. The value, parent value, and field may be nil/invalid. GetDoc uses the given label to format the documentation with FormatDoc before returning it.
func StructGoString ¶
StructGoString creates a GoString for the given struct, omitting any zero values.
func TypeName ¶
TypeName returns the long, full package-path qualified type name. This is guaranteed to be unique and used for the Types registry.
func TypeNameValue ¶ added in v0.2.0
TypeNameValue returns the long, full package-path qualified type name of the given Go value. Automatically finds the non-pointer base type. This is guaranteed to be unique and used for the Types registry.
Types ¶
type Field ¶
type Field struct { // Name is the name of the field (eg: Icon) Name string // Doc has all of the comment documentation // info as one string with directives removed. Doc string }
Field represents a field or embed in a struct.
func GetField ¶
GetField recursively attempts to extract the Field with the given name from the given struct reflect.Value, by searching through all of the embeds if it can not find it directly in the struct.
type Func ¶
type Func struct { // Name is the fully qualified name of the function // (eg: cogentcore.org/core/core.NewButton) Name string // Doc has all of the comment documentation // info as one string with directives removed. Doc string // Directives are the parsed comment directives Directives []Directive // Args are the names of the arguments to the function Args []string // Returns are the names of the return values of the function Returns []string // ID is the unique function ID number ID uint64 }
Func represents a global function.
func FuncByName ¶
FuncByName returns a Func by name (package_url.Type, e.g., cogentcore.org/core/core.Button),
func FuncByNameTry ¶
FuncByNameTry returns a Func by name (package_url.Type, e.g., cogentcore.org/core/core.Button), or error if not found
func FuncInfoTry ¶
FuncInfoTry returns function info for given function.
type Method ¶
type Method struct { // Name is the name of the method (eg: NewChild) Name string // Doc has all of the comment documentation // info as one string with directives removed. Doc string // Directives are the parsed comment directives Directives []Directive // Args are the names of the arguments to the function Args []string // Returns are the names of the return values of the function Returns []string }
Method represents a method.
type Type ¶
type Type struct { // Name is the fully package-path-qualified name of the type // (eg: cogentcore.org/core/core.Button). Name string // IDName is the short, package-unqualified, kebab-case name of // the type that is suitable for use in an ID (eg: button). IDName string // Doc has all of the comment documentation // info as one string with directives removed. Doc string // Directives has the parsed comment directives. Directives []Directive // Methods of the type, which are available for all types. Methods []Method // Embedded fields of struct types. Embeds []Field // Fields of struct types. Fields []Field // Instance is an instance of a non-nil pointer to the type, // which is set by [For] and other external functions such that // a [Type] can be used to make new instances of the type by // reflection. It is not set by typegen. Instance any // ID is the unique type ID number set by [AddType]. ID uint64 }
Type represents a type.
func BuiltinTypes ¶ added in v0.2.0
func BuiltinTypes() []*Type
BuiltinTypes returns all of the builtin types in the type registry.
func For ¶ added in v0.2.1
For returns the Type of the generic type parameter, setting its [Type.Instance] to a new(T) if it is nil.
func TypeByName ¶
TypeByName returns a Type by name (package/path.Type, e.g., cogentcore.org/core/core.Button),
func TypeByReflectType ¶
TypeByReflectType returns the Type of the given reflect type
func (*Type) ReflectType ¶
ReflectType returns the reflect.Type for this type, using [Type.Instance].
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
typegen
Command typgen provides the generation of type information for Go types, methods, and functions.
|
Command typgen provides the generation of type information for Go types, methods, and functions. |
Package typgen provides the generation of type information for Go types, methods, and functions.
|
Package typgen provides the generation of type information for Go types, methods, and functions. |