replace meta.SemiColonToken; fix printing stmt.TraitAdaptationList
This commit is contained in:
@@ -393,6 +393,8 @@ func (p *Printer) printNode(n node.Node) {
|
||||
p.printStmtSwitch(n)
|
||||
case *stmt.Throw:
|
||||
p.printStmtThrow(n)
|
||||
case *stmt.TraitAdaptationList:
|
||||
p.printStmtTraitAdaptationList(n)
|
||||
case *stmt.TraitMethodRef:
|
||||
p.printStmtTraitMethodRef(n)
|
||||
case *stmt.TraitUseAlias:
|
||||
@@ -2414,7 +2416,6 @@ func (p *Printer) printStmtNamespace(n node.Node) {
|
||||
|
||||
func (p *Printer) printStmtNop(n node.Node) {
|
||||
p.printMeta(n, meta.NodeStart)
|
||||
p.printMeta(n, meta.SemiColonToken)
|
||||
p.printMeta(n, meta.NodeEnd)
|
||||
}
|
||||
|
||||
@@ -2526,6 +2527,18 @@ func (p *Printer) printStmtThrow(n node.Node) {
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtTraitAdaptationList(n node.Node) {
|
||||
nn := n.(*stmt.TraitAdaptationList)
|
||||
p.printMeta(nn, meta.NodeStart)
|
||||
|
||||
io.WriteString(p.w, "{")
|
||||
p.printNodes(nn.Adaptations)
|
||||
p.printMeta(nn, meta.CloseCurlyBracesToken)
|
||||
io.WriteString(p.w, "}")
|
||||
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtTraitMethodRef(n node.Node) {
|
||||
nn := n.(*stmt.TraitMethodRef)
|
||||
p.printMeta(nn, meta.NodeStart)
|
||||
@@ -2582,15 +2595,7 @@ func (p *Printer) printStmtTraitUse(n node.Node) {
|
||||
io.WriteString(p.w, "use")
|
||||
p.joinPrint(",", nn.Traits)
|
||||
|
||||
if adaptationList, ok := nn.TraitAdaptationList.(*stmt.TraitAdaptationList); ok {
|
||||
p.printMeta(adaptationList, meta.OpenCurlyBracesToken)
|
||||
io.WriteString(p.w, "{")
|
||||
p.printNodes(adaptationList.Adaptations)
|
||||
p.printMeta(adaptationList, meta.CloseCurlyBracesToken)
|
||||
io.WriteString(p.w, "}")
|
||||
} else {
|
||||
p.printMeta(nn.TraitAdaptationList, meta.SemiColonToken)
|
||||
}
|
||||
p.Print(nn.TraitAdaptationList)
|
||||
|
||||
p.printMeta(nn, meta.NodeEnd)
|
||||
}
|
||||
|
||||
@@ -7604,10 +7604,15 @@ func TestPrinterPrintNop(t *testing.T) {
|
||||
Value: " ",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.TokenType,
|
||||
Value: ";",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := ` `
|
||||
expected := ` ;`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
@@ -8075,6 +8080,42 @@ func TestPrinterPrintStmtThrow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitAdaptationList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(&stmt.TraitAdaptationList{
|
||||
Meta: meta.Collection{
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.CloseCurlyBracesToken,
|
||||
},
|
||||
},
|
||||
Adaptations: []node.Node{
|
||||
&stmt.TraitUseAlias{
|
||||
Ref: &stmt.TraitMethodRef{
|
||||
Trait: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
||||
Method: &node.Identifier{Value: "a"},
|
||||
},
|
||||
Alias: &node.Identifier{Value: "b"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expected := ` {Foo::aasb }`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitMethodRef(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@@ -8214,12 +8255,12 @@ func TestPrinterPrintStmtTraitUse(t *testing.T) {
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.SemiColonToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.TokenType,
|
||||
Value: "",
|
||||
TokenName: meta.SemiColonToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -8254,7 +8295,7 @@ func TestPrinterPrintStmtTraitAdaptations(t *testing.T) {
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
Value: " ",
|
||||
TokenName: meta.OpenCurlyBracesToken,
|
||||
TokenName: meta.NodeStart,
|
||||
},
|
||||
&meta.Data{
|
||||
Type: meta.WhiteSpaceType,
|
||||
|
||||
Reference in New Issue
Block a user