| 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } | 661 } |
| 662 | 662 |
| 663 func (p *printer) writeSingleLineComment(comment lexer.Token) { | 663 func (p *printer) writeSingleLineComment(comment lexer.Token) { |
| 664 if comment.Kind != lexer.SingleLineComment { | 664 if comment.Kind != lexer.SingleLineComment { |
| 665 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment
)) | 665 panic(fmt.Sprintf("This is not a SingleLineComment: %s", comment
)) |
| 666 } | 666 } |
| 667 commentText := comment.Text | 667 commentText := comment.Text |
| 668 | 668 |
| 669 // We expect that the first 2 characters are // followed by a space or t
ab. | 669 // We expect that the first 2 characters are // followed by a space or t
ab. |
| 670 // If the third character is not a space or tab, we insert a space. | 670 // If the third character is not a space or tab, we insert a space. |
| 671 » if len(commentText) > 2 && commentText[2] != ' ' && commentText[2] != '\
t' { | 671 » // There is an exception for three forward slashes which are allowed. |
| 672 » if len(commentText) > 2 && !strings.ContainsAny(" \t/", commentText[2:3]
) { |
| 672 commentText = "// " + commentText[2:] | 673 commentText = "// " + commentText[2:] |
| 673 } | 674 } |
| 674 p.write(commentText) | 675 p.write(commentText) |
| 675 } | 676 } |
| 676 | 677 |
| 677 func (p *printer) writeMultiLineComment(comment lexer.Token) { | 678 func (p *printer) writeMultiLineComment(comment lexer.Token) { |
| 678 if comment.Kind != lexer.MultiLineComment { | 679 if comment.Kind != lexer.MultiLineComment { |
| 679 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment)
) | 680 panic(fmt.Sprintf("This is not a MultiLineComment: %s", comment)
) |
| 680 } | 681 } |
| 681 | 682 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 949 |
| 949 // See sort.Interface. | 950 // See sort.Interface. |
| 950 func (ifs *importedFilesSorter) Less(i, j int) bool { | 951 func (ifs *importedFilesSorter) Less(i, j int) bool { |
| 951 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName | 952 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName |
| 952 } | 953 } |
| 953 | 954 |
| 954 // See sort.Interface. | 955 // See sort.Interface. |
| 955 func (ifs *importedFilesSorter) Swap(i, j int) { | 956 func (ifs *importedFilesSorter) Swap(i, j int) { |
| 956 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] | 957 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] |
| 957 } | 958 } |
| OLD | NEW |