Documentation ¶
Overview ¶
Package analysis defines the types structures used by every output format. It may be seen as an extension of `go/types`.
Index ¶
- Constants
- Variables
- func LoadSource(sourceFile string) (*packages.Package, error)
- func LoadSources(sourceFiles []string) ([]*packages.Package, string, error)
- func LocalName(ty Type) string
- type Analysis
- type AnonymousType
- type Array
- type Basic
- type BasicKind
- type CommentKind
- type Enum
- type EnumMember
- type Linker
- type Map
- type Named
- type PkgSelector
- type Pointer
- type SpecialComment
- type Struct
- type StructField
- type Time
- type Type
- type Union
Constants ¶
const ( // ExhaustiveTypeSwitch may be used as marker to make futur refactor easier ExhaustiveTypeSwitch = "exhaustive analysis.Type type switch" // ExhaustiveAnonymousTypeSwitch may be used as marker to make futur refactor easier ExhaustiveAnonymousTypeSwitch = "exhaustive analysis.AnonymousType type switch" // ExhaustiveBasicKindSwitch may be used as marker to make futur refactor easier ExhaustiveBasicKindSwitch = "exhaustive analysis.BasicKind switch" )
const IgnoreDeclComment = "gomacro:no-enum"
Variables ¶
Functions ¶
func LoadSource ¶
LoadSource returns the `packages.Package` containing the given file.
func LoadSources ¶
LoadSources returns for each source file, the `*packages.Package` containing it. Since it only calls `packages.Load` once, it is a faster alternative to repeated `LoadSource` calls. It also returns the common (root) directory for all the files.
Types ¶
type Analysis ¶
type Analysis struct { // Types adds the additional analysis of this package, // and contains all the types needed by `Outline` and // their dependencies. Types map[types.Type]Type // Root is the root package used to query type information. Root *packages.Package // Source is the list of top-level types // defined in the analysis input file. Source []types.Type }
Analysis is the result of analyzing one package.
func NewAnalysisFromFile ¶
NewAnalysisFromFile uses the given Package to build the analysis for the types defined in `sourceFile`.
func NewAnalysisFromTypes ¶
NewAnalysisFromTypes build the analysis for the given `types`. `root` is the root package, required to query type information.
type AnonymousType ¶
type AnonymousType interface { Type // contains filtered or unexported methods }
AnonymousType are the types which may be seen without associated names. Contrary to the Go language, this package does not support anonymous structs, enums and unions.
type Basic ¶
Basic represents all simple types. Enums are special cased, meaning they are not of type `Basic`.
type BasicKind ¶
type BasicKind uint8
BasicKind is a simplified information of the kind of a basic type, typically shared by Dart, JSON and TypeScript generator
type CommentKind ¶
type CommentKind uint8
const (
// CommentSQL is used to add SQL statements to the generated tables creation code
CommentSQL CommentKind
)
type Enum ¶
type Enum struct { // Members contains all the values, even the unexported one Members []EnumMember // IsIota is `true` if the enum exported values are consecutive positive integer starting at zero. IsIota bool // contains filtered or unexported fields }
func (*Enum) Get ¶
func (e *Enum) Get(name string) EnumMember
Get return the enum value with Go name [name]. It panics if [name] is not found
func (*Enum) IsInteger ¶
IsInteger returns `true` is this enum is backed by integers (which may be negative and not contiguous)
func (*Enum) Underlying ¶
Underlying returns the basic type used by this enum/
type EnumMember ¶
type EnumMember struct { Const *types.Const // Comment is an optional comment associated with // the enum value. // If provided, it is used as label. Comment string }
EnumMember decribe the value of one item in an enumeration type.
type Linker ¶
type Linker struct { // Extension is added to all the output files returned // by the linker. Extension string // contains filtered or unexported fields }
Linker is responsible for attributing the correct output file to a given type, recreating the package tree.
func (Linker) GetOutput ¶
GetOutput returns the file where [ty] should be defined, adding [Extension]
func (Linker) IsPredefined ¶
func (Linker) OutputFiles ¶
OutputFiles returns a list of file names, adding [Extension]
type Named ¶
type Named struct { Underlying AnonymousType // contains filtered or unexported fields }
Named is a named type pointing to an `AnonymousType`. Structs, enums, and unions are NOT `Named`
type PkgSelector ¶
type PkgSelector struct {
// contains filtered or unexported fields
}
PkgSelector allows to retrict the packages import graph walk to the user written.
func NewPkgSelector ¶
func NewPkgSelector(root *packages.Package) PkgSelector
type SpecialComment ¶
type SpecialComment struct { Content string Kind CommentKind }
SpecialComment is a comment found on a struct declaration. See `CommentKind` for the supported comments.
type Struct ¶
type Struct struct { Name *types.Named Fields []StructField Comments []SpecialComment Implements []*Union }
type StructField ¶
type StructField struct { Type Type Field *types.Var // returned by Struct.Field() Tag reflect.StructTag // returned by Struct.Tag() }
func (StructField) Exported ¶
func (st StructField) Exported() bool
Exported returns `true` is the field is exported and should be included in the generated code. Ignored field are either :
- unexported
- with a 'json' tag '-'
- with a 'gomacro' tag 'ignore'
func (StructField) IsOpaqueFor ¶
func (st StructField) IsOpaqueFor(target string) bool
IsOpaqueFor returns true if the field should be considered as dynamic when generating code for [target]
func (StructField) JSONName ¶
func (st StructField) JSONName() string
JSONName returns the field name used by Go json package, that is, taking into account the json struct tag.
type Time ¶
type Time struct { // IsDate is true if only year/month/day are actually // of interest for this type. // The following heuristic is used to compute it : // - a type containing Date in its name (case insensitive match) will have IsDate = true IsDate bool }
Time is a special case for *time.Time, which is not handled like a regular "pointer to named struct"
type Type ¶
Type is the common interface for all the supported types. All implementation are pointers, so that they can easily be mapped to output types.
type Union ¶
type Union struct { // The types implementing this interface, sorted by name. // By construction, their Type() method will always return a *types.Named, // and Obj().Name() should be used as an identifier tag // accros the generators. Members []Type // contains filtered or unexported fields }
Union is deduced from interfaces, with the limitation that only types defined in the same package are considered as members of the union
func (*Union) IsExported ¶
IsExported returns `true` is the interface is exported.
Directories ¶
Path | Synopsis |
---|---|
test/echo
Package echo is a substitute for the http framework echo package.
|
Package echo is a substitute for the http framework echo package. |
test/inner
Package inner is only used to test apigen.
|
Package inner is only used to test apigen. |
Package sql implements the logic required to analyze the links between SQL tables (represented as structs in the Go source code).
|
Package sql implements the logic required to analyze the links between SQL tables (represented as structs in the Go source code). |
test/pq
Package pq is used as replacement for "github.com/lib/pq" in tests
|
Package pq is used as replacement for "github.com/lib/pq" in tests |