model

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRecursive added in v0.5.0

func IsRecursive(node Node, typ types.Type) bool

IsRecursive checks if the given type is the same as any of the ancestor nodes in the tree rooted at the given node. If true, it means there is a recursive reference in the tree.

func IterateStructFields added in v0.5.0

func IterateStructFields(structNode Node, cb func(Node) (done bool))

IterateStructFields iterates through all the fields of the given structNode and calls the given callback function for each one. If the callback function returns true, the iteration stops.

func IterateStructMethods added in v0.5.0

func IterateStructMethods(structNode Node, cb func(Node) (done bool))

IterateStructMethods iterates through all the methods of the given structNode and calls the given callback function for each one. Only those methods that comply with the getter compliant method will be processed. If the callback function returns true, the iteration stops.

Types

type ConverterNode added in v0.5.0

type ConverterNode struct {
	// contains filtered or unexported fields
}

ConverterNode is a node that represents a converter function.

func (ConverterNode) AssignExpr added in v0.5.0

func (n ConverterNode) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (ConverterNode) ExprType added in v0.5.0

func (n ConverterNode) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (ConverterNode) MatcherExpr added in v0.5.0

func (n ConverterNode) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (ConverterNode) NullCheckExpr added in v0.5.0

func (n ConverterNode) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (ConverterNode) ObjName added in v0.5.0

func (n ConverterNode) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (ConverterNode) ObjNullable added in v0.5.0

func (n ConverterNode) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (ConverterNode) Parent added in v0.5.0

func (n ConverterNode) Parent() Node

Parent returns the container of the node or nil.

func (ConverterNode) ReturnsError added in v0.5.0

func (n ConverterNode) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type Copier added in v0.5.0

type Copier struct {
	IsRoot      bool   // true means this copier refers the convergen method. false means it becomes an inner function.
	Name        string // name becomes a copier function's name.
	LHS         types.Type
	RHS         types.Type
	HandleCount int
}

Copier contains a helper function information.

func NewCopier added in v0.5.0

func NewCopier(name string, lhs, rhs types.Type) *Copier

NewCopier creates a new Copier.

func (*Copier) MarkHandle added in v0.5.0

func (h *Copier) MarkHandle(lhs, rhs types.Type) bool

MarkHandle returns true if the copier has handled the given types.

type MethodEntry

type MethodEntry struct {
	Method     types.Object
	Opts       option.Options
	DocComment *ast.CommentGroup
}

MethodEntry contains a method information.

func (*MethodEntry) Args

func (m *MethodEntry) Args() []types.Type

Args returns the argument types.

func (*MethodEntry) DstVar

func (m *MethodEntry) DstVar() *types.Var

DstVar returns a variable that is a copy destination. It assumes that there is only one destination variable.

func (*MethodEntry) Name

func (m *MethodEntry) Name() string

Name returns the method name.

func (*MethodEntry) Recv

func (m *MethodEntry) Recv() types.Type

Recv returns the receiver type.

func (*MethodEntry) Results

func (m *MethodEntry) Results() []types.Type

Results returns the result types.

func (*MethodEntry) RetError

func (m *MethodEntry) RetError() bool

RetError returns true if the last result is an error.

func (*MethodEntry) SrcVar

func (m *MethodEntry) SrcVar() *types.Var

SrcVar returns a variable that is a copy source. It assumes that there is only one source variable.

type MethodsInfo

type MethodsInfo struct {
	Marker  string
	Methods []*MethodEntry
}

MethodsInfo contains a list of MethodEntry.

type Node added in v0.5.0

type Node interface {
	// Parent returns the container of the node or nil.
	Parent() Node

	// ObjName returns the ident of the leaf element.
	// For example, it returns "Status" in both of dst.User.Status or dst.User.Status().
	ObjName() string

	// ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.
	ObjNullable() bool

	// AssignExpr returns a value evaluate expression for assignment.
	// For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.
	AssignExpr() string

	// MatcherExpr returns a value evaluate expression for assignment but omits the root variable name.
	// For example, it returns "User.Status()" in "dst.User.Status()".
	MatcherExpr() string

	// NullCheckExpr returns a value evaluate expression for null check conditional.
	// For example, it returns "dst.Node.Child".
	NullCheckExpr() string

	// ExprType returns the evaluated result type of the node.
	// For example, it returns the type that "dst.User.Status()" returns.
	// An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".
	ExprType() types.Type

	// ReturnsError indicates whether the expression returns an error object as the second returning value.
	ReturnsError() bool
}

