OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart_style.example.format; | 5 library dart_style.example.format; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 26 matching lines...) Expand all Loading... |
37 try { | 37 try { |
38 var formatter = new DartFormatter(pageWidth: pageWidth); | 38 var formatter = new DartFormatter(pageWidth: pageWidth); |
39 | 39 |
40 var result; | 40 var result; |
41 if (isCompilationUnit) { | 41 if (isCompilationUnit) { |
42 result = formatter.format(source); | 42 result = formatter.format(source); |
43 } else { | 43 } else { |
44 result = formatter.formatStatement(source); | 44 result = formatter.formatStatement(source); |
45 } | 45 } |
46 | 46 |
47 if (debug.useAnsiColors) { | |
48 result = result.replaceAll(" ", debug.gray(debug.unicodeMidDot)); | |
49 } | |
50 | |
51 drawRuler("before", pageWidth); | 47 drawRuler("before", pageWidth); |
52 print(source); | 48 print(source); |
53 drawRuler("after", pageWidth); | 49 drawRuler("after", pageWidth); |
54 print(result); | 50 print(result); |
55 } on FormatterException catch (error) { | 51 } on FormatterException catch (error) { |
56 print(error.message()); | 52 print(error.message()); |
57 } | 53 } |
58 } | 54 } |
59 | 55 |
60 void drawRuler(String label, int width) { | 56 void drawRuler(String label, int width) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 source = source.replaceAll("‹", ""); | 156 source = source.replaceAll("‹", ""); |
161 | 157 |
162 var end = source.indexOf("›"); | 158 var end = source.indexOf("›"); |
163 source = source.replaceAll("›", ""); | 159 source = source.replaceAll("›", ""); |
164 | 160 |
165 return new SourceCode(source, | 161 return new SourceCode(source, |
166 isCompilationUnit: isCompilationUnit, | 162 isCompilationUnit: isCompilationUnit, |
167 selectionStart: start == -1 ? null : start, | 163 selectionStart: start == -1 ? null : start, |
168 selectionLength: end == -1 ? null : end - start); | 164 selectionLength: end == -1 ? null : end - start); |
169 } | 165 } |
OLD | NEW |