1package pgs 2 3import "github.com/golang/protobuf/protoc-gen-go/descriptor" 4 5// Package is a container that encapsulates all the files under a single 6// package namespace. 7type Package interface { 8 Node 9 10 // The name of the proto package. 11 ProtoName() Name 12 13 // All the files loaded for this Package 14 Files() []File 15 16 addFile(f File) 17 18 setComments(c string) 19} 20 21type pkg struct { 22 fd *descriptor.FileDescriptorProto 23 files []File 24 25 comments string 26} 27 28func (p *pkg) ProtoName() Name { return Name(p.fd.GetPackage()) } 29func (p *pkg) Comments() string { return p.comments } 30 31func (p *pkg) Files() []File { return p.files } 32 33func (p *pkg) accept(v Visitor) (err error) { 34 if v == nil { 35 return nil 36 } 37 38 if v, err = v.VisitPackage(p); err != nil || v == nil { 39 return 40 } 41 42 for _, f := range p.Files() { 43 if err = f.accept(v); err != nil { 44 return 45 } 46 } 47 48 return 49} 50 51func (p *pkg) addFile(f File) { 52 f.setPackage(p) 53 p.files = append(p.files, f) 54} 55 56func (p *pkg) setComments(comments string) { 57 p.comments = comments 58} 59