func NewConverterNode added in v0.5.0

func NewConverterNode(arg Node, converter *option.FieldConverter) Node

NewConverterNode creates a new ConverterNode.

func NewScalarNode added in v0.5.0

func NewScalarNode(parent Node, name string, typ types.Type) Node

NewScalarNode creates a new ScalarNode.

func NewStringer added in v0.5.0

func NewStringer(inner Node) Node

NewStringer creates a new StringerEntry.

func NewTypecast added in v0.5.0

func NewTypecast(scope *types.Scope, imports util.ImportNames, t types.Type, inner Node) (Node, bool)

NewTypecast creates a new TypecastEntry.

type RootNode added in v0.5.0

type RootNode struct {
	// contains filtered or unexported fields
}

RootNode is a special node that represents the root of the expression tree.

func NewRootNode added in v0.5.0

func NewRootNode(name string, typ types.Type) RootNode

NewRootNode creates a new RootNode.

func (RootNode) AssignExpr added in v0.5.0

func (n RootNode) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (RootNode) ExprType added in v0.5.0

func (n RootNode) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (RootNode) MatcherExpr added in v0.5.0

func (n RootNode) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (RootNode) NullCheckExpr added in v0.5.0

func (n RootNode) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (RootNode) ObjName added in v0.5.0

func (n RootNode) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (RootNode) ObjNullable added in v0.5.0

func (n RootNode) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (RootNode) Parent added in v0.5.0

func (n RootNode) Parent() Node

Parent returns the container of the node or nil.

func (RootNode) ReturnsError added in v0.5.0

func (n RootNode) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type ScalarNode added in v0.5.0

type ScalarNode struct {
	// contains filtered or unexported fields
}

ScalarNode is a node that represents a leaf element of the expression tree.

func (ScalarNode) AssignExpr added in v0.5.0

func (n ScalarNode) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (ScalarNode) ExprType added in v0.5.0

func (n ScalarNode) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (ScalarNode) MatcherExpr added in v0.5.0

func (n ScalarNode) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (ScalarNode) NullCheckExpr added in v0.5.0

func (n ScalarNode) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (ScalarNode) ObjName added in v0.5.0

func (n ScalarNode) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (ScalarNode) ObjNullable added in v0.5.0

func (n ScalarNode) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (ScalarNode) Parent added in v0.5.0

func (n ScalarNode) Parent() Node

Parent returns the container of the node or nil.

func (ScalarNode) ReturnsError added in v0.5.0

func (n ScalarNode) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type StringerEntry added in v0.5.0

type StringerEntry struct {
	// contains filtered or unexported fields
}

StringerEntry is a node that represents a Stringer interface.

func (StringerEntry) AssignExpr added in v0.5.0

func (e StringerEntry) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (StringerEntry) ExprType added in v0.5.0

func (e StringerEntry) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (StringerEntry) MatcherExpr added in v0.5.0

func (e StringerEntry) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (StringerEntry) NullCheckExpr added in v0.5.0

func (e StringerEntry) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (StringerEntry) ObjName added in v0.5.0

func (e StringerEntry) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (StringerEntry) ObjNullable added in v0.5.0

func (e StringerEntry) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (StringerEntry) Parent added in v0.5.0

func (e StringerEntry) Parent() Node

Parent returns the container of the node or nil.

func (StringerEntry) ReturnsError added in v0.5.0

func (e StringerEntry) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type StructFieldNode added in v0.5.0

type StructFieldNode struct {
	// contains filtered or unexported fields
}

StructFieldNode represents a struct field.

func NewStructFieldNode added in v0.5.0

