php-parser/node/stmt/class.go
2017-12-27 16:55:09 +02:00

69 lines
1.4 KiB
Go

package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Class struct {
node.SimpleNode
token token.Token
modifiers []node.Node
args []node.Node
extends node.Node
implements []node.Node
stmts []node.Node
}
func NewClass(token token.Token, modifiers []node.Node, args []node.Node, extends node.Node, implements []node.Node, stmts []node.Node) node.Node {
return Class{
node.SimpleNode{Name: "Class", Attributes: make(map[string]string)},
token,
modifiers,
args,
extends,
implements,
stmts,
}
}
func (n Class) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
if n.modifiers != nil {
fmt.Fprintf(out, "\n%vmotifiers:", indent+" ")
for _, nn := range n.modifiers {
nn.Print(out, indent+" ")
}
}
if n.args != nil {
fmt.Fprintf(out, "\n%vargs:", indent+" ")
for _, nn := range n.args {
nn.Print(out, indent+" ")
}
}
if n.extends != nil {
fmt.Fprintf(out, "\n%vextends:", indent+" ")
n.extends.Print(out, indent+" ")
}
if n.implements != nil {
fmt.Fprintf(out, "\n%vimplements:", indent+" ")
for _, nn := range n.implements {
nn.Print(out, indent+" ")
}
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
}
}