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
b888fcc8
Commit
b888fcc8
authored
Dec 16, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18743 from caesarxuchao/second-comment-blcok
Auto commit by PR queue bot
parents
caae39b1
5f0509a3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
9 deletions
+70
-9
parse.go
cmd/libs/go2idl/parser/parse.go
+12
-9
parse_test.go
cmd/libs/go2idl/parser/parse_test.go
+41
-0
types.go
cmd/libs/go2idl/types/types.go
+17
-0
No files found.
cmd/libs/go2idl/parser/parse.go
View file @
b888fcc8
...
...
@@ -300,7 +300,13 @@ func (b *Builder) FindTypes() (types.Universe, error) {
tn
,
ok
:=
obj
.
(
*
tc
.
TypeName
)
if
ok
{
t
:=
b
.
walkType
(
u
,
nil
,
tn
.
Type
())
t
.
CommentLines
=
b
.
priorCommentLines
(
obj
.
Pos
())
c1
:=
b
.
priorCommentLines
(
obj
.
Pos
(),
1
)
t
.
CommentLines
=
c1
.
Text
()
if
c1
==
nil
{
t
.
SecondClosestCommentLines
=
b
.
priorCommentLines
(
obj
.
Pos
(),
2
)
.
Text
()
}
else
{
t
.
SecondClosestCommentLines
=
b
.
priorCommentLines
(
c1
.
List
[
0
]
.
Slash
,
2
)
.
Text
()
}
}
tf
,
ok
:=
obj
.
(
*
tc
.
Func
)
// We only care about functions, not concrete/abstract methods.
...
...
@@ -319,14 +325,11 @@ func (b *Builder) FindTypes() (types.Universe, error) {
return
u
,
nil
}
// if there's a comment on the line before pos, return its text, otherwise "".
func
(
b
*
Builder
)
priorCommentLines
(
pos
token
.
Pos
)
string
{
// if there's a comment on the line
`lines`
before pos, return its text, otherwise "".
func
(
b
*
Builder
)
priorCommentLines
(
pos
token
.
Pos
,
lines
int
)
*
ast
.
CommentGroup
{
position
:=
b
.
fset
.
Position
(
pos
)
key
:=
fileLine
{
position
.
Filename
,
position
.
Line
-
1
}
if
c
,
ok
:=
b
.
endLineToCommentGroup
[
key
];
ok
{
return
c
.
Text
()
}
return
""
key
:=
fileLine
{
position
.
Filename
,
position
.
Line
-
lines
}
return
b
.
endLineToCommentGroup
[
key
]
}
func
tcFuncNameToName
(
in
string
)
types
.
Name
{
...
...
@@ -401,7 +404,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
Embedded
:
f
.
Anonymous
(),
Tags
:
t
.
Tag
(
i
),
Type
:
b
.
walkType
(
u
,
nil
,
f
.
Type
()),
CommentLines
:
b
.
priorCommentLines
(
f
.
Pos
()),
CommentLines
:
b
.
priorCommentLines
(
f
.
Pos
()
,
1
)
.
Text
(
),
}
out
.
Members
=
append
(
out
.
Members
,
m
)
}
...
...
cmd/libs/go2idl/parser/parse_test.go
View file @
b888fcc8
...
...
@@ -211,6 +211,47 @@ type Blah struct {
}
}
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
}
`
},
"Blah's SecondClosestCommentLines.
\n
Another line.
\n
"
,
},
{
map
[
string
]
string
{
fileName
:
`package foo
// Blah's SecondClosestCommentLines.
// Another line.
type Blah struct {
a int
}
`
},
"Blah's SecondClosestCommentLines.
\n
Another line.
\n
"
,
},
}
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
;
e
!=
a
{
t
.
Errorf
(
"struct second closest comment wrong, wanted %v, got %v"
,
e
,
a
)
}
}
}
func
TestTypeKindParse
(
t
*
testing
.
T
)
{
var
testFiles
=
map
[
string
]
string
{
"a/foo.go"
:
"package a
\n
type Test string
\n
"
,
...
...
cmd/libs/go2idl/types/types.go
View file @
b888fcc8
...
...
@@ -231,6 +231,23 @@ type Type struct {
// they will be recorded here.
CommentLines
string
// If there are comment lines preceding the `CommentLines`, they will be
// recorded here. There are two cases:
// ---
// SecondClosestCommentLines
// a blank line
// CommentLines
// type definition
// ---
//
// or
// ---
// SecondClosestCommentLines
// a blank line
// type definition
// ---
SecondClosestCommentLines
string
// If Kind == Struct
Members
[]
Member
...
...
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