| 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 test_utils; | 5 library test_utils; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/scanner.dart'; | 12 import 'package:analyzer/src/generated/scanner.dart'; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/parser.dart'; | 14 import 'package:analyzer/src/generated/parser.dart'; |
| 15 | 15 |
| 16 | 16 |
| 17 /// Instances of the class [_GatheringErrorListener] implement an error listener | 17 /// Instances of the class [_GatheringErrorListener] implement an error listener |
| 18 /// that collects all of the errors passed to it for later examination. | 18 /// that collects all of the errors passed to it for later examination. |
| 19 class _GatheringErrorListener implements AnalysisErrorListener { | 19 class _GatheringErrorListener implements AnalysisErrorListener { |
| 20 | |
| 21 /// The source being parsed. | |
| 22 String _rawSource; | |
| 23 | |
| 24 /// The source being parsed after inserting a marker at the beginning and end | |
| 25 /// of the range of the most recent error. | |
| 26 String _markedSource; | |
| 27 | |
| 28 /// A list containing the errors that were collected. | 20 /// A list containing the errors that were collected. |
| 29 final List<AnalysisError> _errors = new List<AnalysisError>(); | 21 final List<AnalysisError> _errors = new List<AnalysisError>(); |
| 30 | 22 |
| 31 /// A table mapping sources to the line information for the source. | 23 /// A table mapping sources to the line information for the source. |
| 32 final Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); | 24 final Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); |
| 33 | 25 |
| 34 void onError(AnalysisError error) { | 26 void onError(AnalysisError error) { |
| 35 if (_rawSource != null) { | |
| 36 var left = error.offset; | |
| 37 var right = left + error.length - 1; | |
| 38 _markedSource = '${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}'; | |
| 39 } | |
| 40 _errors.add(error); | 27 _errors.add(error); |
| 41 } | 28 } |
| 42 | 29 |
| 43 | 30 |
| 44 /// Sets the line information associated with the given source to the given | 31 /// Sets the line information associated with the given source to the given |
| 45 /// information. | 32 /// information. |
| 46 void setLineInfo(Source source, List<int> lineStarts) { | 33 void setLineInfo(Source source, List<int> lineStarts) { |
| 47 _lineInfoMap[source] = new LineInfo(lineStarts); | 34 _lineInfoMap[source] = new LineInfo(lineStarts); |
| 48 } | 35 } |
| 49 | 36 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 var parser = new Parser(null, listener); | 195 var parser = new Parser(null, listener); |
| 209 var statement = parser.parseStatement(token); | 196 var statement = parser.parseStatement(token); |
| 210 expect(statement, isNotNull); | 197 expect(statement, isNotNull); |
| 211 | 198 |
| 212 if (expectedErrorCodes != null) { | 199 if (expectedErrorCodes != null) { |
| 213 listener.expectErrors(expectedErrorCodes); | 200 listener.expectErrors(expectedErrorCodes); |
| 214 } | 201 } |
| 215 | 202 |
| 216 return statement; | 203 return statement; |
| 217 } | 204 } |
| OLD | NEW |