php-parser/node/stmt/n_group_use.go

88 lines
1.7 KiB
Go

package stmt
import (
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// GroupUse node
type GroupUse struct {
Meta []meta.Meta
Position *position.Position
UseType node.Node
Prefix node.Node
UseList []node.Node
}
// NewGroupUse node constructor
func NewGroupUse(UseType node.Node, Prefix node.Node, UseList []node.Node) *GroupUse {
return &GroupUse{
UseType: UseType,
Prefix: Prefix,
UseList: UseList,
}
}
// SetPosition sets node position
func (n *GroupUse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *GroupUse) GetPosition() *position.Position {
return n.Position
}
func (n *GroupUse) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *GroupUse) GetMeta() []meta.Meta {
return n.Meta
}
// Attributes returns node attributes as map
func (n *GroupUse) Attributes() map[string]interface{} {
return nil
}
// SetUseType set use type and returns node
func (n *GroupUse) SetUseType(UseType node.Node) node.Node {
n.UseType = UseType
return n
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *GroupUse) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.UseType != nil {
v.EnterChildNode("UseType", n)
n.UseType.Walk(v)
v.LeaveChildNode("UseType", n)
}
if n.Prefix != nil {
v.EnterChildNode("Prefix", n)
n.Prefix.Walk(v)
v.LeaveChildNode("Prefix", n)
}
if n.UseList != nil {
v.EnterChildList("UseList", n)
for _, nn := range n.UseList {
if nn != nil {
nn.Walk(v)
}
}
v.LeaveChildList("UseList", n)
}
v.LeaveNode(n)
}