model

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRecursive

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

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

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

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

ConverterNode is a node that represents a converter function.

func (ConverterNode) AssignExpr

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

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

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

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

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

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

func (n ConverterNode) Parent() Node

Parent returns the container of the node or nil.

func (ConverterNode) ReturnsError

func (n ConverterNode) ReturnsError() bool

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

type Copier

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

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

NewCopier creates a new Copier.

func (*Copier) MarkHandle

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

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

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

NewConverterNode creates a new ConverterNode.

func NewScalarNode

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

NewScalarNode creates a new ScalarNode.

func NewStringer

func NewStringer(inner Node) Node

NewStringer creates a new StringerEntry.

func NewTypecast

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

NewTypecast creates a new TypecastEntry.

type RootNode

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

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

func NewRootNode

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

NewRootNode creates a new RootNode.

func (RootNode) AssignExpr

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

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

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

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

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

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

func (n RootNode) Parent() Node

Parent returns the container of the node or nil.

func (RootNode) ReturnsError

func (n RootNode) ReturnsError() bool

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

type ScalarNode

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

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

func (ScalarNode) AssignExpr

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

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

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

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

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

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

func (n ScalarNode) Parent() Node

Parent returns the container of the node or nil.

func (ScalarNode) ReturnsError

func (n ScalarNode) ReturnsError() bool

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

type StringerEntry

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

StringerEntry is a node that represents a Stringer interface.

func (StringerEntry) AssignExpr

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

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

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

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

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

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

func (e StringerEntry) Parent() Node

Parent returns the container of the node or nil.

func (StringerEntry) ReturnsError

func (e StringerEntry) ReturnsError() bool

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

type StructFieldNode

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

StructFieldNode represents a struct field.

func NewStructFieldNode

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

NewStructFieldNode creates a new StructFieldNode.

func (StructFieldNode) AssignExpr

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

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

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

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

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

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

func (n StructFieldNode) Parent() Node

Parent returns the container of the node or nil.

func (StructFieldNode) ReturnsError

func (n StructFieldNode) ReturnsError() bool

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

type StructMethodNode

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

StructMethodNode represents a struct method.

func NewStructMethodNode

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

NewStructMethodNode creates a new StructMethodNode.

func (StructMethodNode) AssignExpr

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

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

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

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

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

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

func (n StructMethodNode) Parent() Node

Parent returns the container of the node or nil.

func (StructMethodNode) ReturnsError

func (n StructMethodNode) ReturnsError() bool

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

type TypecastEntry

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

TypecastEntry is a node that represents a typecast expression.

func (TypecastEntry) AssignExpr

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

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

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

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

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

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

func (n TypecastEntry) Parent() Node

Parent returns the container of the node or nil.

func (TypecastEntry) ReturnsError

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