scanner

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoGoPathSet = errors.New("GOPATH environment variable is not set")

ErrNoGoPathSet is the error returned when the GOPATH variable is not set.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	*BaseType
	// Type represents the type being declared
	Type Type
	// Underlying represent the aliased type.
	Underlying Type
}

Alias represents a type declaration from a type to another type

func (Alias) IsNullable

func (a Alias) IsNullable() bool

func (Alias) IsRepeated

func (a Alias) IsRepeated() bool

func (Alias) String

func (a Alias) String() string

String returns a string representation for the type

func (Alias) TypeString

func (a Alias) TypeString() string

TypeString returns a string representation for the type casting

func (Alias) UnqualifiedName

func (a Alias) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type BaseType

type BaseType struct {
	Repeated bool
	Nullable bool
}

BaseType contains the common fields for all the types.

func (*BaseType) IsNullable

func (t *BaseType) IsNullable() bool

IsNullable reports wether the type is a pointer or not.

func (*BaseType) IsRepeated

func (t *BaseType) IsRepeated() bool

IsRepeated reports wether the type is repeated or not.

func (*BaseType) SetNullable

func (t *BaseType) SetNullable(v bool)

SetNullable sets the type as pointer.

func (*BaseType) SetRepeated

func (t *BaseType) SetRepeated(v bool)

SetRepeated sets the type as repeated or not repeated.

func (*BaseType) String

func (t *BaseType) String() string

String returns a string representation for the type

func (*BaseType) TypeString

func (t *BaseType) TypeString() string

TypeString returns a string representation for the type casting

func (*BaseType) UnqualifiedName

func (t *BaseType) UnqualifiedName() string

String returns a string representation for the type

type Basic

type Basic struct {
	*BaseType
	Name string
}

Basic is a basic type, which only is identified by its name.

func (Basic) IsNullable

func (b Basic) IsNullable() bool

IsNullable returns true. Basic types though cannot be nullable, they are considered so in protobuf.

func (Basic) String

func (b Basic) String() string

String returns a string representation for the type

func (Basic) TypeString

func (b Basic) TypeString() string

TypeString returns a string representation for the type casting

func (Basic) UnqualifiedName

func (b Basic) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Docs

type Docs struct {
	Doc []string
}

Docs holds the documentation of a struct, enum, value, field, etc.

func (*Docs) SetDocs

func (d *Docs) SetDocs(comments *ast.CommentGroup)

SetDocs sets the documentation from an AST comment group. It removes the //proteus:generate comment from the comments.

type Documentable

type Documentable interface {
	// SetDocs sets the documentation from an AST comment group.
	SetDocs(*ast.CommentGroup)
}

Documentable is something whose documentation can be set.

type Enum

type Enum struct {
	Docs
	Name       string
	Values     []*EnumValue
	IsStringer bool
}

Enum consists of a list of possible values.

type EnumValue

type EnumValue struct {
	Docs
	Name string
}

EnumValue is a possible value of an enum.

type Field

type Field struct {
	Docs
	Name string
	Type Type
}

Field contains name and type of a struct field.

type Func

type Func struct {
	Docs
	Name string
	// Receiver will not be nil if it's a method.
	Receiver Type
	Input    []Type
	Output   []Type
	// IsVariadic will be true if the last input parameter is variadic.
	IsVariadic bool
}

Func is either a function or a method. Receiver will be nil in functions, otherwise it is a method.

type Map

type Map struct {
	*BaseType
	Key   Type
	Value Type
}

Map is a map type with a key and a value type.

func (Map) String

func (m Map) String() string

String returns a string representation for the type

func (Map) TypeString

func (m Map) TypeString() string

TypeString returns a string representation for the type casting

func (Map) UnqualifiedName

func (m Map) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Named

type Named struct {
	*BaseType
	Path string
	Name string
}

Named is non-basic type identified by a name on some package.

func (Named) String

func (n Named) String() string

String returns a string representation for the type

func (Named) TypeString

func (n Named) TypeString() string

TypeString returns a string representation for the type casting

func (Named) UnqualifiedName

func (n Named) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Package

type Package struct {
	Resolved bool
	Path     string
	Name     string
	Structs  []*Struct
	Enums    []*Enum
	Funcs    []*Func
	Aliases  map[string]Type
}

Package holds information about a single Go package and a reference of all defined structs and type aliases. A Package is only safe to use once it is resolved.

type Scanner

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

Scanner scans packages looking for Go source files to parse and extract types and structs from.

func New

func New(packages ...string) (*Scanner, error)

New creates a new Scanner that will look for types and structs only in the given packages.

func (*Scanner) Scan

func (s *Scanner) Scan() ([]*Package, error)

Scan retrieves the scanned packages containing the extracted go types and structs.

type Struct

type Struct struct {
	Docs
	Generate   bool
	Name       string
	Fields     []*Field
	IsStringer bool
}

Struct represents a Go struct with its name and fields. All structs

func (*Struct) HasField

func (s *Struct) HasField(name string) bool

HasField reports wether a struct has a given field name.

type Type

type Type interface {
	fmt.Stringer
	SetRepeated(bool)
	IsRepeated() bool
	SetNullable(bool)
	IsNullable() bool
	// TypeString returns a string representing the final type.
	// Though this might seem that this should be just String, for Alias types
	// both representations are different: a string representation of the final
	// type, this is just the alias, while string contains also the underlying type.
	TypeString() string
	// Name returns the unqualified name.
	UnqualifiedName() string
}

Type is the common interface for all possible types supported in protogo. Type is neither a representation of a Go type nor a representation of a protobuf type. Is an intermediate representation to ease future steps in the conversion from Go to protobuf. All types can be repeated (or not).

func NewAlias

func NewAlias(typ, underlying Type) Type

func NewBasic

func NewBasic(name string) Type

NewBasic creates a new basic type given its name.

func NewMap

func NewMap(key, val Type) Type

NewMap creates a new map type with the given key and value types.

func NewNamed

func NewNamed(path, name string) Type

NewNamed creates a new named type given its package path and name.

Jump to

Keyboard shortcuts

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