File: source_code_info.go

package info (click to toggle)
golang-github-lyft-protoc-gen-star 2.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: makefile: 145
file content (56 lines) | stat: -rw-r--r-- 2,416 bytes parent folder | download | duplicates (2)
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
package pgs

import (
	descriptor "google.golang.org/protobuf/types/descriptorpb"
)

const (
	packagePath               int32 = 2  // FileDescriptorProto.Package
	messageTypePath           int32 = 4  // FileDescriptorProto.MessageType
	enumTypePath              int32 = 5  // FileDescriptorProto.EnumType
	servicePath               int32 = 6  // FileDescriptorProto.Service
	syntaxPath                int32 = 12 // FileDescriptorProto.Syntax
	messageTypeFieldPath      int32 = 2  // DescriptorProto.Field
	messageTypeNestedTypePath int32 = 3  // DescriptorProto.NestedType
	messageTypeEnumTypePath   int32 = 4  // DescriptorProto.EnumType
	messageTypeOneofDeclPath  int32 = 8  // DescriptorProto.OneofDecl
	enumTypeValuePath         int32 = 2  // EnumDescriptorProto.Value
	serviceTypeMethodPath     int32 = 2  // ServiceDescriptorProto.Method
)

// SourceCodeInfo represents data about an entity from the source. Currently
// this only contains information about comments protoc associates with
// entities.
//
// All comments have their // or /* */ stripped by protoc. See the
// SourceCodeInfo documentation for more details about how comments are
// associated with entities.
type SourceCodeInfo interface {
	// Location returns the SourceCodeInfo_Location from the file descriptor.
	Location() *descriptor.SourceCodeInfo_Location

	// LeadingComments returns any comment immediately preceding the entity,
	// without any whitespace between it and the comment.
	LeadingComments() string

	// LeadingDetachedComments returns each comment block or line above the
	// entity but separated by whitespace.
	LeadingDetachedComments() []string

	// TrailingComments returns any comment immediately following the entity,
	// without any whitespace between it and the comment. If the comment would be
	// a leading comment for another entity, it won't be considered a trailing
	// comment.
	TrailingComments() string
}

type sci struct {
	desc *descriptor.SourceCodeInfo_Location
}

func (info sci) Location() *descriptor.SourceCodeInfo_Location { return info.desc }
func (info sci) LeadingComments() string                       { return info.desc.GetLeadingComments() }
func (info sci) LeadingDetachedComments() []string             { return info.desc.GetLeadingDetachedComments() }
func (info sci) TrailingComments() string                      { return info.desc.GetTrailingComments() }

var _ SourceCodeInfo = sci{}