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

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

Issue 1522583005: Issue 25238. Update LoclaElement(s) visible ranges during incremental resolution. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 analyzer.test.generated.incremental_resolver_test; 5 library analyzer.test.generated.incremental_resolver_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 4426 matching lines...) Expand 10 before | Expand all | Expand 10 after
4437 foo(int p) {} 4437 foo(int p) {}
4438 '''); 4438 ''');
4439 // Complete analysis, e.g. compute VERIFY_ERRORS. 4439 // Complete analysis, e.g. compute VERIFY_ERRORS.
4440 _runTasks(); 4440 _runTasks();
4441 // Invalidate VERIFY_ERRORS. 4441 // Invalidate VERIFY_ERRORS.
4442 AnalysisCache cache = analysisContext2.analysisCache; 4442 AnalysisCache cache = analysisContext2.analysisCache;
4443 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4443 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4444 CacheEntry cacheEntry = cache.get(target); 4444 CacheEntry cacheEntry = cache.get(target);
4445 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(2)); 4445 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(2));
4446 cacheEntry.setState(VERIFY_ERRORS, CacheState.INVALID); 4446 cacheEntry.setState(VERIFY_ERRORS, CacheState.INVALID);
4447 // Don't run tasks, so don't recompute VERIFY_ERRORS before incremental. 4447 // Perform incremental resolution.
4448 _updateAndValidate( 4448 _resetWithIncremental(true);
4449 analysisContext2.setContents(
4450 source,
4449 r''' 4451 r'''
4450 main() { 4452 main() {
4451 foo(0); 4453 foo(0);
4452 } 4454 }
4453 main2() { 4455 main2() {
4454 foo('bbb'); 4456 foo('bbb');
4455 } 4457 }
4456 foo(int p) {} 4458 foo(int p) {}
4457 ''', 4459 ''');
4458 runTasksBeforeIncremental: false); 4460 // VERIFY_ERRORS is still invalid.
4459 // Incremental analysis should have left VERIFY_ERRORS invalid, 4461 expect(cacheEntry.getState(VERIFY_ERRORS), CacheState.INVALID);
4460 // so it was correctly recomputed later during the full analysis. 4462 // Continue analysis - run tasks, so recompute VERIFY_ERRORS.
4463 _runTasks();
4464 expect(cacheEntry.getState(VERIFY_ERRORS), CacheState.VALID);
4461 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(1)); 4465 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(1));
4462 } 4466 }
4463 4467
4464 void test_updateErrors_removeExisting_hint() { 4468 void test_updateErrors_removeExisting_hint() {
4465 _resolveUnit(r''' 4469 _resolveUnit(r'''
4466 int main() { 4470 int main() {
4467 } 4471 }
4468 '''); 4472 ''');
4469 _updateAndValidate(r''' 4473 _updateAndValidate(r'''
4470 int main() { 4474 int main() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4516 } 4520 }
4517 f2() { 4521 f2() {
4518 print(22); 4522 print(22);
4519 } 4523 }
4520 f3() { 4524 f3() {
4521 print(333) 4525 print(333)
4522 } 4526 }
4523 '''); 4527 ''');
4524 } 4528 }
4525 4529
4530 void test_visibleRange() {
4531 _resolveUnit(r'''
4532 class Test {
4533 method1(p1) {
4534 var v1;
4535 f1() {}
4536 return 1;
4537 }
4538 method2(p2) {
4539 var v2;
4540 f2() {}
4541 return 2;
4542 }
4543 method3(p3) {
4544 var v3;
4545 f3() {}
4546 return 3;
4547 }
4548 }
4549 ''');
4550 _updateAndValidate(r'''
4551 class Test {
4552 method1(p1) {
4553 var v1;
4554 f1() {}
4555 return 1;
4556 }
4557 method2(p2) {
4558 var v2;
4559 f2() {}
4560 return 2222;
4561 }
4562 method3(p3) {
4563 var v3;
4564 f3() {}
4565 return 3;
4566 }
4567 }
4568 ''');
4569 }
4570
4526 void test_whitespace_getElementAt() { 4571 void test_whitespace_getElementAt() {
4527 _resolveUnit(r''' 4572 _resolveUnit(r'''
4528 class A {} 4573 class A {}
4529 class B extends A {} 4574 class B extends A {}
4530 '''); 4575 ''');
4531 { 4576 {
4532 ClassElement typeA = oldUnitElement.getType('A'); 4577 ClassElement typeA = oldUnitElement.getType('A');
4533 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA); 4578 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA);
4534 } 4579 }
4535 { 4580 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4621 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary), 4666 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary),
4622 same(oldUnit)); 4667 same(oldUnit));
4623 // The only expected pending task should return the same resolved 4668 // The only expected pending task should return the same resolved
4624 // "newUnit", so all clients will get it using the usual way. 4669 // "newUnit", so all clients will get it using the usual way.
4625 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); 4670 AnalysisResult analysisResult = analysisContext.performAnalysisTask();
4626 ChangeNotice notice = analysisResult.changeNotices[0]; 4671 ChangeNotice notice = analysisResult.changeNotices[0];
4627 expect(notice.resolvedDartUnit, same(newUnit)); 4672 expect(notice.resolvedDartUnit, same(newUnit));
4628 // Resolve "newCode" from scratch. 4673 // Resolve "newCode" from scratch.
4629 if (compareWithFull) { 4674 if (compareWithFull) {
4630 _resetWithIncremental(false); 4675 _resetWithIncremental(false);
4676 changeSource(source, '');
4631 changeSource(source, newCode); 4677 changeSource(source, newCode);
4632 _runTasks(); 4678 _runTasks();
4633 LibraryElement library = resolve2(source); 4679 LibraryElement library = resolve2(source);
4634 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); 4680 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library);
4635 // Validate tokens. 4681 // Validate tokens.
4636 _assertEqualTokens(newUnit, fullNewUnit); 4682 _assertEqualTokens(newUnit, fullNewUnit);
4637 // Validate LineInfo 4683 // Validate LineInfo
4638 _assertEqualLineInfo(newLineInfo, analysisContext.getLineInfo(source)); 4684 _assertEqualLineInfo(newLineInfo, analysisContext.getLineInfo(source));
4639 // Validate that "incremental" and "full" units have the same resolution. 4685 // Validate that "incremental" and "full" units have the same resolution.
4640 try { 4686 try {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4892 return ResolutionContextBuilder.contextFor(node, listener).scope; 4938 return ResolutionContextBuilder.contextFor(node, listener).scope;
4893 } 4939 }
4894 } 4940 }
4895 4941
4896 class _Edit { 4942 class _Edit {
4897 final int offset; 4943 final int offset;
4898 final int length; 4944 final int length;
4899 final String replacement; 4945 final String replacement;
4900 _Edit(this.offset, this.length, this.replacement); 4946 _Edit(this.offset, this.length, this.replacement);
4901 } 4947 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698