| 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; | 7 import 'package:analyzer/src/context/cache.dart' as task; |
| 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 3854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3865 } | 3865 } |
| 3866 f2() { | 3866 f2() { |
| 3867 print(22); | 3867 print(22); |
| 3868 } | 3868 } |
| 3869 f3() { | 3869 f3() { |
| 3870 print(333) | 3870 print(333) |
| 3871 } | 3871 } |
| 3872 '''); | 3872 '''); |
| 3873 } | 3873 } |
| 3874 | 3874 |
| 3875 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) { |
| 3876 for (int offset = 0; offset < 1000; offset++) { |
| 3877 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset); |
| 3878 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset); |
| 3879 if (incrLocation.lineNumber != fullLocation.lineNumber || |
| 3880 incrLocation.columnNumber != fullLocation.columnNumber) { |
| 3881 fail('At offset $offset ' + |
| 3882 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' + |
| 3883 ' != ' + |
| 3884 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})'); |
| 3885 } |
| 3886 } |
| 3887 } |
| 3888 |
| 3875 /** | 3889 /** |
| 3876 * Reset the analysis context to have the 'incremental' option set to the | 3890 * Reset the analysis context to have the 'incremental' option set to the |
| 3877 * given value. | 3891 * given value. |
| 3878 */ | 3892 */ |
| 3879 void _resetWithIncremental(bool enable) { | 3893 void _resetWithIncremental(bool enable) { |
| 3880 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 3894 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 3881 analysisOptions.incremental = enable; | 3895 analysisOptions.incremental = enable; |
| 3882 analysisOptions.incrementalApi = enable; | 3896 analysisOptions.incrementalApi = enable; |
| 3883 // log.logger = log.PRINT_LOGGER; | 3897 // log.logger = log.PRINT_LOGGER; |
| 3884 log.logger = log.NULL_LOGGER; | 3898 log.logger = log.NULL_LOGGER; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3903 void _updateAndValidate(String newCode, | 3917 void _updateAndValidate(String newCode, |
| 3904 {bool expectedSuccess: true, bool compareWithFull: true}) { | 3918 {bool expectedSuccess: true, bool compareWithFull: true}) { |
| 3905 // Run any pending tasks tasks. | 3919 // Run any pending tasks tasks. |
| 3906 _runTasks(); | 3920 _runTasks(); |
| 3907 // Update the source - currently this may cause incremental resolution. | 3921 // Update the source - currently this may cause incremental resolution. |
| 3908 // Then request the updated resolved unit. | 3922 // Then request the updated resolved unit. |
| 3909 _resetWithIncremental(true); | 3923 _resetWithIncremental(true); |
| 3910 analysisContext2.setContents(source, newCode); | 3924 analysisContext2.setContents(source, newCode); |
| 3911 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); | 3925 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); |
| 3912 List<AnalysisError> newErrors = analysisContext.computeErrors(source); | 3926 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
| 3927 LineInfo newLineInfo = analysisContext.getLineInfo(source); |
| 3913 // check for expected failure | 3928 // check for expected failure |
| 3914 if (!expectedSuccess) { | 3929 if (!expectedSuccess) { |
| 3915 expect(newUnit.element, isNot(same(oldUnitElement))); | 3930 expect(newUnit.element, isNot(same(oldUnitElement))); |
| 3916 return; | 3931 return; |
| 3917 } | 3932 } |
| 3918 // The existing CompilationUnitElement should be updated. | 3933 // The existing CompilationUnitElement should be updated. |
| 3919 expect(newUnit.element, same(oldUnitElement)); | 3934 expect(newUnit.element, same(oldUnitElement)); |
| 3920 // The only expected pending task should return the same resolved | 3935 // The only expected pending task should return the same resolved |
| 3921 // "newUnit", so all clients will get it using the usual way. | 3936 // "newUnit", so all clients will get it using the usual way. |
| 3922 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); | 3937 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); |
| 3923 ChangeNotice notice = analysisResult.changeNotices[0]; | 3938 ChangeNotice notice = analysisResult.changeNotices[0]; |
| 3924 expect(notice.resolvedDartUnit, same(newUnit)); | 3939 expect(notice.resolvedDartUnit, same(newUnit)); |
| 3925 // Resolve "newCode" from scratch. | 3940 // Resolve "newCode" from scratch. |
| 3926 if (compareWithFull) { | 3941 if (compareWithFull) { |
| 3927 _resetWithIncremental(false); | 3942 _resetWithIncremental(false); |
| 3928 source = addSource(newCode + ' '); | 3943 source = addSource(newCode + ' '); |
| 3929 source = addSource(newCode); | 3944 source = addSource(newCode); |
| 3930 _runTasks(); | 3945 _runTasks(); |
| 3931 LibraryElement library = resolve2(source); | 3946 LibraryElement library = resolve2(source); |
| 3932 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); | 3947 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); |
| 3933 // Validate tokens. | 3948 // Validate tokens. |
| 3934 _assertEqualTokens(newUnit, fullNewUnit); | 3949 _assertEqualTokens(newUnit, fullNewUnit); |
| 3950 // Validate LineInfo |
| 3951 _assertEqualLineInfo(newLineInfo, analysisContext.getLineInfo(source)); |
| 3935 // Validate that "incremental" and "full" units have the same resolution. | 3952 // Validate that "incremental" and "full" units have the same resolution. |
| 3936 try { | 3953 try { |
| 3937 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); | 3954 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); |
| 3938 } on IncrementalResolutionMismatch catch (mismatch) { | 3955 } on IncrementalResolutionMismatch catch (mismatch) { |
| 3939 fail(mismatch.message); | 3956 fail(mismatch.message); |
| 3940 } | 3957 } |
| 3941 List<AnalysisError> newFullErrors = | 3958 List<AnalysisError> newFullErrors = |
| 3942 analysisContext.getErrors(source).errors; | 3959 analysisContext.getErrors(source).errors; |
| 3943 _assertEqualErrors(newErrors, newFullErrors); | 3960 _assertEqualErrors(newErrors, newFullErrors); |
| 3944 // TODO(scheglov) check line info | |
| 3945 } | 3961 } |
| 3946 } | 3962 } |
| 3947 | 3963 |
| 3948 static void _assertEqualToken(Token incrToken, Token fullToken) { | 3964 static void _assertEqualToken(Token incrToken, Token fullToken) { |
| 3949 // print('[${incrToken.offset}] |$incrToken| vs. [${fullToken.offset}] |$full
Token|'); | 3965 // print('[${incrToken.offset}] |$incrToken| vs. [${fullToken.offset}] |$full
Token|'); |
| 3950 expect(incrToken.type, fullToken.type); | 3966 expect(incrToken.type, fullToken.type); |
| 3951 expect(incrToken.offset, fullToken.offset); | 3967 expect(incrToken.offset, fullToken.offset); |
| 3952 expect(incrToken.length, fullToken.length); | 3968 expect(incrToken.length, fullToken.length); |
| 3953 expect(incrToken.lexeme, fullToken.lexeme); | 3969 expect(incrToken.lexeme, fullToken.lexeme); |
| 3954 } | 3970 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4176 return ResolutionContextBuilder.contextFor(node, listener).scope; | 4192 return ResolutionContextBuilder.contextFor(node, listener).scope; |
| 4177 } | 4193 } |
| 4178 } | 4194 } |
| 4179 | 4195 |
| 4180 class _Edit { | 4196 class _Edit { |
| 4181 final int offset; | 4197 final int offset; |
| 4182 final int length; | 4198 final int length; |
| 4183 final String replacement; | 4199 final String replacement; |
| 4184 _Edit(this.offset, this.length, this.replacement); | 4200 _Edit(this.offset, this.length, this.replacement); |
| 4185 } | 4201 } |
| OLD | NEW |