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

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

Issue 23769004: java2dart improvement - use field if getter/setter are trivial. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
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 library engine.test_support; 3 library engine.test_support;
4 import 'package:analyzer_experimental/src/generated/java_core.dart'; 4 import 'package:analyzer_experimental/src/generated/java_core.dart';
5 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 5 import 'package:analyzer_experimental/src/generated/java_junit.dart';
6 import 'package:analyzer_experimental/src/generated/source.dart'; 6 import 'package:analyzer_experimental/src/generated/source.dart';
7 import 'package:analyzer_experimental/src/generated/error.dart'; 7 import 'package:analyzer_experimental/src/generated/error.dart';
8 import 'package:analyzer_experimental/src/generated/scanner.dart'; 8 import 'package:analyzer_experimental/src/generated/scanner.dart';
9 import 'package:analyzer_experimental/src/generated/ast.dart' show ASTNode, Node Locator; 9 import 'package:analyzer_experimental/src/generated/ast.dart' show ASTNode, Node Locator;
10 import 'package:analyzer_experimental/src/generated/element.dart' show Interface Type, MethodElement, PropertyAccessorElement; 10 import 'package:analyzer_experimental/src/generated/element.dart' show Interface Type, MethodElement, PropertyAccessorElement;
(...skipping 12 matching lines...) Expand all
23 23
24 /** 24 /**
25 * The source being parsed after inserting a marker at the beginning and end o f the range of the 25 * The source being parsed after inserting a marker at the beginning and end o f the range of the
26 * most recent error. 26 * most recent error.
27 */ 27 */
28 String _markedSource; 28 String _markedSource;
29 29
30 /** 30 /**
31 * A list containing the errors that were collected. 31 * A list containing the errors that were collected.
32 */ 32 */
33 List<AnalysisError> _errors = new List<AnalysisError>(); 33 final List<AnalysisError> errors = new List<AnalysisError>();
34 34
35 /** 35 /**
36 * A table mapping sources to the line information for the source. 36 * A table mapping sources to the line information for the source.
37 */ 37 */
38 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); 38 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>();
39 39
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);
(...skipping 25 matching lines...) Expand all
69 /** 69 /**
70 * Assert that the number of errors that have been gathered matches the number of errors that are 70 * Assert that the number of errors that have been gathered matches the number of errors that are
71 * given and that they have the expected error codes and locations. The order in which the errors 71 * given and that they have the expected error codes and locations. The order in which the errors
72 * were gathered is ignored. 72 * were gathered is ignored.
73 * 73 *
74 * @param errorCodes the errors that should have been gathered 74 * @param errorCodes the errors that should have been gathered
75 * @throws AssertionFailedError if a different number of errors have been gath ered than were 75 * @throws AssertionFailedError if a different number of errors have been gath ered than were
76 * expected or if they do not have the same codes and locations 76 * expected or if they do not have the same codes and locations
77 */ 77 */
78 void assertErrors(List<AnalysisError> expectedErrors) { 78 void assertErrors(List<AnalysisError> expectedErrors) {
79 if (_errors.length != expectedErrors.length) { 79 if (errors.length != expectedErrors.length) {
80 fail(expectedErrors); 80 fail(expectedErrors);
81 } 81 }
82 List<AnalysisError> remainingErrors = new List<AnalysisError>(); 82 List<AnalysisError> remainingErrors = new List<AnalysisError>();
83 for (AnalysisError error in expectedErrors) { 83 for (AnalysisError error in expectedErrors) {
84 remainingErrors.add(error); 84 remainingErrors.add(error);
85 } 85 }
86 for (AnalysisError error in _errors) { 86 for (AnalysisError error in errors) {
87 if (!foundAndRemoved(remainingErrors, error)) { 87 if (!foundAndRemoved(remainingErrors, error)) {
88 fail(expectedErrors); 88 fail(expectedErrors);
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 /** 93 /**
94 * Assert that the number of errors that have been gathered matches the number of errors that are 94 * Assert that the number of errors that have been gathered matches the number of errors that are
95 * given and that they have the expected error codes. The order in which the e rrors were gathered 95 * given and that they have the expected error codes. The order in which the e rrors were gathered
96 * is ignored. 96 * is ignored.
(...skipping 11 matching lines...) Expand all
108 for (ErrorCode code in expectedErrorCodes) { 108 for (ErrorCode code in expectedErrorCodes) {
109 int count = expectedCounts[code]; 109 int count = expectedCounts[code];
110 if (count == null) { 110 if (count == null) {
111 count = 1; 111 count = 1;
112 } else { 112 } else {
113 count = count + 1; 113 count = count + 1;
114 } 114 }
115 expectedCounts[code] = count; 115 expectedCounts[code] = count;
116 } 116 }
117 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A nalysisError>>(); 117 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A nalysisError>>();
118 for (AnalysisError error in _errors) { 118 for (AnalysisError error in errors) {
119 ErrorCode code = error.errorCode; 119 ErrorCode code = error.errorCode;
120 List<AnalysisError> list = errorsByCode[code]; 120 List<AnalysisError> list = errorsByCode[code];
121 if (list == null) { 121 if (list == null) {
122 list = new List<AnalysisError>(); 122 list = new List<AnalysisError>();
123 errorsByCode[code] = list; 123 errorsByCode[code] = list;
124 } 124 }
125 list.add(error); 125 list.add(error);
126 } 126 }
127 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) { 127 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) {
128 ErrorCode code = entry.getKey(); 128 ErrorCode code = entry.getKey();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int expectedWarningCount = 0; 189 int expectedWarningCount = 0;
190 for (ErrorSeverity severity in expectedSeverities) { 190 for (ErrorSeverity severity in expectedSeverities) {
191 if (identical(severity, ErrorSeverity.ERROR)) { 191 if (identical(severity, ErrorSeverity.ERROR)) {
192 expectedErrorCount++; 192 expectedErrorCount++;
193 } else { 193 } else {
194 expectedWarningCount++; 194 expectedWarningCount++;
195 } 195 }
196 } 196 }
197 int actualErrorCount = 0; 197 int actualErrorCount = 0;
198 int actualWarningCount = 0; 198 int actualWarningCount = 0;
199 for (AnalysisError error in _errors) { 199 for (AnalysisError error in errors) {
200 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { 200 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) {
201 actualErrorCount++; 201 actualErrorCount++;
202 } else { 202 } else {
203 actualWarningCount++; 203 actualWarningCount++;
204 } 204 }
205 } 205 }
206 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual WarningCount) { 206 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual WarningCount) {
207 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount} warnings"); 207 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount} warnings");
208 } 208 }
209 } 209 }
210 210
211 /** 211 /**
212 * Assert that no errors have been gathered. 212 * Assert that no errors have been gathered.
213 * 213 *
214 * @throws AssertionFailedError if any errors have been gathered 214 * @throws AssertionFailedError if any errors have been gathered
215 */ 215 */
216 void assertNoErrors() { 216 void assertNoErrors() {
217 assertErrors(_NO_ERRORS); 217 assertErrors(_NO_ERRORS);
218 } 218 }
219 219
220 /** 220 /**
221 * Return the errors that were collected.
222 *
223 * @return the errors that were collected
224 */
225 List<AnalysisError> get errors => _errors;
226
227 /**
228 * Return the line information associated with the given source, or `null` if no line 221 * Return the line information associated with the given source, or `null` if no line
229 * information has been associated with the source. 222 * information has been associated with the source.
230 * 223 *
231 * @param source the source with which the line information is associated 224 * @param source the source with which the line information is associated
232 * @return the line information associated with the source 225 * @return the line information associated with the source
233 */ 226 */
234 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; 227 LineInfo getLineInfo(Source source) => _lineInfoMap[source];
235 228
236 /** 229 /**
237 * Return `true` if an error with the given error code has been gathered. 230 * Return `true` if an error with the given error code has been gathered.
238 * 231 *
239 * @param errorCode the error code being searched for 232 * @param errorCode the error code being searched for
240 * @return `true` if an error with the given error code has been gathered 233 * @return `true` if an error with the given error code has been gathered
241 */ 234 */
242 bool hasError(ErrorCode errorCode2) { 235 bool hasError(ErrorCode errorCode2) {
243 for (AnalysisError error in _errors) { 236 for (AnalysisError error in errors) {
244 if (identical(error.errorCode, errorCode2)) { 237 if (identical(error.errorCode, errorCode2)) {
245 return true; 238 return true;
246 } 239 }
247 } 240 }
248 return false; 241 return false;
249 } 242 }
250 243
251 /** 244 /**
252 * Return `true` if at least one error has been gathered. 245 * Return `true` if at least one error has been gathered.
253 * 246 *
254 * @return `true` if at least one error has been gathered 247 * @return `true` if at least one error has been gathered
255 */ 248 */
256 bool hasErrors() => _errors.length > 0; 249 bool hasErrors() => errors.length > 0;
257 void onError(AnalysisError error) { 250 void onError(AnalysisError error) {
258 if (_rawSource != null) { 251 if (_rawSource != null) {
259 int left = error.offset; 252 int left = error.offset;
260 int right = left + error.length - 1; 253 int right = left + error.length - 1;
261 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l eft, right)}^${_rawSource.substring(right)}"; 254 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l eft, right)}^${_rawSource.substring(right)}";
262 } 255 }
263 _errors.add(error); 256 errors.add(error);
264 } 257 }
265 258
266 /** 259 /**
267 * Set the line information associated with the given source to the given info rmation. 260 * Set the line information associated with the given source to the given info rmation.
268 * 261 *
269 * @param source the source with which the line information is associated 262 * @param source the source with which the line information is associated
270 * @param lineStarts the line start information to be associated with the sour ce 263 * @param lineStarts the line start information to be associated with the sour ce
271 */ 264 */
272 void setLineInfo(Source source, List<int> lineStarts) { 265 void setLineInfo(Source source, List<int> lineStarts) {
273 _lineInfoMap[source] = new LineInfo(lineStarts); 266 _lineInfoMap[source] = new LineInfo(lineStarts);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 writer.printf(" %s %s (%d, %d/%d)", [ 330 writer.printf(" %s %s (%d, %d/%d)", [
338 source == null ? "" : source.shortName, 331 source == null ? "" : source.shortName,
339 error.errorCode, 332 error.errorCode,
340 location.lineNumber, 333 location.lineNumber,
341 location.columnNumber, 334 location.columnNumber,
342 error.length]); 335 error.length]);
343 } 336 }
344 } 337 }
345 writer.newLine(); 338 writer.newLine();
346 writer.print("found "); 339 writer.print("found ");
347 writer.print(_errors.length); 340 writer.print(errors.length);
348 writer.print(" errors:"); 341 writer.print(" errors:");
349 for (AnalysisError error in _errors) { 342 for (AnalysisError error in errors) {
350 Source source = error.source; 343 Source source = error.source;
351 LineInfo lineInfo = _lineInfoMap[source]; 344 LineInfo lineInfo = _lineInfoMap[source];
352 writer.newLine(); 345 writer.newLine();
353 if (lineInfo == null) { 346 if (lineInfo == null) {
354 int offset = error.offset; 347 int offset = error.offset;
355 writer.printf(" %s %s (%d..%d): %s", [ 348 writer.printf(" %s %s (%d..%d): %s", [
356 source == null ? "" : source.shortName, 349 source == null ? "" : source.shortName,
357 error.errorCode, 350 error.errorCode,
358 offset, 351 offset,
359 offset + error.length, 352 offset + error.length,
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return trampoline(target, arguments[0], arguments[1]); 835 return trampoline(target, arguments[0], arguments[1]);
843 case 3: 836 case 3:
844 return trampoline(target, arguments[0], arguments[1], arguments[2]); 837 return trampoline(target, arguments[0], arguments[1], arguments[2]);
845 case 4: 838 case 4:
846 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 839 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
847 default: 840 default:
848 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 841 throw new IllegalArgumentException("Not implemented for > 4 arguments");
849 } 842 }
850 } 843 }
851 } 844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698