| 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'; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 lineEnding = "\r\n"; | 95 lineEnding = "\r\n"; |
| 96 } else { | 96 } else { |
| 97 lineEnding = "\n"; | 97 lineEnding = "\n"; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 errorListener.throwIfErrors(); | 101 errorListener.throwIfErrors(); |
| 102 | 102 |
| 103 // Parse it. | 103 // Parse it. |
| 104 var parser = new Parser(stringSource, errorListener); | 104 var parser = new Parser(stringSource, errorListener); |
| 105 parser.parseGenericMethods = true; |
| 105 | 106 |
| 106 AstNode node; | 107 AstNode node; |
| 107 if (source.isCompilationUnit) { | 108 if (source.isCompilationUnit) { |
| 108 node = parser.parseCompilationUnit(startToken); | 109 node = parser.parseCompilationUnit(startToken); |
| 109 } else { | 110 } else { |
| 110 node = parser.parseStatement(startToken); | 111 node = parser.parseStatement(startToken); |
| 111 | 112 |
| 112 // Make sure we consumed all of the source. | 113 // Make sure we consumed all of the source. |
| 113 var token = node.endToken.next; | 114 var token = node.endToken.next; |
| 114 if (token.type != TokenType.EOF) { | 115 if (token.type != TokenType.EOF) { |
| 115 var error = new AnalysisError( | 116 var error = new AnalysisError( |
| 116 stringSource, | 117 stringSource, |
| 117 token.offset, | 118 token.offset, |
| 118 math.max(token.length, 1), | 119 math.max(token.length, 1), |
| 119 ParserErrorCode.UNEXPECTED_TOKEN, | 120 ParserErrorCode.UNEXPECTED_TOKEN, |
| 120 [token.lexeme]); | 121 [token.lexeme]); |
| 121 | 122 |
| 122 throw new FormatterException([error]); | 123 throw new FormatterException([error]); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 errorListener.throwIfErrors(); | 127 errorListener.throwIfErrors(); |
| 127 | 128 |
| 128 // Format it. | 129 // Format it. |
| 129 var visitor = new SourceVisitor(this, lineInfo, source); | 130 var visitor = new SourceVisitor(this, lineInfo, source); |
| 130 return visitor.run(node); | 131 return visitor.run(node); |
| 131 } | 132 } |
| 132 } | 133 } |
| OLD | NEW |