1/*
2Copyright 2015 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package generator
18
19import (
20	"io"
21
22	"k8s.io/gengo/namer"
23	"k8s.io/gengo/types"
24)
25
26const (
27	GolangFileType = "golang"
28)
29
30// DefaultGen implements a do-nothing Generator.
31//
32// It can be used to implement static content files.
33type DefaultGen struct {
34	// OptionalName, if present, will be used for the generator's name, and
35	// the filename (with ".go" appended).
36	OptionalName string
37
38	// OptionalBody, if present, will be used as the return from the "Init"
39	// method. This causes it to be static content for the entire file if
40	// no other generator touches the file.
41	OptionalBody []byte
42}
43
44func (d DefaultGen) Name() string                                        { return d.OptionalName }
45func (d DefaultGen) Filter(*Context, *types.Type) bool                   { return true }
46func (d DefaultGen) Namers(*Context) namer.NameSystems                   { return nil }
47func (d DefaultGen) Imports(*Context) []string                           { return []string{} }
48func (d DefaultGen) PackageVars(*Context) []string                       { return []string{} }
49func (d DefaultGen) PackageConsts(*Context) []string                     { return []string{} }
50func (d DefaultGen) GenerateType(*Context, *types.Type, io.Writer) error { return nil }
51func (d DefaultGen) Filename() string                                    { return d.OptionalName + ".go" }
52func (d DefaultGen) FileType() string                                    { return GolangFileType }
53func (d DefaultGen) Finalize(*Context, io.Writer) error                  { return nil }
54
55func (d DefaultGen) Init(c *Context, w io.Writer) error {
56	_, err := w.Write(d.OptionalBody)
57	return err
58}
59
60var (
61	_ = Generator(DefaultGen{})
62)
63