Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b01ac472
Commit
b01ac472
authored
Jun 16, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go2idl: Consistently handle comments as []string
This makes subsequent comment-tag PRs more consistent.
parent
57c31969
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
30 additions
and
39 deletions
+30
-39
generator_fake_for_type.go
...idl/client-gen/generators/fake/generator_fake_for_type.go
+2
-4
generator_for_group.go
cmd/libs/go2idl/client-gen/generators/generator_for_group.go
+2
-5
conversion.go
cmd/libs/go2idl/conversion-gen/generators/conversion.go
+1
-4
generator.go
cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go
+3
-4
parse.go
cmd/libs/go2idl/parser/parse.go
+9
-8
parse_test.go
cmd/libs/go2idl/parser/parse_test.go
+8
-8
comments.go
cmd/libs/go2idl/types/comments.go
+1
-2
types.go
cmd/libs/go2idl/types/types.go
+4
-4
No files found.
cmd/libs/go2idl/client-gen/generators/fake/generator_fake_for_type.go
View file @
b01ac472
...
@@ -95,12 +95,10 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
...
@@ -95,12 +95,10 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
}
}
// allow user to define a group name that's different from the one parsed from the directory.
// allow user to define a group name that's different from the one parsed from the directory.
for
_
,
comment
:=
range
c
.
Universe
.
Package
(
g
.
inputPackage
)
.
DocComments
{
p
:=
c
.
Universe
.
Package
(
g
.
inputPackage
)
comment
=
strings
.
TrimLeft
(
comment
,
"//"
)
if
override
,
ok
:=
types
.
ExtractCommentTags
(
"+"
,
p
.
DocComments
)[
"groupName"
];
ok
{
if
override
,
ok
:=
types
.
ExtractCommentTags
(
"+"
,
comment
)[
"groupName"
];
ok
{
groupName
=
override
groupName
=
override
}
}
}
m
:=
map
[
string
]
interface
{}{
m
:=
map
[
string
]
interface
{}{
"type"
:
t
,
"type"
:
t
,
...
...
cmd/libs/go2idl/client-gen/generators/generator_for_group.go
View file @
b01ac472
...
@@ -18,7 +18,6 @@ package generators
...
@@ -18,7 +18,6 @@ package generators
import
(
import
(
"io"
"io"
"strings"
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
"k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators/normalization"
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
"k8s.io/kubernetes/cmd/libs/go2idl/generator"
...
@@ -74,12 +73,10 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
...
@@ -74,12 +73,10 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
groupName
=
""
groupName
=
""
}
}
// allow user to define a group name that's different from the one parsed from the directory.
// allow user to define a group name that's different from the one parsed from the directory.
for
_
,
comment
:=
range
c
.
Universe
.
Package
(
g
.
inputPacakge
)
.
DocComments
{
p
:=
c
.
Universe
.
Package
(
g
.
inputPacakge
)
comment
=
strings
.
TrimLeft
(
comment
,
"//"
)
if
override
,
ok
:=
types
.
ExtractCommentTags
(
"+"
,
p
.
DocComments
)[
"groupName"
];
ok
&&
override
!=
""
{
if
override
,
ok
:=
types
.
ExtractCommentTags
(
"+"
,
comment
)[
"groupName"
];
ok
&&
override
!=
""
{
groupName
=
override
groupName
=
override
}
}
}
m
:=
map
[
string
]
interface
{}{
m
:=
map
[
string
]
interface
{}{
"group"
:
normalization
.
BeforeFirstDot
(
g
.
group
),
"group"
:
normalization
.
BeforeFirstDot
(
g
.
group
),
...
...
cmd/libs/go2idl/conversion-gen/generators/conversion.go
View file @
b01ac472
...
@@ -232,12 +232,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
...
@@ -232,12 +232,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
// Only generate conversions for package which explicitly requested it
// Only generate conversions for package which explicitly requested it
// byt setting "+genversion=true" in their doc.go file.
// byt setting "+genversion=true" in their doc.go file.
filtered
:=
false
filtered
:=
false
for
_
,
comment
:=
range
p
.
DocComments
{
if
types
.
ExtractCommentTags
(
"+"
,
p
.
DocComments
)[
"genconversion"
]
==
"true"
{
comment
:=
strings
.
Trim
(
comment
,
"//"
)
if
types
.
ExtractCommentTags
(
"+"
,
comment
)[
"genconversion"
]
==
"true"
{
filtered
=
true
filtered
=
true
}
}
}
if
!
filtered
{
if
!
filtered
{
continue
continue
}
}
...
...
cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go
View file @
b01ac472
...
@@ -268,7 +268,7 @@ func (b bodyGen) doAlias(sw *generator.SnippetWriter) error {
...
@@ -268,7 +268,7 @@ func (b bodyGen) doAlias(sw *generator.SnippetWriter) error {
Members
:
[]
types
.
Member
{
Members
:
[]
types
.
Member
{
{
{
Name
:
"Items"
,
Name
:
"Items"
,
CommentLines
:
fmt
.
Sprintf
(
"items, if empty, will result in an empty %s
\n
"
,
kind
)
,
CommentLines
:
[]
string
{
fmt
.
Sprintf
(
"items, if empty, will result in an empty %s
\n
"
,
kind
)}
,
Type
:
b
.
t
.
Underlying
,
Type
:
b
.
t
.
Underlying
,
},
},
},
},
...
@@ -410,7 +410,7 @@ type protoField struct {
...
@@ -410,7 +410,7 @@ type protoField struct {
Nullable
bool
Nullable
bool
Extras
map
[
string
]
string
Extras
map
[
string
]
string
CommentLines
string
CommentLines
[]
string
}
}
var
(
var
(
...
@@ -687,8 +687,7 @@ func membersToFields(locator ProtobufLocator, t *types.Type, localPackage types.
...
@@ -687,8 +687,7 @@ func membersToFields(locator ProtobufLocator, t *types.Type, localPackage types.
return
fields
,
nil
return
fields
,
nil
}
}
func
genComment
(
out
io
.
Writer
,
comment
,
indent
string
)
{
func
genComment
(
out
io
.
Writer
,
lines
[]
string
,
indent
string
)
{
lines
:=
strings
.
Split
(
comment
,
"
\n
"
)
for
{
for
{
l
:=
len
(
lines
)
l
:=
len
(
lines
)
if
l
==
0
||
len
(
lines
[
l
-
1
])
!=
0
{
if
l
==
0
||
len
(
lines
[
l
-
1
])
!=
0
{
...
...
cmd/libs/go2idl/parser/parse.go
View file @
b01ac472
...
@@ -371,10 +371,7 @@ func (b *Builder) FindTypes() (types.Universe, error) {
...
@@ -371,10 +371,7 @@ func (b *Builder) FindTypes() (types.Universe, error) {
for
_
,
f
:=
range
b
.
parsed
[
pkgPath
]
{
for
_
,
f
:=
range
b
.
parsed
[
pkgPath
]
{
if
strings
.
HasSuffix
(
f
.
name
,
"/doc.go"
)
{
if
strings
.
HasSuffix
(
f
.
name
,
"/doc.go"
)
{
if
f
.
file
.
Doc
!=
nil
{
if
f
.
file
.
Doc
!=
nil
{
tp
:=
u
.
Package
(
pkgPath
)
u
.
Package
(
pkgPath
)
.
DocComments
=
splitLines
(
f
.
file
.
Doc
.
Text
())
for
_
,
c
:=
range
f
.
file
.
Doc
.
List
{
tp
.
DocComments
=
append
(
tp
.
DocComments
,
c
.
Text
)
}
}
}
}
}
}
}
...
@@ -386,11 +383,11 @@ func (b *Builder) FindTypes() (types.Universe, error) {
...
@@ -386,11 +383,11 @@ func (b *Builder) FindTypes() (types.Universe, error) {
if
ok
{
if
ok
{
t
:=
b
.
walkType
(
u
,
nil
,
tn
.
Type
())
t
:=
b
.
walkType
(
u
,
nil
,
tn
.
Type
())
c1
:=
b
.
priorCommentLines
(
obj
.
Pos
(),
1
)
c1
:=
b
.
priorCommentLines
(
obj
.
Pos
(),
1
)
t
.
CommentLines
=
c1
.
Text
(
)
t
.
CommentLines
=
splitLines
(
c1
.
Text
()
)
if
c1
==
nil
{
if
c1
==
nil
{
t
.
SecondClosestCommentLines
=
b
.
priorCommentLines
(
obj
.
Pos
(),
2
)
.
Text
(
)
t
.
SecondClosestCommentLines
=
splitLines
(
b
.
priorCommentLines
(
obj
.
Pos
(),
2
)
.
Text
()
)
}
else
{
}
else
{
t
.
SecondClosestCommentLines
=
b
.
priorCommentLines
(
c1
.
List
[
0
]
.
Slash
,
2
)
.
Text
(
)
t
.
SecondClosestCommentLines
=
splitLines
(
b
.
priorCommentLines
(
c1
.
List
[
0
]
.
Slash
,
2
)
.
Text
()
)
}
}
}
}
tf
,
ok
:=
obj
.
(
*
tc
.
Func
)
tf
,
ok
:=
obj
.
(
*
tc
.
Func
)
...
@@ -418,6 +415,10 @@ func (b *Builder) priorCommentLines(pos token.Pos, lines int) *ast.CommentGroup
...
@@ -418,6 +415,10 @@ func (b *Builder) priorCommentLines(pos token.Pos, lines int) *ast.CommentGroup
return
b
.
endLineToCommentGroup
[
key
]
return
b
.
endLineToCommentGroup
[
key
]
}
}
func
splitLines
(
str
string
)
[]
string
{
return
strings
.
Split
(
strings
.
TrimRight
(
str
,
"
\n
"
),
"
\n
"
)
}
func
tcFuncNameToName
(
in
string
)
types
.
Name
{
func
tcFuncNameToName
(
in
string
)
types
.
Name
{
name
:=
strings
.
TrimLeft
(
in
,
"func "
)
name
:=
strings
.
TrimLeft
(
in
,
"func "
)
nameParts
:=
strings
.
Split
(
name
,
"("
)
nameParts
:=
strings
.
Split
(
name
,
"("
)
...
@@ -494,7 +495,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
...
@@ -494,7 +495,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
Embedded
:
f
.
Anonymous
(),
Embedded
:
f
.
Anonymous
(),
Tags
:
t
.
Tag
(
i
),
Tags
:
t
.
Tag
(
i
),
Type
:
b
.
walkType
(
u
,
nil
,
f
.
Type
()),
Type
:
b
.
walkType
(
u
,
nil
,
f
.
Type
()),
CommentLines
:
b
.
priorCommentLines
(
f
.
Pos
(),
1
)
.
Text
(
),
CommentLines
:
splitLines
(
b
.
priorCommentLines
(
f
.
Pos
(),
1
)
.
Text
()
),
}
}
out
.
Members
=
append
(
out
.
Members
,
m
)
out
.
Members
=
append
(
out
.
Members
,
m
)
}
}
...
...
cmd/libs/go2idl/parser/parse_test.go
View file @
b01ac472
...
@@ -197,13 +197,13 @@ type Blah struct {
...
@@ -197,13 +197,13 @@ type Blah struct {
if
e
,
a
:=
types
.
Struct
,
blahT
.
Kind
;
e
!=
a
{
if
e
,
a
:=
types
.
Struct
,
blahT
.
Kind
;
e
!=
a
{
t
.
Errorf
(
"struct kind wrong, wanted %v, got %v"
,
e
,
a
)
t
.
Errorf
(
"struct kind wrong, wanted %v, got %v"
,
e
,
a
)
}
}
if
e
,
a
:=
"Blah is a test.
\n
A test, I tell you.
\n
"
,
blahT
.
CommentLines
;
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 %
v, got %v
"
,
e
,
a
)
t
.
Errorf
(
"struct comment wrong, wanted %
q, got %q
"
,
e
,
a
)
}
}
m
:=
types
.
Member
{
m
:=
types
.
Member
{
Name
:
"B"
,
Name
:
"B"
,
Embedded
:
false
,
Embedded
:
false
,
CommentLines
:
"B is the second field.
\n
Multiline comments work.
\n
"
,
CommentLines
:
[]
string
{
"B is the second field."
,
"Multiline comments work."
}
,
Tags
:
`json:"b"`
,
Tags
:
`json:"b"`
,
Type
:
types
.
String
,
Type
:
types
.
String
,
}
}
...
@@ -216,7 +216,7 @@ func TestParseSecondClosestCommentLines(t *testing.T) {
...
@@ -216,7 +216,7 @@ func TestParseSecondClosestCommentLines(t *testing.T) {
const
fileName
=
"base/foo/proto/foo.go"
const
fileName
=
"base/foo/proto/foo.go"
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
testFile
map
[
string
]
string
testFile
map
[
string
]
string
expected
string
expected
[]
string
}{
}{
{
{
map
[
string
]
string
{
fileName
:
`package foo
map
[
string
]
string
{
fileName
:
`package foo
...
@@ -229,7 +229,7 @@ type Blah struct {
...
@@ -229,7 +229,7 @@ type Blah struct {
a int
a int
}
}
`
},
`
},
"Blah's SecondClosestCommentLines.
\n
Another line.
\n
"
,
[]
string
{
"Blah's SecondClosestCommentLines."
,
"Another line."
}
,
},
},
{
{
map
[
string
]
string
{
fileName
:
`package foo
map
[
string
]
string
{
fileName
:
`package foo
...
@@ -240,15 +240,15 @@ type Blah struct {
...
@@ -240,15 +240,15 @@ type Blah struct {
a int
a int
}
}
`
},
`
},
"Blah's SecondClosestCommentLines.
\n
Another line.
\n
"
,
[]
string
{
"Blah's SecondClosestCommentLines."
,
"Another line."
}
,
},
},
}
}
for
_
,
test
:=
range
testCases
{
for
_
,
test
:=
range
testCases
{
_
,
u
,
o
:=
construct
(
t
,
test
.
testFile
,
namer
.
NewPublicNamer
(
0
))
_
,
u
,
o
:=
construct
(
t
,
test
.
testFile
,
namer
.
NewPublicNamer
(
0
))
t
.
Logf
(
"%#v"
,
o
)
t
.
Logf
(
"%#v"
,
o
)
blahT
:=
u
.
Type
(
types
.
Name
{
Package
:
"base/foo/proto"
,
Name
:
"Blah"
})
blahT
:=
u
.
Type
(
types
.
Name
{
Package
:
"base/foo/proto"
,
Name
:
"Blah"
})
if
e
,
a
:=
test
.
expected
,
blahT
.
SecondClosestCommentLines
;
e
!=
a
{
if
e
,
a
:=
test
.
expected
,
blahT
.
SecondClosestCommentLines
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"struct second closest comment wrong, wanted %
v, got %v
"
,
e
,
a
)
t
.
Errorf
(
"struct second closest comment wrong, wanted %
q, got %q
"
,
e
,
a
)
}
}
}
}
}
}
...
...
cmd/libs/go2idl/types/comments.go
View file @
b01ac472
...
@@ -39,8 +39,7 @@ import (
...
@@ -39,8 +39,7 @@ import (
// TODO: Basically we need to define a standard way of giving instructions to
// TODO: Basically we need to define a standard way of giving instructions to
// autogenerators in the comments of a type. This is a first iteration of that.
// autogenerators in the comments of a type. This is a first iteration of that.
// TODO: allow multiple values per key?
// TODO: allow multiple values per key?
func
ExtractCommentTags
(
marker
,
allLines
string
)
map
[
string
]
string
{
func
ExtractCommentTags
(
marker
string
,
lines
[]
string
)
map
[
string
]
string
{
lines
:=
strings
.
Split
(
allLines
,
"
\n
"
)
out
:=
map
[
string
]
string
{}
out
:=
map
[
string
]
string
{}
for
_
,
line
:=
range
lines
{
for
_
,
line
:=
range
lines
{
line
=
strings
.
Trim
(
line
,
" "
)
line
=
strings
.
Trim
(
line
,
" "
)
...
...
cmd/libs/go2idl/types/types.go
View file @
b01ac472
...
@@ -235,7 +235,7 @@ type Type struct {
...
@@ -235,7 +235,7 @@ type Type struct {
// If there are comment lines immediately before the type definition,
// If there are comment lines immediately before the type definition,
// they will be recorded here.
// they will be recorded here.
CommentLines
string
CommentLines
[]
string
// If there are comment lines preceding the `CommentLines`, they will be
// If there are comment lines preceding the `CommentLines`, they will be
// recorded here. There are two cases:
// recorded here. There are two cases:
...
@@ -252,7 +252,7 @@ type Type struct {
...
@@ -252,7 +252,7 @@ type Type struct {
// a blank line
// a blank line
// type definition
// type definition
// ---
// ---
SecondClosestCommentLines
string
SecondClosestCommentLines
[]
string
// If Kind == Struct
// If Kind == Struct
Members
[]
Member
Members
[]
Member
...
@@ -330,7 +330,7 @@ type Member struct {
...
@@ -330,7 +330,7 @@ type Member struct {
// If there are comment lines immediately before the member in the type
// If there are comment lines immediately before the member in the type
// definition, they will be recorded here.
// definition, they will be recorded here.
CommentLines
string
CommentLines
[]
string
// If there are tags along with this member, they will be saved here.
// If there are tags along with this member, they will be saved here.
Tags
string
Tags
string
...
@@ -358,7 +358,7 @@ type Signature struct {
...
@@ -358,7 +358,7 @@ type Signature struct {
// If there are comment lines immediately before this
// If there are comment lines immediately before this
// signature/method/function declaration, they will be recorded here.
// signature/method/function declaration, they will be recorded here.
CommentLines
string
CommentLines
[]
string
}
}
// Built in types.
// Built in types.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment