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

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

Issue 818173003: Use all library units for hints during incremental resolution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 } 2425 }
2426 // update tokens 2426 // update tokens
2427 { 2427 {
2428 int delta = edit.replacement.length - edit.length; 2428 int delta = edit.replacement.length - edit.length;
2429 _shiftTokens(unit.beginToken, offset, delta); 2429 _shiftTokens(unit.beginToken, offset, delta);
2430 } 2430 }
2431 // do incremental resolution 2431 // do incremental resolution
2432 int updateOffset = edit.offset; 2432 int updateOffset = edit.offset;
2433 int updateEndOld = updateOffset + edit.length; 2433 int updateEndOld = updateOffset + edit.length;
2434 int updateOldNew = updateOffset + edit.replacement.length; 2434 int updateOldNew = updateOffset + edit.replacement.length;
2435 IncrementalResolver resolver = new IncrementalResolver( 2435 IncrementalResolver resolver =
2436 unit.element, 2436 new IncrementalResolver(<Source, CompilationUnit>{
2437 updateOffset, 2437 source: newUnit
2438 updateEndOld, 2438 }, unit.element, updateOffset, updateEndOld, updateOldNew);
2439 updateOldNew);
2440 bool success = resolver.resolve(newNode); 2439 bool success = resolver.resolve(newNode);
2441 expect(success, isTrue); 2440 expect(success, isTrue);
2442 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors; 2441 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors;
2443 // resolve "newCode" from scratch 2442 // resolve "newCode" from scratch
2444 CompilationUnit fullNewUnit; 2443 CompilationUnit fullNewUnit;
2445 { 2444 {
2446 source = addSource(newCode); 2445 source = addSource(newCode);
2447 _runTasks(); 2446 _runTasks();
2448 LibraryElement library = resolve(source); 2447 LibraryElement library = resolve(source);
2449 fullNewUnit = resolveCompilationUnit(source, library); 2448 fullNewUnit = resolveCompilationUnit(source, library);
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 '''); 3051 ''');
3053 _updateAndValidate(r''' 3052 _updateAndValidate(r'''
3054 class A { 3053 class A {
3055 main(int b) { 3054 main(int b) {
3056 print(b); 3055 print(b);
3057 } 3056 }
3058 } 3057 }
3059 '''); 3058 ''');
3060 } 3059 }
3061 3060
3061 void test_unusedHint_add_wasUsedOnlyInPart() {
3062 Source partSource = addNamedSource('/my_unit.dart', r'''
3063 part of lib;
3064
3065 f(A a) {
3066 a._foo();
3067 }
3068 ''');
3069 _resolveUnit(r'''
3070 library lib;
3071 part 'my_unit.dart';
3072 class A {
3073 _foo() {
3074 print(1);
3075 }
3076 }
3077 ''');
3078 _runTasks();
3079 // perform incremental resolution
3080 _resetWithIncremental(true);
3081 analysisContext2.setContents(partSource, r'''
3082 part of lib;
3083
3084 f(A a) {
3085 // a._foo();
3086 }
3087 ''');
3088 // a new hint should be added
3089 List<AnalysisError> errors = analysisContext.getErrors(source).errors;
3090 expect(errors, hasLength(1));
3091 expect(errors[0].errorCode.type, ErrorType.HINT);
3092 // the same hint should be reported using a ChangeNotice
3093 bool noticeFound = false;
3094 AnalysisResult result = analysisContext2.performAnalysisTask();
3095 for (ChangeNotice notice in result.changeNotices) {
3096 if (notice.source == source) {
3097 expect(notice.errors, contains(errors[0]));
3098 noticeFound = true;
3099 }
3100 }
3101 expect(noticeFound, isTrue);
3102 }
3103
3104 void test_unusedHint_false_stillUsedInPart() {
3105 addNamedSource('/my_unit.dart', r'''
3106 part of lib;
3107
3108 f(A a) {
3109 a._foo();
3110 }
3111 ''');
3112 _resolveUnit(r'''
3113 library lib;
3114 part 'my_unit.dart';
3115 class A {
3116 _foo() {
3117 print(1);
3118 }
3119 }
3120 ''');
3121 // perform incremental resolution
3122 _resetWithIncremental(true);
3123 analysisContext2.setContents(source, r'''
3124 library lib;
3125 part 'my_unit.dart';
3126 class A {
3127 _foo() {
3128 print(12);
3129 }
3130 }
3131 ''');
3132 // no hints
3133 List<AnalysisError> errors = analysisContext.getErrors(source).errors;
3134 expect(errors, isEmpty);
3135 }
3136
3062 void test_updateErrors_addNew_hint() { 3137 void test_updateErrors_addNew_hint() {
3063 _resolveUnit(r''' 3138 _resolveUnit(r'''
3064 int main() { 3139 int main() {
3065 return 42; 3140 return 42;
3066 } 3141 }
3067 '''); 3142 ''');
3068 _updateAndValidate(r''' 3143 _updateAndValidate(r'''
3069 int main() { 3144 int main() {
3070 } 3145 }
3071 '''); 3146 ''');
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
3566 } 3641 }
3567 } 3642 }
3568 3643
3569 3644
3570 class _Edit { 3645 class _Edit {
3571 final int offset; 3646 final int offset;
3572 final int length; 3647 final int length;
3573 final String replacement; 3648 final String replacement;
3574 _Edit(this.offset, this.length, this.replacement); 3649 _Edit(this.offset, this.length, this.replacement);
3575 } 3650 }
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