| OLD | NEW |
| 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 'package:analyzer/src/generated/java_core.dart'; | 6 import 'package:analyzer/src/generated/java_core.dart'; |
| 7 import 'package:analyzer/src/generated/java_junit.dart'; | 7 import 'package:analyzer/src/generated/java_junit.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/generated/error.dart'; | 9 import 'package:analyzer/src/generated/error.dart'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * The source being parsed after inserting a marker at the beginning and end o
f the range of the | 27 * The source being parsed after inserting a marker at the beginning and end o
f the range of the |
| 28 * most recent error. | 28 * most recent error. |
| 29 */ | 29 */ |
| 30 String _markedSource; | 30 String _markedSource; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * A list containing the errors that were collected. | 33 * A list containing the errors that were collected. |
| 34 */ | 34 */ |
| 35 final List<AnalysisError> errors = new List<AnalysisError>(); | 35 List<AnalysisError> _errors = new List<AnalysisError>(); |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * A table mapping sources to the line information for the source. | 38 * A table mapping sources to the line information for the source. |
| 39 */ | 39 */ |
| 40 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); | 40 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * An empty array of errors used when no errors are expected. | 43 * An empty array of errors used when no errors are expected. |
| 44 */ | 44 */ |
| 45 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); | 45 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 /** | 71 /** |
| 72 * Assert that the number of errors that have been gathered matches the number
of errors that are | 72 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 73 * given and that they have the expected error codes and locations. The order
in which the errors | 73 * given and that they have the expected error codes and locations. The order
in which the errors |
| 74 * were gathered is ignored. | 74 * were gathered is ignored. |
| 75 * | 75 * |
| 76 * @param errorCodes the errors that should have been gathered | 76 * @param errorCodes the errors that should have been gathered |
| 77 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 77 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 78 * expected or if they do not have the same codes and locations | 78 * expected or if they do not have the same codes and locations |
| 79 */ | 79 */ |
| 80 void assertErrors(List<AnalysisError> expectedErrors) { | 80 void assertErrors(List<AnalysisError> expectedErrors) { |
| 81 if (errors.length != expectedErrors.length) { | 81 if (_errors.length != expectedErrors.length) { |
| 82 fail(expectedErrors); | 82 fail(expectedErrors); |
| 83 } | 83 } |
| 84 List<AnalysisError> remainingErrors = new List<AnalysisError>(); | 84 List<AnalysisError> remainingErrors = new List<AnalysisError>(); |
| 85 for (AnalysisError error in expectedErrors) { | 85 for (AnalysisError error in expectedErrors) { |
| 86 remainingErrors.add(error); | 86 remainingErrors.add(error); |
| 87 } | 87 } |
| 88 for (AnalysisError error in errors) { | 88 for (AnalysisError error in _errors) { |
| 89 if (!foundAndRemoved(remainingErrors, error)) { | 89 if (!foundAndRemoved(remainingErrors, error)) { |
| 90 fail(expectedErrors); | 90 fail(expectedErrors); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Assert that the number of errors that have been gathered matches the number
of errors that are | 96 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 97 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 97 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 98 * is ignored. | 98 * is ignored. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 for (ErrorCode code in expectedErrorCodes) { | 110 for (ErrorCode code in expectedErrorCodes) { |
| 111 int count = expectedCounts[code]; | 111 int count = expectedCounts[code]; |
| 112 if (count == null) { | 112 if (count == null) { |
| 113 count = 1; | 113 count = 1; |
| 114 } else { | 114 } else { |
| 115 count = count + 1; | 115 count = count + 1; |
| 116 } | 116 } |
| 117 expectedCounts[code] = count; | 117 expectedCounts[code] = count; |
| 118 } | 118 } |
| 119 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A
nalysisError>>(); | 119 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A
nalysisError>>(); |
| 120 for (AnalysisError error in errors) { | 120 for (AnalysisError error in _errors) { |
| 121 ErrorCode code = error.errorCode; | 121 ErrorCode code = error.errorCode; |
| 122 List<AnalysisError> list = errorsByCode[code]; | 122 List<AnalysisError> list = errorsByCode[code]; |
| 123 if (list == null) { | 123 if (list == null) { |
| 124 list = new List<AnalysisError>(); | 124 list = new List<AnalysisError>(); |
| 125 errorsByCode[code] = list; | 125 errorsByCode[code] = list; |
| 126 } | 126 } |
| 127 list.add(error); | 127 list.add(error); |
| 128 } | 128 } |
| 129 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) { | 129 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) { |
| 130 ErrorCode code = entry.getKey(); | 130 ErrorCode code = entry.getKey(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 int expectedWarningCount = 0; | 191 int expectedWarningCount = 0; |
| 192 for (ErrorSeverity severity in expectedSeverities) { | 192 for (ErrorSeverity severity in expectedSeverities) { |
| 193 if (identical(severity, ErrorSeverity.ERROR)) { | 193 if (identical(severity, ErrorSeverity.ERROR)) { |
| 194 expectedErrorCount++; | 194 expectedErrorCount++; |
| 195 } else { | 195 } else { |
| 196 expectedWarningCount++; | 196 expectedWarningCount++; |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 int actualErrorCount = 0; | 199 int actualErrorCount = 0; |
| 200 int actualWarningCount = 0; | 200 int actualWarningCount = 0; |
| 201 for (AnalysisError error in errors) { | 201 for (AnalysisError error in _errors) { |
| 202 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { | 202 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { |
| 203 actualErrorCount++; | 203 actualErrorCount++; |
| 204 } else { | 204 } else { |
| 205 actualWarningCount++; | 205 actualWarningCount++; |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { | 208 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { |
| 209 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); | 209 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 /** | 213 /** |
| 214 * Assert that no errors have been gathered. | 214 * Assert that no errors have been gathered. |
| 215 * | 215 * |
| 216 * @throws AssertionFailedError if any errors have been gathered | 216 * @throws AssertionFailedError if any errors have been gathered |
| 217 */ | 217 */ |
| 218 void assertNoErrors() { | 218 void assertNoErrors() { |
| 219 assertErrors(_NO_ERRORS); | 219 assertErrors(_NO_ERRORS); |
| 220 } | 220 } |
| 221 | 221 |
| 222 /** | 222 /** |
| 223 * Return the errors that were collected. |
| 224 * |
| 225 * @return the errors that were collected |
| 226 */ |
| 227 List<AnalysisError> get errors => _errors; |
| 228 |
| 229 /** |
| 223 * Return the line information associated with the given source, or `null` if
no line | 230 * Return the line information associated with the given source, or `null` if
no line |
| 224 * information has been associated with the source. | 231 * information has been associated with the source. |
| 225 * | 232 * |
| 226 * @param source the source with which the line information is associated | 233 * @param source the source with which the line information is associated |
| 227 * @return the line information associated with the source | 234 * @return the line information associated with the source |
| 228 */ | 235 */ |
| 229 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; | 236 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; |
| 230 | 237 |
| 231 /** | 238 /** |
| 232 * Return `true` if an error with the given error code has been gathered. | 239 * Return `true` if an error with the given error code has been gathered. |
| 233 * | 240 * |
| 234 * @param errorCode the error code being searched for | 241 * @param errorCode the error code being searched for |
| 235 * @return `true` if an error with the given error code has been gathered | 242 * @return `true` if an error with the given error code has been gathered |
| 236 */ | 243 */ |
| 237 bool hasError(ErrorCode errorCode) { | 244 bool hasError(ErrorCode errorCode) { |
| 238 for (AnalysisError error in errors) { | 245 for (AnalysisError error in _errors) { |
| 239 if (identical(error.errorCode, errorCode)) { | 246 if (identical(error.errorCode, errorCode)) { |
| 240 return true; | 247 return true; |
| 241 } | 248 } |
| 242 } | 249 } |
| 243 return false; | 250 return false; |
| 244 } | 251 } |
| 245 | 252 |
| 246 /** | 253 /** |
| 247 * Return `true` if at least one error has been gathered. | 254 * Return `true` if at least one error has been gathered. |
| 248 * | 255 * |
| 249 * @return `true` if at least one error has been gathered | 256 * @return `true` if at least one error has been gathered |
| 250 */ | 257 */ |
| 251 bool hasErrors() => errors.length > 0; | 258 bool hasErrors() => _errors.length > 0; |
| 252 | 259 |
| 253 void onError(AnalysisError error) { | 260 void onError(AnalysisError error) { |
| 254 if (_rawSource != null) { | 261 if (_rawSource != null) { |
| 255 int left = error.offset; | 262 int left = error.offset; |
| 256 int right = left + error.length - 1; | 263 int right = left + error.length - 1; |
| 257 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; | 264 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; |
| 258 } | 265 } |
| 259 errors.add(error); | 266 _errors.add(error); |
| 260 } | 267 } |
| 261 | 268 |
| 262 /** | 269 /** |
| 263 * Set the line information associated with the given source to the given info
rmation. | 270 * Set the line information associated with the given source to the given info
rmation. |
| 264 * | 271 * |
| 265 * @param source the source with which the line information is associated | 272 * @param source the source with which the line information is associated |
| 266 * @param lineStarts the line start information to be associated with the sour
ce | 273 * @param lineStarts the line start information to be associated with the sour
ce |
| 267 */ | 274 */ |
| 268 void setLineInfo(Source source, List<int> lineStarts) { | 275 void setLineInfo(Source source, List<int> lineStarts) { |
| 269 _lineInfoMap[source] = new LineInfo(lineStarts); | 276 _lineInfoMap[source] = new LineInfo(lineStarts); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 writer.printf(" %s %s (%d, %d/%d)", [ | 340 writer.printf(" %s %s (%d, %d/%d)", [ |
| 334 source == null ? "" : source.shortName, | 341 source == null ? "" : source.shortName, |
| 335 error.errorCode, | 342 error.errorCode, |
| 336 location.lineNumber, | 343 location.lineNumber, |
| 337 location.columnNumber, | 344 location.columnNumber, |
| 338 error.length]); | 345 error.length]); |
| 339 } | 346 } |
| 340 } | 347 } |
| 341 writer.newLine(); | 348 writer.newLine(); |
| 342 writer.print("found "); | 349 writer.print("found "); |
| 343 writer.print(errors.length); | 350 writer.print(_errors.length); |
| 344 writer.print(" errors:"); | 351 writer.print(" errors:"); |
| 345 for (AnalysisError error in errors) { | 352 for (AnalysisError error in _errors) { |
| 346 Source source = error.source; | 353 Source source = error.source; |
| 347 LineInfo lineInfo = _lineInfoMap[source]; | 354 LineInfo lineInfo = _lineInfoMap[source]; |
| 348 writer.newLine(); | 355 writer.newLine(); |
| 349 if (lineInfo == null) { | 356 if (lineInfo == null) { |
| 350 int offset = error.offset; | 357 int offset = error.offset; |
| 351 writer.printf(" %s %s (%d..%d): %s", [ | 358 writer.printf(" %s %s (%d..%d): %s", [ |
| 352 source == null ? "" : source.shortName, | 359 source == null ? "" : source.shortName, |
| 353 error.errorCode, | 360 error.errorCode, |
| 354 offset, | 361 offset, |
| 355 offset + error.length, | 362 offset + error.length, |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 return trampoline(target, arguments[0], arguments[1]); | 866 return trampoline(target, arguments[0], arguments[1]); |
| 860 case 3: | 867 case 3: |
| 861 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 868 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 862 case 4: | 869 case 4: |
| 863 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 870 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 864 default: | 871 default: |
| 865 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 872 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 866 } | 873 } |
| 867 } | 874 } |
| 868 } | 875 } |
| OLD | NEW |