| 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 2160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 String code; | 2171 String code; |
| 2172 LibraryElement oldLibrary; | 2172 LibraryElement oldLibrary; |
| 2173 CompilationUnit oldUnit; | 2173 CompilationUnit oldUnit; |
| 2174 CompilationUnitElement oldUnitElement; | 2174 CompilationUnitElement oldUnitElement; |
| 2175 | 2175 |
| 2176 void setUp() { | 2176 void setUp() { |
| 2177 super.setUp(); | 2177 super.setUp(); |
| 2178 _resetWithIncremental(true); | 2178 _resetWithIncremental(true); |
| 2179 } | 2179 } |
| 2180 | 2180 |
| 2181 void test_false_topLevelFunction_name() { |
| 2182 _resolveUnit(r''' |
| 2183 a() {} |
| 2184 b() {} |
| 2185 '''); |
| 2186 _updateAndValidate(r''' |
| 2187 a() {} |
| 2188 bb() {} |
| 2189 ''', expectedSuccess: false); |
| 2190 } |
| 2191 |
| 2181 void test_inBody_expression() { | 2192 void test_inBody_expression() { |
| 2182 _resolveUnit(r''' | 2193 _resolveUnit(r''' |
| 2183 class A { | 2194 class A { |
| 2184 m() { | 2195 m() { |
| 2185 print(1); | 2196 print(1); |
| 2186 } | 2197 } |
| 2187 } | 2198 } |
| 2188 '''); | 2199 '''); |
| 2189 _updateAndValidate(r''' | 2200 _updateAndValidate(r''' |
| 2190 class A { | 2201 class A { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2232 } | 2243 } |
| 2233 }'''); | 2244 }'''); |
| 2234 for (int i = 0; i < 6; i++) { | 2245 for (int i = 0; i < 6; i++) { |
| 2235 if (i.isEven) { | 2246 if (i.isEven) { |
| 2236 _updateAndValidate(r''' | 2247 _updateAndValidate(r''' |
| 2237 class A { | 2248 class A { |
| 2238 m() { | 2249 m() { |
| 2239 return true; | 2250 return true; |
| 2240 | 2251 |
| 2241 } | 2252 } |
| 2242 }''', false); | 2253 }''', compareWithFull: false); |
| 2243 } else { | 2254 } else { |
| 2244 _updateAndValidate(r''' | 2255 _updateAndValidate(r''' |
| 2245 class A { | 2256 class A { |
| 2246 m() { | 2257 m() { |
| 2247 return true; | 2258 return true; |
| 2248 } | 2259 } |
| 2249 }''', false); | 2260 }''', compareWithFull: false); |
| 2250 } | 2261 } |
| 2251 } | 2262 } |
| 2252 } | 2263 } |
| 2253 | 2264 |
| 2254 void test_multiple_expression() { | 2265 void test_multiple_expression() { |
| 2255 _resolveUnit(r''' | 2266 _resolveUnit(r''' |
| 2256 main() { | 2267 main() { |
| 2257 print(1); | 2268 print(1); |
| 2258 }'''); | 2269 }'''); |
| 2259 for (int i = 0; i < 6; i++) { | 2270 for (int i = 0; i < 6; i++) { |
| 2260 if (i.isEven) { | 2271 if (i.isEven) { |
| 2261 _updateAndValidate(r''' | 2272 _updateAndValidate(r''' |
| 2262 main() { | 2273 main() { |
| 2263 print(12); | 2274 print(12); |
| 2264 }''', false); | 2275 }''', compareWithFull: false); |
| 2265 } else { | 2276 } else { |
| 2266 _updateAndValidate(r''' | 2277 _updateAndValidate(r''' |
| 2267 main() { | 2278 main() { |
| 2268 print(1); | 2279 print(1); |
| 2269 }''', false); | 2280 }''', compareWithFull: false); |
| 2270 } | 2281 } |
| 2271 } | 2282 } |
| 2272 } | 2283 } |
| 2273 | 2284 |
| 2285 void test_true_emptyLine_betweenClassMembers_insert() { |
| 2286 _resolveUnit(r''' |
| 2287 class A { |
| 2288 a() {} |
| 2289 b() {} |
| 2290 } |
| 2291 '''); |
| 2292 _updateAndValidate(r''' |
| 2293 class A { |
| 2294 a() {} |
| 2295 |
| 2296 b() {} |
| 2297 } |
| 2298 '''); |
| 2299 } |
| 2300 |
| 2301 void test_true_emptyLine_betweenClassMembers_remove() { |
| 2302 _resolveUnit(r''' |
| 2303 class A { |
| 2304 a() {} |
| 2305 |
| 2306 b() {} |
| 2307 } |
| 2308 '''); |
| 2309 _updateAndValidate(r''' |
| 2310 class A { |
| 2311 a() {} |
| 2312 b() {} |
| 2313 } |
| 2314 '''); |
| 2315 } |
| 2316 |
| 2317 void test_true_emptyLine_betweenCompilationUnitMembers_insert() { |
| 2318 _resolveUnit(r''' |
| 2319 a() {} |
| 2320 b() {} |
| 2321 '''); |
| 2322 _updateAndValidate(r''' |
| 2323 a() {} |
| 2324 |
| 2325 b() {} |
| 2326 '''); |
| 2327 } |
| 2328 |
| 2329 void test_true_emptyLine_betweenCompilationUnitMembers_remove() { |
| 2330 _resolveUnit(r''' |
| 2331 a() { |
| 2332 print(1) |
| 2333 } |
| 2334 |
| 2335 b() { |
| 2336 foo(42); |
| 2337 } |
| 2338 foo(String p) {}; |
| 2339 '''); |
| 2340 _updateAndValidate(r''' |
| 2341 a() { |
| 2342 print(1) |
| 2343 } |
| 2344 b() { |
| 2345 foo(42); |
| 2346 } |
| 2347 foo(String p) {}; |
| 2348 '''); |
| 2349 } |
| 2350 |
| 2274 void test_true_wholeConstructor() { | 2351 void test_true_wholeConstructor() { |
| 2275 _resolveUnit(r''' | 2352 _resolveUnit(r''' |
| 2276 class A { | 2353 class A { |
| 2277 A(int a) { | 2354 A(int a) { |
| 2278 print(a); | 2355 print(a); |
| 2279 } | 2356 } |
| 2280 } | 2357 } |
| 2281 '''); | 2358 '''); |
| 2282 _updateAndValidate(r''' | 2359 _updateAndValidate(r''' |
| 2283 class A { | 2360 class A { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2486 oldUnitElement = oldUnit.element; | 2563 oldUnitElement = oldUnit.element; |
| 2487 } | 2564 } |
| 2488 | 2565 |
| 2489 void _runTasks() { | 2566 void _runTasks() { |
| 2490 AnalysisResult result = analysisContext.performAnalysisTask(); | 2567 AnalysisResult result = analysisContext.performAnalysisTask(); |
| 2491 while (result.changeNotices != null) { | 2568 while (result.changeNotices != null) { |
| 2492 result = analysisContext.performAnalysisTask(); | 2569 result = analysisContext.performAnalysisTask(); |
| 2493 } | 2570 } |
| 2494 } | 2571 } |
| 2495 | 2572 |
| 2496 void _updateAndValidate(String newCode, [bool compareWithFull = true]) { | 2573 void _updateAndValidate(String newCode, {bool expectedSuccess: true, |
| 2574 bool compareWithFull: true}) { |
| 2497 // Run any pending tasks tasks. | 2575 // Run any pending tasks tasks. |
| 2498 _runTasks(); | 2576 _runTasks(); |
| 2499 // Update the source - currently this may cause incremental resolution. | 2577 // Update the source - currently this may cause incremental resolution. |
| 2500 // Then request the updated resolved unit. | 2578 // Then request the updated resolved unit. |
| 2501 _resetWithIncremental(true); | 2579 _resetWithIncremental(true); |
| 2502 analysisContext2.setContents(source, newCode); | 2580 analysisContext2.setContents(source, newCode); |
| 2503 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); | 2581 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); |
| 2504 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors; | 2582 List<AnalysisError> newErrors = analysisContext.getErrors(source).errors; |
| 2583 // check for expected failure |
| 2584 if (!expectedSuccess) { |
| 2585 expect(newUnit.element, isNot(same(oldUnitElement))); |
| 2586 return; |
| 2587 } |
| 2505 // The existing CompilationUnitElement should be updated. | 2588 // The existing CompilationUnitElement should be updated. |
| 2506 expect(newUnit.element, same(oldUnitElement)); | 2589 expect(newUnit.element, same(oldUnitElement)); |
| 2507 // The only expected pending task should return the same resolved | 2590 // The only expected pending task should return the same resolved |
| 2508 // "newUnit", so all clients will get it using the usual way. | 2591 // "newUnit", so all clients will get it using the usual way. |
| 2509 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); | 2592 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); |
| 2510 ChangeNotice notice = analysisResult.changeNotices[0]; | 2593 ChangeNotice notice = analysisResult.changeNotices[0]; |
| 2511 expect(notice.compilationUnit, same(newUnit)); | 2594 expect(notice.compilationUnit, same(newUnit)); |
| 2512 // Resolve "newCode" from scratch. | 2595 // Resolve "newCode" from scratch. |
| 2513 if (compareWithFull) { | 2596 if (compareWithFull) { |
| 2514 _resetWithIncremental(false); | 2597 _resetWithIncremental(false); |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3633 _visitList(node.metadata, other.metadata); | 3716 _visitList(node.metadata, other.metadata); |
| 3634 _visitNode(node.identifier, other.identifier); | 3717 _visitNode(node.identifier, other.identifier); |
| 3635 } | 3718 } |
| 3636 | 3719 |
| 3637 static void assertSameResolution(CompilationUnit actual, | 3720 static void assertSameResolution(CompilationUnit actual, |
| 3638 CompilationUnit expected) { | 3721 CompilationUnit expected) { |
| 3639 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 3722 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 3640 actual.accept(validator); | 3723 actual.accept(validator); |
| 3641 } | 3724 } |
| 3642 } | 3725 } |
| OLD | NEW |