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

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

Issue 23441007: Directory processing for the formatter main. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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_experimental/bin/formatter.dart
===================================================================
--- pkg/analyzer_experimental/bin/formatter.dart (revision 26800)
+++ pkg/analyzer_experimental/bin/formatter.dart (working copy)
@@ -4,7 +4,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'dart:convert';
import 'dart:io';
import 'package:args/args.dart';
@@ -13,6 +12,7 @@
const BINARY_NAME = 'dartfmt';
+const DART_EXT = '.dart';
final argParser = _initArgParser();
void main() {
@@ -24,26 +24,51 @@
if (options.rest.isEmpty) {
_formatStdin(options);
} else {
- _formatFiles(options.rest);
+ _formatPaths(options.rest);
}
}
-_formatFiles(files) {
- for (var file in files) {
- _formatFile(file);
+_formatPaths(paths) {
+ paths.forEach((path) {
+ if (FileSystemEntity.isDirectorySync(path)) {
+ _formatDirectory(new Directory(path));
+ } else {
+ _formatFile(new File(path));
+ }
+ });
+}
+
+_formatResource(resource) {
+ if (resource is Directory) {
+ _formatDirectory(resource);
+ } else if (resource is File) {
+ _formatFile(resource);
}
}
-_formatFile(path) {
- var buffer = new StringBuffer();
- var file = new File(path);
- file.openRead()
- .transform(UTF8.decoder)
- .listen((data) => buffer.write(data),
- onError: (error) => print('Error, could not open "$path"'),
- onDone: () => print(_formatCU(buffer.toString())));
+_formatDirectory(dir) =>
+ dir.listSync().forEach((resource) => _formatResource(resource));
+
+
+void _formatFile(file) {
+ Uri.parse(file).pathSegments.last;
+ print(file.path);
+ if (_isDartFile(file)) {
+ try {
+ var buffer = new StringBuffer();
+ var rawSource = file.readAsStringSync();
+ var formatted = _formatCU(rawSource);
+ print(formatted);
+ file.writeAsStringSync(formatted);
+ } catch (e) {
+ _log('Error formatting "${file.path}": $e');
+ }
+ }
}
+//TODO(pquitslund): fix this using 'path'
+_isDartFile(file) => !file.path.startsWith('.') && file.path.endsWith(DART_EXT);
+
_formatStdin(options) {
_log('not supported yet!');
// stdin.transform(new StringDecoder())
« 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