// New initialises a new Generator for the corresponding package's variable
//
// Returns an error if the package or variable are invalid
183339
func New(pkg string, variable string) (*Generator, error) {
	scope, docs, err := parsePackageSource(pkg)
	if err != nil {
		return nil, err
	}

	importer, funcs, err := analyzeCode(scope, docs, variable)
	if err != nil {
		return nil, err
	}

	return &Generator{
		Name:    docs.Name,
		Imports: importer.Imports(),
		funcs:   funcs,
	}, nil
}
1230143
func New(code int32, message string, args ...interface{}) Error {
	if len(args) > 0 {
		return &apiError{code, fmt.Sprintf(message, args...)}
	}
	return &apiError{code, message}
}
1142213
func NewGenerator(pattern string, inputArgs *GeneratorArgs) (generator Generator, err error) {
	args := GeneratorArgs{}

	// Copy inputArgs so the caller can't change them.
	if inputArgs != nil {
		args = *inputArgs
	}
	if err = args.initialize(); err != nil {
		return nil, err
	}

	var regexp *syntax.Regexp
	regexp, err = syntax.Parse(pattern, args.Flags)
	if err != nil {
		return
	}

	var gen *internalGenerator
	gen, err = newGenerator(regexp, &args)
	if err != nil {
		return
	}

	return gen, nil
}
891879
func NewGenerator(pkg, iface string) (*Generator, error) {
	p, err := importer.DefaultWithTestFiles().Import(pkg)
	if err != nil {
		return nil, err
	}
	obj := p.Scope().Lookup(iface)
	if obj == nil {
		return nil, fmt.Errorf("interface %s missing", iface)
	}
	if !types.IsInterface(obj.Type()) {
		return nil, fmt.Errorf("%s should be an interface, was %s", iface, obj.Type())
	}
	g := &Generator{
		ifaceName: iface,
		pkg:       p,
		iface:     obj.Type().Underlying().(*types.Interface).Complete(),
	}
	g.SetTemplate(defaultMockTemplate)
	return g, nil
}
618780
func New(typesMap derive.TypesMap, p derive.Printer, deps map[string]derive.Dependency) derive.Generator {
	return &gen{
		TypesMap: typesMap,
		printer:  p,
		mathPkg:  p.NewImport("math", "math"),
		keys:     deps["keys"],
		sort:     deps["sort"],
	}
}
856963
func New(loader Loader) *Env {
	if loader == nil {
		loader = &StringLoader{}
	}
	return &Env{loader, make(map[string]Func), make(map[string]Filter), make(map[string]Test), make([]parse.NodeVisitor, 0)}
}
675892
func New(reg *descriptor.Registry, useRequestContext bool, registerFuncSuffix, pathTypeString string, allowPatchFeature bool) gen.Generator {
	var imports []descriptor.GoPackage
	for _, pkgpath := range []string{
		"context",
		"io",
		"net/http",
		"github.com/grpc-ecosystem/grpc-gateway/runtime",
		"github.com/grpc-ecosystem/grpc-gateway/utilities",
		"github.com/golang/protobuf/proto",
		"google.golang.org/grpc",
		"google.golang.org/grpc/codes",
		"google.golang.org/grpc/grpclog",
		"google.golang.org/grpc/status",
	} {
		pkg := descriptor.GoPackage{
			Path: pkgpath,
			Name: path.Base(pkgpath),
		}
		if err := reg.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
			for i := 0; ; i++ {
				alias := fmt.Sprintf("%s_%d", pkg.Name, i)
				if err := reg.ReserveGoPackageAlias(alias, pkg.Path); err != nil {
					continue
				}
				pkg.Alias = alias
				break
			}
		}
		imports = append(imports, pkg)
	}

	var pathType pathType
	switch pathTypeString {
	case "", "import":
		// paths=import is default
	case "source_relative":
		pathType = pathTypeSourceRelative
	default:
		glog.Fatalf(`Unknown path type %q: want "import" or "source_relative".`, pathTypeString)
	}

	return &generator{
		reg:                reg,
		baseImports:        imports,
		useRequestContext:  useRequestContext,
		registerFuncSuffix: registerFuncSuffix,
		pathType:           pathType,
		allowPatchFeature:  allowPatchFeature,
	}
}
478592
func New(m string, a ...interface{}) error {
	return errors.Wrap(fmt.Errorf(m, a...), 1)
}
261767
func NewGenerator(options *Options) *Generator {
	var g = &Generator{}
	// first we validate the flags
	if err := options.Validate(); err != nil {
		panic(err)
	}
	g.options = options
	// we initiate the values on the generator
	g.init()
	return g
}
1035715
func New(cfg ...Config) *html.Engine {
	c := DefaultConfig()
	if len(cfg) > 0 {
		c = cfg[0]
	}
	// pass the Pug/Jade configs to the html's configuration

	s := html.New(html.Config(c))
	s.Middleware = jade.Parse
	return s
}
60403
func New(initializer Initializer) *Value {
	f := &Value{
		initializer: initializer,
	}
	f.Lock()
	return f
}
1292076
func New(branch int) (generator.Generator, error) {
	if branch < 1 {
		return nil, fmt.Errorf("invalid branch factor %d", branch)
	}
	nt, err := node.NewType("/tn")
	if err != nil {
		return nil, err
	}
	p, err := predicate.NewImmutable("parent_of")
	if err != nil {
		return nil, err
	}
	return &treeGenerator{
		branch:    branch,
		nodeType:  nt,
		predicate: p,
	}, nil
}
1190226
func New(id string, runtime *runc.Runc, stdio proc.Stdio) *Init {
	p := &Init{
		id:        id,
		runtime:   runtime,
		stdio:     stdio,
		status:    0,
		waitBlock: make(chan struct{}),
	}
	p.initState = &createdState{p: p}
	return p
}
275903
func NewGenerator(genfunc string, imports []*codegen.ImportSpec, flags map[string]string, customflags []string) (*Generator, error) {
	var (
		outDir, designPkgPath string
		debug                 bool
	)

	if o, ok := flags["out"]; ok {
		outDir = o
	}
	if d, ok := flags["design"]; ok {
		designPkgPath = d
	}
	if d, ok := flags["debug"]; ok {
		var err error
		debug, err = strconv.ParseBool(d)
		if err != nil {
			return nil, fmt.Errorf("failed to parse debug flag: %s", err)
		}
	}

	return &Generator{
		Genfunc:       genfunc,
		Imports:       imports,
		Flags:         flags,
		CustomFlags:   customflags,
		OutDir:        outDir,
		DesignPkgPath: designPkgPath,
		debug:         debug,
	}, nil
}
6148
func NewGenerator(iface *Interface, pkg string, inPackage bool) *Generator {

	var roots []string

	for _, root := range filepath.SplitList(build.Default.GOPATH) {
		roots = append(roots, filepath.Join(root, "src"))
	}

	g := &Generator{
		iface:             iface,
		pkg:               pkg,
		ip:                inPackage,
		localizationCache: make(map[string]string),
		packagePathToName: make(map[string]string),
		nameToPackagePath: make(map[string]string),
		packageRoots:      roots,
	}

	g.addPackageImportWithName("github.com/stretchr/testify/mock", "mock")
	return g
}
1233420
func (l loader) New(ctx context.Context) (backend.Crypto, error) {
	out.Debug(ctx, "Using Crypto Backend: %s (EXPERIMENTAL)", name)
	return New(ctxutil.GetConfigDir(ctx), client.GetClient(ctx))
}
665763
func New(cfg interface{}, gadgets ...Gadgeter) *App {
	config := GetConfig(cfg)
	return &App{
		gadgets: config.CreateGadgets(gadgets...),
	}
}