generate

package
v0.0.0-...-2b35e24 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2019 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// YEPPath is the go import path of the base yep package
	YEPPath string = "github.com/npiganeau/yep"
	// ModelsPath is the go import path of the yep/models package
	ModelsPath string = "github.com/npiganeau/yep/yep/models"
	// TypesPath is the go import path of the yep/models/types package
	TypesPath string = "github.com/npiganeau/yep/yep/models/types"
	// GeneratePath is the go import path of this package
	GeneratePath string = "github.com/npiganeau/yep/yep/tools/generate"
	// PoolPath is the go import path of the autogenerated pool package
	PoolPath string = "github.com/npiganeau/yep/pool"
)

Variables

View Source
var (

	// YEPDir is the directory of the base yep package
	YEPDir string
)

Functions

func CreateFileFromTemplate

func CreateFileFromTemplate(fileName string, template *template.Template, data interface{})

CreateFileFromTemplate generates a new file from the given template and data

func CreatePool

func CreatePool(program *loader.Program, dir string)

CreatePool generates the pool package by parsing the source code AST of the given program. The generated package will be put in the given dir.

func GetModelsASTData

func GetModelsASTData(program *loader.Program) map[string]ModelASTData

GetModelsASTData returns the ModelASTData of all models found when parsing program.

func GetModelsASTDataForModules

func GetModelsASTDataForModules(modInfos []*ModuleInfo) map[string]ModelASTData

GetModelsASTDataForModules returns the MethodASTData for all methods in given modules.

func GetModulePaths

func GetModulePaths(program *loader.Program) []string

GetModulePaths returns the list of paths of all packages that are part of a module.

Types

type FieldASTData

type FieldASTData struct {
	Name     string
	RelModel string
	Type     TypeData
	IsRS     bool
}

A FieldASTData is a holder for a field's data that will be used for pool code generation

type MethodASTData

type MethodASTData struct {
	Name    string
	Doc     string
	PkgPath string
	Params  []ParamData
	Returns []TypeData
}

A MethodASTData is a holder for a method's data that will be used for pool code generation

type ModelASTData

type ModelASTData struct {
	Name    string
	Fields  map[string]FieldASTData
	Methods map[string]MethodASTData
	Mixins  map[string]bool
	Embeds  map[string]bool
}

A ModelASTData holds fields and methods data of a Model

type ModuleInfo

type ModuleInfo struct {
	loader.PackageInfo
	ModType PackageType
}

A ModuleInfo is a wrapper around loader.Package with additional data to describe a module.

func GetModulePackages

func GetModulePackages(program *loader.Program) []*ModuleInfo

GetModulePackages returns a slice of PackageInfo for packages that are yep modules, that is: - A package that declares a "MODULE_NAME" constant - A package that is in a subdirectory of a package Also returns the 'yep/models' package since all models are initialized there

func NewModuleInfo

func NewModuleInfo(pack *loader.PackageInfo, modType PackageType) *ModuleInfo

NewModuleInfo returns a pointer to a new moduleInfo instance

type PackageType

type PackageType int8

A PackageType describes a type of module

const (
	// Base is the PackageType for the base package of a module
	Base PackageType = iota
	// Subs is the PackageType for a sub package of a module
	Subs
	// Models is the PackageType for the yep/models package
	Models
)

type ParamData

type ParamData struct {
	Name     string
	Variadic bool
	Type     TypeData
}

A ParamData holds the name and type of a method parameter

type TypeData

type TypeData struct {
	Type       string
	ImportPath string
}

A TypeData holds a Type string and optional import path for this type.

Jump to

Keyboard shortcuts

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