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

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

Issue 758383003: Incremental resolution of updated DartDoc comments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
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 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 _shiftTokens(unit.beginToken, offset, delta); 2092 _shiftTokens(unit.beginToken, offset, delta);
2093 } 2093 }
2094 // replace the node 2094 // replace the node
2095 AstNode oldNode = _findNodeAt(unit, offset, predicate); 2095 AstNode oldNode = _findNodeAt(unit, offset, predicate);
2096 AstNode newNode = _findNodeAt(newUnit, offset, predicate); 2096 AstNode newNode = _findNodeAt(newUnit, offset, predicate);
2097 bool success = NodeReplacer.replace(oldNode, newNode); 2097 bool success = NodeReplacer.replace(oldNode, newNode);
2098 expect(success, isTrue); 2098 expect(success, isTrue);
2099 // do incremental resolution 2099 // do incremental resolution
2100 IncrementalResolver resolver = new IncrementalResolver( 2100 IncrementalResolver resolver = new IncrementalResolver(
2101 typeProvider, 2101 typeProvider,
2102 library,
2103 unit.element, 2102 unit.element,
2104 source,
2105 edit.offset, 2103 edit.offset,
2106 edit.length, 2104 edit.length,
2107 edit.replacement.length); 2105 edit.replacement.length);
2108 resolver.resolve(newNode); 2106 resolver.resolve(newNode);
2109 // resolve "newCode" from scratch 2107 // resolve "newCode" from scratch
2110 CompilationUnit fullNewUnit; 2108 CompilationUnit fullNewUnit;
2111 { 2109 {
2112 source = addSource(newCode); 2110 source = addSource(newCode);
2113 LibraryElement library = resolve(source); 2111 LibraryElement library = resolve(source);
2114 fullNewUnit = resolveCompilationUnit(source, library); 2112 fullNewUnit = resolveCompilationUnit(source, library);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 String code; 2169 String code;
2172 LibraryElement oldLibrary; 2170 LibraryElement oldLibrary;
2173 CompilationUnit oldUnit; 2171 CompilationUnit oldUnit;
2174 CompilationUnitElement oldUnitElement; 2172 CompilationUnitElement oldUnitElement;
2175 2173
2176 void setUp() { 2174 void setUp() {
2177 super.setUp(); 2175 super.setUp();
2178 _resetWithIncremental(true); 2176 _resetWithIncremental(true);
2179 } 2177 }
2180 2178
2179 void test_dartDoc_beforeField() {
2180 _resolveUnit(r'''
2181 class A {
2182 /**
2183 * A field [field] of type [int] in class [A].
2184 */
2185 int field;
2186 }
2187 ''');
2188 _updateAndValidate(r'''
2189 class A {
2190 /**
2191 * A field [field] of the type [int] in the class [A].
2192 * Updated, with a reference to the [String] type.
2193 */
2194 int field;
2195 }
2196 ''');
2197 }
2198
2199 void test_dartDoc_clumsy_addReference() {
2200 _resolveUnit(r'''
2201 /**
2202 * aaa bbbb
2203 */
2204 main() {
2205 }
2206 ''');
2207 _updateAndValidate(r'''
2208 /**
2209 * aaa [main] bbbb
2210 */
2211 main() {
2212 }
2213 ''');
2214 }
2215
2216 void test_dartDoc_clumsy_removeReference() {
2217 _resolveUnit(r'''
2218 /**
2219 * aaa [main] bbbb
2220 */
2221 main() {
2222 }
2223 ''');
2224 _updateAndValidate(r'''
2225 /**
2226 * aaa bbbb
2227 */
2228 main() {
2229 }
2230 ''');
2231 }
2232
2233 void test_dartDoc_clumsy_updateText() {
2234 _resolveUnit(r'''
2235 /**
2236 * A function [main] with a parameter [p] of type [int].
2237 */
2238 main(int p) {
2239 }
2240 /**
2241 * Other comment.
2242 */
2243 foo() {}
2244 ''');
2245 _updateAndValidate(r'''
2246 /**
2247 * A function [main] with a parameter [p] of type [int].
2248 * Updated.
2249 */
2250 main(int p) {
2251 }
2252 /**
2253 * Other comment.
2254 */
2255 foo() {}
2256 ''');
2257 }
2258
2259 void test_dartDoc_clumsy_updateText_beforeKeywordToken() {
2260 _resolveUnit(r'''
2261 /**
2262 * A comment with the [int] type reference.
2263 */
2264 class A {}
2265 ''');
2266 _updateAndValidate(r'''
2267 /**
2268 * A comment with the [int] type reference.
2269 * Plus reference to [A] itself.
2270 */
2271 class A {}
2272 ''');
2273 }
2274
2275 void test_dartDoc_elegant_addReference() {
2276 _resolveUnit(r'''
2277 /// aaa bbb
2278 main() {
2279 return 1;
2280 }
2281 ''');
2282 _updateAndValidate(r'''
2283 /// aaa [main] bbb
2284 /// ccc [int] ddd
2285 main() {
2286 return 2;
2287 }
2288 ''');
2289 }
2290
2291 void test_dartDoc_elegant_removeReference() {
2292 _resolveUnit(r'''
2293 /// aaa [main] bbb
2294 /// ccc [int] ddd
2295 main() {
2296 return 1;
2297 }
2298 ''');
2299 _updateAndValidate(r'''
2300 /// aaa bbb
2301 main() {
2302 return 2;
2303 }
2304 ''');
2305 }
2306
2181 void test_false_topLevelFunction_name() { 2307 void test_false_topLevelFunction_name() {
2182 _resolveUnit(r''' 2308 _resolveUnit(r'''
2183 a() {} 2309 a() {}
2184 b() {} 2310 b() {}
2185 '''); 2311 ''');
2186 _updateAndValidate(r''' 2312 _updateAndValidate(r'''
2187 a() {} 2313 a() {}
2188 bb() {} 2314 bb() {}
2189 ''', expectedSuccess: false); 2315 ''', expectedSuccess: false);
2190 } 2316 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 } 2769 }
2644 2770
2645 static void _assertEqualTokens(CompilationUnit incrUnit, 2771 static void _assertEqualTokens(CompilationUnit incrUnit,
2646 CompilationUnit fullUnit) { 2772 CompilationUnit fullUnit) {
2647 Token incrToken = incrUnit.beginToken; 2773 Token incrToken = incrUnit.beginToken;
2648 Token fullToken = fullUnit.beginToken; 2774 Token fullToken = fullUnit.beginToken;
2649 while (incrToken.type != TokenType.EOF && fullToken.type != TokenType.EOF) { 2775 while (incrToken.type != TokenType.EOF && fullToken.type != TokenType.EOF) {
2650 // print('$incrToken @ ${incrToken.offset}'); 2776 // print('$incrToken @ ${incrToken.offset}');
2651 // print('$fullToken @ ${fullToken.offset}'); 2777 // print('$fullToken @ ${fullToken.offset}');
2652 _assertEqualToken(incrToken, fullToken); 2778 _assertEqualToken(incrToken, fullToken);
2779 // comments
2780 {
2781 Token incrComment = incrToken.precedingComments;
2782 Token fullComment = fullToken.precedingComments;
2783 while (true) {
2784 if (fullComment == null) {
2785 expect(incrComment, isNull);
2786 break;
2787 }
2788 _assertEqualToken(incrComment, fullComment);
2789 incrComment = incrComment.next;
2790 fullComment = fullComment.next;
2791 }
2792 }
2793 // next tokens
2653 incrToken = incrToken.next; 2794 incrToken = incrToken.next;
2654 fullToken = fullToken.next; 2795 fullToken = fullToken.next;
2655 } 2796 }
2656 } 2797 }
2657 } 2798 }
2658 2799
2659 2800
2660 class ResolutionContextBuilderTest extends EngineTestCase { 2801 class ResolutionContextBuilderTest extends EngineTestCase {
2661 GatheringErrorListener listener = new GatheringErrorListener(); 2802 GatheringErrorListener listener = new GatheringErrorListener();
2662 2803
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 _visitList(node.metadata, other.metadata); 3857 _visitList(node.metadata, other.metadata);
3717 _visitNode(node.identifier, other.identifier); 3858 _visitNode(node.identifier, other.identifier);
3718 } 3859 }
3719 3860
3720 static void assertSameResolution(CompilationUnit actual, 3861 static void assertSameResolution(CompilationUnit actual,
3721 CompilationUnit expected) { 3862 CompilationUnit expected) {
3722 _SameResolutionValidator validator = new _SameResolutionValidator(expected); 3863 _SameResolutionValidator validator = new _SameResolutionValidator(expected);
3723 actual.accept(validator); 3864 actual.accept(validator);
3724 } 3865 }
3725 } 3866 }
OLDNEW
« pkg/analyzer/lib/src/generated/scanner.dart ('K') | « pkg/analyzer/lib/src/generated/scanner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698