Documentation
¶
Overview ¶
typegraph forms a graph by drawing edges between a named type and other named type.
Index ¶
- Constants
- func FirstTypeIdent(m map[Ident][]Edge) (Ident, Edge)
- func TraverseToNamed(ty types.Type, cb func(named *types.Named, stack []EdgeRouteNode) error, ...) error
- func TraverseTypes(ty types.Type, stopper func(ty types.Type, currentStack []EdgeRouteNode) bool, ...) error
- type Edge
- func (e Edge) HasSingleNamedTypeArg(additionalCond func(named *types.Named) bool) (ok bool, pointer bool)
- func (e Edge) IsChildMatched() bool
- func (e Edge) IsTypeArgMatched() bool
- func (e Edge) LastPointer() option.Option[EdgeRouteNode]
- func (e Edge) PrintChildArg(i int, importMap imports.ImportMap) string
- func (e Edge) PrintChildArgConverted(converter func(ty *types.Named, isMatched bool) (*types.Named, bool), ...) string
- func (e Edge) PrintChildType(importMap imports.ImportMap) string
- type EdgeKind
- type EdgeMap
- func (em EdgeMap) ByFieldName(fieldName string) (Edge, *types.Var, reflect.StructTag, bool)
- func (em EdgeMap) ByFieldPos(pos int) (Edge, *types.Var, reflect.StructTag, bool)
- func (em EdgeMap) Fields() iter.Seq2[int, Edge]
- func (em EdgeMap) FieldsName() iter.Seq2[string, Edge]
- func (em EdgeMap) First() (Ident, Edge, bool)
- type EdgeRouteNode
- type Graph
- func (g *Graph) EnumerateTypes() iter.Seq2[Ident, *Node]
- func (g *Graph) EnumerateTypesKeys(keys iter.Seq[Ident]) iter.Seq2[Ident, *Node]
- func (g *Graph) GatherReplaceData(parser *imports.ImportParser, ...) (data map[*ast.File]*ReplaceData, err error)
- func (g *Graph) Get(i Ident) (*Node, bool)
- func (g *Graph) GetByType(ty types.Type) (*Node, bool)
- func (g *Graph) IterUpward(includeMatched bool, edgeFilter func(edge Edge) bool) iter.Seq2[Ident, *Node]
- func (g *Graph) MarkDependant(edgeFilter func(edge Edge) bool)
- type Ident
- type MatchKind
- type Node
- type Option
- type PrivParser
- type ReplaceData
- type TypeArg
Constants ¶
const ( MatchKindMatched = MatchKind(1 << iota) MatchKindDependant MatchKindExternal )
const ( EdgeKindAlias = EdgeKind(1 << iota) EdgeKindArray EdgeKindChan EdgeKindInterface EdgeKindMap EdgeKindNamed EdgeKindPointer EdgeKindSlice EdgeKindStruct )
Variables ¶
This section is empty.
Functions ¶
func TraverseToNamed ¶
func TraverseToNamed( ty types.Type, cb func(named *types.Named, stack []EdgeRouteNode) error, stack []EdgeRouteNode, ) error
func TraverseTypes ¶
func TraverseTypes( ty types.Type, stopper func(ty types.Type, currentStack []EdgeRouteNode) bool, cb func(ty types.Type, named *types.Named, stack []EdgeRouteNode) error, stack []EdgeRouteNode, ) error
Types ¶
type Edge ¶
type Edge struct { Stack []EdgeRouteNode TypeArgs []TypeArg // non-instantiated parent ParentNode *Node // instantiated child ChildType *types.Named // non-instantiated child node. ChildNode *Node }
func (Edge) HasSingleNamedTypeArg ¶
func (Edge) IsChildMatched ¶
func (Edge) IsTypeArgMatched ¶
func (Edge) LastPointer ¶
func (e Edge) LastPointer() option.Option[EdgeRouteNode]
func (Edge) PrintChildArgConverted ¶
type EdgeMap ¶
type EdgeMap struct {
// contains filtered or unexported fields
}
func (EdgeMap) ByFieldName ¶
ByFieldName is like EdgeMap.ByFieldPos but queries for fieldName.
func (EdgeMap) ByFieldPos ¶
ByFieldPos returns the edge, the field var and the struct tag for the field positioned at pos in source code order, It assumes node's underlying is struct type, otherwise panics.
func (EdgeMap) Fields ¶
Fields enumerates its children edges as iter.Seq2[int, typeDependencyEdge] assuming node's underlying type is struct. The key of the iterator is position of field in source code order.
func (EdgeMap) FieldsName ¶
FieldsName is like EdgeMap.Fields but the key of the pair is field name.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph enumerates type decls in given []*packages.Package and forms a type-dependency graph. It lists types which matches input matcher. Callers can traverse graph from a node upwards and downwards.
. ... +──────+ . ┠─... │ node │────... +──────+ ┠─(as struct member)──────────────+──────+ │ node │──╂─(as struct member map elem)─────│ node │────... +──────+ ┠─(as struct member elt of [][]T)─+──────+ . ┠─... │ node │────... . ... +──────+
Nodes are connected by [typeDependencyEdge].
func (*Graph) EnumerateTypesKeys ¶
func (*Graph) GatherReplaceData ¶
func (g *Graph) GatherReplaceData( parser *imports.ImportParser, seqFactory func(g *Graph) iter.Seq2[Ident, *Node], ) (data map[*ast.File]*ReplaceData, err error)
GatherReplaceData converts g into a map of *ast.File to *ReplaceData. The data can be later used to modify ast.
func (*Graph) IterUpward ¶
func (*Graph) MarkDependant ¶
type Ident ¶
func IdentFromTypesObject ¶
func (Ident) TargetType ¶
func (t Ident) TargetType() imports.TargetType
type Node ¶
type Node struct { Parent map[Ident][]Edge Children map[Ident][]Edge Matched MatchKind Pkg *packages.Package File *ast.File // nth type spec in the file. Pos int Ts *ast.TypeSpec Type *types.Named Priv any }
func (*Node) ByFieldName ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithPrivParser ¶
func WithPrivParser(privParser PrivParser) Option