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/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 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 _assertMatchKind(DeclarationMatchKind.MISMATCH_OK, oldContent, newContent); | 2440 _assertMatchKind(DeclarationMatchKind.MISMATCH_OK, oldContent, newContent); |
2441 } | 2441 } |
2442 | 2442 |
2443 void _assertMatches(String oldContent, String newContent) { | 2443 void _assertMatches(String oldContent, String newContent) { |
2444 _assertMatchKind(DeclarationMatchKind.MATCH, oldContent, newContent); | 2444 _assertMatchKind(DeclarationMatchKind.MATCH, oldContent, newContent); |
2445 } | 2445 } |
2446 | 2446 |
2447 void _assertMatchKind( | 2447 void _assertMatchKind( |
2448 DeclarationMatchKind expectMatch, String oldContent, String newContent) { | 2448 DeclarationMatchKind expectMatch, String oldContent, String newContent) { |
2449 Source source = addSource(oldContent); | 2449 Source source = addSource(oldContent); |
2450 LibraryElement library = resolve(source); | 2450 LibraryElement library = resolve2(source); |
2451 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 2451 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
2452 // parse | 2452 // parse |
2453 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); | 2453 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); |
2454 // build elements | 2454 // build elements |
2455 { | 2455 { |
2456 ElementHolder holder = new ElementHolder(); | 2456 ElementHolder holder = new ElementHolder(); |
2457 ElementBuilder builder = new ElementBuilder(holder); | 2457 ElementBuilder builder = new ElementBuilder(holder); |
2458 newUnit.accept(builder); | 2458 newUnit.accept(builder); |
2459 } | 2459 } |
2460 // match | 2460 // match |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2817 .getReadableSourceEntryOrNull(source), null, null, unit.element, | 2817 .getReadableSourceEntryOrNull(source), null, null, unit.element, |
2818 updateOffset, updateEndOld, updateOldNew); | 2818 updateOffset, updateEndOld, updateOldNew); |
2819 bool success = resolver.resolve(newNode); | 2819 bool success = resolver.resolve(newNode); |
2820 expect(success, isTrue); | 2820 expect(success, isTrue); |
2821 List<AnalysisError> newErrors = analysisContext.computeErrors(source); | 2821 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
2822 // resolve "newCode" from scratch | 2822 // resolve "newCode" from scratch |
2823 CompilationUnit fullNewUnit; | 2823 CompilationUnit fullNewUnit; |
2824 { | 2824 { |
2825 source = addSource(newCode); | 2825 source = addSource(newCode); |
2826 _runTasks(); | 2826 _runTasks(); |
2827 LibraryElement library = resolve(source); | 2827 LibraryElement library = resolve2(source); |
2828 fullNewUnit = resolveCompilationUnit(source, library); | 2828 fullNewUnit = resolveCompilationUnit(source, library); |
2829 } | 2829 } |
2830 try { | 2830 try { |
2831 assertSameResolution(unit, fullNewUnit); | 2831 assertSameResolution(unit, fullNewUnit); |
2832 } on IncrementalResolutionMismatch catch (mismatch) { | 2832 } on IncrementalResolutionMismatch catch (mismatch) { |
2833 fail(mismatch.message); | 2833 fail(mismatch.message); |
2834 } | 2834 } |
2835 // errors | 2835 // errors |
2836 List<AnalysisError> newFullErrors = | 2836 List<AnalysisError> newFullErrors = |
2837 analysisContext.getErrors(source).errors; | 2837 analysisContext.getErrors(source).errors; |
2838 _assertEqualErrors(newErrors, newFullErrors); | 2838 _assertEqualErrors(newErrors, newFullErrors); |
2839 // prepare for the next cycle | 2839 // prepare for the next cycle |
2840 code = newCode; | 2840 code = newCode; |
2841 } | 2841 } |
2842 | 2842 |
2843 void _resolveUnit(String code) { | 2843 void _resolveUnit(String code) { |
2844 this.code = code; | 2844 this.code = code; |
2845 source = addSource(code); | 2845 source = addSource(code); |
2846 library = resolve(source); | 2846 library = resolve2(source); |
2847 unit = resolveCompilationUnit(source, library); | 2847 unit = resolveCompilationUnit(source, library); |
2848 _runTasks(); | 2848 _runTasks(); |
2849 } | 2849 } |
2850 | 2850 |
2851 void _runTasks() { | 2851 void _runTasks() { |
2852 AnalysisResult result = analysisContext.performAnalysisTask(); | 2852 AnalysisResult result = analysisContext.performAnalysisTask(); |
2853 while (result.changeNotices != null) { | 2853 while (result.changeNotices != null) { |
2854 result = analysisContext.performAnalysisTask(); | 2854 result = analysisContext.performAnalysisTask(); |
2855 } | 2855 } |
2856 } | 2856 } |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3861 analysisOptions.incremental = enable; | 3861 analysisOptions.incremental = enable; |
3862 analysisOptions.incrementalApi = enable; | 3862 analysisOptions.incrementalApi = enable; |
3863 // log.logger = log.PRINT_LOGGER; | 3863 // log.logger = log.PRINT_LOGGER; |
3864 log.logger = log.NULL_LOGGER; | 3864 log.logger = log.NULL_LOGGER; |
3865 analysisContext2.analysisOptions = analysisOptions; | 3865 analysisContext2.analysisOptions = analysisOptions; |
3866 } | 3866 } |
3867 | 3867 |
3868 void _resolveUnit(String code) { | 3868 void _resolveUnit(String code) { |
3869 this.code = code; | 3869 this.code = code; |
3870 source = addSource(code); | 3870 source = addSource(code); |
3871 oldLibrary = resolve(source); | 3871 oldLibrary = resolve2(source); |
3872 oldUnit = resolveCompilationUnit(source, oldLibrary); | 3872 oldUnit = resolveCompilationUnit(source, oldLibrary); |
3873 oldUnitElement = oldUnit.element; | 3873 oldUnitElement = oldUnit.element; |
3874 } | 3874 } |
3875 | 3875 |
3876 void _runTasks() { | 3876 void _runTasks() { |
3877 AnalysisResult result = analysisContext.performAnalysisTask(); | 3877 AnalysisResult result = analysisContext.performAnalysisTask(); |
3878 while (result.changeNotices != null) { | 3878 while (result.changeNotices != null) { |
3879 result = analysisContext.performAnalysisTask(); | 3879 result = analysisContext.performAnalysisTask(); |
3880 } | 3880 } |
3881 } | 3881 } |
(...skipping 19 matching lines...) Expand all Loading... |
3901 // "newUnit", so all clients will get it using the usual way. | 3901 // "newUnit", so all clients will get it using the usual way. |
3902 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); | 3902 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); |
3903 ChangeNotice notice = analysisResult.changeNotices[0]; | 3903 ChangeNotice notice = analysisResult.changeNotices[0]; |
3904 expect(notice.resolvedDartUnit, same(newUnit)); | 3904 expect(notice.resolvedDartUnit, same(newUnit)); |
3905 // Resolve "newCode" from scratch. | 3905 // Resolve "newCode" from scratch. |
3906 if (compareWithFull) { | 3906 if (compareWithFull) { |
3907 _resetWithIncremental(false); | 3907 _resetWithIncremental(false); |
3908 source = addSource(newCode + ' '); | 3908 source = addSource(newCode + ' '); |
3909 source = addSource(newCode); | 3909 source = addSource(newCode); |
3910 _runTasks(); | 3910 _runTasks(); |
3911 LibraryElement library = resolve(source); | 3911 LibraryElement library = resolve2(source); |
3912 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); | 3912 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); |
3913 // Validate tokens. | 3913 // Validate tokens. |
3914 _assertEqualTokens(newUnit, fullNewUnit); | 3914 _assertEqualTokens(newUnit, fullNewUnit); |
3915 // Validate that "incremental" and "full" units have the same resolution. | 3915 // Validate that "incremental" and "full" units have the same resolution. |
3916 try { | 3916 try { |
3917 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); | 3917 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); |
3918 } on IncrementalResolutionMismatch catch (mismatch) { | 3918 } on IncrementalResolutionMismatch catch (mismatch) { |
3919 fail(mismatch.message); | 3919 fail(mismatch.message); |
3920 } | 3920 } |
3921 List<AnalysisError> newFullErrors = | 3921 List<AnalysisError> newFullErrors = |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4156 return ResolutionContextBuilder.contextFor(node, listener).scope; | 4156 return ResolutionContextBuilder.contextFor(node, listener).scope; |
4157 } | 4157 } |
4158 } | 4158 } |
4159 | 4159 |
4160 class _Edit { | 4160 class _Edit { |
4161 final int offset; | 4161 final int offset; |
4162 final int length; | 4162 final int length; |
4163 final String replacement; | 4163 final String replacement; |
4164 _Edit(this.offset, this.length, this.replacement); | 4164 _Edit(this.offset, this.length, this.replacement); |
4165 } | 4165 } |
OLD | NEW |