refactoring: remove StmtTraitAdaptationList node
This commit is contained in:
@@ -858,19 +858,6 @@ func (v *Dumper) StmtTrait(n *ast.StmtTrait) {
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
|
||||
func (v *Dumper) StmtTraitAdaptationList(n *ast.StmtTraitAdaptationList) {
|
||||
v.print(0, "&ast.StmtTraitAdaptationList{\n")
|
||||
v.indent++
|
||||
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
|
||||
v.dumpVertexList("Adaptations", n.Adaptations)
|
||||
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
|
||||
|
||||
v.indent--
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
|
||||
func (v *Dumper) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
|
||||
v.print(0, "&ast.StmtTraitMethodRef{\n")
|
||||
v.indent++
|
||||
@@ -892,7 +879,10 @@ func (v *Dumper) StmtTraitUse(n *ast.StmtTraitUse) {
|
||||
v.dumpToken("UseTkn", n.UseTkn)
|
||||
v.dumpVertexList("Traits", n.Traits)
|
||||
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
|
||||
v.dumpVertex("Adaptations", n.Adaptations)
|
||||
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
|
||||
v.dumpVertexList("Adaptations", n.Adaptations)
|
||||
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
|
||||
v.dumpToken("SemiColonTkn", n.SemiColonTkn)
|
||||
|
||||
v.indent--
|
||||
v.print(v.indent, "},\n")
|
||||
|
||||
@@ -886,21 +886,6 @@ func (f *formatter) StmtTrait(n *ast.StmtTrait) {
|
||||
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
|
||||
}
|
||||
|
||||
func (f *formatter) StmtTraitAdaptationList(n *ast.StmtTraitAdaptationList) {
|
||||
n.OpenCurlyBracketTkn = f.newToken('{', []byte("{"))
|
||||
|
||||
if len(n.Adaptations) > 0 {
|
||||
f.indent++
|
||||
f.formatStmts(&n.Adaptations)
|
||||
f.indent--
|
||||
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte("\n"))
|
||||
f.addIndent()
|
||||
}
|
||||
|
||||
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
|
||||
}
|
||||
|
||||
func (f *formatter) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
|
||||
if n.Trait != nil {
|
||||
n.Trait.Accept(f)
|
||||
@@ -916,11 +901,27 @@ func (f *formatter) StmtTraitUse(n *ast.StmtTraitUse) {
|
||||
|
||||
n.SeparatorTkns = f.formatList(n.Traits, ',')
|
||||
|
||||
if _, ok := n.Adaptations.(*ast.StmtTraitAdaptationList); ok {
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
}
|
||||
n.OpenCurlyBracketTkn = nil
|
||||
n.CloseCurlyBracketTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
|
||||
n.Adaptations.Accept(f)
|
||||
if len(n.Adaptations) > 0 {
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
n.OpenCurlyBracketTkn = f.newToken('{', []byte("{"))
|
||||
|
||||
if len(n.Adaptations) > 0 {
|
||||
f.indent++
|
||||
f.formatStmts(&n.Adaptations)
|
||||
f.indent--
|
||||
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte("\n"))
|
||||
f.addIndent()
|
||||
}
|
||||
|
||||
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
|
||||
} else {
|
||||
n.SemiColonTkn = f.newToken(';', []byte(";"))
|
||||
}
|
||||
}
|
||||
|
||||
func (f *formatter) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
|
||||
|
||||
@@ -2503,76 +2503,6 @@ func TestFormatter_StmtTrait_Implements(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatter_StmtTraitAdaptationList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
n := &ast.StmtTraitAdaptationList{}
|
||||
|
||||
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
|
||||
n.Accept(f)
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n.Accept(p)
|
||||
|
||||
expected := `{}`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatter_StmtTraitAdaptationList_List(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
n := &ast.StmtTraitAdaptationList{
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Method: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
},
|
||||
Alias: &ast.Identifier{
|
||||
Value: []byte("bar"),
|
||||
},
|
||||
},
|
||||
&ast.StmtTraitUsePrecedence{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Method: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
},
|
||||
Insteadof: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{
|
||||
Value: []byte("bar"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
|
||||
n.Accept(f)
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n.Accept(p)
|
||||
|
||||
expected := `{
|
||||
foo as bar;
|
||||
foo insteadof bar;
|
||||
}`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatter_StmtTraitMethodRef(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@@ -2646,7 +2576,6 @@ func TestFormatter_StmtTraitUse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Adaptations: &ast.StmtNop{},
|
||||
}
|
||||
|
||||
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
|
||||
@@ -2683,7 +2612,18 @@ func TestFormatter_StmtTraitUse_Adaptations(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Adaptations: &ast.StmtTraitAdaptationList{},
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Method: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
},
|
||||
Alias: &ast.Identifier{
|
||||
Value: []byte("baz"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
|
||||
@@ -2692,7 +2632,9 @@ func TestFormatter_StmtTraitUse_Adaptations(t *testing.T) {
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n.Accept(p)
|
||||
|
||||
expected := `use foo, bar {}`
|
||||
expected := `use foo, bar {
|
||||
foo as baz;
|
||||
}`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
|
||||
@@ -184,23 +184,21 @@ func (nsr *NamespaceResolver) StmtTraitUse(n *ast.StmtTraitUse) {
|
||||
nsr.ResolveName(t, "")
|
||||
}
|
||||
|
||||
if adaptationList, ok := n.Adaptations.(*ast.StmtTraitAdaptationList); ok {
|
||||
for _, a := range adaptationList.Adaptations {
|
||||
switch aa := a.(type) {
|
||||
case *ast.StmtTraitUsePrecedence:
|
||||
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
|
||||
if refTrait != nil {
|
||||
nsr.ResolveName(refTrait, "")
|
||||
}
|
||||
for _, insteadOf := range aa.Insteadof {
|
||||
nsr.ResolveName(insteadOf, "")
|
||||
}
|
||||
for _, a := range n.Adaptations {
|
||||
switch aa := a.(type) {
|
||||
case *ast.StmtTraitUsePrecedence:
|
||||
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
|
||||
if refTrait != nil {
|
||||
nsr.ResolveName(refTrait, "")
|
||||
}
|
||||
for _, insteadOf := range aa.Insteadof {
|
||||
nsr.ResolveName(insteadOf, "")
|
||||
}
|
||||
|
||||
case *ast.StmtTraitUseAlias:
|
||||
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
|
||||
if refTrait != nil {
|
||||
nsr.ResolveName(refTrait, "")
|
||||
}
|
||||
case *ast.StmtTraitUseAlias:
|
||||
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
|
||||
if refTrait != nil {
|
||||
nsr.ResolveName(refTrait, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,22 +354,20 @@ func TestResolveTraitUse(t *testing.T) {
|
||||
nameB,
|
||||
relativeNameB,
|
||||
},
|
||||
Adaptations: &ast.StmtTraitAdaptationList{
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUsePrecedence{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: fullyQualifiedNameB,
|
||||
Method: &ast.Identifier{Value: []byte("foo")},
|
||||
},
|
||||
Insteadof: []ast.Vertex{fullyQualifiedNameBC},
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUsePrecedence{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: fullyQualifiedNameB,
|
||||
Method: &ast.Identifier{Value: []byte("foo")},
|
||||
},
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: relativeNameBC,
|
||||
Method: &ast.Identifier{Value: []byte("foo")},
|
||||
},
|
||||
Alias: &ast.Identifier{Value: []byte("bar")},
|
||||
Insteadof: []ast.Vertex{fullyQualifiedNameBC},
|
||||
},
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: relativeNameBC,
|
||||
Method: &ast.Identifier{Value: []byte("foo")},
|
||||
},
|
||||
Alias: &ast.Identifier{Value: []byte("bar")},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -206,10 +206,6 @@ func (v *Null) StmtTrait(_ *ast.StmtTrait) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtTraitAdaptationList(_ *ast.StmtTraitAdaptationList) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtTraitMethodRef(_ *ast.StmtTraitMethodRef) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -531,12 +531,6 @@ func (p *printer) StmtTrait(n *ast.StmtTrait) {
|
||||
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
|
||||
}
|
||||
|
||||
func (p *printer) StmtTraitAdaptationList(n *ast.StmtTraitAdaptationList) {
|
||||
p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
|
||||
p.printList(n.Adaptations)
|
||||
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
|
||||
}
|
||||
|
||||
func (p *printer) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
|
||||
p.printNode(n.Trait)
|
||||
p.printToken(n.DoubleColonTkn, p.ifNode(n.Trait, []byte("::")))
|
||||
@@ -546,7 +540,10 @@ func (p *printer) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
|
||||
func (p *printer) StmtTraitUse(n *ast.StmtTraitUse) {
|
||||
p.printToken(n.UseTkn, []byte("use"))
|
||||
p.printSeparatedList(n.Traits, n.SeparatorTkns, []byte(","))
|
||||
p.printNode(n.Adaptations)
|
||||
p.printToken(n.OpenCurlyBracketTkn, p.ifNodeList(n.Adaptations, []byte("{")))
|
||||
p.printList(n.Adaptations)
|
||||
p.printToken(n.CloseCurlyBracketTkn, p.ifNodeList(n.Adaptations, []byte("}")))
|
||||
p.printToken(n.SemiColonTkn, p.ifNotToken(n.OpenCurlyBracketTkn, p.ifNotNodeList(n.Adaptations, []byte(";"))))
|
||||
}
|
||||
|
||||
func (p *printer) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
|
||||
|
||||
@@ -4339,31 +4339,6 @@ func TestPrinterPrintStmtThrow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitAdaptationList(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n := &ast.StmtTraitAdaptationList{
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Method: &ast.Identifier{Value: []byte("a")},
|
||||
},
|
||||
Alias: &ast.Identifier{Value: []byte("b")},
|
||||
},
|
||||
},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
expected := `{Foo::a as b;}`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintStmtTraitMethodRef(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@@ -4454,7 +4429,6 @@ func TestPrinterPrintStmtTraitUse(t *testing.T) {
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
},
|
||||
Adaptations: &ast.StmtNop{},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
@@ -4475,15 +4449,13 @@ func TestPrinterPrintStmtTraitAdaptations(t *testing.T) {
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
},
|
||||
Adaptations: &ast.StmtTraitAdaptationList{
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Method: &ast.Identifier{Value: []byte("a")},
|
||||
},
|
||||
Alias: &ast.Identifier{Value: []byte("b")},
|
||||
Adaptations: []ast.Vertex{
|
||||
&ast.StmtTraitUseAlias{
|
||||
Ref: &ast.StmtTraitMethodRef{
|
||||
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Method: &ast.Identifier{Value: []byte("a")},
|
||||
},
|
||||
Alias: &ast.Identifier{Value: []byte("b")},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user