| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.src.dart_formatter; | 5 library dart_style.src.dart_formatter; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/src/dart/scanner/reader.dart'; | 11 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 12 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 12 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; | 13 import 'package:analyzer/src/generated/parser.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/string_source.dart'; | 15 import 'package:analyzer/src/string_source.dart'; |
| 16 | 16 |
| 17 import 'error_listener.dart'; | 17 import 'error_listener.dart'; |
| 18 import 'formatter_exception.dart'; | 18 import 'exceptions.dart'; |
| 19 import 'source_code.dart'; | 19 import 'source_code.dart'; |
| 20 import 'source_visitor.dart'; | 20 import 'source_visitor.dart'; |
| 21 import 'string_compare.dart' as string_compare; | 21 import 'string_compare.dart' as string_compare; |
| 22 | 22 |
| 23 /// Dart source code formatter. | 23 /// Dart source code formatter. |
| 24 class DartFormatter { | 24 class DartFormatter { |
| 25 /// The string that newlines should use. | 25 /// The string that newlines should use. |
| 26 /// | 26 /// |
| 27 /// If not explicitly provided, this is inferred from the source text. If the | 27 /// If not explicitly provided, this is inferred from the source text. If the |
| 28 /// first newline is `\r\n` (Windows), it will use that. Otherwise, it uses | 28 /// first newline is `\r\n` (Windows), it will use that. Otherwise, it uses |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 throw new FormatterException([error]); | 124 throw new FormatterException([error]); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 errorListener.throwIfErrors(); | 128 errorListener.throwIfErrors(); |
| 129 | 129 |
| 130 // Format it. | 130 // Format it. |
| 131 var visitor = new SourceVisitor(this, lineInfo, source); | 131 var visitor = new SourceVisitor(this, lineInfo, source); |
| 132 var output = visitor.run(node); | 132 var output = visitor.run(node); |
| 133 if (!string_compare.equalIgnoringWhitespace(source.text, output.text)) { | 133 if (!string_compare.equalIgnoringWhitespace(source.text, output.text)) { |
| 134 throw new FormatException('Cannot safely format file as formatting ' | 134 throw new UnexpectedOutputException(source.text, output.text); |
| 135 'would cause non-whitespace change(s).'); | |
| 136 } | 135 } |
| 137 | 136 |
| 138 return output; | 137 return output; |
| 139 } | 138 } |
| 140 } | 139 } |
| OLD | NEW |