php-parser/node/stmt/n_trait_use.go
2018-06-26 00:07:02 +03:00

77 lines
1.7 KiB
Go

package stmt
import (
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitUse node
type TraitUse struct {
Comments []*comment.Comment
Position *position.Position
Traits []node.Node
TraitAdaptationList *TraitAdaptationList
}
// NewTraitUse node constructor
func NewTraitUse(Traits []node.Node, InnerAdaptationList *TraitAdaptationList) *TraitUse {
return &TraitUse{
Traits: Traits,
TraitAdaptationList: InnerAdaptationList,
}
}
// SetPosition sets node position
func (n *TraitUse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitUse) GetPosition() *position.Position {
return n.Position
}
func (n *TraitUse) AddComments(cc []*comment.Comment, tn comment.TokenName) {
for _, c := range cc {
c.SetTokenName(tn)
}
n.Comments = append(n.Comments, cc...)
}
func (n *TraitUse) GetComments() []*comment.Comment {
return n.Comments
}
// Attributes returns node attributes as map
func (n *TraitUse) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *TraitUse) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Traits != nil {
v.EnterChildList("Traits", n)
for _, nn := range n.Traits {
if nn != nil {
nn.Walk(v)
}
}
v.LeaveChildList("Traits", n)
}
if n.TraitAdaptationList != nil {
v.EnterChildNode("TraitAdaptationList", n)
n.TraitAdaptationList.Walk(v)
v.LeaveChildNode("TraitAdaptationList", n)
}
v.LeaveNode(n)
}