73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package stmt
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
|
"github.com/z7zmey/php-parser/token"
|
|
)
|
|
|
|
func(n Class) Name() string {
|
|
return "Class"
|
|
}
|
|
|
|
type Class struct {
|
|
name string
|
|
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{
|
|
"Class",
|
|
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+" ")
|
|
}
|
|
}
|
|
}
|