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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java

Issue 8395013: DartC User Warning Framework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use new ErrorCode enums in single onError() method. Created 9 years, 1 month 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 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.base.Joiner; 7 import com.google.common.base.Joiner;
8 import com.google.common.base.Splitter; 8 import com.google.common.base.Splitter;
9 import com.google.common.collect.Lists; 9 import com.google.common.collect.Lists;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
11 import com.google.dart.compiler.DartCompilerErrorCode;
12 import com.google.dart.compiler.DartCompilerListener; 11 import com.google.dart.compiler.DartCompilerListener;
13 import com.google.dart.compiler.ErrorCode; 12 import com.google.dart.compiler.ErrorCode;
14 import com.google.dart.compiler.ast.DartClass; 13 import com.google.dart.compiler.ast.DartClass;
15 import com.google.dart.compiler.ast.DartIdentifier; 14 import com.google.dart.compiler.ast.DartIdentifier;
16 import com.google.dart.compiler.ast.DartNode; 15 import com.google.dart.compiler.ast.DartNode;
17 import com.google.dart.compiler.ast.DartTypeNode; 16 import com.google.dart.compiler.ast.DartTypeNode;
18 import com.google.dart.compiler.ast.DartTypeParameter; 17 import com.google.dart.compiler.ast.DartTypeParameter;
19 import com.google.dart.compiler.ast.DartUnit; 18 import com.google.dart.compiler.ast.DartUnit;
20 import com.google.dart.compiler.parser.DartParser; 19 import com.google.dart.compiler.parser.DartParser;
21 import com.google.dart.compiler.parser.DartScannerParserContext; 20 import com.google.dart.compiler.parser.DartScannerParserContext;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return getParser(string).parseUnit(source); 275 return getParser(string).parseUnit(source);
277 } 276 }
278 277
279 private DartParser getParser(String string) { 278 private DartParser getParser(String string) {
280 return new DartParser(new DartScannerParserContext(null, string, getListener ())); 279 return new DartParser(new DartScannerParserContext(null, string, getListener ()));
281 } 280 }
282 281
283 private DartCompilerListener getListener() { 282 private DartCompilerListener getListener() {
284 return new DartCompilerListener() { 283 return new DartCompilerListener() {
285 @Override 284 @Override
286 public void compilationError(DartCompilationError event) { 285 public void onError(DartCompilationError event) {
287 encounteredErrors.add(event); 286 encounteredErrors.add(event);
288 } 287 }
289 288
290 @Override 289 @Override
291 public void compilationWarning(DartCompilationError event) {
292 compilationError(event);
293 }
294
295 @Override
296 public void typeError(DartCompilationError event) {
297 compilationError(event);
298 }
299
300 @Override
301 public void unitCompiled(DartUnit unit) { 290 public void unitCompiled(DartUnit unit) {
302 } 291 }
303 }; 292 };
304 } 293 }
305 294
306 protected void checkExpectedErrors(ErrorCode[] errorCodes) { 295 protected void checkExpectedErrors(ErrorCode[] errorCodes) {
307 checkExpectedErrors(encounteredErrors, errorCodes, null); 296 checkExpectedErrors(encounteredErrors, errorCodes, null);
308 } 297 }
309 298
310 /** 299 /**
(...skipping 24 matching lines...) Expand all
335 } 324 }
336 325
337 /** 326 /**
338 * Returns a context with a listener that remembers all DartCompilationErrors and records 327 * Returns a context with a listener that remembers all DartCompilationErrors and records
339 * them. 328 * them.
340 * @return 329 * @return
341 */ 330 */
342 protected TestCompilerContext getContext() { 331 protected TestCompilerContext getContext() {
343 return new TestCompilerContext() { 332 return new TestCompilerContext() {
344 @Override 333 @Override
345 public void compilationError(DartCompilationError event) { 334 public void onError(DartCompilationError event) {
346 recordError(event); 335 recordError(event);
347 } 336 }
348 }; 337 };
349 } 338 }
350 339
351 /** 340 /**
352 * Resets the global list of encountered errors. Call this before evaluating a new test. 341 * Resets the global list of encountered errors. Call this before evaluating a new test.
353 */ 342 */
354 protected void resetExpectedErrors() { 343 protected void resetExpectedErrors() {
355 encounteredErrors = Lists.newArrayList(); 344 encounteredErrors = Lists.newArrayList();
(...skipping 13 matching lines...) Expand all
369 for (String line : Splitter.on("\n").split(source)) { 358 for (String line : Splitter.on("\n").split(source)) {
370 System.out.println(String.format(" %02d: %s", count++, line)); 359 System.out.println(String.format(" %02d: %s", count++, line));
371 } 360 }
372 } 361 }
373 } 362 }
374 /** 363 /**
375 * For debugging. 364 * For debugging.
376 */ 365 */
377 protected void printEncountered(List<DartCompilationError> encountered) { 366 protected void printEncountered(List<DartCompilationError> encountered) {
378 for (DartCompilationError error : encountered) { 367 for (DartCompilationError error : encountered) {
379 DartCompilerErrorCode errorCode = (DartCompilerErrorCode) error 368 ErrorCode errorCode = (ErrorCode) error.getErrorCode();
380 .getErrorCode(); 369 String msg =
381 String msg = String.format("%s > %s (%d:%d)", errorCode.name(), error 370 String.format(
382 .getMessage(), error.getLineNumber(), error.getColumnNumber()); 371 "%s > %s (%d:%d)",
372 errorCode.toString(),
373 error.getMessage(),
374 error.getLineNumber(),
375 error.getColumnNumber());
383 System.out.println(msg); 376 System.out.println(msg);
384 } 377 }
385 } 378 }
386 379
387 /** 380 /**
388 * Convenience method to parse and resolve a code snippet, then test for error codes. 381 * Convenience method to parse and resolve a code snippet, then test for error codes.
389 */ 382 */
390 protected void resolveAndTest(String source, ErrorCode... errorCodes) { 383 protected void resolveAndTest(String source, ErrorCode... errorCodes) {
391 resetExpectedErrors(); 384 resetExpectedErrors();
392 final List<DartCompilationError> encountered = Lists.newArrayList(); 385 final List<DartCompilationError> encountered = Lists.newArrayList();
393 TestCompilerContext ctx = new TestCompilerContext() { 386 TestCompilerContext ctx = new TestCompilerContext() {
394 @Override 387 @Override
395 public void compilationError(DartCompilationError event) { 388 public void onError(DartCompilationError event) {
396 encountered.add(event); 389 encountered.add(event);
397 } 390 }
398 }; 391 };
399 DartUnit unit = parseUnit(source); 392 DartUnit unit = parseUnit(source);
400 if (encounteredErrors.size() != 0) { 393 if (encounteredErrors.size() != 0) {
401 printSource(source); 394 printSource(source);
402 printEncountered(encounteredErrors); 395 printEncountered(encounteredErrors);
403 assertEquals("Expected no errors in parse step:", 0, encounteredErrors.siz e()); 396 assertEquals("Expected no errors in parse step:", 0, encounteredErrors.siz e());
404 } 397 }
405 resolve(unit, ctx); 398 resolve(unit, ctx);
406 checkExpectedErrors(encountered, errorCodes, source); 399 checkExpectedErrors(encountered, errorCodes, source);
407 } 400 }
408 } 401 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698