mirror of
https://github.com/golang/go
synced 2024-11-26 08:17:59 -07:00
go/ast: print CommentMap contents in source order
Sort the comment map entries before printing. Makes it easier to use the output for debugging. For #39753. Change-Id: Ic8e7d27dd2df59173e2c3a04a6b71ae966703885 Reviewed-on: https://go-review.googlesource.com/c/go/+/315370 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
06ac303f6a
commit
0dfb6fb490
@ -315,9 +315,17 @@ loop:
|
||||
}
|
||||
|
||||
func (cmap CommentMap) String() string {
|
||||
// print map entries in sorted order
|
||||
var nodes []Node
|
||||
for node := range cmap {
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
sort.Sort(byInterval(nodes))
|
||||
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintln(&buf, "CommentMap {")
|
||||
for node, comment := range cmap {
|
||||
for _, node := range nodes {
|
||||
comment := cmap[node]
|
||||
// print name of identifiers; print node type for other nodes
|
||||
var s string
|
||||
if ident, ok := node.(*Ident); ok {
|
||||
|
Loading…
Reference in New Issue
Block a user