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>
}
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 {