Documentation ¶
Index ¶
- Variables
- func FormatDoc(doc, name, label string) string
- func FuncName(f any) string
- func GetDoc(val, owner reflect.Value, field *reflect.StructField, label string) (string, bool)
- func StructGoString(str any) string
- func TypeName(typ reflect.Type) string
- func TypeNameObj(v any) string
- type Directive
- type Field
- type Func
- type Method
- type Type
- func AddType(typ *Type) *Type
- func AllEmbeddersOf(typ *Type) []*Type
- func TypeByName(nm string) *Type
- func TypeByNameTry(nm string) (*Type, error)
- func TypeByReflectType(typ reflect.Type) *Type
- func TypeByReflectTypeTry(typ reflect.Type) (*Type, error)
- func TypeByValue(val any) *Type
- func TypeByValueTry(val any) (*Type, error)
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/gi.Button Funcs = map[string]*Func{} // FuncIDCounter is an atomically incremented uint64 used // for assigning new [Func.ID] numbers FuncIDCounter uint64 )
var ( // Types records all types (i.e., a type registry) // key is long type name: package_url.Type, e.g., cogentcore.org/core/gi.Button Types = map[string]*Type{} // TypeIDCounter is an atomically incremented uint64 used // for assigning new [Type.ID] numbers TypeIDCounter uint64 )
Functions ¶
func FormatDoc ¶ added in v0.0.5
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 owner value, field, and label. The value, owner value, and field may be nil/invalid. The owner value, if valid, is the value that contains the value (the parent struct, map, slice, or array). The field, if non-nil, is the struct field that the value represents. 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 TypeNameObj ¶
TypeNameObj returns the long, full package-path qualified type name from given object. 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 gti.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/gi.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/gi.Button),
func FuncByNameTry ¶
FuncByNameTry returns a Func by name (package_url.Type, e.g., cogentcore.org/core/gi.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/gi.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 are available for all types Methods []Method // Embedded fields for struct types Embeds []Field // Fields for struct types Fields []Field // Instance is an optional instance of the type Instance any // ID is the unique type ID number ID uint64 // All embedded fields (including nested ones) for struct types; // not set by gtigen -- HasEmbed automatically compiles it as needed. // Key is the ID of the type. AllEmbeds map[uint64]*Type }
Type represents a type
func AllEmbeddersOf ¶
AllEmbeddersOf returns all registered types that embed the given type. List is sorted in alpha order by fully package-path-qualified Name.
func TypeByName ¶
TypeByName returns a Type by name (package_url.Type, e.g., cogentcore.org/core/gi.Button),
func TypeByNameTry ¶
TypeByNameTry returns a Type by name (package_url.Type, e.g., cogentcore.org/core/gi.Button), or error if not found
func TypeByReflectType ¶
TypeByReflectType returns the Type of the given reflect type
func TypeByReflectTypeTry ¶
TypeByReflectTypeTry returns the Type of the given reflect type, or an error if it is not found
func TypeByValueTry ¶
TypeByValueTry returns the Type of the given value, or an error if it is not found
func (*Type) CompileEmbeds ¶
func (tp *Type) CompileEmbeds()
func (*Type) HasEmbed ¶
HasEmbed returns true if this type has the given type at any level of embedding depth, including if this type is the given type. The first time called it will Compile a map of all embedded types so subsequent calls are very fast.
func (*Type) ReflectType ¶
ReflectType returns the reflect.Type for this type, using the Instance