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
5f0509a3
Commit
5f0509a3
authored
Dec 15, 2015
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add SecondClosestCommentLines to go2idl types.Type
parent
582c84b5
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 @
5f0509a3
...
@@ -300,7 +300,13 @@ func (b *Builder) FindTypes() (types.Universe, error) {
...
@@ -300,7 +300,13 @@ func (b *Builder) FindTypes() (types.Universe, error) {
tn
,
ok
:=
obj
.
(
*
tc
.
TypeName
)
tn
,
ok
:=
obj
.
(
*
tc
.
TypeName
)
if
ok
{
if
ok
{
t
:=
b
.
walkType
(
u
,
nil
,
tn
.
Type
())
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
)
tf
,
ok
:=
obj
.
(
*
tc
.
Func
)
// We only care about functions, not concrete/abstract methods.
// We only care about functions, not concrete/abstract methods.
...
@@ -319,14 +325,11 @@ func (b *Builder) FindTypes() (types.Universe, error) {
...
@@ -319,14 +325,11 @@ func (b *Builder) FindTypes() (types.Universe, error) {
return
u
,
nil
return
u
,
nil
}
}
// if there's a comment on the line before pos, return its text, otherwise "".
// if there's a comment on the line
`lines`
before pos, return its text, otherwise "".
func
(
b
*
Builder
)
priorCommentLines
(
pos
token
.
Pos
)
string
{
func
(
b
*
Builder
)
priorCommentLines
(
pos
token
.
Pos
,
lines
int
)
*
ast
.
CommentGroup
{
position
:=
b
.
fset
.
Position
(
pos
)
position
:=
b
.
fset
.
Position
(
pos
)
key
:=
fileLine
{
position
.
Filename
,
position
.
Line
-
1
}
key
:=
fileLine
{
position
.
Filename
,
position
.
Line
-
lines
}
if
c
,
ok
:=
b
.
endLineToCommentGroup
[
key
];
ok
{
return
b
.
endLineToCommentGroup
[
key
]
return
c
.
Text
()
}
return
""
}
}
func
tcFuncNameToName
(
in
string
)
types
.
Name
{
func
tcFuncNameToName
(
in
string
)
types
.
Name
{
...
@@ -401,7 +404,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
...
@@ -401,7 +404,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
()),
CommentLines
:
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 @
5f0509a3
...
@@ -211,6 +211,47 @@ type Blah struct {
...
@@ -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
)
{
func
TestTypeKindParse
(
t
*
testing
.
T
)
{
var
testFiles
=
map
[
string
]
string
{
var
testFiles
=
map
[
string
]
string
{
"a/foo.go"
:
"package a
\n
type Test string
\n
"
,
"a/foo.go"
:
"package a
\n
type Test string
\n
"
,
...
...
cmd/libs/go2idl/types/types.go
View file @
5f0509a3
...
@@ -231,6 +231,23 @@ type Type struct {
...
@@ -231,6 +231,23 @@ type Type struct {
// 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
// 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
// If Kind == Struct
Members
[]
Member
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