generator

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package generator provides tools to generate ObjectBox entity bindings between GO structs & ObjectBox schema

Index

Constants

View Source
const Version = "4.0.0"

Version specifies the current generator version.

View Source
const VersionId = 6

VersionId specifies the current generator version identifier. It is used to validate generated code compatibility and is increased when there are changes in the generated code. This validation seems to be limited to Go: the generated code "knows" its version, and thus we can check at runtime if the generated code matches the lib version. Internal generator changes that don't change the output (in an incompatible way) do not cause an increase.

Variables

This section is empty.

Functions

func Clean

func Clean(codeGenerator CodeGenerator, path string) error

Clean removes generated files in the given path. Removes *.obx.* and objectbox-model.[go|h|...] but keeps objectbox-model.json

func ModelInfoFile

func ModelInfoFile(dir string) string

ModelInfoFile returns the model info JSON file name in the given directory

func PathIsDirOrPattern

func PathIsDirOrPattern(path string) bool

PathIsDirOrPattern checks whether the given path is a path pattern, a directory or a single file.

func Process

func Process(options Options) error

Process is the main API method of the package it takes source file & model-information file paths and generates bindings (as a sibling file to the source file)

func WriteFile

func WriteFile(file string, data []byte, permSource string) error

WriteFile writes data to targetFile, while using permissions either from the targetFile or permSource

Types

type CodeGenerator

type CodeGenerator interface {
	// BindingFiles returns the names of language binding files for the given entity file.
	// TODO "binding files" is not intuitive name (especially without mentioning "**language** binding").
	//      Rename to "language", "generated" or "output" files instead?
	//      Rename functions, variables, etc. accordingly.
	BindingFiles(forFile string, options Options) []string

	// ModelFile returns the language-specific model source file for the given JSON info file path
	ModelFile(forFile string, options Options) string

	// IsGeneratedFile returns true if the given path is recognized as a file generated by this generator
	IsGeneratedFile(file string) bool

	// IsSourceFile returns true if the given path is recognized as an input file by this generator.
	// E.g. for Go files, ending with ".go", and for C++ ending with ".fbs".
	IsSourceFile(file string) bool

	// ParseSource reads the input file and creates a model representation
	ParseSource(sourceFile string) (*model.ModelInfo, error)

	// WriteBindingFiles generates and writes binding source code files
	WriteBindingFiles(sourceFile string, options Options, mergedModel *model.ModelInfo) error

	// WriteModelBindingFile generates and writes binding source code file for model setup
	WriteModelBindingFile(options Options, mergedModel *model.ModelInfo) error
}

CodeGenerator interface is used to abstract per-language generators, e.g. for Go, C, C++, etc

type Options

type Options struct {
	ModelInfoFile  string
	Rand           *rand.Rand
	InPath         string
	OutPath        string
	OutHeadersPath string

	// NOTE - currently only supports one
	CodeGenerator CodeGenerator
}

Options provide configuration for the generator

Directories

Path Synopsis
c
go

Jump to

Keyboard shortcuts

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