source

package
v0.0.0-...-7342f7f Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package source helps deal with Go source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoFmt

func GoFmt(dst io.Writer, src io.Reader) error

GoFmt reads all of src, applies "gofmt" to it, and then writes the result to dst.

func GoImports

func GoImports(dst io.Writer, src io.Reader) error

GoImports executes the 'goimports' command, piping in the contents of src and writing the results to dst.

func GoPath

func GoPath() (string, error)

GoPath returns the GOPATH using Go 1.8 and later rules. If the GOPATH environment var is defined, it uses that, otherwise it assumes $HOME/go.

Types

type ScopedQualifier

type ScopedQualifier struct{ Scope, Qual string }

ScopedQualifier is a simple pair of strings: a scope and a qualifying identifier (a package name).

type StringSet

type StringSet map[string]struct{}

StringSet stores an unordered set of strings.

func NewStringSet

func NewStringSet(values ...string) StringSet

NewStringSet creates a StringSet with some elements.

func Union

func Union(sets ...StringSet) StringSet

Union returns a set containing all elements in any of the input sets.

func (StringSet) Add

func (s StringSet) Add(x string)

Add adds an element to a StringSet

func (StringSet) Del

func (s StringSet) Del(x string)

Del removes an element from a StringSet

func (StringSet) Ni

func (s StringSet) Ni(x string) bool

Ni checks if an element is in the set.

func (StringSet) Slice

func (s StringSet) Slice() []string

Slice returns the elements in a slice, sorted.

func (StringSet) String

func (s StringSet) String() string

type Type

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

Type represents a genericised type. Examples: $T, []$T, chan $T, map[$K]$V, struct { F $T }, and so on. It only understands types, it does not support genericised type _declarations_. Each type parameter may belong to a different scope after refinement, but each Type is constructed initially within a single scope.

func MustNewType

func MustNewType(scope, t string) *Type

MustNewType is NewType but where all errors cause a panic.

func NewType

func NewType(scope, t string) (*Type, error)

NewType parses a generic type string into a Type. All parameters and selector expressions are assumed to belong to the one given scope.

func (*Type) Params

func (p *Type) Params() []TypeParam

Params returns a sorted slice of parameter names.

func (*Type) Plain

func (p *Type) Plain() bool

Plain is true if the type has no parameters (is not generic).

func (*Type) Refine

func (p *Type) Refine(in TypeInferenceMap) (bool, error)

Refine fills in type parameters according to the provided map. It returns true if the refinement had any effect. If a parameter is not in the input map, it is left unrefined. If no parameters are in the input map, it does nothing.

func (*Type) RenameQualifier

func (p *Type) RenameQualifier(scope, oldq, newq string)

RenameQualifier looks for qualified identifiers from the given scope and if the X is an ident matching oldx, then it is renamed to newx. This is useful for renaming an import.

func (*Type) ScopedQualifiers

func (p *Type) ScopedQualifiers() map[ScopedQualifier]struct{}

ScopedQualifiers returns a new set with all the qualifiers used in qualified identifiers, and their originating scope.

func (*Type) String

func (p *Type) String() string

type TypeInferenceMap

type TypeInferenceMap map[TypeParam]*Type

TypeInferenceMap (TypeParam -> *Type) holds inferences made about type parameters.s

func (TypeInferenceMap) ApplyDefault

func (m TypeInferenceMap) ApplyDefault(t *Type)

ApplyDefault sets all keys associated with a nil type to a given default type.

func (TypeInferenceMap) Infer

func (m TypeInferenceMap) Infer(p, q *Type) error

Infer attempts to add inferences to the map `m` such that `p.Refine(m)` and `q.Refine(m)` are similar. It returns an error if this is impossible.

func (TypeInferenceMap) Note

func (m TypeInferenceMap) Note(t *Type)

Note ensures type params from t are keys in the map.

type TypeParam

type TypeParam struct {
	Scope, Ident string
}

TypeParam identifies a type parameter in a pattern.

Jump to

Keyboard shortcuts

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