| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 analyzer; | 5 library analyzer; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as pathos; | 9 import 'package:path/path.dart' as pathos; |
| 10 | 10 |
| 11 import 'src/error.dart'; | 11 import 'src/error.dart'; |
| 12 import 'src/generated/ast.dart'; | 12 import 'src/generated/ast.dart'; |
| 13 import 'src/generated/error.dart'; | 13 import 'src/generated/error.dart'; |
| 14 import 'src/generated/java_io.dart'; | |
| 15 import 'src/generated/parser.dart'; | 14 import 'src/generated/parser.dart'; |
| 16 import 'src/generated/scanner.dart'; | 15 import 'src/generated/scanner.dart'; |
| 17 import 'src/generated/source_io.dart'; | 16 import 'src/generated/source_io.dart'; |
| 18 | 17 |
| 19 export 'src/error.dart'; | 18 export 'src/error.dart'; |
| 20 export 'src/generated/ast.dart'; | 19 export 'src/generated/ast.dart'; |
| 21 export 'src/generated/error.dart'; | 20 export 'src/generated/error.dart'; |
| 22 export 'src/generated/utilities_dart.dart'; | 21 export 'src/generated/utilities_dart.dart'; |
| 23 | 22 |
| 24 /// Parses a Dart file into an AST. | 23 /// Parses a Dart file into an AST. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 var unit = parser.parseCompilationUnit(token); | 41 var unit = parser.parseCompilationUnit(token); |
| 43 unit.lineInfo = new LineInfo(scanner.lineStarts); | 42 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 44 | 43 |
| 45 if (errorCollector.hasErrors) throw errorCollector.group; | 44 if (errorCollector.hasErrors) throw errorCollector.group; |
| 46 | 45 |
| 47 return unit; | 46 return unit; |
| 48 } | 47 } |
| 49 | 48 |
| 50 /// Converts an AST node representing a string literal into a [String]. | 49 /// Converts an AST node representing a string literal into a [String]. |
| 51 String stringLiteralToString(StringLiteral literal) { | 50 String stringLiteralToString(StringLiteral literal) { |
| 52 if (literal is AdjacentStrings) { | 51 return literal.stringValue; |
| 53 return literal.strings.map(stringLiteralToString).join(); | |
| 54 } else if (literal is SimpleStringLiteral) { | |
| 55 return literal.value; | |
| 56 } else { | |
| 57 throw new ArgumentError("Can't convert $literal to a Dart string."); | |
| 58 } | |
| 59 } | 52 } |
| 60 | 53 |
| 61 /// A simple error listener that collects errors into an [AnalysisErrorGroup]. | 54 /// A simple error listener that collects errors into an [AnalysisErrorGroup]. |
| 62 class _ErrorCollector extends AnalysisErrorListener { | 55 class _ErrorCollector extends AnalysisErrorListener { |
| 63 final _errors = <AnalysisError>[]; | 56 final _errors = <AnalysisError>[]; |
| 64 | 57 |
| 65 /// Whether any errors where collected. | 58 /// Whether any errors where collected. |
| 66 bool get hasErrors => !_errors.isEmpty; | 59 bool get hasErrors => !_errors.isEmpty; |
| 67 | 60 |
| 68 /// The group of errors collected. | 61 /// The group of errors collected. |
| 69 AnalyzerErrorGroup get group => | 62 AnalyzerErrorGroup get group => |
| 70 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); | 63 new AnalyzerErrorGroup.fromAnalysisErrors(_errors); |
| 71 | 64 |
| 72 _ErrorCollector(); | 65 _ErrorCollector(); |
| 73 | 66 |
| 74 void onError(AnalysisError error) => _errors.add(error); | 67 void onError(AnalysisError error) => _errors.add(error); |
| 75 } | 68 } |
| OLD | NEW |