descriptor

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Overview

Package descriptor provides descriptor types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareFileLocations

func CompareFileLocations(one FileLocation, two FileLocation) int

CompareFileLocations returns -1 if one < two, 1 if one > two, 0 otherwise.

Types

type FileDescriptor

type FileDescriptor interface {
	// ProtoreflectFileDescriptor returns the protoreflect.FileDescriptor representing this FileDescriptor.
	//
	// This will always contain SourceCodeInfo.
	ProtoreflectFileDescriptor() protoreflect.FileDescriptor

	// FileDescriptorProto returns the FileDescriptorProto representing this File.
	//
	// This is not a copy - do not modify!
	FileDescriptorProto() *descriptorpb.FileDescriptorProto
	// IsImport returns true if the File is an import.
	//
	// An import is a file that is either:
	//
	//   - A Well-Known Type included from the compiler and imported by a targeted file.
	//   - A file that was included from a Buf module dependency and imported by a targeted file.
	//   - A file that was not targeted, but was imported by a targeted file.
	//
	// We use "import" as this matches with the protoc concept of --include_imports, however
	// import is a bit of an overloaded term.
	IsImport() bool

	// IsSyntaxUnspecified denotes whether the file did not have a syntax explicitly specified.
	//
	// Per the FileDescriptorProto spec, it would be fine in this case to just leave the syntax field
	// unset to denote this and to set the syntax field to "proto2" if it is specified. However,
	// protoc does not set the syntax field if it was "proto2". Plugins may want to differentiate
	// between "proto2" and unset, and this field allows them to.
	IsSyntaxUnspecified() bool

	// UnusedDependencyIndexes are the indexes within the Dependency field on FileDescriptorProto for
	// those dependencies that are not used.
	//
	// This matches the shape of the PublicDependency and WeakDependency fields.
	UnusedDependencyIndexes() []int32

	// ToProto converts the FileDescriptor to its Protobuf representation.
	ToProto() *descriptorv1.FileDescriptor
	// contains filtered or unexported methods
}

FileDescriptor is a protoreflect.FileDescriptor with additional properties.

The raw FileDescriptorProto is also provided from this interface. are provided.

func FileDescriptorsForProtoFileDescriptors

func FileDescriptorsForProtoFileDescriptors(protoFileDescriptors []*descriptorv1.FileDescriptor) ([]FileDescriptor, error)

FileDescriptorsForProtoFileDescriptors returns a new slice of FileDescriptors for the given descriptorv1.FileDescriptorDescriptors.

type FileLocation

type FileLocation interface {
	// FileDescriptor is the FileDescriptor associated with the FileLocation.
	//
	// Always present.
	FileDescriptor() FileDescriptor
	// SourcePath returns the path within the FileDescriptorProto of the FileLocation.
	SourcePath() protoreflect.SourcePath

	// StartLine returns the zero-indexed start line, if known.
	StartLine() int
	// StartColumn returns the zero-indexed start column, if known.
	StartColumn() int
	// EndLine returns the zero-indexed end line, if known.
	EndLine() int
	// EndColumn returns the zero-indexed end column, if known.
	EndColumn() int
	// LeadingComments returns any leading comments, if known.
	LeadingComments() string
	// TrailingComments returns any trailing comments, if known.
	TrailingComments() string
	// LeadingDetachedComments returns any leading detached comments, if known.
	LeadingDetachedComments() []string
	// ToProto converts the FileLocation to its Protobuf representation.
	ToProto() *descriptorv1.FileLocation
	// contains filtered or unexported methods
}

FileLocation is a reference to a FileDescriptor or to a location within a FileDescriptor.

A FileLocation always has a file name.

func NewFileLocation

func NewFileLocation(
	fileDescriptor FileDescriptor,
	sourceLocation protoreflect.SourceLocation,
) FileLocation

NewFileLocation returns a new FileLocation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL