-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefer_stmt.go
40 lines (32 loc) · 907 Bytes
/
defer_stmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package goastutil
import (
"fmt"
"go/ast"
)
type DeferStmt struct {
parent Stmt
*ast.DeferStmt
}
func NewDeferStmt(parent Stmt, stmt *ast.DeferStmt) *DeferStmt {
return &DeferStmt{DeferStmt: stmt, parent: parent}
}
func (s *DeferStmt) PrependStmt(st string) error {
return prependStmt(st, s.parent, s.DeferStmt)
}
func (s *DeferStmt) AppendStmt(st string) error {
return appendStmt(st, s.parent, s.DeferStmt)
}
func (ds *DeferStmt) StmtType() StmtType {
return DeferStmtType
}
func (ds *DeferStmt) Call() Expr {
return NewExpr(ds.DeferStmt.Call)
}
// String returns a string representation of the DeferStmt object.
//
// It formats the DeferStmt object as "defer [Call result]", where [Call result] is the
// string representation of the result of the Call method.
// It then returns the formatted string.
func (ds *DeferStmt) String() string {
return fmt.Sprintf("defer %v", ds.Call())
}