Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: mojom/mojom_parser/formatter/printer.go

Issue 1770243002: Change line limit to 80 char. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojom/mojom_parser/formatter/formatter_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // token that begins a block where formatting has been disabled. 56 // token that begins a block where formatting has been disabled.
57 noFormatStart lexer.Token 57 noFormatStart lexer.Token
58 58
59 // indentSize at the time noFormat is set. 59 // indentSize at the time noFormat is set.
60 noFormatStartIndent int 60 noFormatStartIndent int
61 } 61 }
62 62
63 // newPrinter is a constructor for printer. 63 // newPrinter is a constructor for printer.
64 func newPrinter() (p *printer) { 64 func newPrinter() (p *printer) {
65 p = new(printer) 65 p = new(printer)
66 » p.maxLineLength = 100 66 » p.maxLineLength = 80
67 return 67 return
68 } 68 }
69 69
70 // result returns the pretty-printed version of what was given to the printer. 70 // result returns the pretty-printed version of what was given to the printer.
71 // Usually, this is a pretty-printed MojomFile. 71 // Usually, this is a pretty-printed MojomFile.
72 func (p *printer) result() string { 72 func (p *printer) result() string {
73 return p.buffer.String() 73 return p.buffer.String()
74 } 74 }
75 75
76 // writeMojomFile is the entry point of the pretty printer. 76 // writeMojomFile is the entry point of the pretty printer.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 scratch.writeMethodParams(params) 233 scratch.writeMethodParams(params)
234 if len(scratch.result())+p.lineLength() > p.maxLineLength { 234 if len(scratch.result())+p.lineLength() > p.maxLineLength {
235 ownLine = true 235 ownLine = true
236 } 236 }
237 } 237 }
238 p.write("(") 238 p.write("(")
239 declaredObjects := params.GetDeclaredObjects() 239 declaredObjects := params.GetDeclaredObjects()
240 240
241 extraIndent := p.lineLength() - p.indentSize 241 extraIndent := p.lineLength() - p.indentSize
242 if ownLine { 242 if ownLine {
243 // If we are printing every parameter on its own line, check to see if
244 // aligning the parameters to the right of the method name can b e done.
245 for _, param := range declaredObjects {
246 scratch := newPrinter()
247 scratch.maxLineLength = -1
248 scratch.writeMethodParam(param.(*mojom.StructField))
249 // If any parameter would go beyond the maximum line len gth, start the
250 // list of parameters on the line after the method name and indented 4
251 // more than the method itself.
252 if len(scratch.result())+p.lineLength() > p.maxLineLengt h {
253 p.nl()
254 extraIndent = 4
255 break
256 }
257 }
258
243 p.indentSize += extraIndent 259 p.indentSize += extraIndent
244 } 260 }
245 261
246 for i, param := range declaredObjects { 262 for i, param := range declaredObjects {
247 p.writeMethodParam(param.(*mojom.StructField)) 263 p.writeMethodParam(param.(*mojom.StructField))
248 if i < len(declaredObjects)-1 { 264 if i < len(declaredObjects)-1 {
249 p.write(",") 265 p.write(",")
250 if ownLine { 266 if ownLine {
251 p.nl() 267 p.nl()
252 } else { 268 } else {
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 851
836 // See sort.Interface. 852 // See sort.Interface.
837 func (ifs *importedFilesSorter) Less(i, j int) bool { 853 func (ifs *importedFilesSorter) Less(i, j int) bool {
838 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName 854 return ifs.imports[i].SpecifiedName < ifs.imports[j].SpecifiedName
839 } 855 }
840 856
841 // See sort.Interface. 857 // See sort.Interface.
842 func (ifs *importedFilesSorter) Swap(i, j int) { 858 func (ifs *importedFilesSorter) Swap(i, j int) {
843 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i] 859 ifs.imports[i], ifs.imports[j] = ifs.imports[j], ifs.imports[i]
844 } 860 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/formatter/formatter_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698