| OLD | NEW |
| 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/context/cache.dart' as task; | |
| 8 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisCache; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/incremental_logger.dart' as log; | 12 import 'package:analyzer/src/generated/incremental_logger.dart' as log; |
| 14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; | 13 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; |
| 15 import 'package:analyzer/src/generated/incremental_resolver.dart'; | 14 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
| 16 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 17 import 'package:analyzer/src/generated/parser.dart'; | 16 import 'package:analyzer/src/generated/parser.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/scanner.dart'; | 18 import 'package:analyzer/src/generated/scanner.dart'; |
| 20 import 'package:analyzer/src/generated/source_io.dart'; | 19 import 'package:analyzer/src/generated/source_io.dart'; |
| 21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| (...skipping 2997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3019 | 3018 |
| 3020 @reflectiveTest | 3019 @reflectiveTest |
| 3021 class IncrementalResolverTest extends ResolverTestCase { | 3020 class IncrementalResolverTest extends ResolverTestCase { |
| 3022 Source source; | 3021 Source source; |
| 3023 String code; | 3022 String code; |
| 3024 LibraryElement library; | 3023 LibraryElement library; |
| 3025 CompilationUnit unit; | 3024 CompilationUnit unit; |
| 3026 | 3025 |
| 3027 @override | 3026 @override |
| 3028 void reset() { | 3027 void reset() { |
| 3029 if (AnalysisEngine.instance.useTaskModel) { | 3028 analysisContext2 = AnalysisContextFactory.contextWithCore(); |
| 3030 analysisContext2 = AnalysisContextFactory.contextWithCore(); | |
| 3031 } else { | |
| 3032 analysisContext2 = AnalysisContextFactory.oldContextWithCore(); | |
| 3033 } | |
| 3034 } | 3029 } |
| 3035 | 3030 |
| 3036 @override | 3031 @override |
| 3037 void resetWithOptions(AnalysisOptions options) { | 3032 void resetWithOptions(AnalysisOptions options) { |
| 3038 if (AnalysisEngine.instance.useTaskModel) { | 3033 AnalysisContextFactory.contextWithCoreAndOptions(options); |
| 3039 analysisContext2 = | |
| 3040 AnalysisContextFactory.contextWithCoreAndOptions(options); | |
| 3041 } else { | |
| 3042 analysisContext2 = | |
| 3043 AnalysisContextFactory.oldContextWithCoreAndOptions(options); | |
| 3044 } | |
| 3045 } | 3034 } |
| 3046 | 3035 |
| 3047 void setUp() { | 3036 void setUp() { |
| 3048 super.setUp(); | 3037 super.setUp(); |
| 3049 test_resolveApiChanges = true; | 3038 test_resolveApiChanges = true; |
| 3050 log.logger = log.NULL_LOGGER; | 3039 log.logger = log.NULL_LOGGER; |
| 3051 } | 3040 } |
| 3052 | 3041 |
| 3053 void test_classMemberAccessor_body() { | 3042 void test_classMemberAccessor_body() { |
| 3054 _resolveUnit(r''' | 3043 _resolveUnit(r''' |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3384 // update tokens | 3373 // update tokens |
| 3385 { | 3374 { |
| 3386 int delta = edit.replacement.length - edit.length; | 3375 int delta = edit.replacement.length - edit.length; |
| 3387 _shiftTokens(unit.beginToken, offset, delta); | 3376 _shiftTokens(unit.beginToken, offset, delta); |
| 3388 } | 3377 } |
| 3389 // do incremental resolution | 3378 // do incremental resolution |
| 3390 int updateOffset = edit.offset; | 3379 int updateOffset = edit.offset; |
| 3391 int updateEndOld = updateOffset + edit.length; | 3380 int updateEndOld = updateOffset + edit.length; |
| 3392 int updateOldNew = updateOffset + edit.replacement.length; | 3381 int updateOldNew = updateOffset + edit.replacement.length; |
| 3393 IncrementalResolver resolver; | 3382 IncrementalResolver resolver; |
| 3394 if (AnalysisEngine.instance.useTaskModel) { | 3383 LibrarySpecificUnit lsu = new LibrarySpecificUnit(source, source); |
| 3395 LibrarySpecificUnit lsu = new LibrarySpecificUnit(source, source); | 3384 AnalysisCache cache = analysisContext2.analysisCache; |
| 3396 task.AnalysisCache cache = analysisContext2.analysisCache; | 3385 resolver = new IncrementalResolver(cache.get(source), cache.get(lsu), |
| 3397 resolver = new IncrementalResolver( | 3386 unit.element, updateOffset, updateEndOld, updateOldNew); |
| 3398 null, | |
| 3399 cache.get(source), | |
| 3400 cache.get(lsu), | |
| 3401 unit.element, | |
| 3402 updateOffset, | |
| 3403 updateEndOld, | |
| 3404 updateOldNew); | |
| 3405 } else { | |
| 3406 resolver = new IncrementalResolver( | |
| 3407 (analysisContext2 as AnalysisContextImpl) | |
| 3408 .getReadableSourceEntryOrNull(source), | |
| 3409 null, | |
| 3410 null, | |
| 3411 unit.element, | |
| 3412 updateOffset, | |
| 3413 updateEndOld, | |
| 3414 updateOldNew); | |
| 3415 } | |
| 3416 bool success = resolver.resolve(newNode); | 3387 bool success = resolver.resolve(newNode); |
| 3417 expect(success, isTrue); | 3388 expect(success, isTrue); |
| 3418 List<AnalysisError> newErrors = analysisContext.computeErrors(source); | 3389 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
| 3419 // resolve "newCode" from scratch | 3390 // resolve "newCode" from scratch |
| 3420 CompilationUnit fullNewUnit; | 3391 CompilationUnit fullNewUnit; |
| 3421 { | 3392 { |
| 3422 source = addSource(newCode); | 3393 source = addSource(newCode); |
| 3423 _runTasks(); | 3394 _runTasks(); |
| 3424 LibraryElement library = resolve2(source); | 3395 LibraryElement library = resolve2(source); |
| 3425 fullNewUnit = resolveCompilationUnit(source, library); | 3396 fullNewUnit = resolveCompilationUnit(source, library); |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4463 main2() { | 4434 main2() { |
| 4464 foo('bbb'); | 4435 foo('bbb'); |
| 4465 } | 4436 } |
| 4466 foo(int p) {} | 4437 foo(int p) {} |
| 4467 '''); | 4438 '''); |
| 4468 // Complete analysis, e.g. compute VERIFY_ERRORS. | 4439 // Complete analysis, e.g. compute VERIFY_ERRORS. |
| 4469 _runTasks(); | 4440 _runTasks(); |
| 4470 // Invalidate VERIFY_ERRORS. | 4441 // Invalidate VERIFY_ERRORS. |
| 4471 AnalysisCache cache = analysisContext2.analysisCache; | 4442 AnalysisCache cache = analysisContext2.analysisCache; |
| 4472 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4443 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4473 task.CacheEntry cacheEntry = cache.get(target); | 4444 CacheEntry cacheEntry = cache.get(target); |
| 4474 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(2)); | 4445 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(2)); |
| 4475 cacheEntry.setState(VERIFY_ERRORS, CacheState.INVALID); | 4446 cacheEntry.setState(VERIFY_ERRORS, CacheState.INVALID); |
| 4476 // Don't run tasks, so don't recompute VERIFY_ERRORS before incremental. | 4447 // Don't run tasks, so don't recompute VERIFY_ERRORS before incremental. |
| 4477 _updateAndValidate( | 4448 _updateAndValidate( |
| 4478 r''' | 4449 r''' |
| 4479 main() { | 4450 main() { |
| 4480 foo(0); | 4451 foo(0); |
| 4481 } | 4452 } |
| 4482 main2() { | 4453 main2() { |
| 4483 foo('bbb'); | 4454 foo('bbb'); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4921 return ResolutionContextBuilder.contextFor(node, listener).scope; | 4892 return ResolutionContextBuilder.contextFor(node, listener).scope; |
| 4922 } | 4893 } |
| 4923 } | 4894 } |
| 4924 | 4895 |
| 4925 class _Edit { | 4896 class _Edit { |
| 4926 final int offset; | 4897 final int offset; |
| 4927 final int length; | 4898 final int length; |
| 4928 final String replacement; | 4899 final String replacement; |
| 4929 _Edit(this.offset, this.length, this.replacement); | 4900 _Edit(this.offset, this.length, this.replacement); |
| 4930 } | 4901 } |
| OLD | NEW |