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

Unified Diff: pkg/analyzer/bin/formatter.dart

Issue 152863006: pkg/analyzer: fix formatter bin crash due to empty selection flag (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: a few more return types 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/bin/formatter.dart
diff --git a/pkg/analyzer/bin/formatter.dart b/pkg/analyzer/bin/formatter.dart
index 0466f40df5042446743cfcedab6981d78ed04335..01eb5306a2ed26b2938325e441a1ec879a34b50b 100755
--- a/pkg/analyzer/bin/formatter.dart
+++ b/pkg/analyzer/bin/formatter.dart
@@ -18,7 +18,7 @@ final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false);
final argParser = _initArgParser();
final defaultSelection = new Selection(-1, -1);
-var formatterSettings;
+FormatterOptions formatterSettings;
CodeKind kind;
bool machineFormat;
@@ -39,7 +39,7 @@ const MAX_LINE_FLAG = 'max_line_length';
const FOLLOW_LINKS = false;
-main(args) {
+main(List<String> args) {
pquitslund 2014/02/10 04:01:50 Is this ever NOT a List of Strings? What's the be
var options = argParser.parse(args);
if (options['help']) {
_printUsage();
@@ -56,7 +56,7 @@ main(args) {
}
}
-_readOptions(options) {
+_readOptions(ArgResults options) {
pquitslund 2014/02/10 04:01:50 Really? It's like you're provoking me... ;) Sure
kind = _parseKind(options[KIND_FLAG]);
machineFormat = options[MACHINE_FLAG];
overwriteFileContents = options[WRITE_FLAG];
@@ -66,7 +66,7 @@ _readOptions(options) {
pageWidth: _parseLineLength(options[MAX_LINE_FLAG]));
}
-CodeKind _parseKind(kindOption) {
+CodeKind _parseKind(String kindOption) {
pquitslund 2014/02/10 04:01:50 OK, and especially here. Isn't it obvious from th
switch(kindOption) {
case 'stmt' :
return CodeKind.STATEMENT;
@@ -90,15 +90,15 @@ int _parseLineLength(String lengthOption) {
}
-Selection _parseSelection(selectionOption) {
- if (selectionOption != null) {
- var units = selectionOption.split(',');
- if (units.length == 2) {
- var offset = _toInt(units[0]);
- var length = _toInt(units[1]);
- if (offset != null && length != null) {
- return new Selection(offset, length);
- }
+Selection _parseSelection(String selectionOption) {
+ if(selectionOption == null) return null;
+
+ var units = selectionOption.split(',');
+ if (units.length == 2) {
+ var offset = _toInt(units[0]);
+ var length = _toInt(units[1]);
+ if (offset != null && length != null) {
+ return new Selection(offset, length);
}
}
throw new FormatterException('Selections are specified as integer pairs '
@@ -152,9 +152,9 @@ _formatFile(file) {
}
}
-_isPatchFile(file) => file.path.endsWith('_patch.dart');
+bool _isPatchFile(file) => file.path.endsWith('_patch.dart');
-_isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path));
+bool _isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path));
_formatStdin(kind) {
var input = new StringBuffer();
@@ -221,7 +221,7 @@ String _format(src, kind) {
return formatResult.source;
}
-_toJson(formatResult) =>
+String _toJson(formatResult) =>
// Actual JSON format TBD
JSON.encode({'source': formatResult.source,
'selection': {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698