Merge pull request #31731 from lavalamp/gengo
Automatic merge from submit-queue Gengo go2idl is now gengo.
This commit is contained in:
38
Godeps/Godeps.json
generated
38
Godeps/Godeps.json
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ImportPath": "k8s.io/kubernetes",
|
||||
"GoVersion": "go1.6",
|
||||
"GodepVersion": "v74",
|
||||
"GodepVersion": "v69",
|
||||
"Packages": [
|
||||
"github.com/ugorji/go/codec/codecgen",
|
||||
"github.com/onsi/ginkgo/ginkgo",
|
||||
@@ -2591,6 +2591,42 @@
|
||||
"ImportPath": "gopkg.in/yaml.v2",
|
||||
"Rev": "53feefa2559fb8dfa8d81baad31be332c97d6c77"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/args",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/import-boss/generators",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/generators",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/sets",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/generator",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/namer",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/parser",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/types",
|
||||
"Rev": "9d004f4877d8dc116a678d35e43498404625599d"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/heapster/metrics/api/v1/types",
|
||||
"Comment": "v1.2.0-beta.1",
|
||||
|
1890
Godeps/LICENSES
generated
1890
Godeps/LICENSES
generated
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
"SelectorRegexp": "k8s[.]io",
|
||||
"AllowedPrefixes": [
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl",
|
||||
"k8s.io/gengo",
|
||||
"k8s.io/kubernetes/third_party",
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
]
|
||||
|
@@ -22,13 +22,13 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
clientgenargs "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/fake"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@@ -22,10 +22,10 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
clientgenargs "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
|
@@ -21,10 +21,10 @@ import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
|
@@ -21,9 +21,9 @@ import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genFakeForGroup produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
|
@@ -21,9 +21,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genFakeForType produces a file for each top-level type.
|
||||
|
@@ -21,10 +21,10 @@ import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
)
|
||||
|
||||
|
@@ -22,8 +22,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genExpansion produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
|
@@ -19,10 +19,10 @@ package generators
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
)
|
||||
|
||||
// genGroup produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
|
@@ -21,9 +21,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genClientForType produces a file for each top-level type.
|
||||
|
@@ -18,7 +18,7 @@ package generators
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/gengo/args"
|
||||
clientgenargs "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
@@ -135,6 +135,7 @@ func parseIncludedTypesOverrides() (map[unversioned.GroupVersion][]string, error
|
||||
|
||||
func main() {
|
||||
arguments := args.Default()
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
flag.Parse()
|
||||
var cmdArgs string
|
||||
flag.VisitAll(func(f *flag.Flag) {
|
||||
|
@@ -23,10 +23,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@@ -35,7 +35,9 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/conversion-gen/generators"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@@ -47,6 +49,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
arguments.OutputFileBaseName = "conversion_generated"
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
|
||||
// Custom args.
|
||||
customArgs := &generators.CustomArgs{
|
||||
|
@@ -1,344 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generators
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
)
|
||||
|
||||
func Test_isRootedUnder(t *testing.T) {
|
||||
testCases := []struct {
|
||||
path string
|
||||
roots []string
|
||||
expect bool
|
||||
}{
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: nil,
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"/bad",
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"/foo",
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"/bad",
|
||||
"/foo",
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar/qux/zorb",
|
||||
roots: []string{
|
||||
"/foo/bar/qux",
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"/foo/bar",
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
path: "/foo/barn",
|
||||
roots: []string{
|
||||
"/foo/bar",
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"/foo/barn",
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
path: "/foo/bar",
|
||||
roots: []string{
|
||||
"",
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
r := isRootedUnder(tc.path, tc.roots)
|
||||
if r != tc.expect {
|
||||
t.Errorf("case[%d]: expected %t, got %t for %q in %q", i, tc.expect, r, tc.path, tc.roots)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_hasDeepCopyMethod(t *testing.T) {
|
||||
testCases := []struct {
|
||||
typ types.Type
|
||||
expect bool
|
||||
}{
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
// No DeepCopy method.
|
||||
Methods: map[string]*types.Type{},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// No DeepCopy method.
|
||||
"method": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func()"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{},
|
||||
Results: []*types.Type{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// Wrong signature (no result).
|
||||
"DeepCopy": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func()"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{},
|
||||
Results: []*types.Type{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// Wrong signature (wrong result).
|
||||
"DeepCopy": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func() int"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{},
|
||||
Results: []*types.Type{
|
||||
{
|
||||
Name: types.Name{Name: "int"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// Correct signature.
|
||||
"DeepCopy": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func() pkgname.typename"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{},
|
||||
Results: []*types.Type{
|
||||
{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// Wrong signature (has params).
|
||||
"DeepCopy": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func(int) pkgname.typename"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{
|
||||
{
|
||||
Name: types.Name{Name: "int"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
},
|
||||
Results: []*types.Type{
|
||||
{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: types.Type{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
Methods: map[string]*types.Type{
|
||||
// Wrong signature (extra results).
|
||||
"DeepCopy": {
|
||||
Name: types.Name{Package: "pkgname", Name: "func() (pkgname.typename, int)"},
|
||||
Kind: types.Func,
|
||||
Signature: &types.Signature{
|
||||
Parameters: []*types.Type{},
|
||||
Results: []*types.Type{
|
||||
{
|
||||
Name: types.Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
{
|
||||
Name: types.Name{Name: "int"},
|
||||
Kind: types.Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
r := hasDeepCopyMethod(&tc.typ)
|
||||
if r != tc.expect {
|
||||
t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_extractTagParams(t *testing.T) {
|
||||
testCases := []struct {
|
||||
comments []string
|
||||
expect *tagValue
|
||||
}{
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
},
|
||||
expect: nil,
|
||||
},
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
"+k8s:deepcopy-gen",
|
||||
},
|
||||
expect: &tagValue{
|
||||
value: "",
|
||||
register: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
"+k8s:deepcopy-gen=package",
|
||||
},
|
||||
expect: &tagValue{
|
||||
value: "package",
|
||||
register: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
"+k8s:deepcopy-gen=package,register",
|
||||
},
|
||||
expect: &tagValue{
|
||||
value: "package",
|
||||
register: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
"+k8s:deepcopy-gen=package,register=true",
|
||||
},
|
||||
expect: &tagValue{
|
||||
value: "package",
|
||||
register: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
comments: []string{
|
||||
"Human comment",
|
||||
"+k8s:deepcopy-gen=package,register=false",
|
||||
},
|
||||
expect: &tagValue{
|
||||
value: "package",
|
||||
register: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
r := extractTag(tc.comments)
|
||||
if r == nil && tc.expect != nil {
|
||||
t.Errorf("case[%d]: expected non-nil", i)
|
||||
}
|
||||
if r != nil && tc.expect == nil {
|
||||
t.Errorf("case[%d]: expected nil, got %v", i, *r)
|
||||
}
|
||||
if r != nil && *r != *tc.expect {
|
||||
t.Errorf("case[%d]: expected %v, got %v", i, *tc.expect, *r)
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,8 +48,10 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/deepcopy-gen/generators"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/deepcopy-gen/generators"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
@@ -60,6 +62,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
arguments.OutputFileBaseName = "deepcopy_generated"
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
|
||||
// Custom args.
|
||||
customArgs := &generators.CustomArgs{}
|
||||
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generator_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
)
|
||||
|
||||
func construct(t *testing.T, files map[string]string) *generator.Context {
|
||||
b := parser.New()
|
||||
for name, src := range files {
|
||||
if err := b.AddFile("/tmp/"+name, name, []byte(src)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
c, err := generator.NewContext(b, namer.NameSystems{
|
||||
"public": namer.NewPublicNamer(0),
|
||||
"private": namer.NewPrivateNamer(0),
|
||||
}, "public")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func TestSnippetWriter(t *testing.T) {
|
||||
var structTest = map[string]string{
|
||||
"base/foo/proto/foo.go": `
|
||||
package foo
|
||||
|
||||
// Blah is a test.
|
||||
// A test, I tell you.
|
||||
type Blah struct {
|
||||
// A is the first field.
|
||||
A int64 ` + "`" + `json:"a"` + "`" + `
|
||||
|
||||
// B is the second field.
|
||||
// Multiline comments work.
|
||||
B string ` + "`" + `json:"b"` + "`" + `
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
c := construct(t, structTest)
|
||||
b := &bytes.Buffer{}
|
||||
err := generator.NewSnippetWriter(b, c, "$", "$").
|
||||
Do("$.|public$$.|private$", c.Order[0]).
|
||||
Error()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
}
|
||||
if e, a := "Blahblah", b.String(); e != a {
|
||||
t.Errorf("Expected %q, got %q", e, a)
|
||||
}
|
||||
|
||||
err = generator.NewSnippetWriter(b, c, "$", "$").
|
||||
Do("$.|public", c.Order[0]).
|
||||
Error()
|
||||
if err == nil {
|
||||
t.Errorf("expected error on invalid template")
|
||||
} else {
|
||||
// Dear reader, I apologize for making the worst change
|
||||
// detection test in the history of ever.
|
||||
if e, a := "snippet_writer_test.go:78", err.Error(); !strings.Contains(a, e) {
|
||||
t.Errorf("Expected %q but didn't find it in %q", e, a)
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,11 +26,11 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
@@ -27,9 +27,9 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genProtoIDL produces a .proto IDL.
|
||||
|
@@ -17,8 +17,8 @@ limitations under the License.
|
||||
package protobuf
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
type ImportTracker struct {
|
||||
|
@@ -21,9 +21,9 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
type localNamer struct {
|
||||
|
@@ -25,8 +25,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
func newProtobufPackage(packagePath, packageName string, generateAll bool, omitFieldTypes map[types.Name]struct{}) *protobufPackage {
|
||||
|
@@ -18,7 +18,7 @@ package protobuf
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||
|
@@ -33,7 +33,7 @@ limitations under the License.
|
||||
// {
|
||||
// "SelectorRegexp": "k8s[.]io",
|
||||
// "AllowedPrefixes": [
|
||||
// "k8s.io/kubernetes/cmd/libs/go2idl",
|
||||
// "k8s.io/gengo/examples",
|
||||
// "k8s.io/kubernetes/third_party"
|
||||
// ],
|
||||
// "ForbiddenPrefixes": [
|
||||
@@ -57,9 +57,10 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/import-boss/generators"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/import-boss/generators"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@@ -74,6 +75,7 @@ func main() {
|
||||
"k8s.io/kubernetes/cmd/...",
|
||||
"k8s.io/kubernetes/plugin/...",
|
||||
}
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
// arguments.VerifyOnly = true
|
||||
|
||||
if err := arguments.Execute(
|
||||
|
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package namer
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
)
|
||||
|
||||
func TestNameStrategy(t *testing.T) {
|
||||
u := types.Universe{}
|
||||
|
||||
// Add some types.
|
||||
base := u.Type(types.Name{Package: "foo/bar", Name: "Baz"})
|
||||
base.Kind = types.Struct
|
||||
|
||||
tmp := u.Type(types.Name{Package: "", Name: "[]bar.Baz"})
|
||||
tmp.Kind = types.Slice
|
||||
tmp.Elem = base
|
||||
|
||||
tmp = u.Type(types.Name{Package: "", Name: "map[string]bar.Baz"})
|
||||
tmp.Kind = types.Map
|
||||
tmp.Key = types.String
|
||||
tmp.Elem = base
|
||||
|
||||
tmp = u.Type(types.Name{Package: "foo/other", Name: "Baz"})
|
||||
tmp.Kind = types.Struct
|
||||
tmp.Members = []types.Member{{
|
||||
Embedded: true,
|
||||
Type: base,
|
||||
}}
|
||||
|
||||
u.Type(types.Name{Package: "", Name: "string"})
|
||||
|
||||
o := Orderer{NewPublicNamer(0)}
|
||||
order := o.OrderUniverse(u)
|
||||
orderedNames := make([]string, len(order))
|
||||
for i, t := range order {
|
||||
orderedNames[i] = o.Name(t)
|
||||
}
|
||||
expect := []string{"Baz", "Baz", "MapStringToBaz", "SliceBaz", "String"}
|
||||
if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Wanted %#v, got %#v", e, a)
|
||||
}
|
||||
|
||||
o = Orderer{NewRawNamer("my/package", nil)}
|
||||
order = o.OrderUniverse(u)
|
||||
orderedNames = make([]string, len(order))
|
||||
for i, t := range order {
|
||||
orderedNames[i] = o.Name(t)
|
||||
}
|
||||
|
||||
expect = []string{"[]bar.Baz", "bar.Baz", "map[string]bar.Baz", "other.Baz", "string"}
|
||||
if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Wanted %#v, got %#v", e, a)
|
||||
}
|
||||
|
||||
o = Orderer{NewRawNamer("foo/bar", nil)}
|
||||
order = o.OrderUniverse(u)
|
||||
orderedNames = make([]string, len(order))
|
||||
for i, t := range order {
|
||||
orderedNames[i] = o.Name(t)
|
||||
}
|
||||
|
||||
expect = []string{"Baz", "[]Baz", "map[string]Baz", "other.Baz", "string"}
|
||||
if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Wanted %#v, got %#v", e, a)
|
||||
}
|
||||
|
||||
o = Orderer{NewPublicNamer(1)}
|
||||
order = o.OrderUniverse(u)
|
||||
orderedNames = make([]string, len(order))
|
||||
for i, t := range order {
|
||||
orderedNames[i] = o.Name(t)
|
||||
}
|
||||
expect = []string{"BarBaz", "MapStringToBarBaz", "OtherBaz", "SliceBarBaz", "String"}
|
||||
if e, a := expect, orderedNames; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Wanted %#v, got %#v", e, a)
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package namer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
)
|
||||
|
||||
func TestPluralNamer(t *testing.T) {
|
||||
exceptions := map[string]string{
|
||||
// The type name is already in the plural form
|
||||
"Endpoints": "endpoints",
|
||||
}
|
||||
public := NewPublicPluralNamer(exceptions)
|
||||
private := NewPrivatePluralNamer(exceptions)
|
||||
|
||||
cases := []struct {
|
||||
typeName string
|
||||
expectedPrivate string
|
||||
expectedPublic string
|
||||
}{
|
||||
{
|
||||
"Pod",
|
||||
"pods",
|
||||
"Pods",
|
||||
},
|
||||
{
|
||||
"Entry",
|
||||
"entries",
|
||||
"Entries",
|
||||
},
|
||||
{
|
||||
"Endpoints",
|
||||
"endpoints",
|
||||
"Endpoints",
|
||||
},
|
||||
{
|
||||
"Bus",
|
||||
"buses",
|
||||
"Buses",
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
testType := &types.Type{Name: types.Name{Name: c.typeName}}
|
||||
if e, a := c.expectedPrivate, private.Name(testType); e != a {
|
||||
t.Errorf("Unexpected result from private plural namer. Expected: %s, Got: %s", e, a)
|
||||
}
|
||||
if e, a := c.expectedPublic, public.Name(testType); e != a {
|
||||
t.Errorf("Unexpected result from public plural namer. Expected: %s, Got: %s", e, a)
|
||||
}
|
||||
}
|
||||
}
|
14
cmd/libs/go2idl/openapi-gen/.import-restrictions
Normal file
14
cmd/libs/go2idl/openapi-gen/.import-restrictions
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"Rules": [
|
||||
{
|
||||
"SelectorRegexp": "k8s[.]io",
|
||||
"AllowedPrefixes": [
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl",
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common",
|
||||
"k8s.io/gengo",
|
||||
"k8s.io/kubernetes/third_party",
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -25,10 +25,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
|
||||
|
@@ -24,10 +24,10 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
func construct(t *testing.T, files map[string]string, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) {
|
||||
|
@@ -20,7 +20,9 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/generators"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@@ -31,6 +33,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
arguments.OutputFileBaseName = "openapi_generated"
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
|
||||
// Run it.
|
||||
if err := arguments.Execute(
|
||||
|
@@ -1,420 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package parser_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
)
|
||||
|
||||
func construct(t *testing.T, files map[string]string, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) {
|
||||
b := parser.New()
|
||||
for name, src := range files {
|
||||
if err := b.AddFile(filepath.Dir(name), name, []byte(src)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
u, err := b.FindTypes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
orderer := namer.Orderer{Namer: testNamer}
|
||||
o := orderer.OrderUniverse(u)
|
||||
return b, u, o
|
||||
}
|
||||
|
||||
func TestBuilder(t *testing.T) {
|
||||
var testFiles = map[string]string{
|
||||
"base/foo/proto/foo.go": `
|
||||
package foo
|
||||
|
||||
import (
|
||||
"base/common/proto"
|
||||
)
|
||||
|
||||
type Blah struct {
|
||||
common.Object
|
||||
Count int64
|
||||
Frobbers map[string]*Frobber
|
||||
Baz []Object
|
||||
Nickname *string
|
||||
NumberIsAFavorite map[int]bool
|
||||
}
|
||||
|
||||
type Frobber struct {
|
||||
Name string
|
||||
Amount int64
|
||||
}
|
||||
|
||||
type Object struct {
|
||||
common.Object
|
||||
}
|
||||
|
||||
func AFunc(obj1 common.Object, obj2 Object) Frobber {
|
||||
}
|
||||
|
||||
var AVar Frobber
|
||||
|
||||
var (
|
||||
AnotherVar = Frobber{}
|
||||
)
|
||||
`,
|
||||
"base/common/proto/common.go": `
|
||||
package common
|
||||
|
||||
type Object struct {
|
||||
ID int64
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
var tmplText = `
|
||||
package o
|
||||
{{define "Struct"}}type {{Name .}} interface { {{range $m := .Members}}{{$n := Name $m.Type}}
|
||||
{{if $m.Embedded}}{{$n}}{{else}}{{$m.Name}}() {{$n}}{{if $m.Type.Elem}}{{else}}
|
||||
Set{{$m.Name}}({{$n}}){{end}}{{end}}{{end}}
|
||||
}
|
||||
|
||||
{{end}}
|
||||
{{define "Func"}}{{$s := .Underlying.Signature}}var {{Name .}} func({{range $index,$elem := $s.Parameters}}{{if $index}}, {{end}}{{Raw $elem}}{{end}}) {{if $s.Results|len |gt 1}}({{end}}{{range $index,$elem := $s.Results}}{{if $index}}, {{end}}{{Raw .}}{{end}}{{if $s.Results|len |gt 1}}){{end}} = {{Raw .}}
|
||||
|
||||
{{end}}
|
||||
{{define "Var"}}{{$t := .Underlying}}var {{Name .}} {{Raw $t}} = {{Raw .}}
|
||||
|
||||
{{end}}
|
||||
{{range $t := .}}{{if eq $t.Kind "Struct"}}{{template "Struct" $t}}{{end}}{{end}}
|
||||
{{range $t := .}}{{if eq $t.Kind "DeclarationOf"}}{{if eq $t.Underlying.Kind "Func"}}{{template "Func" $t}}{{end}}{{end}}{{end}}
|
||||
{{range $t := .}}{{if eq $t.Kind "DeclarationOf"}}{{if ne $t.Underlying.Kind "Func"}}{{template "Var" $t}}{{end}}{{end}}{{end}}`
|
||||
|
||||
var expect = `
|
||||
package o
|
||||
|
||||
|
||||
|
||||
type CommonObject interface {
|
||||
ID() Int64
|
||||
SetID(Int64)
|
||||
}
|
||||
|
||||
type FooBlah interface {
|
||||
CommonObject
|
||||
Count() Int64
|
||||
SetCount(Int64)
|
||||
Frobbers() MapStringToPointerFooFrobber
|
||||
Baz() SliceFooObject
|
||||
Nickname() PointerString
|
||||
NumberIsAFavorite() MapIntToBool
|
||||
}
|
||||
|
||||
type FooFrobber interface {
|
||||
Name() String
|
||||
SetName(String)
|
||||
Amount() Int64
|
||||
SetAmount(Int64)
|
||||
}
|
||||
|
||||
type FooObject interface {
|
||||
CommonObject
|
||||
}
|
||||
|
||||
|
||||
var FooAFunc func(proto.Object, proto.Object) proto.Frobber = proto.AFunc
|
||||
|
||||
|
||||
var FooAVar proto.Frobber = proto.AVar
|
||||
|
||||
var FooAnotherVar proto.Frobber = proto.AnotherVar
|
||||
|
||||
`
|
||||
testNamer := namer.NewPublicNamer(1, "proto")
|
||||
rawNamer := namer.NewRawNamer("o", nil)
|
||||
_, u, o := construct(t, testFiles, testNamer)
|
||||
t.Logf("\n%v\n\n", o)
|
||||
args := map[string]interface{}{
|
||||
"Name": testNamer.Name,
|
||||
"Raw": rawNamer.Name,
|
||||
}
|
||||
tmpl := template.Must(
|
||||
template.New("").
|
||||
Funcs(args).
|
||||
Parse(tmplText),
|
||||
)
|
||||
buf := &bytes.Buffer{}
|
||||
tmpl.Execute(buf, o)
|
||||
if e, a := expect, buf.String(); e != a {
|
||||
t.Errorf("Wanted, got:\n%v\n-----\n%v\n", e, a)
|
||||
}
|
||||
if p := u.Package("base/foo/proto"); !p.HasImport("base/common/proto") {
|
||||
t.Errorf("Unexpected lack of import line: %s", p.Imports)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStructParse(t *testing.T) {
|
||||
var structTest = map[string]string{
|
||||
"base/foo/proto/foo.go": `
|
||||
package foo
|
||||
|
||||
// Blah is a test.
|
||||
// A test, I tell you.
|
||||
type Blah struct {
|
||||
// A is the first field.
|
||||
A int64 ` + "`" + `json:"a"` + "`" + `
|
||||
|
||||
// B is the second field.
|
||||
// Multiline comments work.
|
||||
B string ` + "`" + `json:"b"` + "`" + `
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
_, u, o := construct(t, structTest, namer.NewPublicNamer(0))
|
||||
t.Logf("%#v", o)
|
||||
blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"})
|
||||
if blahT == nil {
|
||||
t.Fatal("type not found")
|
||||
}
|
||||
if e, a := types.Struct, blahT.Kind; e != a {
|
||||
t.Errorf("struct kind wrong, wanted %v, got %v", e, a)
|
||||
}
|
||||
if e, a := []string{"Blah is a test.", "A test, I tell you."}, blahT.CommentLines; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("struct comment wrong, wanted %q, got %q", e, a)
|
||||
}
|
||||
m := types.Member{
|
||||
Name: "B",
|
||||
Embedded: false,
|
||||
CommentLines: []string{"B is the second field.", "Multiline comments work."},
|
||||
Tags: `json:"b"`,
|
||||
Type: types.String,
|
||||
}
|
||||
if e, a := m, blahT.Members[1]; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("wanted, got:\n%#v\n%#v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSecondClosestCommentLines(t *testing.T) {
|
||||
const fileName = "base/foo/proto/foo.go"
|
||||
testCases := []struct {
|
||||
testFile map[string]string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
map[string]string{fileName: `package foo
|
||||
// Blah's SecondClosestCommentLines.
|
||||
// Another line.
|
||||
|
||||
// Blah is a test.
|
||||
// A test, I tell you.
|
||||
type Blah struct {
|
||||
a int
|
||||
}
|
||||
`},
|
||||
[]string{"Blah's SecondClosestCommentLines.", "Another line."},
|
||||
},
|
||||
{
|
||||
map[string]string{fileName: `package foo
|
||||
// Blah's SecondClosestCommentLines.
|
||||
// Another line.
|
||||
|
||||
type Blah struct {
|
||||
a int
|
||||
}
|
||||
`},
|
||||
[]string{"Blah's SecondClosestCommentLines.", "Another line."},
|
||||
},
|
||||
}
|
||||
for _, test := range testCases {
|
||||
_, u, o := construct(t, test.testFile, namer.NewPublicNamer(0))
|
||||
t.Logf("%#v", o)
|
||||
blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"})
|
||||
if e, a := test.expected, blahT.SecondClosestCommentLines; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("struct second closest comment wrong, wanted %q, got %q", e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypeKindParse(t *testing.T) {
|
||||
var testFiles = map[string]string{
|
||||
"a/foo.go": "package a\ntype Test string\n",
|
||||
"b/foo.go": "package b\ntype Test map[int]string\n",
|
||||
"c/foo.go": "package c\ntype Test []string\n",
|
||||
"d/foo.go": "package d\ntype Test struct{a int; b struct{a int}; c map[int]string; d *string}\n",
|
||||
"e/foo.go": "package e\ntype Test *string\n",
|
||||
"f/foo.go": `
|
||||
package f
|
||||
import (
|
||||
"a"
|
||||
"b"
|
||||
)
|
||||
type Test []a.Test
|
||||
type Test2 *a.Test
|
||||
type Test3 map[a.Test]b.Test
|
||||
type Test4 struct {
|
||||
a struct {a a.Test; b b.Test}
|
||||
b map[a.Test]b.Test
|
||||
c *a.Test
|
||||
d []a.Test
|
||||
e []string
|
||||
}
|
||||
`,
|
||||
"g/foo.go": `
|
||||
package g
|
||||
type Test func(a, b string) (c, d string)
|
||||
func (t Test) Method(a, b string) (c, d string) { return t(a, b) }
|
||||
type Interface interface{Method(a, b string) (c, d string)}
|
||||
`,
|
||||
}
|
||||
|
||||
// Check that the right types are found, and the namers give the expected names.
|
||||
|
||||
assertions := []struct {
|
||||
Package, Name string
|
||||
k types.Kind
|
||||
names []string
|
||||
}{
|
||||
{
|
||||
Package: "a", Name: "Test", k: types.Alias,
|
||||
names: []string{"Test", "ATest", "test", "aTest", "a.Test"},
|
||||
},
|
||||
{
|
||||
Package: "b", Name: "Test", k: types.Map,
|
||||
names: []string{"Test", "BTest", "test", "bTest", "b.Test"},
|
||||
},
|
||||
{
|
||||
Package: "c", Name: "Test", k: types.Slice,
|
||||
names: []string{"Test", "CTest", "test", "cTest", "c.Test"},
|
||||
},
|
||||
{
|
||||
Package: "d", Name: "Test", k: types.Struct,
|
||||
names: []string{"Test", "DTest", "test", "dTest", "d.Test"},
|
||||
},
|
||||
{
|
||||
Package: "e", Name: "Test", k: types.Pointer,
|
||||
names: []string{"Test", "ETest", "test", "eTest", "e.Test"},
|
||||
},
|
||||
{
|
||||
Package: "f", Name: "Test", k: types.Slice,
|
||||
names: []string{"Test", "FTest", "test", "fTest", "f.Test"},
|
||||
},
|
||||
{
|
||||
Package: "g", Name: "Test", k: types.Func,
|
||||
names: []string{"Test", "GTest", "test", "gTest", "g.Test"},
|
||||
},
|
||||
{
|
||||
Package: "g", Name: "Interface", k: types.Interface,
|
||||
names: []string{"Interface", "GInterface", "interface", "gInterface", "g.Interface"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "string", k: types.Builtin,
|
||||
names: []string{"String", "String", "string", "string", "string"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "int", k: types.Builtin,
|
||||
names: []string{"Int", "Int", "int", "int", "int"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "struct{a int}", k: types.Struct,
|
||||
names: []string{"StructInt", "StructInt", "structInt", "structInt", "struct{a int}"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "struct{a a.Test; b b.Test}", k: types.Struct,
|
||||
names: []string{"StructTestTest", "StructATestBTest", "structTestTest", "structATestBTest", "struct{a a.Test; b b.Test}"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "map[int]string", k: types.Map,
|
||||
names: []string{"MapIntToString", "MapIntToString", "mapIntToString", "mapIntToString", "map[int]string"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "map[a.Test]b.Test", k: types.Map,
|
||||
names: []string{"MapTestToTest", "MapATestToBTest", "mapTestToTest", "mapATestToBTest", "map[a.Test]b.Test"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "[]string", k: types.Slice,
|
||||
names: []string{"SliceString", "SliceString", "sliceString", "sliceString", "[]string"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "[]a.Test", k: types.Slice,
|
||||
names: []string{"SliceTest", "SliceATest", "sliceTest", "sliceATest", "[]a.Test"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "*string", k: types.Pointer,
|
||||
names: []string{"PointerString", "PointerString", "pointerString", "pointerString", "*string"},
|
||||
},
|
||||
{
|
||||
Package: "", Name: "*a.Test", k: types.Pointer,
|
||||
names: []string{"PointerTest", "PointerATest", "pointerTest", "pointerATest", "*a.Test"},
|
||||
},
|
||||
}
|
||||
|
||||
namers := []namer.Namer{
|
||||
namer.NewPublicNamer(0),
|
||||
namer.NewPublicNamer(1),
|
||||
namer.NewPrivateNamer(0),
|
||||
namer.NewPrivateNamer(1),
|
||||
namer.NewRawNamer("", nil),
|
||||
}
|
||||
|
||||
for nameIndex, namer := range namers {
|
||||
_, u, _ := construct(t, testFiles, namer)
|
||||
t.Logf("Found types:\n")
|
||||
for pkgName, pkg := range u {
|
||||
for typeName, cur := range pkg.Types {
|
||||
t.Logf("%q-%q: %s %s", pkgName, typeName, cur.Name, cur.Kind)
|
||||
}
|
||||
}
|
||||
t.Logf("\n\n")
|
||||
|
||||
for _, item := range assertions {
|
||||
n := types.Name{Package: item.Package, Name: item.Name}
|
||||
thisType := u.Type(n)
|
||||
if thisType == nil {
|
||||
t.Errorf("type %s not found", n)
|
||||
continue
|
||||
}
|
||||
underlyingType := thisType
|
||||
if item.k != types.Alias && thisType.Kind == types.Alias {
|
||||
underlyingType = thisType.Underlying
|
||||
if underlyingType == nil {
|
||||
t.Errorf("underlying type %s not found", n)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if e, a := item.k, underlyingType.Kind; e != a {
|
||||
t.Errorf("%v-%s: type kind wrong, wanted %v, got %v (%#v)", nameIndex, n, e, a, underlyingType)
|
||||
}
|
||||
if e, a := item.names[nameIndex], namer.Name(thisType); e != a {
|
||||
t.Errorf("%v-%s: Expected %q, got %q", nameIndex, n, e, a)
|
||||
}
|
||||
}
|
||||
|
||||
// Also do some one-off checks
|
||||
gtest := u.Type(types.Name{Package: "g", Name: "Test"})
|
||||
if e, a := 1, len(gtest.Methods); e != a {
|
||||
t.Errorf("expected %v but found %v methods: %#v", e, a, gtest)
|
||||
}
|
||||
iface := u.Type(types.Name{Package: "g", Name: "Interface"})
|
||||
if e, a := 1, len(iface.Methods); e != a {
|
||||
t.Errorf("expected %v but found %v methods: %#v", e, a, iface)
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,9 +26,10 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/set-gen/generators"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/set-gen/generators"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@@ -40,6 +41,7 @@ func main() {
|
||||
// locations.
|
||||
arguments.InputDirs = []string{"k8s.io/kubernetes/pkg/util/sets/types"}
|
||||
arguments.OutputPackagePath = "k8s.io/kubernetes/pkg/util/sets"
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt")
|
||||
|
||||
if err := arguments.Execute(
|
||||
generators.NameSystems(),
|
||||
|
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractCommentTags(t *testing.T) {
|
||||
commentLines := []string{
|
||||
"Human comment that is ignored.",
|
||||
"+foo=value1",
|
||||
"+bar",
|
||||
"+foo=value2",
|
||||
"+baz=qux,zrb=true",
|
||||
}
|
||||
|
||||
a := ExtractCommentTags("+", commentLines)
|
||||
e := map[string][]string{
|
||||
"foo": {"value1", "value2"},
|
||||
"bar": {""},
|
||||
"baz": {"qux,zrb=true"},
|
||||
}
|
||||
if !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Wanted %q, got %q", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractSingleBoolCommentTag(t *testing.T) {
|
||||
commentLines := []string{
|
||||
"Human comment that is ignored.",
|
||||
"+TRUE=true",
|
||||
"+FALSE=false",
|
||||
"+MULTI=true",
|
||||
"+MULTI=false",
|
||||
"+MULTI=multi",
|
||||
"+NOTBOOL=blue",
|
||||
"+EMPTY",
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
key string
|
||||
def bool
|
||||
exp bool
|
||||
err string // if set, ignore exp.
|
||||
}{
|
||||
{"TRUE", false, true, ""},
|
||||
{"FALSE", true, false, ""},
|
||||
{"MULTI", false, true, ""},
|
||||
{"NOTBOOL", false, true, "is not boolean"},
|
||||
{"EMPTY", false, true, "is not boolean"},
|
||||
{"ABSENT", true, true, ""},
|
||||
{"ABSENT", false, false, ""},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
v, err := ExtractSingleBoolCommentTag("+", tc.key, tc.def, commentLines)
|
||||
if err != nil && tc.err == "" {
|
||||
t.Errorf("[%d]: unexpected failure: %v", i, err)
|
||||
} else if err == nil && tc.err != "" {
|
||||
t.Errorf("[%d]: expected failure: %v", i, tc.err)
|
||||
} else if err != nil {
|
||||
if !strings.Contains(err.Error(), tc.err) {
|
||||
t.Errorf("[%d]: unexpected error: expected %q, got %q", i, tc.err, err)
|
||||
}
|
||||
} else if v != tc.exp {
|
||||
t.Errorf("[%d]: unexpected value: expected %t, got %t", i, tc.exp, v)
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFlatten(t *testing.T) {
|
||||
mapType := &Type{
|
||||
Name: Name{Package: "", Name: "map[string]string"},
|
||||
Kind: Map,
|
||||
Key: String,
|
||||
Elem: String,
|
||||
}
|
||||
m := []Member{
|
||||
{
|
||||
Name: "Baz",
|
||||
Embedded: true,
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkg", Name: "Baz"},
|
||||
Kind: Struct,
|
||||
Members: []Member{
|
||||
{Name: "Foo", Type: String},
|
||||
{
|
||||
Name: "Qux",
|
||||
Embedded: true,
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkg", Name: "Qux"},
|
||||
Kind: Struct,
|
||||
Members: []Member{{Name: "Zot", Type: String}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{Name: "Bar", Type: String},
|
||||
{
|
||||
Name: "NotSureIfLegal",
|
||||
Embedded: true,
|
||||
Type: mapType,
|
||||
},
|
||||
}
|
||||
e := []Member{
|
||||
{Name: "Bar", Type: String},
|
||||
{Name: "NotSureIfLegal", Type: mapType, Embedded: true},
|
||||
{Name: "Foo", Type: String},
|
||||
{Name: "Zot", Type: String},
|
||||
}
|
||||
if a := FlattenMembers(m); !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("Expected \n%#v\n, got \n%#v\n", e, a)
|
||||
}
|
||||
}
|
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetBuiltin(t *testing.T) {
|
||||
u := Universe{}
|
||||
if builtinPkg := u.Package(""); builtinPkg.Has("string") {
|
||||
t.Errorf("Expected builtin package to not have builtins until they're asked for explicitly. %#v", builtinPkg)
|
||||
}
|
||||
s := u.Type(Name{Package: "", Name: "string"})
|
||||
if s != String {
|
||||
t.Errorf("Expected canonical string type.")
|
||||
}
|
||||
if builtinPkg := u.Package(""); !builtinPkg.Has("string") {
|
||||
t.Errorf("Expected builtin package to exist and have builtins by default. %#v", builtinPkg)
|
||||
}
|
||||
if builtinPkg := u.Package(""); len(builtinPkg.Types) != 1 {
|
||||
t.Errorf("Expected builtin package to not have builtins until they're asked for explicitly. %#v", builtinPkg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMarker(t *testing.T) {
|
||||
u := Universe{}
|
||||
n := Name{Package: "path/to/package", Name: "Foo"}
|
||||
f := u.Type(n)
|
||||
if f == nil || f.Name != n {
|
||||
t.Errorf("Expected marker type.")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Type_IsPrimitive(t *testing.T) {
|
||||
testCases := []struct {
|
||||
typ Type
|
||||
expect bool
|
||||
}{
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Alias,
|
||||
Underlying: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "underlying"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Pointer,
|
||||
Elem: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "pointee"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Struct,
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
r := tc.typ.IsPrimitive()
|
||||
if r != tc.expect {
|
||||
t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Type_IsAssignable(t *testing.T) {
|
||||
testCases := []struct {
|
||||
typ Type
|
||||
expect bool
|
||||
}{
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Alias,
|
||||
Underlying: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "underlying"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Pointer,
|
||||
Elem: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "pointee"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Struct, // Empty struct
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Struct,
|
||||
Members: []Member{
|
||||
{
|
||||
Name: "m1",
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "m2",
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Alias,
|
||||
Underlying: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "underlying"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "m3",
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Struct, // Empty struct
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
typ: Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Struct,
|
||||
Members: []Member{
|
||||
{
|
||||
Name: "m1",
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "m2",
|
||||
Type: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "typename"},
|
||||
Kind: Pointer,
|
||||
Elem: &Type{
|
||||
Name: Name{Package: "pkgname", Name: "pointee"},
|
||||
Kind: Builtin,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expect: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
r := tc.typ.IsAssignable()
|
||||
if r != tc.expect {
|
||||
t.Errorf("case[%d]: expected %t, got %t", i, tc.expect, r)
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,8 +25,8 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
go2idlparser "k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
go2idlparser "k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// GetPublicFunctions lists all public functions (not methods) from a golang source file.
|
||||
|
@@ -24,8 +24,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/util/codeinspector"
|
||||
|
@@ -24,8 +24,8 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/util/codeinspector"
|
||||
|
202
vendor/k8s.io/gengo/LICENSE
generated
vendored
Normal file
202
vendor/k8s.io/gengo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
23
cmd/libs/go2idl/args/args.go → vendor/k8s.io/gengo/args/args.go
generated
vendored
23
cmd/libs/go2idl/args/args.go → vendor/k8s.io/gengo/args/args.go
generated
vendored
@@ -19,6 +19,7 @@ package args
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
goflag "flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -27,12 +28,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
utilflag "k8s.io/kubernetes/pkg/util/flag"
|
||||
"k8s.io/kubernetes/pkg/util/logs"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@@ -42,7 +41,7 @@ import (
|
||||
func Default() *GeneratorArgs {
|
||||
generatorArgs := &GeneratorArgs{
|
||||
OutputBase: DefaultSourceTree(),
|
||||
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt"),
|
||||
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"),
|
||||
GeneratedBuildTag: "ignore_autogenerated",
|
||||
}
|
||||
generatorArgs.AddFlags(pflag.CommandLine)
|
||||
@@ -124,7 +123,11 @@ func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
|
||||
// the InputDirs.
|
||||
func (g *GeneratorArgs) InputIncludes(p *types.Package) bool {
|
||||
for _, dir := range g.InputDirs {
|
||||
if strings.HasPrefix(p.Path, dir) {
|
||||
d := dir
|
||||
if strings.HasSuffix(d, "...") {
|
||||
d = strings.TrimSuffix(d, "...")
|
||||
}
|
||||
if strings.HasPrefix(p.Path, d) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -145,8 +148,8 @@ func DefaultSourceTree() string {
|
||||
// If you don't need any non-default behavior, use as:
|
||||
// args.Default().Execute(...)
|
||||
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error {
|
||||
utilflag.InitFlags()
|
||||
logs.InitLogs()
|
||||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
pflag.Parse()
|
||||
|
||||
b, err := g.NewBuilder()
|
||||
if err != nil {
|
@@ -22,11 +22,11 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/set-gen/sets"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
@@ -28,10 +28,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
@@ -53,7 +53,7 @@ func DefaultNameSystem() string {
|
||||
return "raw"
|
||||
}
|
||||
|
||||
// Packages makes the sets package definition.
|
||||
// Packages makes the import-boss package definition.
|
||||
func Packages(c *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||
pkgs := generator.Packages{}
|
||||
c.FileTypes = map[string]generator.FileType{
|
||||
@@ -252,7 +252,7 @@ func (r *importRules) GenerateType(*generator.Context, *types.Type, io.Writer) e
|
||||
func (r *importRules) Filename() string { return ".import-restrictions" }
|
||||
func (r *importRules) FileType() string { return importBossFileType }
|
||||
func (r *importRules) Init(c *generator.Context, w io.Writer) error { return nil }
|
||||
func (r *importRules) Finalize(c *generator.Context, w io.Writer) error { return nil }
|
||||
func (r *importRules) Finalize(*generator.Context, io.Writer) error { return nil }
|
||||
|
||||
func dfsImports(dest *[]string, seen map[string]bool, p *types.Package) {
|
||||
for _, p2 := range p.Imports {
|
@@ -20,10 +20,10 @@ package generators
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/args"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
@@ -18,7 +18,7 @@ package generators
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
203
vendor/k8s.io/gengo/examples/set-gen/sets/byte.go
generated
vendored
Normal file
203
vendor/k8s.io/gengo/examples/set-gen/sets/byte.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Byte is a set of bytes, implemented via map[byte]struct{} for minimal memory consumption.
|
||||
type Byte map[byte]Empty
|
||||
|
||||
// New creates a Byte from a list of values.
|
||||
func NewByte(items ...byte) Byte {
|
||||
ss := Byte{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// ByteKeySet creates a Byte from a keys of a map[byte](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func ByteKeySet(theMap interface{}) Byte {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Byte{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(byte))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Byte) Insert(items ...byte) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Byte) Delete(items ...byte) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Byte) Has(item byte) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Byte) HasAll(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Byte) HasAny(items ...byte) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Byte) Difference(s2 Byte) Byte {
|
||||
result := NewByte()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Byte) Union(s2 Byte) Byte {
|
||||
result := NewByte()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Byte) Intersection(s2 Byte) Byte {
|
||||
var walk, other Byte
|
||||
result := NewByte()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Byte) IsSuperset(s2 Byte) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Byte) Equal(s2 Byte) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfByte []byte
|
||||
|
||||
func (s sortableSliceOfByte) Len() int { return len(s) }
|
||||
func (s sortableSliceOfByte) Less(i, j int) bool { return lessByte(s[i], s[j]) }
|
||||
func (s sortableSliceOfByte) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted byte slice.
|
||||
func (s Byte) List() []byte {
|
||||
res := make(sortableSliceOfByte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []byte(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Byte) UnsortedList() []byte {
|
||||
res := make([]byte, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Byte) PopAny() (byte, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue byte
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Byte) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessByte(lhs, rhs byte) bool {
|
||||
return lhs < rhs
|
||||
}
|
20
vendor/k8s.io/gengo/examples/set-gen/sets/doc.go
generated
vendored
Normal file
20
vendor/k8s.io/gengo/examples/set-gen/sets/doc.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
// Package sets has auto-generated set types.
|
||||
package sets
|
@@ -14,23 +14,10 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generators
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
package sets
|
||||
|
||||
func TestRemoveLastDir(t *testing.T) {
|
||||
table := map[string]struct{ newPath, removedDir string }{
|
||||
"a/b/c": {"a/c", "b"},
|
||||
}
|
||||
for input, expect := range table {
|
||||
gotPath, gotRemoved := removeLastDir(input)
|
||||
if e, a := expect.newPath, gotPath; e != a {
|
||||
t.Errorf("%v: wanted %v, got %v", input, e, a)
|
||||
}
|
||||
if e, a := expect.removedDir, gotRemoved; e != a {
|
||||
t.Errorf("%v: wanted %v, got %v", input, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Empty is public since it is used by some internal API objects for conversions between external
|
||||
// string arrays and internal sets, and conversion logic requires public types today.
|
||||
type Empty struct{}
|
203
vendor/k8s.io/gengo/examples/set-gen/sets/int.go
generated
vendored
Normal file
203
vendor/k8s.io/gengo/examples/set-gen/sets/int.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int is a set of ints, implemented via map[int]struct{} for minimal memory consumption.
|
||||
type Int map[int]Empty
|
||||
|
||||
// New creates a Int from a list of values.
|
||||
func NewInt(items ...int) Int {
|
||||
ss := Int{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// IntKeySet creates a Int from a keys of a map[int](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func IntKeySet(theMap interface{}) Int {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int) Insert(items ...int) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int) Delete(items ...int) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int) Has(item int) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int) HasAll(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int) HasAny(items ...int) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int) Difference(s2 Int) Int {
|
||||
result := NewInt()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int) Union(s2 Int) Int {
|
||||
result := NewInt()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int) Intersection(s2 Int) Int {
|
||||
var walk, other Int
|
||||
result := NewInt()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int) IsSuperset(s2 Int) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int) Equal(s2 Int) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfInt []int
|
||||
|
||||
func (s sortableSliceOfInt) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt) Less(i, j int) bool { return lessInt(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int slice.
|
||||
func (s Int) List() []int {
|
||||
res := make(sortableSliceOfInt, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int) UnsortedList() []int {
|
||||
res := make([]int, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Int) PopAny() (int, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt(lhs, rhs int) bool {
|
||||
return lhs < rhs
|
||||
}
|
203
vendor/k8s.io/gengo/examples/set-gen/sets/int64.go
generated
vendored
Normal file
203
vendor/k8s.io/gengo/examples/set-gen/sets/int64.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.Int64 is a set of int64s, implemented via map[int64]struct{} for minimal memory consumption.
|
||||
type Int64 map[int64]Empty
|
||||
|
||||
// New creates a Int64 from a list of values.
|
||||
func NewInt64(items ...int64) Int64 {
|
||||
ss := Int64{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// Int64KeySet creates a Int64 from a keys of a map[int64](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func Int64KeySet(theMap interface{}) Int64 {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := Int64{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(int64))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s Int64) Insert(items ...int64) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s Int64) Delete(items ...int64) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s Int64) Has(item int64) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s Int64) HasAll(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s Int64) HasAny(items ...int64) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s Int64) Difference(s2 Int64) Int64 {
|
||||
result := NewInt64()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 Int64) Union(s2 Int64) Int64 {
|
||||
result := NewInt64()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 Int64) Intersection(s2 Int64) Int64 {
|
||||
var walk, other Int64
|
||||
result := NewInt64()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 Int64) IsSuperset(s2 Int64) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 Int64) Equal(s2 Int64) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfInt64 []int64
|
||||
|
||||
func (s sortableSliceOfInt64) Len() int { return len(s) }
|
||||
func (s sortableSliceOfInt64) Less(i, j int) bool { return lessInt64(s[i], s[j]) }
|
||||
func (s sortableSliceOfInt64) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted int64 slice.
|
||||
func (s Int64) List() []int64 {
|
||||
res := make(sortableSliceOfInt64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []int64(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s Int64) UnsortedList() []int64 {
|
||||
res := make([]int64, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s Int64) PopAny() (int64, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue int64
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s Int64) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessInt64(lhs, rhs int64) bool {
|
||||
return lhs < rhs
|
||||
}
|
203
vendor/k8s.io/gengo/examples/set-gen/sets/string.go
generated
vendored
Normal file
203
vendor/k8s.io/gengo/examples/set-gen/sets/string.go
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This file was autogenerated by set-gen. Do not edit it manually!
|
||||
|
||||
package sets
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
|
||||
type String map[string]Empty
|
||||
|
||||
// New creates a String from a list of values.
|
||||
func NewString(items ...string) String {
|
||||
ss := String{}
|
||||
ss.Insert(items...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// StringKeySet creates a String from a keys of a map[string](? extends interface{}).
|
||||
// If the value passed in is not actually a map, this will panic.
|
||||
func StringKeySet(theMap interface{}) String {
|
||||
v := reflect.ValueOf(theMap)
|
||||
ret := String{}
|
||||
|
||||
for _, keyValue := range v.MapKeys() {
|
||||
ret.Insert(keyValue.Interface().(string))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Insert adds items to the set.
|
||||
func (s String) Insert(items ...string) {
|
||||
for _, item := range items {
|
||||
s[item] = Empty{}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removes all items from the set.
|
||||
func (s String) Delete(items ...string) {
|
||||
for _, item := range items {
|
||||
delete(s, item)
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if and only if item is contained in the set.
|
||||
func (s String) Has(item string) bool {
|
||||
_, contained := s[item]
|
||||
return contained
|
||||
}
|
||||
|
||||
// HasAll returns true if and only if all items are contained in the set.
|
||||
func (s String) HasAll(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if !s.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasAny returns true if any items are contained in the set.
|
||||
func (s String) HasAny(items ...string) bool {
|
||||
for _, item := range items {
|
||||
if s.Has(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference returns a set of objects that are not in s2
|
||||
// For example:
|
||||
// s1 = {a1, a2, a3}
|
||||
// s2 = {a1, a2, a4, a5}
|
||||
// s1.Difference(s2) = {a3}
|
||||
// s2.Difference(s1) = {a4, a5}
|
||||
func (s String) Difference(s2 String) String {
|
||||
result := NewString()
|
||||
for key := range s {
|
||||
if !s2.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new set which includes items in either s1 or s2.
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a3, a4}
|
||||
// s1.Union(s2) = {a1, a2, a3, a4}
|
||||
// s2.Union(s1) = {a1, a2, a3, a4}
|
||||
func (s1 String) Union(s2 String) String {
|
||||
result := NewString()
|
||||
for key := range s1 {
|
||||
result.Insert(key)
|
||||
}
|
||||
for key := range s2 {
|
||||
result.Insert(key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Intersection returns a new set which includes the item in BOTH s1 and s2
|
||||
// For example:
|
||||
// s1 = {a1, a2}
|
||||
// s2 = {a2, a3}
|
||||
// s1.Intersection(s2) = {a2}
|
||||
func (s1 String) Intersection(s2 String) String {
|
||||
var walk, other String
|
||||
result := NewString()
|
||||
if s1.Len() < s2.Len() {
|
||||
walk = s1
|
||||
other = s2
|
||||
} else {
|
||||
walk = s2
|
||||
other = s1
|
||||
}
|
||||
for key := range walk {
|
||||
if other.Has(key) {
|
||||
result.Insert(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// IsSuperset returns true if and only if s1 is a superset of s2.
|
||||
func (s1 String) IsSuperset(s2 String) bool {
|
||||
for item := range s2 {
|
||||
if !s1.Has(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal returns true if and only if s1 is equal (as a set) to s2.
|
||||
// Two sets are equal if their membership is identical.
|
||||
// (In practice, this means same elements, order doesn't matter)
|
||||
func (s1 String) Equal(s2 String) bool {
|
||||
return len(s1) == len(s2) && s1.IsSuperset(s2)
|
||||
}
|
||||
|
||||
type sortableSliceOfString []string
|
||||
|
||||
func (s sortableSliceOfString) Len() int { return len(s) }
|
||||
func (s sortableSliceOfString) Less(i, j int) bool { return lessString(s[i], s[j]) }
|
||||
func (s sortableSliceOfString) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// List returns the contents as a sorted string slice.
|
||||
func (s String) List() []string {
|
||||
res := make(sortableSliceOfString, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
sort.Sort(res)
|
||||
return []string(res)
|
||||
}
|
||||
|
||||
// UnsortedList returns the slice with contents in random order.
|
||||
func (s String) UnsortedList() []string {
|
||||
res := make([]string, 0, len(s))
|
||||
for key := range s {
|
||||
res = append(res, key)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Returns a single element from the set.
|
||||
func (s String) PopAny() (string, bool) {
|
||||
for key := range s {
|
||||
s.Delete(key)
|
||||
return key, true
|
||||
}
|
||||
var zeroValue string
|
||||
return zeroValue, false
|
||||
}
|
||||
|
||||
// Len returns the size of the set.
|
||||
func (s String) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func lessString(lhs, rhs string) bool {
|
||||
return lhs < rhs
|
||||
}
|
@@ -19,8 +19,8 @@ package generator
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
const (
|
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package generator
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// DefaultPackage contains a default implementation of Package.
|
2
cmd/libs/go2idl/generator/doc.go → vendor/k8s.io/gengo/generator/doc.go
generated
vendored
2
cmd/libs/go2idl/generator/doc.go → vendor/k8s.io/gengo/generator/doc.go
generated
vendored
@@ -28,4 +28,4 @@ limitations under the License.
|
||||
// package. Additionally, all naming systems in the Context will be added as
|
||||
// functions to the parsed template, so that they can be called directly from
|
||||
// your templates!
|
||||
package generator // import "k8s.io/kubernetes/cmd/libs/go2idl/generator"
|
||||
package generator
|
4
cmd/libs/go2idl/generator/execute.go → vendor/k8s.io/gengo/generator/execute.go
generated
vendored
4
cmd/libs/go2idl/generator/execute.go → vendor/k8s.io/gengo/generator/execute.go
generated
vendored
@@ -26,8 +26,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
11
cmd/libs/go2idl/generator/generator.go → vendor/k8s.io/gengo/generator/generator.go
generated
vendored
11
cmd/libs/go2idl/generator/generator.go → vendor/k8s.io/gengo/generator/generator.go
generated
vendored
@@ -20,9 +20,9 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/parser"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// Package contains the contract for generating a package.
|
||||
@@ -110,9 +110,8 @@ type Generator interface {
|
||||
// Generators.)
|
||||
Init(*Context, io.Writer) error
|
||||
|
||||
// Finalize should write finish up codes, and any other content that's not
|
||||
// generated per-type. For example if you are generating one block (function,
|
||||
// type, etc) for all types, this function can be used to close the block.
|
||||
// Finalize should write finish up functions, and any other content that's not
|
||||
// generated per-type.
|
||||
Finalize(*Context, io.Writer) error
|
||||
|
||||
// PackageVars should emit an array of variable lines. They will be
|
@@ -20,8 +20,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
func NewImportTracker(typesToAdd ...*types.Type) namer.ImportTracker {
|
2
cmd/libs/go2idl/namer/doc.go → vendor/k8s.io/gengo/namer/doc.go
generated
vendored
2
cmd/libs/go2idl/namer/doc.go → vendor/k8s.io/gengo/namer/doc.go
generated
vendored
@@ -28,4 +28,4 @@ limitations under the License.
|
||||
//
|
||||
// Additionally, a "RawNamer" can optionally keep track of what needs to be
|
||||
// imported.
|
||||
package namer // import "k8s.io/kubernetes/cmd/libs/go2idl/namer"
|
||||
package namer
|
@@ -19,7 +19,7 @@ package namer
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// ImportTracker may be passed to a namer.RawNamer, to track the imports needed
|
14
cmd/libs/go2idl/namer/namer.go → vendor/k8s.io/gengo/namer/namer.go
generated
vendored
14
cmd/libs/go2idl/namer/namer.go → vendor/k8s.io/gengo/namer/namer.go
generated
vendored
@@ -20,7 +20,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// Returns whether a name is a private Go name.
|
||||
@@ -246,7 +246,11 @@ func (ns *NameStrategy) Name(t *types.Type) string {
|
||||
names = append(names, ns.removePrefixAndSuffix(ns.Name(m.Type)))
|
||||
}
|
||||
name = ns.Join(ns.Prefix, names, ns.Suffix)
|
||||
// TODO: add types.Chan
|
||||
case types.Chan:
|
||||
name = ns.Join(ns.Prefix, []string{
|
||||
"Chan",
|
||||
ns.removePrefixAndSuffix(ns.Name(t.Elem)),
|
||||
}, ns.Suffix)
|
||||
case types.Interface:
|
||||
// TODO: add to name test
|
||||
names := []string{"Interface"}
|
||||
@@ -301,10 +305,10 @@ func (r *rawNamer) Name(t *types.Type) string {
|
||||
if t.Name.Package != "" {
|
||||
var name string
|
||||
if r.tracker != nil {
|
||||
r.tracker.AddType(t)
|
||||
if t.Name.Package == r.pkg {
|
||||
name = t.Name.Name
|
||||
} else {
|
||||
r.tracker.AddType(t)
|
||||
name = r.tracker.LocalNameOf(t.Name.Package) + "." + t.Name.Name
|
||||
}
|
||||
} else {
|
||||
@@ -333,7 +337,9 @@ func (r *rawNamer) Name(t *types.Type) string {
|
||||
elems = append(elems, m.Name+" "+r.Name(m.Type))
|
||||
}
|
||||
name = "struct{" + strings.Join(elems, "; ") + "}"
|
||||
// TODO: add types.Chan
|
||||
case types.Chan:
|
||||
// TODO: include directionality
|
||||
name = "chan " + r.Name(t.Elem)
|
||||
case types.Interface:
|
||||
// TODO: add to name test
|
||||
elems := []string{}
|
2
cmd/libs/go2idl/namer/order.go → vendor/k8s.io/gengo/namer/order.go
generated
vendored
2
cmd/libs/go2idl/namer/order.go → vendor/k8s.io/gengo/namer/order.go
generated
vendored
@@ -19,7 +19,7 @@ package namer
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// Orderer produces an ordering of types given a Namer.
|
2
cmd/libs/go2idl/namer/plural_namer.go → vendor/k8s.io/gengo/namer/plural_namer.go
generated
vendored
2
cmd/libs/go2idl/namer/plural_namer.go → vendor/k8s.io/gengo/namer/plural_namer.go
generated
vendored
@@ -19,7 +19,7 @@ package namer
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
type pluralNamer struct {
|
2
cmd/libs/go2idl/parser/doc.go → vendor/k8s.io/gengo/parser/doc.go
generated
vendored
2
cmd/libs/go2idl/parser/doc.go → vendor/k8s.io/gengo/parser/doc.go
generated
vendored
@@ -16,4 +16,4 @@ limitations under the License.
|
||||
|
||||
// Package parser provides code to parse go files, type-check them, extract the
|
||||
// types.
|
||||
package parser // import "k8s.io/kubernetes/cmd/libs/go2idl/parser"
|
||||
package parser
|
3
cmd/libs/go2idl/parser/parse.go → vendor/k8s.io/gengo/parser/parse.go
generated
vendored
3
cmd/libs/go2idl/parser/parse.go → vendor/k8s.io/gengo/parser/parse.go
generated
vendored
@@ -30,7 +30,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// Builder lets you add all the go files in all the packages that you care
|
||||
@@ -388,6 +388,7 @@ func (b *Builder) makePackage(id string) (*tc.Package, error) {
|
||||
}
|
||||
|
||||
// FindPackages fetches a list of the user-imported packages.
|
||||
// Note that you need to call b.FindTypes() first.
|
||||
func (b *Builder) FindPackages() []string {
|
||||
result := []string{}
|
||||
for pkgPath := range b.pkgs {
|
0
cmd/libs/go2idl/types/comments.go → vendor/k8s.io/gengo/types/comments.go
generated
vendored
0
cmd/libs/go2idl/types/comments.go → vendor/k8s.io/gengo/types/comments.go
generated
vendored
2
cmd/libs/go2idl/types/doc.go → vendor/k8s.io/gengo/types/doc.go
generated
vendored
2
cmd/libs/go2idl/types/doc.go → vendor/k8s.io/gengo/types/doc.go
generated
vendored
@@ -16,4 +16,4 @@ limitations under the License.
|
||||
|
||||
// Package types contains go type information, packaged in a way that makes
|
||||
// auto-generation convenient, whether by template or straight go functions.
|
||||
package types // import "k8s.io/kubernetes/cmd/libs/go2idl/types"
|
||||
package types
|
0
cmd/libs/go2idl/types/flatten.go → vendor/k8s.io/gengo/types/flatten.go
generated
vendored
0
cmd/libs/go2idl/types/flatten.go → vendor/k8s.io/gengo/types/flatten.go
generated
vendored
0
cmd/libs/go2idl/types/types.go → vendor/k8s.io/gengo/types/types.go
generated
vendored
0
cmd/libs/go2idl/types/types.go → vendor/k8s.io/gengo/types/types.go
generated
vendored
Reference in New Issue
Block a user