| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package formatter | 5 package formatter |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "mojom/mojom_parser/lexer" | 10 "mojom/mojom_parser/lexer" |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if attachedComments == nil { | 567 if attachedComments == nil { |
| 568 return | 568 return |
| 569 } | 569 } |
| 570 | 570 |
| 571 p.writeCommentBlocks(attachedComments.Above, true) | 571 p.writeCommentBlocks(attachedComments.Above, true) |
| 572 } | 572 } |
| 573 | 573 |
| 574 func (p *printer) writeFinalComments(container mojom.DeclaredObjectsContainer) { | 574 func (p *printer) writeFinalComments(container mojom.DeclaredObjectsContainer) { |
| 575 el := container.(mojom.MojomElement) | 575 el := container.(mojom.MojomElement) |
| 576 attachedComments := el.AttachedComments() | 576 attachedComments := el.AttachedComments() |
| 577 » if attachedComments == nil || len(attachedComments.Final) == 0 { | 577 » if attachedComments == nil { |
| 578 » » return |
| 579 » } |
| 580 » finalComments := trimEmptyLinesEnd(attachedComments.Final) |
| 581 » if len(finalComments) == 0 { |
| 578 return | 582 return |
| 579 } | 583 } |
| 580 | 584 |
| 581 // Only print blank lines if there is something other than comments in t
he | 585 // Only print blank lines if there is something other than comments in t
he |
| 582 // container. | 586 // container. |
| 583 if len(container.GetDeclaredObjects()) > 0 { | 587 if len(container.GetDeclaredObjects()) > 0 { |
| 584 p.nl() | 588 p.nl() |
| 585 » » if attachedComments.Final[0].Kind == lexer.EmptyLine { | 589 » » if finalComments[0].Kind == lexer.EmptyLine { |
| 586 p.nl() | 590 p.nl() |
| 587 } | 591 } |
| 588 } | 592 } |
| 589 » p.writeCommentBlocks(attachedComments.Final, false) | 593 » p.writeCommentBlocks(finalComments, false) |
| 590 } | 594 } |
| 591 | 595 |
| 592 // writeLeftComments writes the comments left of a MojomElement. | 596 // writeLeftComments writes the comments left of a MojomElement. |
| 593 func (p *printer) writeLeftComments(el mojom.MojomElement) { | 597 func (p *printer) writeLeftComments(el mojom.MojomElement) { |
| 594 attachedComments := el.AttachedComments() | 598 attachedComments := el.AttachedComments() |
| 595 if attachedComments == nil { | 599 if attachedComments == nil { |
| 596 return | 600 return |
| 597 } | 601 } |
| 598 | 602 |
| 599 for _, comment := range attachedComments.Left { | 603 for _, comment := range attachedComments.Left { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 | 948 |
| 945 // See sort.Interface. | 949 // See sort.Interface. |
| 946 func (ifs *importedFilesSorter) Less(i, j int) bool { | 950 func (ifs *importedFilesSorter) Less(i, j int) bool { |
| 947 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName | 951 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName |
| 948 } | 952 } |
| 949 | 953 |
| 950 // See sort.Interface. | 954 // See sort.Interface. |
| 951 func (ifs *importedFilesSorter) Swap(i, j int) { | 955 func (ifs *importedFilesSorter) Swap(i, j int) { |
| 952 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] | 956 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] |
| 953 } | 957 } |
| OLD | NEW |