remove nodesWithEndToken type

This commit is contained in:
z7zmey
2018-06-03 09:35:44 +03:00
parent 2abe1dfb84
commit a488f43496
17 changed files with 1393 additions and 1251 deletions

View File

@@ -13,11 +13,11 @@ type ClassMethod struct {
Modifiers []node.Node
Params []node.Node
ReturnType node.Node
Stmts []node.Node
Stmt node.Node
}
// NewClassMethod node constructor
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmts []node.Node, PhpDocComment string) *ClassMethod {
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
return &ClassMethod{
ReturnsRef,
PhpDocComment,
@@ -25,7 +25,7 @@ func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool
Modifiers,
Params,
ReturnType,
Stmts,
Stmt,
}
}
@@ -72,13 +72,9 @@ func (n *ClassMethod) Walk(v walker.Visitor) {
n.ReturnType.Walk(vv)
}
if n.Stmts != nil {
vv := v.GetChildrenVisitor("Stmts")
for _, nn := range n.Stmts {
if nn != nil {
nn.Walk(vv)
}
}
if n.Stmt != nil {
vv := v.GetChildrenVisitor("Stmt")
n.Stmt.Walk(vv)
}
v.LeaveNode(n)

View File

@@ -2,9 +2,10 @@ package stmt_test
import (
"bytes"
"github.com/z7zmey/php-parser/node/name"
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
@@ -22,7 +23,9 @@ func TestSimpleClassMethod(t *testing.T) {
&stmt.ClassMethod{
PhpDocComment: "",
MethodName: &node.Identifier{Value: "bar"},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -56,7 +59,9 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
&node.Identifier{Value: "final"},
&node.Identifier{Value: "private"},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
&stmt.ClassMethod{
PhpDocComment: "",
@@ -65,7 +70,9 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
Modifiers: []node.Node{
&node.Identifier{Value: "protected"},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -99,7 +106,9 @@ func TestPhp5ClassMethod(t *testing.T) {
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -133,7 +142,9 @@ func TestPhp7ClassMethod(t *testing.T) {
&name.NamePart{Value: "void"},
},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -163,6 +174,7 @@ func TestAbstractClassMethod(t *testing.T) {
&node.Identifier{Value: "abstract"},
&node.Identifier{Value: "public"},
},
Stmt: &stmt.Nop{},
},
},
},
@@ -201,6 +213,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
&name.NamePart{Value: "void"},
},
},
Stmt: &stmt.Nop{},
},
},
},

View File

@@ -82,9 +82,9 @@ var nodesToTest = []struct {
Modifiers: []node.Node{&stmt.Expression{}},
Params: []node.Node{&stmt.Expression{}},
ReturnType: &node.Identifier{},
Stmts: []node.Node{&stmt.Expression{}},
Stmt: &stmt.StmtList{},
},
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmts"},
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmt"},
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
},
{
@@ -360,7 +360,7 @@ var nodesToTest = []struct {
},
{
&stmt.Switch{
Cond: &expr.Variable{},
Cond: &expr.Variable{},
CaseList: &stmt.CaseList{},
},
[]string{"Cond", "CaseList"},

View File

@@ -289,7 +289,9 @@ func TestPhp7ParameterNode(t *testing.T) {
MethodName: &node.Identifier{Value: "foo"},
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
Params: expectedParams,
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -357,7 +359,9 @@ func TestPhp5ParameterNode(t *testing.T) {
MethodName: &node.Identifier{Value: "foo"},
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
Params: expectedParams,
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},