-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/parser: include more comments in a struct or interface
While parsing inside a struct or an interface, skipping over empty lines too to collect the next group of comments. We do not need to skip over more than 1 empty line since gofmt already removes multiple empty consecutive lines. Fixes golang#10858 Change-Id: I0c97b65b5fc44e225e5dc7871ace24f43419ce08 Reviewed-on: https://go-review.googlesource.com/c/go/+/161177 Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
- Loading branch information
Showing
5 changed files
with
353 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
PACKAGE issue10858 | ||
|
||
IMPORTPATH | ||
testdata/issue10858 | ||
|
||
IMPORTS | ||
unsafe | ||
|
||
FILENAMES | ||
testdata/issue10858.go | ||
|
||
CONSTANTS | ||
// First line Second line | ||
const ( | ||
|
||
// C1 comment | ||
C1 int = 1 << 0 | ||
|
||
C2 int = 1 << 1 | ||
|
||
// C3 comment | ||
// | ||
// with a line gap | ||
C3 int = 1 << 2 | ||
) | ||
|
||
|
||
TYPES | ||
// StructTag is a comment with 2 connecting lines | ||
type StructTag string // adjacent comment | ||
|
||
// Get returns the value associated with key in the tag string. | ||
func (tag StructTag) Get(key string) string | ||
|
||
// First line Second line | ||
type Type interface { | ||
// Should be present | ||
|
||
// Align returns the alignment in bytes of a value of | ||
// this type when allocated in memory. | ||
Align() int | ||
|
||
// FieldAlign returns the alignment in bytes of a value of | ||
// this type when used as a field in a struct. | ||
FieldAlign() int // adjacent comment | ||
|
||
// Ptr: Elem | ||
// Slice: Elem | ||
|
||
// Bits returns the size of the type in bits. | ||
|
||
// | ||
// It panics if the type's Kind is not one of the | ||
// sized or unsized Int, Uint, Float, or Complex kinds. | ||
Bits() int | ||
} | ||
|
||
// NewType is a comment ending with this line. | ||
func NewType() Type | ||
|
||
// TypeAlg is a copy of runtime.typeAlg | ||
type TypeAlg struct { | ||
// function for hashing objects of this type | ||
// | ||
// | ||
// (ptr to object, seed) -> hash | ||
Hash func(unsafe.Pointer, uintptr) uintptr | ||
|
||
// include | ||
// include | ||
|
||
// include | ||
|
||
// function for comparing objects of this type | ||
// (ptr to object A, ptr to object B) -> ==? | ||
Equal func(unsafe.Pointer, unsafe.Pointer) bool | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
PACKAGE issue10858 | ||
|
||
IMPORTPATH | ||
testdata/issue10858 | ||
|
||
IMPORTS | ||
unsafe | ||
|
||
FILENAMES | ||
testdata/issue10858.go | ||
|
||
CONSTANTS | ||
// First line Second line | ||
const ( | ||
|
||
// C1 comment | ||
C1 int = 1 << 0 | ||
|
||
C2 int = 1 << 1 | ||
|
||
// C3 comment | ||
// | ||
// with a line gap | ||
C3 int = 1 << 2 | ||
) | ||
|
||
|
||
TYPES | ||
// StructTag is a comment with 2 connecting lines | ||
type StructTag string // adjacent comment | ||
|
||
// Get returns the value associated with key in the tag string. | ||
func (tag StructTag) Get(key string) string | ||
|
||
// First line Second line | ||
type Type interface { | ||
// Should be present | ||
|
||
// Align returns the alignment in bytes of a value of | ||
// this type when allocated in memory. | ||
Align() int | ||
|
||
// FieldAlign returns the alignment in bytes of a value of | ||
// this type when used as a field in a struct. | ||
FieldAlign() int // adjacent comment | ||
|
||
// Ptr: Elem | ||
// Slice: Elem | ||
|
||
// Bits returns the size of the type in bits. | ||
|
||
// | ||
// It panics if the type's Kind is not one of the | ||
// sized or unsized Int, Uint, Float, or Complex kinds. | ||
Bits() int | ||
} | ||
|
||
// NewType is a comment ending with this line. | ||
func NewType() Type | ||
|
||
// TypeAlg is a copy of runtime.typeAlg | ||
type TypeAlg struct { | ||
// function for hashing objects of this type | ||
// | ||
// | ||
// (ptr to object, seed) -> hash | ||
Hash func(unsafe.Pointer, uintptr) uintptr | ||
|
||
// include | ||
// include | ||
|
||
// include | ||
|
||
// function for comparing objects of this type | ||
// (ptr to object A, ptr to object B) -> ==? | ||
Equal func(unsafe.Pointer, unsafe.Pointer) bool | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
PACKAGE issue10858 | ||
|
||
IMPORTPATH | ||
testdata/issue10858 | ||
|
||
IMPORTS | ||
unsafe | ||
|
||
FILENAMES | ||
testdata/issue10858.go | ||
|
||
CONSTANTS | ||
// First line Second line | ||
const ( | ||
|
||
// C1 comment | ||
C1 int = 1 << 0 | ||
|
||
C2 int = 1 << 1 | ||
|
||
// C3 comment | ||
// | ||
// with a line gap | ||
C3 int = 1 << 2 | ||
) | ||
|
||
|
||
TYPES | ||
// StructTag is a comment with 2 connecting lines | ||
type StructTag string // adjacent comment | ||
|
||
// Get returns the value associated with key in the tag string. | ||
func (tag StructTag) Get(key string) string | ||
|
||
// First line Second line | ||
type Type interface { | ||
// Should be present | ||
|
||
// Align returns the alignment in bytes of a value of | ||
// this type when allocated in memory. | ||
Align() int | ||
|
||
// FieldAlign returns the alignment in bytes of a value of | ||
// this type when used as a field in a struct. | ||
FieldAlign() int // adjacent comment | ||
|
||
// Ptr: Elem | ||
// Slice: Elem | ||
|
||
// Bits returns the size of the type in bits. | ||
|
||
// | ||
// It panics if the type's Kind is not one of the | ||
// sized or unsized Int, Uint, Float, or Complex kinds. | ||
Bits() int | ||
} | ||
|
||
// NewType is a comment ending with this line. | ||
func NewType() Type | ||
|
||
// TypeAlg is a copy of runtime.typeAlg | ||
type TypeAlg struct { | ||
// function for hashing objects of this type | ||
// | ||
// | ||
// (ptr to object, seed) -> hash | ||
Hash func(unsafe.Pointer, uintptr) uintptr | ||
|
||
// include | ||
// include | ||
|
||
// include | ||
|
||
// function for comparing objects of this type | ||
// (ptr to object A, ptr to object B) -> ==? | ||
Equal func(unsafe.Pointer, unsafe.Pointer) bool | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package issue10858 | ||
|
||
import "unsafe" | ||
|
||
// Should be ignored | ||
|
||
// First line | ||
// | ||
// Second line | ||
type Type interface { | ||
// Should be present | ||
|
||
// Align returns the alignment in bytes of a value of | ||
// this type when allocated in memory. | ||
Align() int | ||
|
||
// FieldAlign returns the alignment in bytes of a value of | ||
// this type when used as a field in a struct. | ||
FieldAlign() int // adjacent comment | ||
|
||
// Ptr: Elem | ||
// Slice: Elem | ||
|
||
// Bits returns the size of the type in bits. | ||
|
||
// | ||
// It panics if the type's Kind is not one of the | ||
// sized or unsized Int, Uint, Float, or Complex kinds. | ||
Bits() int | ||
|
||
// Should be ignored | ||
} | ||
|
||
// Should be ignored | ||
|
||
// NewType is a comment | ||
// | ||
// ending with this line. | ||
func NewType() Type {} | ||
|
||
// Ignore | ||
|
||
// First line | ||
// | ||
// Second line | ||
const ( | ||
// Should be ignored | ||
|
||
// C1 comment | ||
C1 int = 1 << 0 | ||
|
||
// Should | ||
// | ||
// be ignored | ||
|
||
C2 int = 1 << 1 | ||
|
||
// C3 comment | ||
// | ||
// with a line gap | ||
C3 int = 1 << 2 | ||
|
||
// Should be ignored | ||
) | ||
|
||
// Should be ignored | ||
|
||
// Should be ignored | ||
|
||
// TypeAlg is a | ||
// copy of runtime.typeAlg | ||
type TypeAlg struct { | ||
// function for hashing objects of this type | ||
// | ||
// | ||
// (ptr to object, seed) -> hash | ||
Hash func(unsafe.Pointer, uintptr) uintptr | ||
|
||
// include | ||
// include | ||
|
||
// include | ||
|
||
// function for comparing objects of this type | ||
// (ptr to object A, ptr to object B) -> ==? | ||
Equal func(unsafe.Pointer, unsafe.Pointer) bool | ||
// Should be ignored | ||
} | ||
|
||
// Should be ignored | ||
|
||
// StructTag is a comment | ||
// | ||
// | ||
// with 2 connecting lines | ||
type StructTag string // adjacent comment | ||
|
||
// Should be ignored | ||
|
||
// Get returns the value associated with key in the tag string. | ||
func (tag StructTag) Get(key string) string { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters