// generate all python classes from a RAML document
12897
func GenerateAllClasses(apiDef *raml.APIDefinition, dir string, capnp bool) ([]string, error) {
	// array of tip that need to be generated in the end of this
	// process. because it needs other object to be registered first
	delayedMI := []string{} // delayed multiple inheritance
	template := "./templates/python/class_python.tmpl"
	templateName := "class_python"

	names := []string{}
	for name, t := range types.AllTypes(apiDef, "") {
		var errGen error
		var results []string
		switch tip := t.Type.(type) {
		case string:
			rt := raml.Type{
				Type: tip,
			}
			if rt.IsMultipleInheritance() {
				delayedMI = append(delayedMI, tip)
			}
		case types.TypeInBody:
			newTipName := types.PascalCaseTypeName(tip)
			pc := newClass(apiDef, raml.Type{Type: "object"}, newTipName, "", tip.Properties, capnp)
			results, errGen = pc.generate(dir, template, templateName)
		case raml.Type:
			if name == "UUID" {
				continue
			}
			pc := newClassFromType(apiDef, tip, name, capnp)
			results, errGen = pc.generate(dir, template, templateName)
		}

		if errGen != nil {
			return names, errGen
		}
		names = append(names, results...)
	}

	for _, tip := range delayedMI {
		rt := raml.Type{
			Type: tip,
		}
		if parents, isMult := rt.MultipleInheritance(); isMult {
			pc := newClassFromType(apiDef, rt, strings.Join(parents, ""), capnp)
			results, err := pc.generate(dir, template, templateName)
			if err != nil {
				return names, err
			}
			names = append(names, results...)
		}

	}
	return names, nil

}
44491
func (g *Generator) generateMediaTypes(pkgDir string, funcs template.FuncMap) (err error) {
	funcs["decodegotyperef"] = decodeGoTypeRef
	funcs["decodegotypename"] = decodeGoTypeName
	typeDecodeTmpl := template.Must(template.New("typeDecode").Funcs(funcs).Parse(typeDecodeTmpl))
	var (
		mtFile string
		mtWr   *genapp.MediaTypesWriter
	)
	{
		mtFile = filepath.Join(pkgDir, "media_types.go")
		mtWr, err = genapp.NewMediaTypesWriter(mtFile)
		if err != nil {
			return
		}
	}
	defer func() {
		mtWr.Close()
		if err == nil {
			err = mtWr.FormatCode()
		}
	}()
	title := fmt.Sprintf("%s: Application Media Types", g.API.Context())
	imports := []*codegen.ImportSpec{
		codegen.SimpleImport("github.com/goadesign/goa"),
		codegen.SimpleImport("fmt"),
		codegen.SimpleImport("net/http"),
		codegen.SimpleImport("time"),
		codegen.SimpleImport("unicode/utf8"),
		codegen.NewImport("uuid", "github.com/goadesign/goa/uuid"),
	}
	for _, v := range g.API.MediaTypes {
		imports = codegen.AttributeImports(v.AttributeDefinition, imports, nil)
	}
	if err = mtWr.WriteHeader(title, g.Target, imports); err != nil {
		return err
	}
	g.genfiles = append(g.genfiles, mtFile)
	err = g.API.IterateMediaTypes(func(mt *design.MediaTypeDefinition) error {
		if (mt.Type.IsObject() || mt.Type.IsArray()) && !mt.IsError() {
			if err := mtWr.Execute(mt); err != nil {
				return err
			}
		}
		err := mt.IterateViews(func(view *design.ViewDefinition) error {
			p, _, err := mt.Project(view.Name)
			if err != nil {
				return err
			}
			return typeDecodeTmpl.Execute(mtWr.SourceFile, p)
		})
		return err
	})
	return
}
359859
func (exp *GetAttrExpr) All() []Node {
	res := []Node{exp.Cont, exp.Attr}
	for _, v := range exp.Args {
		res = append(res, v)
	}
	return res
}
136475
func generateDoc(htmlSrc string) string {
	tokenizer := xhtml.NewTokenizer(strings.NewReader(htmlSrc))
	tokens := buildTokenArray(tokenizer)
	scopes := findScopes(tokens)
	return walk(scopes)
}
726979
func (g *Generator) Generate() error {
	// first we read the code from which we should find the types
	if err := g.readPackageCode(g.options.Source); err != nil {
		return err
	}

	// then we generate code for the types given
	for _, rootType := range g.options.Types {
		if err := g.generateStructCode(rootType); err != nil {
			return err
		}
	}

	//
	g.Imports = strings.Join(toolbox.MapKeysToStringSlice(g.imports), "\n")
	return g.writeCode()
}
380170
func generateResource(parent, name string, resource *raml.Resource, t *template.Template, f *os.File) string {
	path := parent + name

	for _, method := range resource.Methods() {
		err := t.Execute(f, HandlerInfo{ramlapi.Variableize(method.DisplayName), method.Name, path, method.Description})
		if err != nil {
			log.Println("executing template:", err)
		}
	}

	// Get all children.
	for nestname, nested := range resource.Nested {
		return generateResource(path, nestname, nested, t, f)
	}
	return path
}
72674
func (gr *goResource) generateAPIImplementations(dir string) error {
	// generate the main API impl file, which only contains struct
	mainCtx := map[string]interface{}{
		"PackageName": gr.PackageName,
		"Name":        gr.Name,
		"Endpoint":    gr.Endpoint,
	}

	mainFile := filepath.Join(dir, strings.ToLower(gr.Name)+"_api")
	if err := commons.GenerateFile(mainCtx, "./templates/golang/server_resource_api_main_go.tmpl",
		"server_resource_api_main_go", mainFile+".go", false); err != nil {
		return err
	}

	// generate per methods file
	for _, sm := range gr.Methods {
		ctx := map[string]interface{}{
			"Method":      sm,
			"APIName":     gr.Name,
			"PackageName": gr.PackageName,
		}
		filename := mainFile + "_" + sm.MethodName + ".go"
		if err := commons.GenerateFile(ctx, "./templates/golang/server_resource_api_impl_go.tmpl",
			"server_resource_api_impl_go", filename, false); err != nil {
			return err
		}
	}
	return nil
}
727044
func (pc *class) generate(dir, template, name string) ([]string, error) {
	fileName := filepath.Join(dir, pc.Name()+".py")

	if pc.AliasOf != "" {
		return []string{pc.Name()}, commons.GenerateFile(pc, "./templates/python/class_alias.tmpl",
			"class_alias", fileName, true)
	}

	// generate enums
	typeNames := make([]string, 0)
	for _, f := range pc.Fields {
		if f.Enum != nil {
			typeNames = append(typeNames, f.Enum.Name)
			if err := f.Enum.generate(dir); err != nil {
				return typeNames, err
			}
		}
	}

	if pc.Enum != nil {
		typeNames = append(typeNames, pc.Enum.Name)
		return typeNames, pc.Enum.generate(dir)
	}

	typeNames = append(typeNames, pc.Name())
	return typeNames, commons.GenerateFile(pc, template, name, fileName, true)
}
128648
func (d *dataset) generate(dir string, limit int, test bool) {
	d.once.Do(func() {
		// Mark the dataset generated after we're done. This is needed for remote
		defer atomic.StoreUint32(&d.done, 1)

		csize := cacheSize(d.epoch*epochLength + 1)
		dsize := datasetSize(d.epoch*epochLength + 1)
		seed := seedHash(d.epoch*epochLength + 1)
		if test {
			csize = 1024
			dsize = 32 * 1024
		}
		// If we don't store anything on disk, generate and return
		if dir == "" {
			cache := make([]uint32, csize/4)
			generateCache(cache, d.epoch, seed)

			d.dataset = make([]uint32, dsize/4)
			generateDataset(d.dataset, d.epoch, cache)

			return
		}
		// Disk storage is needed, this will get fancy
		var endian string
		if !isLittleEndian() {
			endian = ".be"
		}
		path := filepath.Join(dir, fmt.Sprintf("full-R%d-%x%s", algorithmRevision, seed[:8], endian))
		logger := log.New("epoch", d.epoch)

		// We're about to mmap the file, ensure that the mapping is cleaned up when the
		// cache becomes unused.
		runtime.SetFinalizer(d, (*dataset).finalizer)

		// Try to load the file from disk and memory map it
		var err error
		d.dump, d.mmap, d.dataset, err = memoryMap(path)
		if err == nil {
			logger.Debug("Loaded old ethash dataset from disk")
			return
		}
		logger.Debug("Failed to load old ethash dataset", "err", err)

		// No previous dataset available, create a new dataset file to fill
		cache := make([]uint32, csize/4)
		generateCache(cache, d.epoch, seed)

		d.dump, d.mmap, d.dataset, err = memoryMapAndGenerate(path, dsize, func(buffer []uint32) { generateDataset(buffer, d.epoch, cache) })
		if err != nil {
			logger.Error("Failed to generate mapped ethash dataset", "err", err)

			d.dataset = make([]uint32, dsize/2)
			generateDataset(d.dataset, d.epoch, cache)
		}
		// Iterate over all previous instances and delete old ones
		for ep := int(d.epoch) - limit; ep >= 0; ep-- {
			seed := seedHash(uint64(ep)*epochLength + 1)
			path := filepath.Join(dir, fmt.Sprintf("full-R%d-%x%s", algorithmRevision, seed[:8], endian))
			os.Remove(path)
		}
	})
}
264832
func Generate(schema *rdl.Schema, params *GeneratorParams) error {
	packageDir, err := GenerationDir(params.Outdir, schema, params.Namespace)
	if err != nil {
		return err
	}
	//	getSetters := GenerationBoolOptionSet(options, "getsetters")
	registry := rdl.NewTypeRegistry(schema)
	for _, t := range schema.Types {
		tName, _, _ := rdl.TypeInfo(t)
		if strings.HasPrefix(string(tName), "rdl.") {
			continue
		}
		err := generateJavaType(params.Banner, schema, registry, packageDir, t, params.Namespace, params.GetSetters)
		if err != nil {
			return err
		}
	}
	cName := capitalize(string(schema.Name)) + "Schema"
	out, file, _, err := genutil.OutputWriter(packageDir, cName, ".java")
	if err != nil {
		return err
	}
	err = GenerateSchema(schema, cName, out, params.Namespace, params.Banner)
	out.Flush()
	file.Close()
	if err != nil {
		return err
	}
	return nil
}
697982
func main() {
	p := params{Timestamp: time.Now(), Name: "codegen"}
	for i := 0; i < numTypes; i++ {
		p.StringTypeNames = append(p.StringTypeNames, fmt.Sprintf("Test%03d", i))
	}

	baseDir, err := os.Getwd()
	die(err)
	baseDir = filepath.Join(baseDir, "..")

	fmt.Printf("Generating test files in %v\n", filepath.Join(baseDir, "_gen"))
	apath := filepath.Join(baseDir, "_gen", "A")

	_ = os.MkdirAll(apath, 0755)

	instantiateTemplate(modelTemplate, p, filepath.Join(apath, "codegen_model.go"))
	instantiateTemplate(schemaTemplate, p, filepath.Join(apath, "codegen_schema.go"))
	instantiateTemplate(dataTemplate, p, filepath.Join(apath, "codegen_data.go"))
}
1214336
func (_class VMPPClass) GetAll(sessionID SessionRef) (_retval []VMPPRef, _err error) {
	_method := "VMPP.get_all"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVMPPRefSetToGo(_method + " -> ", _result.Value)
	return
}
765735
func main() {
	var (
		settings         []Option
		settingsTemplate = createTemplate("templates/query_params.go.tmpl")
		filepath         = "../../search/query_params.go"
	)

	for _, opt := range options {
		if isSearch(opt.Kind) {
			settings = append(settings, opt)
		}
	}

	generateFile(settingsTemplate, settings, filepath)
}
66758
func (mhg MaterialAttributesHg) GenerateGeneric() (ma map[string]interface{}) {
	ma = map[string]interface{}{
		"auto_update":   mhg.AutoUpdate,
		"destination":   mhg.Destination,
		"invert_filter": mhg.InvertFilter,
		"name":          mhg.Name,
		"url":           mhg.URL,
	}

	if f := mhg.Filter.GenerateGeneric(); f != nil {
		ma["filter"] = f
	}
	return
}
1107739
func (c *CORS) generatePatterns() {
	if c.AllowOrigins != nil {
		for _, origin := range c.AllowOrigins {
			pattern := regexp.QuoteMeta(origin)
			pattern = strings.Replace(pattern, "\\*", ".*", -1)
			pattern = strings.Replace(pattern, "\\?", ".", -1)
			c.allowOriginPatterns = append(c.allowOriginPatterns, "^"+pattern+"$")
		}
	}
}
301709
func (v *version) RuntimeClasses() RuntimeClassInformer {
	return &runtimeClassInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
61639
func (codegen *CodeGenerator) Generate() (string, error) {
	for index, rawSchema := range codegen.rawSchemas {
		parsedSchema, err := ParseSchema(rawSchema)
		if err != nil {
			return "", err
		}

		schema, ok := parsedSchema.(*RecordSchema)
		if !ok {
			return "", errors.New("Not a Record schema.")
		}
		schemaInfo, err := newRecordSchemaInfo(schema)
		if err != nil {
			return "", err
		}

		buffer := &bytes.Buffer{}
		codegen.codeSnippets = append(codegen.codeSnippets, buffer)

		// write package and import only once
		if index == 0 {
			err = codegen.writePackageName(schemaInfo)
			if err != nil {
				return "", err
			}

			err = codegen.writeImportStatement()
			if err != nil {
				return "", err
			}
		}

		err = codegen.writeStruct(schemaInfo)
		if err != nil {
			return "", err
		}
	}

	formatted, err := format.Source([]byte(codegen.collectResult()))
	if err != nil {
		return "", err
	}

	return string(formatted), nil
}