ast

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

This code is borrowed from https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.

func CamelCaseSlice

func CamelCaseSlice(elem []string) string

CamelCaseSlice is like CamelCase, but the argument is a slice of strings to be joined with "_".

func PrintComment

func PrintComment(hasEnum bool, file *ast.File)

PrintComment todo

func Rewrite

func Rewrite(g *protogen.Plugin)

Rewrite 重新文件

Types

type FieldInfo

type FieldInfo struct {
	FieldNameInProto string
	FieldNameInGo    string
	FieldTag         reflect.StructTag
}

type FileInfo

type FileInfo struct {
	FileName    string
	StructInfos []StructInfo
	HasEnum     bool
}

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(protoFiles []FileInfo, protoGenerator *protogen.Plugin) *Generator

func (*Generator) Generate

func (g *Generator) Generate(module string)

Generate produces the rewrite content to proto's Generator.

func (*Generator) ParseGoContent

func (g *Generator) ParseGoContent(outerFile *pluginpb.CodeGeneratorResponse_File)

ParseGoContent analyzes the single package constructed from the patterns and tags. ParseGoContent exits if there is an error.

type GoFile

type GoFile struct {
	// contains filtered or unexported fields
}

GoFile holds a single parsed astFile and associated data.

func (*GoFile) FoundProtoMessage

func (g *GoFile) FoundProtoMessage(typ string) (StructInfo, bool)

func (*GoFile) HasEnum

func (g *GoFile) HasEnum() bool

HasEnum todo

type StructInfo

type StructInfo struct {
	StructNameInProto string
	StructNameInGo    string
	FieldInfos        []FieldInfo
}

func WalkDescriptorProto

func WalkDescriptorProto(g *protogen.Plugin, dp *descriptor.DescriptorProto, typeNames []string) []StructInfo

func (*StructInfo) FindField

func (si *StructInfo) FindField(name string) (FieldInfo, bool)

Jump to

Keyboard shortcuts

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