-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwraps.go
487 lines (410 loc) · 8.17 KB
/
wraps.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
package astrav
import "go/ast"
// Comment wraps ast.Comment
type Comment struct {
*ast.Comment
baseNode
}
// CommentGroup wraps ast.CommentGroup
type CommentGroup struct {
*ast.CommentGroup
baseNode
}
// Field wraps ast.Field
type Field struct {
*ast.Field
baseNode
}
// FieldList wraps ast.FieldList
type FieldList struct {
*ast.FieldList
baseNode
}
// BadExpr wraps ast.BadExpr
type BadExpr struct {
*ast.BadExpr
baseNode
}
// Ident wraps ast.Ident
type Ident struct {
*ast.Ident
baseNode
}
// Ellipsis wraps ast.Ellipsis
type Ellipsis struct {
*ast.Ellipsis
baseNode
}
// BasicLit wraps ast.BasicLit
type BasicLit struct {
*ast.BasicLit
baseNode
}
// FuncLit wraps ast.FuncLit
type FuncLit struct {
*ast.FuncLit
baseNode
}
// CompositeLit wraps ast.CompositeLit
type CompositeLit struct {
*ast.CompositeLit
baseNode
}
// ParenExpr wraps ast.ParenExpr
type ParenExpr struct {
*ast.ParenExpr
baseNode
}
// SelectorExpr wraps ast.SelectorExpr
type SelectorExpr struct {
*ast.SelectorExpr
baseNode
}
// PackageName returns the package name
func (s *SelectorExpr) PackageName() *Ident {
if s.X == nil {
return nil
}
if _, ok := s.X.(*ast.Ident); !ok {
return nil
}
return s.findChildByAstNode(s.X).(*Ident)
}
// IndexExpr wraps ast.IndexExpr
type IndexExpr struct {
*ast.IndexExpr
baseNode
}
// SliceExpr wraps ast.SliceExpr
type SliceExpr struct {
*ast.SliceExpr
baseNode
}
// TypeAssertExpr wraps ast.TypeAssertExpr
type TypeAssertExpr struct {
*ast.TypeAssertExpr
baseNode
}
// CallExpr wraps ast.CallExpr
type CallExpr struct {
*ast.CallExpr
baseNode
}
// SelExpr returns the SelectorExpr for the function.
func (s *CallExpr) SelExpr() Node {
return s.findChildByAstNode(s.node.(*ast.CallExpr).Fun)
}
// Args returns the Arguments for the function.
func (s *CallExpr) Args() []Node {
var nodes []Node
for _, arg := range s.node.(*ast.CallExpr).Args {
nodes = append(nodes, s.findChildByAstNode(arg))
}
return nodes
}
// StarExpr wraps ast.StarExpr
type StarExpr struct {
*ast.StarExpr
baseNode
}
// UnaryExpr wraps ast.UnaryExpr
type UnaryExpr struct {
*ast.UnaryExpr
baseNode
}
// BinaryExpr wraps ast.BinaryExpr
type BinaryExpr struct {
*ast.BinaryExpr
baseNode
}
// X returns left hand side nodes
func (s *BinaryExpr) X() Node {
return s.findChildByAstNode(s.node.(*ast.BinaryExpr).X)
}
// Y returns left hand side nodes
func (s *BinaryExpr) Y() Node {
return s.findChildByAstNode(s.node.(*ast.BinaryExpr).Y)
}
// KeyValueExpr wraps ast.KeyValueExpr
type KeyValueExpr struct {
*ast.KeyValueExpr
baseNode
}
// ArrayType wraps ast.ArrayType
type ArrayType struct {
*ast.ArrayType
baseNode
}
// StructType wraps ast.StructType
type StructType struct {
*ast.StructType
baseNode
}
// FuncType wraps ast.FuncType
type FuncType struct {
*ast.FuncType
baseNode
}
// Params returns the parameter FieldList
func (s *FuncType) Params() *FieldList {
if s.FuncType.Params == nil {
return nil
}
return s.findChildByAstNode(s.FuncType.Params).(*FieldList)
}
// Results returns the return parameter FieldList
func (s *FuncType) Results() *FieldList {
if s.FuncType.Results == nil {
return nil
}
return s.findChildByAstNode(s.FuncType.Results).(*FieldList)
}
// InterfaceType wraps ast.InterfaceType
type InterfaceType struct {
*ast.InterfaceType
baseNode
}
// MapType wraps ast.MapType
type MapType struct {
*ast.MapType
baseNode
}
// ChanType wraps ast.ChanType
type ChanType struct {
*ast.ChanType
baseNode
}
// BadStmt wraps ast.BadStmt
type BadStmt struct {
*ast.BadStmt
baseNode
}
// DeclStmt wraps ast.DeclStmt
type DeclStmt struct {
*ast.DeclStmt
baseNode
}
// EmptyStmt wraps ast.EmptyStmt
type EmptyStmt struct {
*ast.EmptyStmt
baseNode
}
// LabeledStmt wraps ast.LabeledStmt
type LabeledStmt struct {
*ast.LabeledStmt
baseNode
}
// ExprStmt wraps ast.ExprStmt
type ExprStmt struct {
*ast.ExprStmt
baseNode
}
// SendStmt wraps ast.SendStmt
type SendStmt struct {
*ast.SendStmt
baseNode
}
// IncDecStmt wraps ast.IncDecStmt
type IncDecStmt struct {
*ast.IncDecStmt
baseNode
}
// AssignStmt wraps ast.AssignStmt
type AssignStmt struct {
*ast.AssignStmt
baseNode
}
// RHS returns right hand side nodes
func (s *AssignStmt) RHS() []Node {
var nodes []Node
for _, node := range s.node.(*ast.AssignStmt).Rhs {
nodes = append(nodes, s.findChildByAstNode(node))
}
return nodes
}
// LHS returns left hand side nodes
func (s *AssignStmt) LHS() []Node {
var nodes []Node
for _, node := range s.node.(*ast.AssignStmt).Lhs {
nodes = append(nodes, s.findChildByAstNode(node))
}
return nodes
}
// GoStmt wraps ast.GoStmt
type GoStmt struct {
*ast.GoStmt
baseNode
}
// DeferStmt wraps ast.DeferStmt
type DeferStmt struct {
*ast.DeferStmt
baseNode
}
// ReturnStmt wraps ast.ReturnStmt
type ReturnStmt struct {
*ast.ReturnStmt
baseNode
}
// BranchStmt wraps ast.BranchStmt
type BranchStmt struct {
*ast.BranchStmt
baseNode
}
// BlockStmt wraps ast.BlockStmt
type BlockStmt struct {
*ast.BlockStmt
baseNode
}
// IfStmt wraps ast.IfStmt
type IfStmt struct {
*ast.IfStmt
baseNode
}
// Init returns the init node of the if statement
func (s *IfStmt) Init() Node {
if s.IfStmt.Init == nil {
return nil
}
return s.findChildByAstNode(s.IfStmt.Init)
}
// Cond returns the condition node of the if statement
func (s *IfStmt) Cond() Node {
if s.IfStmt.Cond == nil {
return nil
}
return s.findChildByAstNode(s.IfStmt.Cond)
}
// Body returns the body node of the if statement
func (s *IfStmt) Body() Node {
if s.IfStmt.Body == nil {
return nil
}
return s.findChildByAstNode(s.IfStmt.Body)
}
// Else returns the else node of the if statement
func (s *IfStmt) Else() Node {
if s.IfStmt.Else == nil {
return nil
}
return s.findChildByAstNode(s.IfStmt.Else)
}
// CaseClause wraps ast.CaseClause
type CaseClause struct {
*ast.CaseClause
baseNode
}
// SwitchStmt wraps ast.SwitchStmt
type SwitchStmt struct {
*ast.SwitchStmt
baseNode
}
// TypeSwitchStmt wraps ast.TypeSwitchStmt
type TypeSwitchStmt struct {
*ast.TypeSwitchStmt
baseNode
}
// CommClause wraps ast.CommClause
type CommClause struct {
*ast.CommClause
baseNode
}
// SelectStmt wraps ast.SelectStmt
type SelectStmt struct {
*ast.SelectStmt
baseNode
}
// ForStmt wraps ast.ForStmt
type ForStmt struct {
*ast.ForStmt
baseNode
}
// Init returns the init node of the for loop
func (s *ForStmt) Init() Node {
if s.ForStmt.Init == nil {
return nil
}
return s.findChildByAstNode(s.ForStmt.Init)
}
// Cond returns the condition node of the for loop
func (s *ForStmt) Cond() Node {
if s.ForStmt.Cond == nil {
return nil
}
return s.findChildByAstNode(s.ForStmt.Cond)
}
// Post returns the post iteration node of the for loop
func (s *ForStmt) Post() Node {
if s.ForStmt.Post == nil {
return nil
}
return s.findChildByAstNode(s.ForStmt.Post)
}
// RangeStmt wraps ast.RangeStmt
type RangeStmt struct {
*ast.RangeStmt
baseNode
}
// Key returns the key of the range statment
func (s *RangeStmt) Key() Node {
if s.RangeStmt.Key == nil {
return nil
}
return s.findChildByAstNode(s.RangeStmt.Key)
}
// Value returns the value of the range statment
func (s *RangeStmt) Value() Node {
if s.RangeStmt.Value == nil {
return nil
}
return s.findChildByAstNode(s.RangeStmt.Value)
}
// X returns the variable to range over
func (s *RangeStmt) X() Node {
if s.RangeStmt.X == nil {
return nil
}
return s.findChildByAstNode(s.RangeStmt.X)
}
// ImportSpec wraps ast.ImportSpec
type ImportSpec struct {
*ast.ImportSpec
baseNode
}
// ValueSpec wraps ast.ValueSpec
type ValueSpec struct {
*ast.ValueSpec
baseNode
}
// TypeSpec wraps ast.TypeSpec
type TypeSpec struct {
*ast.TypeSpec
baseNode
}
// BadDecl wraps ast.BadDecl
type BadDecl struct {
*ast.BadDecl
baseNode
}
// GenDecl wraps ast.GenDecl
type GenDecl struct {
*ast.GenDecl
baseNode
}
// FuncDecl wraps ast.FuncDecl
type FuncDecl struct {
*ast.FuncDecl
baseNode
}
// Params returns the parameter FieldList
func (s *FuncDecl) Params() *FieldList {
return s.ChildByNodeType(NodeTypeFuncType).(*FuncType).Params()
}
// Results returns the return parameter FieldList
func (s *FuncDecl) Results() *FieldList {
return s.ChildByNodeType(NodeTypeFuncType).(*FuncType).Results()
}
// File wraps ast.File
type File struct {
*ast.File
baseNode
}