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

Side by Side Diff: pkg/analyzer/bin/formatter.dart

Issue 139263011: dartfmt line wrapping bypass option support. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 2
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 // for details. All rights reserved. Use of this source code is governed by a 4 // for details. All rights reserved. Use of this source code is governed by a
5 // BSD-style license that can be found in the LICENSE file. 5 // BSD-style license that can be found in the LICENSE file.
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 } 57 }
58 58
59 _readOptions(options) { 59 _readOptions(options) {
60 kind = _parseKind(options[KIND_FLAG]); 60 kind = _parseKind(options[KIND_FLAG]);
61 machineFormat = options[MACHINE_FLAG]; 61 machineFormat = options[MACHINE_FLAG];
62 overwriteFileContents = options[WRITE_FLAG]; 62 overwriteFileContents = options[WRITE_FLAG];
63 selection = _parseSelection(options[SELECTION_FLAG]); 63 selection = _parseSelection(options[SELECTION_FLAG]);
64 formatterSettings = 64 formatterSettings =
65 new FormatterOptions(codeTransforms: options[TRANSFORM_FLAG], 65 new FormatterOptions(codeTransforms: options[TRANSFORM_FLAG],
66 pageWidth: _toInt(options[MAX_LINE_FLAG])); 66 pageWidth: _parseLineLength(options[MAX_LINE_FLAG]));
67 } 67 }
68 68
69 CodeKind _parseKind(kindOption) { 69 CodeKind _parseKind(kindOption) {
70 switch(kindOption) { 70 switch(kindOption) {
71 case 'stmt' : 71 case 'stmt' :
72 return CodeKind.STATEMENT; 72 return CodeKind.STATEMENT;
73 default: 73 default:
74 return CodeKind.COMPILATION_UNIT; 74 return CodeKind.COMPILATION_UNIT;
75 } 75 }
76 } 76 }
77 77
78 int _parseLineLength(String lengthOption) {
79 var length = _toInt(lengthOption);
80 if (length == null) {
81 if (lengthOption.toUpperCase() == 'INF') {
lukechurch 2014/01/27 20:39:44 I would recommend also supporting INFINITY - to su
pquitslund 2014/01/27 22:23:37 Done.
82 length = -1;
83 } else {
84 throw new FormatterException('Line length is specified as an Integer or '
85 'the value "Inf".');
86 }
87 }
88 return length;
89 }
90
91
78 Selection _parseSelection(selectionOption) { 92 Selection _parseSelection(selectionOption) {
79 if (selectionOption != null) { 93 if (selectionOption != null) {
80 var units = selectionOption.split(','); 94 var units = selectionOption.split(',');
81 if (units.length == 2) { 95 if (units.length == 2) {
82 var offset = _toInt(units[0]); 96 var offset = _toInt(units[0]);
83 var length = _toInt(units[1]); 97 var length = _toInt(units[1]);
84 if (offset != null && length != null) { 98 if (offset != null && length != null) {
85 return new Selection(offset, length); 99 return new Selection(offset, length);
86 } 100 }
87 } 101 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 /// Initialize the arg parser instance. 166 /// Initialize the arg parser instance.
153 ArgParser _initArgParser() { 167 ArgParser _initArgParser() {
154 // NOTE: these flags are placeholders only! 168 // NOTE: these flags are placeholders only!
155 var parser = new ArgParser(); 169 var parser = new ArgParser();
156 parser.addFlag(WRITE_FLAG, abbr: 'w', negatable: false, 170 parser.addFlag(WRITE_FLAG, abbr: 'w', negatable: false,
157 help: 'Write reformatted sources to files (overwriting contents). ' 171 help: 'Write reformatted sources to files (overwriting contents). '
158 'Do not print reformatted sources to standard output.'); 172 'Do not print reformatted sources to standard output.');
159 parser.addFlag(TRANSFORM_FLAG, abbr: 't', negatable: false, 173 parser.addFlag(TRANSFORM_FLAG, abbr: 't', negatable: false,
160 help: 'Perform code transformations.'); 174 help: 'Perform code transformations.');
161 parser.addOption(MAX_LINE_FLAG, abbr: 'l', defaultsTo: '80', 175 parser.addOption(MAX_LINE_FLAG, abbr: 'l', defaultsTo: '80',
162 help: 'Wrap lines longer than this length.'); 176 help: 'Wrap lines longer than this length. '
177 'To never wrap, specify "Inf".');
163 parser.addOption(KIND_FLAG, abbr: 'k', defaultsTo: 'cu', 178 parser.addOption(KIND_FLAG, abbr: 'k', defaultsTo: 'cu',
164 help: 'Specify source snippet kind ("stmt" or "cu")' 179 help: 'Specify source snippet kind ("stmt" or "cu") '
165 ' --- [PROVISIONAL API].', hide: true); 180 '--- [PROVISIONAL API].', hide: true);
166 parser.addOption(SELECTION_FLAG, abbr: 's', 181 parser.addOption(SELECTION_FLAG, abbr: 's',
167 help: 'Specify selection information as an offset,length pair ' 182 help: 'Specify selection information as an offset,length pair '
168 '(e.g., -s "0,4").', hide: true); 183 '(e.g., -s "0,4").', hide: true);
169 parser.addFlag(MACHINE_FLAG, abbr: 'm', negatable: false, 184 parser.addFlag(MACHINE_FLAG, abbr: 'm', negatable: false,
170 help: 'Produce output in a format suitable for parsing.'); 185 help: 'Produce output in a format suitable for parsing.');
171 parser.addFlag(HELP_FLAG, abbr: 'h', negatable: false, 186 parser.addFlag(HELP_FLAG, abbr: 'h', negatable: false,
172 help: 'Print this usage information.'); 187 help: 'Print this usage information.');
173 return parser; 188 return parser;
174 } 189 }
175 190
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 'offset': formatResult.selection.offset, 227 'offset': formatResult.selection.offset,
213 'length': formatResult.selection.length 228 'length': formatResult.selection.length
214 } 229 }
215 }); 230 });
216 231
217 /// Log the given [msg]. 232 /// Log the given [msg].
218 _log(String msg) { 233 _log(String msg) {
219 //TODO(pquitslund): add proper log support 234 //TODO(pquitslund): add proper log support
220 print(msg); 235 print(msg);
221 } 236 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/services/formatter_impl.dart » ('j') | pkg/analyzer/lib/src/services/writer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698