scanner

package
v0.0.0-...-a699420 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT, MIT Imports: 21 Imported by: 6

Documentation

Overview

Extracted from: gopkg.in/src-d/proteus.v1/scanner

Index

Constants

View Source
const (
	// Use default Golang proxy (???)
	GoProxy = "https://proxy.golang.org/"
)

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

func GetTempGoModFilepath

func GetTempGoModFilepath(rawPath string) string

GetTempGoModFilepath gets the go.mod file with which the package was loaded.

func RemoveGoPath

func RemoveGoPath(pkg *types.Package) string

func RemoveGoSrcClonePath

func RemoveGoSrcClonePath(pkgPath string) string

func SplitPathVersion

func SplitPathVersion(rawPath string) (path string, version string)

SplitPathVersion splits a path string (e.g. example.com/hello/world@1.0.1) into its path and version components. If no version notation is present, rawPath is returned.

func StringRemoveGoPath

func StringRemoveGoPath(pkgPath string) string

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) 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
	Ptr      bool
	Struct   bool
	ID       string
	TypesVar *types.Var
	Variadic bool
	Basic    bool
	Type     types.Type
}

BaseType contains the common fields for all the types.

func (*BaseType) GetType

func (t *BaseType) GetType() types.Type

func (*BaseType) GetTypesVar

func (t *BaseType) GetTypesVar() *types.Var

func (*BaseType) IsBasic

func (t *BaseType) IsBasic() bool

func (*BaseType) IsNullable

func (t *BaseType) IsNullable() bool

IsNullable reports wether the type is a pointer or not.

func (*BaseType) IsPtr

func (t *BaseType) IsPtr() bool

func (*BaseType) IsStruct

func (t *BaseType) IsStruct() bool

func (*BaseType) IsVariadic

func (t *BaseType) IsVariadic() bool

func (*BaseType) SetIsBasic

func (t *BaseType) SetIsBasic(v bool)

func (*BaseType) SetIsPtr

func (t *BaseType) SetIsPtr(v bool)

func (*BaseType) SetIsStruct

func (t *BaseType) SetIsStruct(v bool)

func (*BaseType) SetIsVariadic

func (t *BaseType) SetIsVariadic(v bool)

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) SetType

func (t *BaseType) SetType(v types.Type)

func (*BaseType) SetTypesVar

func (t *BaseType) SetTypesVar(v *types.Var)

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) IsBasic

func (b Basic) IsBasic() bool

func (Basic) IsNullable

func (b Basic) IsNullable() bool

IsNullable returns true ONLY if it's also a pointer. Otherwise, Basic types are not nullable, and have just the zero values.

Basic types: int, int8, int16, int32, int64 uint, uint8, uint16, uint32, uint64 uintptr float32, float64 byte rune string complex64, complex128

See: https://nilsmagnus.github.io/post/nillability-in-go/

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 Chan

type Chan struct {
	*BaseType
	Elem *types.Chan
}

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

func (Chan) String

func (m Chan) String() string

String returns a string representation for the type

func (Chan) TypeString

func (m Chan) TypeString() string

TypeString returns a string representation for the type casting

func (Chan) UnqualifiedName

func (m Chan) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Docs

type Docs struct {
	Doc     []string
	Comment []string
}

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

func (*Docs) SetComments

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

SetComments sets the documentation from an AST comment group.

func (*Docs) SetDocs

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

SetDocs sets the documentation from an AST comment group.

type Documentable

type Documentable interface {
	// SetDocs sets the documentation from an AST comment group.
	SetDocs(*ast.CommentGroup)
	SetComments(*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 {
	*BaseType
	Docs
	Name string
	// Receiver will not be nil if it's a method.
	Receiver Type
	Input    []Type
	Output   []Type
	// Variadic will be true if the last input parameter is variadic.
	Variadic  bool
	Signature string
	PkgPath   string
	PkgName   string
}

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

func (Func) String

func (m Func) String() string

String returns a string representation for the type

func (Func) TypeString

func (m Func) TypeString() string

TypeString returns a string representation for the type casting

func (Func) UnqualifiedName

func (m Func) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Interface

type Interface struct {
	*BaseType
	Docs
	Name    string
	Methods []*Func
}

Interface is an interface.

func (Interface) String

func (m Interface) String() string

String returns a string representation for the type

func (Interface) TypeString

func (m Interface) TypeString() string

TypeString returns a string representation for the type casting

func (Interface) UnqualifiedName

func (m Interface) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type MMap

type MMap struct {
	*BaseType
	Key   Type
	Value Type
}

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

func (MMap) String

func (m MMap) String() string

String returns a string representation for the type

func (MMap) TypeString

func (m MMap) TypeString() string

TypeString returns a string representation for the type casting

func (MMap) UnqualifiedName

func (m MMap) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Named

type Named struct {
	*BaseType
	Docs
	Path   string
	Name   string
	Object types.Object
}

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 {
	Path   string
	Name   string
	Module *packages.Module

	Structs    []*Struct
	Funcs      []*Func
	Interfaces []*Interface
	Methods    []*Func
	Types      []*Named // Types contains types found in the package.
}

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. A provided package path can be in the form `path@version`, or just `path` and the latest version will be used. For Go standard library packages, the local version is used (must have Go installed).

func NewDEPRECATED

func NewDEPRECATED(addGoPath bool, 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.

func (*Scanner) ScanWithCustomScanner

func (s *Scanner) ScanWithCustomScanner(sc ScannerFunc) ([]*Package, error)

ScanWithCustomScanner retrieves the scanned packages containing the extracted go types and structs; it uses the provided ScannerFunc.

type ScannerFunc

type ScannerFunc func(path string) (*packages.Package, error)

type Struct

type Struct struct {
	*BaseType
	Docs
	Name          string
	Fields        []*Field
	Type          *types.Named
	AnonymousType *types.Struct
	Embedded      []Type
}

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.

func (Struct) String

func (m Struct) String() string

String returns a string representation for the type

func (Struct) TypeString

func (m Struct) TypeString() string

TypeString returns a string representation for the type casting

func (Struct) UnqualifiedName

func (m Struct) UnqualifiedName() string

UnqualifiedName returns the bare name, without the package.

type Type

type Type interface {
	fmt.Stringer

	SetNullable(bool)
	IsNullable() bool

	SetIsPtr(bool)
	IsPtr() bool

	SetIsStruct(bool)
	IsStruct() 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

	GetTypesVar() *types.Var
	SetTypesVar(*types.Var)

	GetType() types.Type
	SetType(types.Type)

	SetIsVariadic(bool)
	IsVariadic() bool

	SetIsBasic(v bool)
	IsBasic() bool
}

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 NewChan

func NewChan(elem *types.Chan) Type

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

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