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

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 901713004: Invalidate hints instead of computing them in the incremental resolver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Invalidate hints for included parts too Created 5 years, 10 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/lib/src/generated/incremental_resolver.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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.incremental_resolver_test; 5 library engine.incremental_resolver_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 2488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 } 2499 }
2500 // update tokens 2500 // update tokens
2501 { 2501 {
2502 int delta = edit.replacement.length - edit.length; 2502 int delta = edit.replacement.length - edit.length;
2503 _shiftTokens(unit.beginToken, offset, delta); 2503 _shiftTokens(unit.beginToken, offset, delta);
2504 } 2504 }
2505 // do incremental resolution 2505 // do incremental resolution
2506 int updateOffset = edit.offset; 2506 int updateOffset = edit.offset;
2507 int updateEndOld = updateOffset + edit.length; 2507 int updateEndOld = updateOffset + edit.length;
2508 int updateOldNew = updateOffset + edit.replacement.length; 2508 int updateOldNew = updateOffset + edit.replacement.length;
2509 IncrementalResolver resolver = 2509 IncrementalResolver resolver = new IncrementalResolver(
2510 new IncrementalResolver(<Source, CompilationUnit>{ 2510 unit.element,
2511 source: newUnit 2511 updateOffset,
2512 }, unit.element, updateOffset, updateEndOld, updateOldNew); 2512 updateEndOld,
2513 updateOldNew);
2513 bool success = resolver.resolve(newNode); 2514 bool success = resolver.resolve(newNode);
2514 expect(success, isTrue); 2515 expect(success, isTrue);
2515 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors; 2516 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
2516 // resolve "newCode" from scratch 2517 // resolve "newCode" from scratch
2517 CompilationUnit fullNewUnit; 2518 CompilationUnit fullNewUnit;
2518 { 2519 {
2519 source = addSource(newCode); 2520 source = addSource(newCode);
2520 _runTasks(); 2521 _runTasks();
2521 LibraryElement library = resolve(source); 2522 LibraryElement library = resolve(source);
2522 fullNewUnit = resolveCompilationUnit(source, library); 2523 fullNewUnit = resolveCompilationUnit(source, library);
2523 } 2524 }
2524 try { 2525 try {
2525 assertSameResolution(unit, fullNewUnit); 2526 assertSameResolution(unit, fullNewUnit);
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
3204 _runTasks(); 3205 _runTasks();
3205 // perform incremental resolution 3206 // perform incremental resolution
3206 _resetWithIncremental(true); 3207 _resetWithIncremental(true);
3207 analysisContext2.setContents(partSource, r''' 3208 analysisContext2.setContents(partSource, r'''
3208 part of lib; 3209 part of lib;
3209 3210
3210 f(A a) { 3211 f(A a) {
3211 // a._foo(); 3212 // a._foo();
3212 } 3213 }
3213 '''); 3214 ''');
3215 // no hints right now, because we delay hints computing
3216 {
3217 List<AnalysisError> errors = analysisContext.getErrors(source).errors;
3218 expect(errors, isEmpty);
3219 }
3214 // a new hint should be added 3220 // a new hint should be added
3215 List<AnalysisError> errors = analysisContext.getErrors(source).errors; 3221 List<AnalysisError> errors = analysisContext.computeErrors(source);
3216 expect(errors, hasLength(1)); 3222 expect(errors, hasLength(1));
3217 expect(errors[0].errorCode.type, ErrorType.HINT); 3223 expect(errors[0].errorCode.type, ErrorType.HINT);
3218 // the same hint should be reported using a ChangeNotice 3224 // the same hint should be reported using a ChangeNotice
3219 bool noticeFound = false; 3225 bool noticeFound = false;
3220 AnalysisResult result = analysisContext2.performAnalysisTask(); 3226 AnalysisResult result = analysisContext2.performAnalysisTask();
3221 for (ChangeNotice notice in result.changeNotices) { 3227 for (ChangeNotice notice in result.changeNotices) {
3222 if (notice.source == source) { 3228 if (notice.source == source) {
3223 expect(notice.errors, contains(errors[0])); 3229 expect(notice.errors, contains(errors[0]));
3224 noticeFound = true; 3230 noticeFound = true;
3225 } 3231 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
3451 3457
3452 void _updateAndValidate(String newCode, {bool expectedSuccess: true, 3458 void _updateAndValidate(String newCode, {bool expectedSuccess: true,
3453 bool compareWithFull: true}) { 3459 bool compareWithFull: true}) {
3454 // Run any pending tasks tasks. 3460 // Run any pending tasks tasks.
3455 _runTasks(); 3461 _runTasks();
3456 // Update the source - currently this may cause incremental resolution. 3462 // Update the source - currently this may cause incremental resolution.
3457 // Then request the updated resolved unit. 3463 // Then request the updated resolved unit.
3458 _resetWithIncremental(true); 3464 _resetWithIncremental(true);
3459 analysisContext2.setContents(source, newCode); 3465 analysisContext2.setContents(source, newCode);
3460 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); 3466 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
3461 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors; 3467 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
3462 // check for expected failure 3468 // check for expected failure
3463 if (!expectedSuccess) { 3469 if (!expectedSuccess) {
3464 expect(newUnit.element, isNot(same(oldUnitElement))); 3470 expect(newUnit.element, isNot(same(oldUnitElement)));
3465 return; 3471 return;
3466 } 3472 }
3467 // The existing CompilationUnitElement should be updated. 3473 // The existing CompilationUnitElement should be updated.
3468 expect(newUnit.element, same(oldUnitElement)); 3474 expect(newUnit.element, same(oldUnitElement));
3469 // The only expected pending task should return the same resolved 3475 // The only expected pending task should return the same resolved
3470 // "newUnit", so all clients will get it using the usual way. 3476 // "newUnit", so all clients will get it using the usual way.
3471 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); 3477 AnalysisResult analysisResult = analysisContext.performAnalysisTask();
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
3770 } 3776 }
3771 } 3777 }
3772 3778
3773 3779
3774 class _Edit { 3780 class _Edit {
3775 final int offset; 3781 final int offset;
3776 final int length; 3782 final int length;
3777 final String replacement; 3783 final String replacement;
3778 _Edit(this.offset, this.length, this.replacement); 3784 _Edit(this.offset, this.length, this.replacement);
3779 } 3785 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698