forked from lyft/protoc-gen-star
-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.go
58 lines (42 loc) · 1 KB
/
package.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
package pgs
import descriptor "google.golang.org/protobuf/types/descriptorpb"
// Package is a container that encapsulates all the files under a single
// package namespace.
type Package interface {
Node
// The name of the proto package.
ProtoName() Name
// All the files loaded for this Package
Files() []File
addFile(f File)
setComments(c string)
}
type pkg struct {
fd *descriptor.FileDescriptorProto
files []File
comments string
}
func (p *pkg) ProtoName() Name { return Name(p.fd.GetPackage()) }
func (p *pkg) Comments() string { return p.comments }
func (p *pkg) Files() []File { return p.files }
func (p *pkg) accept(v Visitor) (err error) {
if v == nil {
return nil
}
if v, err = v.VisitPackage(p); err != nil || v == nil {
return
}
for _, f := range p.Files() {
if err = f.accept(v); err != nil {
return
}
}
return
}
func (p *pkg) addFile(f File) {
f.setPackage(p)
p.files = append(p.files, f)
}
func (p *pkg) setComments(comments string) {
p.comments = comments
}