genutil

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package genutil contains helper functions for autogenerating code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutogenString

func AutogenString() string

AutogenString returns the string which makes gondola identify this file as autogenerated.

func IsAutogen

func IsAutogen(filename string) bool

IsAutogen returns wheter the given filename exists and was autogenerated by a gondola tool.

func WriteAutogen

func WriteAutogen(filename string, data []byte) error

WriteAutogen writes the given autogenerated data to the given filename. Code will be first formatted using go/format. It will only overwrite the existing file if it was autogenerated. Tools autogenerating code should always use this function to avoid overwriting files which are not autogenerated.

Types

type Package

type Package struct {
	*types.Package
	// contains filtered or unexported fields
}

Package represents a parsed package with all its dependencies. Use NewPackage to create a Package.

func NewPackage

func NewPackage(path string) (*Package, error)

NewPackage returns a new Package struct, which can be used to generate code related to the package. The package might be given as either an absolute path or an import path. If the package can't be found or the package is not compilable, this function returns an error.

func (*Package) ASTFiles

func (p *Package) ASTFiles() map[string]*ast.File

func (*Package) Dir

func (p *Package) Dir() string

Dir returns the package source directory.

func (*Package) ExportedTypes

func (p *Package) ExportedTypes(include *regexp.Regexp, exclude *regexp.Regexp) []*types.Named

ExportedTypes works like Types, but only returns types that are exported.

func (*Package) FileSet

func (p *Package) FileSet() *token.FileSet

func (*Package) Info

func (p *Package) Info() *types.Info

func (*Package) SelectedTypes

func (p *Package) SelectedTypes(include *regexp.Regexp, exclude *regexp.Regexp, names []string) ([]*types.Named, error)

SelectedTypes works similarly to Types, but tests all types if include != nil or exclude != nil, otherwise it acts like p.ExportedTypes(nil, nil). Types explicitely named in the names argument are always included in the returned value. If any of the named types does not exist, an error is returned.

func (*Package) Types

func (p *Package) Types(include *regexp.Regexp, exclude *regexp.Regexp) []*types.Named

Types returns the types declared in the package which match the required constraints. If excluded != nil, any type matching it gets excluded. If include != nil, only types matching it are returned.

Jump to

Keyboard shortcuts

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