Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: pkg/analyzer_experimental/test/generated/test_support.dart

Issue 14308011: New Analysis Engine snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer_experimental/test/generated/scanner_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.test_support; 4 library engine.test_support;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:uri'; 7 import 'dart:uri';
8 import 'package:analyzer_experimental/src/generated/java_core.dart'; 8 import 'package:analyzer_experimental/src/generated/java_core.dart';
9 import 'package:analyzer_experimental/src/generated/java_engine.dart'; 9 import 'package:analyzer_experimental/src/generated/java_engine.dart';
10 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 10 import 'package:analyzer_experimental/src/generated/java_junit.dart';
11 import 'package:analyzer_experimental/src/generated/source.dart'; 11 import 'package:analyzer_experimental/src/generated/source.dart';
12 import 'package:analyzer_experimental/src/generated/error.dart'; 12 import 'package:analyzer_experimental/src/generated/error.dart';
13 import 'package:analyzer_experimental/src/generated/scanner.dart'; 13 import 'package:analyzer_experimental/src/generated/scanner.dart';
14 import 'package:analyzer_experimental/src/generated/element.dart' show Interface Type, MethodElement, PropertyAccessorElement; 14 import 'package:analyzer_experimental/src/generated/element.dart' show Interface Type, MethodElement, PropertyAccessorElement;
15 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo ntext; 15 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo ntext, AnalysisContextImpl;
16 import 'package:unittest/unittest.dart' as _ut; 16 import 'package:unittest/unittest.dart' as _ut;
17 17
18 /** 18 /**
19 * Instances of the class {@code GatheringErrorListener} implement an error list ener that collects 19 * Instances of the class {@code GatheringErrorListener} implement an error list ener that collects
20 * all of the errors passed to it for later examination. 20 * all of the errors passed to it for later examination.
21 */ 21 */
22 class GatheringErrorListener implements AnalysisErrorListener { 22 class GatheringErrorListener implements AnalysisErrorListener {
23 /** 23 /**
24 * The source being parsed. 24 * The source being parsed.
25 */ 25 */
(...skipping 12 matching lines...) Expand all
38 */ 38 */
39 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); 39 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>();
40 /** 40 /**
41 * An empty array of errors used when no errors are expected. 41 * An empty array of errors used when no errors are expected.
42 */ 42 */
43 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); 43 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0);
44 /** 44 /**
45 * Initialize a newly created error listener to collect errors. 45 * Initialize a newly created error listener to collect errors.
46 */ 46 */
47 GatheringErrorListener() : super() { 47 GatheringErrorListener() : super() {
48 _jtd_constructor_321_impl(); 48 _jtd_constructor_347_impl();
49 } 49 }
50 _jtd_constructor_321_impl() { 50 _jtd_constructor_347_impl() {
51 } 51 }
52 /** 52 /**
53 * Initialize a newly created error listener to collect errors. 53 * Initialize a newly created error listener to collect errors.
54 */ 54 */
55 GatheringErrorListener.con1(String rawSource2) { 55 GatheringErrorListener.con1(String rawSource2) {
56 _jtd_constructor_322_impl(rawSource2); 56 _jtd_constructor_348_impl(rawSource2);
57 } 57 }
58 _jtd_constructor_322_impl(String rawSource2) { 58 _jtd_constructor_348_impl(String rawSource2) {
59 this._rawSource = rawSource2; 59 this._rawSource = rawSource2;
60 this._markedSource = rawSource2; 60 this._markedSource = rawSource2;
61 } 61 }
62 /** 62 /**
63 * Assert that the number of errors that have been gathered matches the number of errors that are 63 * Assert that the number of errors that have been gathered matches the number of errors that are
64 * given and that they have the expected error codes and locations. The order in which the errors 64 * given and that they have the expected error codes and locations. The order in which the errors
65 * were gathered is ignored. 65 * were gathered is ignored.
66 * @param errorCodes the errors that should have been gathered 66 * @param errorCodes the errors that should have been gathered
67 * @throws AssertionFailedError if a different number of errors have been gath ered than were 67 * @throws AssertionFailedError if a different number of errors have been gath ered than were
68 * expected or if they do not have the same codes and locations 68 * expected or if they do not have the same codes and locations
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 */ 198 */
199 void assertNoErrors() { 199 void assertNoErrors() {
200 assertErrors(_NO_ERRORS); 200 assertErrors(_NO_ERRORS);
201 } 201 }
202 /** 202 /**
203 * Return the errors that were collected. 203 * Return the errors that were collected.
204 * @return the errors that were collected 204 * @return the errors that were collected
205 */ 205 */
206 List<AnalysisError> get errors => _errors; 206 List<AnalysisError> get errors => _errors;
207 /** 207 /**
208 * Return the line information associated with the given source, or {@code nul l} if no line
209 * information has been associated with the source.
210 * @param source the source with which the line information is associated
211 * @return the line information associated with the source
212 */
213 LineInfo getLineInfo(Source source) => _lineInfoMap[source];
214 /**
208 * Return {@code true} if an error with the given error code has been gathered . 215 * Return {@code true} if an error with the given error code has been gathered .
209 * @param errorCode the error code being searched for 216 * @param errorCode the error code being searched for
210 * @return {@code true} if an error with the given error code has been gathere d 217 * @return {@code true} if an error with the given error code has been gathere d
211 */ 218 */
212 bool hasError(ErrorCode errorCode5) { 219 bool hasError(ErrorCode errorCode5) {
213 for (AnalysisError error in _errors) { 220 for (AnalysisError error in _errors) {
214 if (identical(error.errorCode, errorCode5)) { 221 if (identical(error.errorCode, errorCode5)) {
215 return true; 222 return true;
216 } 223 }
217 } 224 }
218 return false; 225 return false;
219 } 226 }
227 /**
228 * Return {@code true} if at least one error has been gathered.
229 * @return {@code true} if at least one error has been gathered
230 */
231 bool hasErrors() => _errors.length > 0;
220 void onError(AnalysisError error) { 232 void onError(AnalysisError error) {
221 if (_rawSource != null) { 233 if (_rawSource != null) {
222 int left = error.offset; 234 int left = error.offset;
223 int right = left + error.length - 1; 235 int right = left + error.length - 1;
224 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l eft, right)}^${_rawSource.substring(right)}"; 236 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l eft, right)}^${_rawSource.substring(right)}";
225 } 237 }
226 _errors.add(error); 238 _errors.add(error);
227 } 239 }
228 /** 240 /**
229 * Set the line information associated with the given source to the given info rmation. 241 * Set the line information associated with the given source to the given info rmation.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 * is ignored. 280 * is ignored.
269 * @param errorCodes the errors that should have been gathered 281 * @param errorCodes the errors that should have been gathered
270 * @throws AssertionFailedError with 282 * @throws AssertionFailedError with
271 */ 283 */
272 void fail(List<AnalysisError> expectedErrors) { 284 void fail(List<AnalysisError> expectedErrors) {
273 PrintStringWriter writer = new PrintStringWriter(); 285 PrintStringWriter writer = new PrintStringWriter();
274 writer.print("Expected "); 286 writer.print("Expected ");
275 writer.print(expectedErrors.length); 287 writer.print(expectedErrors.length);
276 writer.print(" errors:"); 288 writer.print(" errors:");
277 for (AnalysisError error in expectedErrors) { 289 for (AnalysisError error in expectedErrors) {
278 Source source11 = error.source; 290 Source source16 = error.source;
279 LineInfo lineInfo = _lineInfoMap[source11]; 291 LineInfo lineInfo = _lineInfoMap[source16];
280 writer.println(); 292 writer.println();
281 if (lineInfo == null) { 293 if (lineInfo == null) {
282 int offset10 = error.offset; 294 int offset10 = error.offset;
283 writer.printf(" %s %s (%d..%d)", [source11 == null ? "" : source11.shor tName, error.errorCode, offset10, offset10 + error.length]); 295 writer.printf(" %s %s (%d..%d)", [source16 == null ? "" : source16.shor tName, error.errorCode, offset10, offset10 + error.length]);
284 } else { 296 } else {
285 LineInfo_Location location = lineInfo.getLocation(error.offset); 297 LineInfo_Location location = lineInfo.getLocation(error.offset);
286 writer.printf(" %s %s (%d, %d/%d)", [source11 == null ? "" : source11.s hortName, error.errorCode, location.lineNumber, location.columnNumber, error.len gth]); 298 writer.printf(" %s %s (%d, %d/%d)", [source16 == null ? "" : source16.s hortName, error.errorCode, location.lineNumber, location.columnNumber, error.len gth]);
287 } 299 }
288 } 300 }
289 writer.println(); 301 writer.println();
290 writer.print("found "); 302 writer.print("found ");
291 writer.print(_errors.length); 303 writer.print(_errors.length);
292 writer.print(" errors:"); 304 writer.print(" errors:");
293 for (AnalysisError error in _errors) { 305 for (AnalysisError error in _errors) {
294 Source source12 = error.source; 306 Source source17 = error.source;
295 LineInfo lineInfo = _lineInfoMap[source12]; 307 LineInfo lineInfo = _lineInfoMap[source17];
296 writer.println(); 308 writer.println();
297 if (lineInfo == null) { 309 if (lineInfo == null) {
298 int offset11 = error.offset; 310 int offset11 = error.offset;
299 writer.printf(" %s %s (%d..%d): %s", [source12 == null ? "" : source12. shortName, error.errorCode, offset11, offset11 + error.length, error.message]); 311 writer.printf(" %s %s (%d..%d): %s", [source17 == null ? "" : source17. shortName, error.errorCode, offset11, offset11 + error.length, error.message]);
300 } else { 312 } else {
301 LineInfo_Location location = lineInfo.getLocation(error.offset); 313 LineInfo_Location location = lineInfo.getLocation(error.offset);
302 writer.printf(" %s %s (%d, %d/%d): %s", [source12 == null ? "" : source 12.shortName, error.errorCode, location.lineNumber, location.columnNumber, error .length, error.message]); 314 writer.printf(" %s %s (%d, %d/%d): %s", [source17 == null ? "" : source 17.shortName, error.errorCode, location.lineNumber, location.columnNumber, error .length, error.message]);
303 } 315 }
304 } 316 }
305 JUnitTestCase.fail(writer.toString()); 317 JUnitTestCase.fail(writer.toString());
306 } 318 }
307 /** 319 /**
308 * Search through the given list of errors for an error that is equal to the t arget error. If one 320 * Search through the given list of errors for an error that is equal to the t arget error. If one
309 * is found, remove it from the list and return {@code true}, otherwise return {@code false}without modifying the list. 321 * is found, remove it from the list and return {@code true}, otherwise return {@code false}without modifying the list.
310 * @param errors the errors through which we are searching 322 * @param errors the errors through which we are searching
311 * @param targetError the error being searched for 323 * @param targetError the error being searched for
312 * @return {@code true} if the error is found and removed from the list 324 * @return {@code true} if the error is found and removed from the list
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 * elements 541 * elements
530 */ 542 */
531 static void assertSize2(int expectedSize, Map<Object, Object> map) { 543 static void assertSize2(int expectedSize, Map<Object, Object> map) {
532 if (map == null) { 544 if (map == null) {
533 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null"); 545 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null");
534 } else if (map.length != expectedSize) { 546 } else if (map.length != expectedSize) {
535 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map. length} elements"); 547 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map. length} elements");
536 } 548 }
537 } 549 }
538 /** 550 /**
551 * Assert that the given set is non-{@code null} and has the expected number o f elements.
552 * @param expectedSize the expected number of elements
553 * @param set the set being tested
554 * @throws AssertionFailedError if the set is {@code null} or does not have th e expected number of
555 * elements
556 */
557 static void assertSize3(int expectedSize, Set<Object> set) {
558 if (set == null) {
559 JUnitTestCase.fail("Expected set of size ${expectedSize}; found null");
560 } else if (set.length != expectedSize) {
561 JUnitTestCase.fail("Expected set of size ${expectedSize}; contained ${set. length} elements");
562 }
563 }
564 /**
539 * Convert the given array of lines into a single source string. 565 * Convert the given array of lines into a single source string.
540 * @param lines the lines to be merged into a single source string 566 * @param lines the lines to be merged into a single source string
541 * @return the source string composed of the given lines 567 * @return the source string composed of the given lines
542 */ 568 */
543 static String createSource(List<String> lines) { 569 static String createSource(List<String> lines) {
544 PrintStringWriter writer = new PrintStringWriter(); 570 PrintStringWriter writer = new PrintStringWriter();
545 for (String line in lines) { 571 for (String line in lines) {
546 writer.printlnObject(line); 572 writer.printlnObject(line);
547 } 573 }
548 return writer.toString(); 574 return writer.toString();
(...skipping 11 matching lines...) Expand all
560 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { 586 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) {
561 diffPos = i; 587 diffPos = i;
562 break; 588 break;
563 } 589 }
564 } 590 }
565 if (diffPos == -1 && str1.length != str2.length) { 591 if (diffPos == -1 && str1.length != str2.length) {
566 diffPos = len1; 592 diffPos = len1;
567 } 593 }
568 return diffPos; 594 return diffPos;
569 } 595 }
596 AnalysisContextImpl createAnalysisContext() {
597 AnalysisContextImpl context = new AnalysisContextImpl();
598 context.sourceFactory = new SourceFactory.con2([]);
599 return context;
600 }
570 /** 601 /**
571 * Return the getter in the given type with the given name. Inherited getters are ignored. 602 * Return the getter in the given type with the given name. Inherited getters are ignored.
572 * @param type the type in which the getter is declared 603 * @param type the type in which the getter is declared
573 * @param getterName the name of the getter to be returned 604 * @param getterName the name of the getter to be returned
574 * @return the property accessor element representing the getter with the give n name 605 * @return the property accessor element representing the getter with the give n name
575 */ 606 */
576 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { 607 PropertyAccessorElement getGetter(InterfaceType type, String getterName) {
577 for (PropertyAccessorElement accessor in type.element.accessors) { 608 for (PropertyAccessorElement accessor in type.element.accessors) {
578 if (accessor.isGetter() && accessor.name == getterName) { 609 if (accessor.isGetter() && accessor.name == getterName) {
579 return accessor; 610 return accessor;
(...skipping 19 matching lines...) Expand all
599 } 630 }
600 static dartSuite() { 631 static dartSuite() {
601 _ut.group('EngineTestCase', () { 632 _ut.group('EngineTestCase', () {
602 }); 633 });
603 } 634 }
604 } 635 }
605 main() { 636 main() {
606 } 637 }
607 638
608 class TestSource implements Source { 639 class TestSource implements Source {
640 int get hashCode => 0;
609 bool operator ==(Object object) { 641 bool operator ==(Object object) {
610 return this == object; 642 return object is TestSource;
611 } 643 }
612 AnalysisContext get context { 644 AnalysisContext get context {
613 throw new UnsupportedOperationException(); 645 throw new UnsupportedOperationException();
614 } 646 }
615 void getContents(Source_ContentReceiver receiver) { 647 void getContents(Source_ContentReceiver receiver) {
616 throw new UnsupportedOperationException(); 648 throw new UnsupportedOperationException();
617 } 649 }
618 String get fullName { 650 String get fullName {
619 throw new UnsupportedOperationException(); 651 throw new UnsupportedOperationException();
620 } 652 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 return trampoline(target, arguments[0], arguments[1]); 691 return trampoline(target, arguments[0], arguments[1]);
660 case 3: 692 case 3:
661 return trampoline(target, arguments[0], arguments[1], arguments[2]); 693 return trampoline(target, arguments[0], arguments[1], arguments[2]);
662 case 4: 694 case 4:
663 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 695 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
664 default: 696 default:
665 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 697 throw new IllegalArgumentException("Not implemented for > 4 arguments");
666 } 698 }
667 } 699 }
668 } 700 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/test/generated/scanner_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698