-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
52 lines (47 loc) · 918 Bytes
/
types.go
File metadata and controls
52 lines (47 loc) · 918 Bytes
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
package gogencli
import (
"go/ast"
"strings"
)
func (g *Generator) IsGoGenerateLine(node ast.Node) bool {
if node == nil || g.root == nil || g.root.TokenFile == nil {
return false
}
switch n := node.(type) {
case *ast.CommentGroup:
if n == nil {
return false
}
for _, c := range n.List {
if g.IsGoGenerateLine(c) {
return true
}
}
case *ast.Comment:
if n == nil {
return false
}
if !n.Pos().IsValid() {
return false
}
// check if the comment is a //go:generate comment
text := n.Text
if !strings.HasPrefix(text, "//go:generate") {
return false
}
// check if the comment is on the same line as $GOLINE
var line int
for l := range g.root.TokenFile.Lines() {
if g.root.TokenFile.LineStart(l+1) > n.Pos() {
break
}
// $GOLINE env var is 1-based.
line = l + 1
}
if line != g.goLine {
return false
}
return true
}
return false
}