Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / k8s.io / gengo / generator / default_package.go
1 /*
2 Copyright 2015 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package generator
18
19 import (
20         "k8s.io/gengo/types"
21 )
22
23 // DefaultPackage contains a default implementation of Package.
24 type DefaultPackage struct {
25         // Short name of package, used in the "package xxxx" line.
26         PackageName string
27         // Import path of the package, and the location on disk of the package.
28         PackagePath string
29
30         // Emitted at the top of every file.
31         HeaderText []byte
32
33         // Emitted only for a "doc.go" file; appended to the HeaderText for
34         // that file.
35         PackageDocumentation []byte
36
37         // If non-nil, will be called on "Generators"; otherwise, the static
38         // list will be used. So you should set only one of these two fields.
39         GeneratorFunc func(*Context) []Generator
40         GeneratorList []Generator
41
42         // Optional; filters the types exposed to the generators.
43         FilterFunc func(*Context, *types.Type) bool
44 }
45
46 func (d *DefaultPackage) Name() string { return d.PackageName }
47 func (d *DefaultPackage) Path() string { return d.PackagePath }
48
49 func (d *DefaultPackage) Filter(c *Context, t *types.Type) bool {
50         if d.FilterFunc != nil {
51                 return d.FilterFunc(c, t)
52         }
53         return true
54 }
55
56 func (d *DefaultPackage) Generators(c *Context) []Generator {
57         if d.GeneratorFunc != nil {
58                 return d.GeneratorFunc(c)
59         }
60         return d.GeneratorList
61 }
62
63 func (d *DefaultPackage) Header(filename string) []byte {
64         if filename == "doc.go" {
65                 return append(d.HeaderText, d.PackageDocumentation...)
66         }
67         return d.HeaderText
68 }
69
70 var (
71         _ = Package(&DefaultPackage{})
72 )