func NewStructFieldNode(container Node, field *types.Var) StructFieldNode

NewStructFieldNode creates a new StructFieldNode.

func (StructFieldNode) AssignExpr added in v0.5.0

func (n StructFieldNode) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (StructFieldNode) ExprType added in v0.5.0

func (n StructFieldNode) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (StructFieldNode) MatcherExpr added in v0.5.0

func (n StructFieldNode) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (StructFieldNode) NullCheckExpr added in v0.5.0

func (n StructFieldNode) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (StructFieldNode) ObjName added in v0.5.0

func (n StructFieldNode) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (StructFieldNode) ObjNullable added in v0.5.0

func (n StructFieldNode) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (StructFieldNode) Parent added in v0.5.0

func (n StructFieldNode) Parent() Node

Parent returns the container of the node or nil.

func (StructFieldNode) ReturnsError added in v0.5.0

func (n StructFieldNode) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type StructMethodNode added in v0.5.0

type StructMethodNode struct {
	// contains filtered or unexported fields
}

StructMethodNode represents a struct method.

func NewStructMethodNode added in v0.5.0

func NewStructMethodNode(container Node, method *types.Func) StructMethodNode

NewStructMethodNode creates a new StructMethodNode.

func (StructMethodNode) AssignExpr added in v0.5.0

func (n StructMethodNode) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (StructMethodNode) ExprType added in v0.5.0

func (n StructMethodNode) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (StructMethodNode) MatcherExpr added in v0.5.0

func (n StructMethodNode) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (StructMethodNode) NullCheckExpr added in v0.5.0

func (n StructMethodNode) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (StructMethodNode) ObjName added in v0.5.0

func (n StructMethodNode) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (StructMethodNode) ObjNullable added in v0.5.0

func (n StructMethodNode) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (StructMethodNode) Parent added in v0.5.0

func (n StructMethodNode) Parent() Node

Parent returns the container of the node or nil.

func (StructMethodNode) ReturnsError added in v0.5.0

func (n StructMethodNode) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

type TypecastEntry added in v0.5.0

type TypecastEntry struct {
	// contains filtered or unexported fields
}

TypecastEntry is a node that represents a typecast expression.

func (TypecastEntry) AssignExpr added in v0.5.0

func (n TypecastEntry) AssignExpr() string

AssignExpr returns a value evaluate expression for assignment. For example, it returns "dst.User.Name", "dst.User.Status()", "strconv.Itoa(dst.User.Score())", etc.

func (TypecastEntry) ExprType added in v0.5.0

func (n TypecastEntry) ExprType() types.Type

ExprType returns the evaluated result type of the node. For example, it returns the type that "dst.User.Status()" returns. An expression may be in converter form, such as "strconv.Itoa(dst.User.Status())".

func (TypecastEntry) MatcherExpr added in v0.5.0

func (n TypecastEntry) MatcherExpr() string

MatcherExpr returns a value evaluate expression for assignment but omits the root variable name. For example, it returns "User.Status()" in "dst.User.Status()".

func (TypecastEntry) NullCheckExpr added in v0.5.0

func (n TypecastEntry) NullCheckExpr() string

NullCheckExpr returns a value evaluate expression for null check conditional. For example, it returns "dst.Node.Child".

func (TypecastEntry) ObjName added in v0.5.0

func (n TypecastEntry) ObjName() string

ObjName returns the ident of the leaf element. For example, it returns "Status" in both of dst.User.Status or dst.User.Status().

func (TypecastEntry) ObjNullable added in v0.5.0

func (n TypecastEntry) ObjNullable() bool

ObjNullable indicates whether the node itself is a pointer type so that it can be nil at runtime.

func (TypecastEntry) Parent added in v0.5.0

func (n TypecastEntry) Parent() Node

Parent returns the container of the node or nil.

func (TypecastEntry) ReturnsError added in v0.5.0

func (n TypecastEntry) ReturnsError() bool

ReturnsError indicates whether the expression returns an error object as the second returning value.

Jump to

Keyboard shortcuts

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