Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 import '../reflective_tests.dart'; | 21 import '../reflective_tests.dart'; |
| 22 import 'parser_test.dart'; | 22 import 'parser_test.dart'; |
| 23 import 'resolver_test.dart'; | 23 import 'resolver_test.dart'; |
| 24 import 'test_support.dart'; | 24 import 'test_support.dart'; |
| 25 | 25 |
| 26 | 26 |
| 27 main() { | 27 main() { |
| 28 groupSep = ' | '; | 28 groupSep = ' | '; |
| 29 runReflectiveTests(DeclarationMatcherTest); | 29 runReflectiveTests(DeclarationMatcherTest); |
| 30 runReflectiveTests(IncrementalResolverTest); | 30 runReflectiveTests(IncrementalResolverTest); |
| 31 runReflectiveTests(PoorMansIncrementalResolutionTest); | |
| 31 runReflectiveTests(ScopeBuilderTest); | 32 runReflectiveTests(ScopeBuilderTest); |
| 32 } | 33 } |
| 33 | 34 |
| 34 | 35 |
| 35 class DeclarationMatcherTest extends ResolverTestCase { | 36 class DeclarationMatcherTest extends ResolverTestCase { |
| 36 void fail_test_methodDeclarationMatches_false_localVariable() { | 37 void fail_test_methodDeclarationMatches_false_localVariable() { |
| 37 // TODO(scheglov) as I understand DeclarationMatcher, we care only | 38 // TODO(scheglov) as I understand DeclarationMatcher, we care only |
| 38 // about externally visible model changes. So, because we analyze (at least | 39 // about externally visible model changes. So, because we analyze (at least |
| 39 // right now) incremental changes on method level, local variable can be | 40 // right now) incremental changes on method level, local variable can be |
| 40 // ignored. | 41 // ignored. |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 var errorListener = new BooleanErrorListener(); | 1356 var errorListener = new BooleanErrorListener(); |
| 1356 var reader = new CharSequenceReader(code); | 1357 var reader = new CharSequenceReader(code); |
| 1357 var scanner = new Scanner(null, reader, errorListener); | 1358 var scanner = new Scanner(null, reader, errorListener); |
| 1358 var token = scanner.tokenize(); | 1359 var token = scanner.tokenize(); |
| 1359 var parser = new Parser(null, errorListener); | 1360 var parser = new Parser(null, errorListener); |
| 1360 return parser.parseCompilationUnit(token); | 1361 return parser.parseCompilationUnit(token); |
| 1361 } | 1362 } |
| 1362 } | 1363 } |
| 1363 | 1364 |
| 1364 | 1365 |
| 1366 /** | |
| 1367 * The test for [poorMansIncrementalResolution] function and its integration | |
| 1368 * into [AnalysisContext]. | |
| 1369 */ | |
| 1370 class PoorMansIncrementalResolutionTest extends ResolverTestCase { | |
|
Brian Wilkerson
2014/11/24 15:09:14
It would be good to test some cases where incremen
scheglov
2014/11/24 18:59:06
Agree, but not in this CL.
| |
| 1371 Source source; | |
| 1372 String code; | |
| 1373 LibraryElement oldLibrary; | |
| 1374 CompilationUnit oldUnit; | |
| 1375 CompilationUnitElement oldUnitElement; | |
| 1376 | |
| 1377 void setUp() { | |
| 1378 super.setUp(); | |
| 1379 _resetWithIncremental(true); | |
| 1380 } | |
| 1381 | |
| 1382 void test_inBody_expression() { | |
| 1383 _resolveUnit(r''' | |
| 1384 class A { | |
| 1385 m() { | |
| 1386 print(1); | |
| 1387 } | |
| 1388 } | |
| 1389 '''); | |
| 1390 _updateAndValidate(r''' | |
| 1391 class A { | |
| 1392 m() { | |
| 1393 print(2 + 3); | |
| 1394 } | |
| 1395 } | |
| 1396 '''); | |
| 1397 } | |
| 1398 | |
| 1399 void test_inBody_insertStatement() { | |
| 1400 _resolveUnit(r''' | |
| 1401 main() { | |
| 1402 print(1); | |
| 1403 } | |
| 1404 '''); | |
| 1405 _updateAndValidate(r''' | |
| 1406 main() { | |
| 1407 print(0); | |
| 1408 print(1); | |
| 1409 } | |
| 1410 '''); | |
| 1411 } | |
| 1412 | |
| 1413 void test_inBody_tokenToNode() { | |
| 1414 _resolveUnit(r''' | |
| 1415 main() { | |
| 1416 var v = 42; | |
| 1417 } | |
| 1418 '''); | |
| 1419 _updateAndValidate(r''' | |
| 1420 main() { | |
| 1421 int v = 42; | |
| 1422 } | |
| 1423 '''); | |
| 1424 } | |
| 1425 | |
| 1426 void test_twice() { | |
| 1427 _resolveUnit(r''' | |
| 1428 main() { | |
| 1429 print(1); | |
| 1430 }'''); | |
| 1431 _updateAndValidate(r''' | |
| 1432 main() { | |
| 1433 print(12); | |
| 1434 }''', false); | |
| 1435 _updateAndValidate(r''' | |
| 1436 main() { | |
| 1437 print(1); | |
| 1438 }''', false); | |
| 1439 } | |
| 1440 | |
| 1441 void test_twice2() { | |
| 1442 _resolveUnit(r''' | |
| 1443 class A { | |
| 1444 m() { | |
| 1445 int vvvvvvvv = 42; | |
| 1446 print(vvvvvvvv); | |
| 1447 } | |
| 1448 }'''); | |
| 1449 _updateAndValidate(r''' | |
| 1450 class A { | |
| 1451 m() { | |
| 1452 int vvvvvvvv2 = 42; | |
| 1453 print(vvvvvvvv2); | |
| 1454 } | |
| 1455 }''', false); | |
| 1456 _updateAndValidate(r''' | |
| 1457 class A { | |
| 1458 m() { | |
| 1459 int vvvvvvvv = 42; | |
| 1460 print(vvvvvvvv); | |
| 1461 } | |
| 1462 }''', false); | |
| 1463 } | |
| 1464 | |
| 1465 void test_withImport() { | |
| 1466 _resolveUnit(r''' | |
| 1467 import 'dart:async'; | |
| 1468 import 'dart:io'; | |
| 1469 main() { | |
| 1470 print(1); | |
| 1471 } | |
| 1472 '''); | |
| 1473 _updateAndValidate(r''' | |
| 1474 import 'dart:async'; | |
| 1475 import 'dart:io'; | |
| 1476 main() { | |
| 1477 print(2 + 3); | |
| 1478 } | |
| 1479 '''); | |
| 1480 } | |
| 1481 | |
| 1482 /** | |
| 1483 * Reset the analysis context to have the 'incremental' option set to the | |
| 1484 * given value. | |
| 1485 */ | |
| 1486 void _resetWithIncremental(bool enable) { | |
| 1487 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | |
| 1488 analysisOptions.incremental = enable; | |
| 1489 analysisContext2.analysisOptions = analysisOptions; | |
| 1490 } | |
| 1491 | |
| 1492 void _resolveUnit(String code) { | |
| 1493 this.code = code; | |
| 1494 source = addSource(code); | |
| 1495 oldLibrary = resolve(source); | |
| 1496 oldUnit = resolveCompilationUnit(source, oldLibrary); | |
| 1497 oldUnitElement = oldUnit.element; | |
| 1498 } | |
| 1499 | |
| 1500 void _runTasks() { | |
| 1501 AnalysisResult result = analysisContext.performAnalysisTask(); | |
| 1502 while (result.changeNotices != null) { | |
| 1503 result = analysisContext.performAnalysisTask(); | |
| 1504 } | |
| 1505 } | |
| 1506 | |
| 1507 void _updateAndValidate(String newCode, [bool compareWithFull = true]) { | |
| 1508 // Run any pending tasks tasks. | |
| 1509 _runTasks(); | |
| 1510 // Update the source - currently this may cause incremental resolution. | |
| 1511 // Then request the updated resolved unit. | |
| 1512 _resetWithIncremental(true); | |
| 1513 analysisContext2.setContents(source, newCode); | |
| 1514 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); | |
| 1515 // The existing CompilationUnitElement should be updated. | |
| 1516 expect(newUnit.element, same(oldUnitElement)); | |
| 1517 // The only expected pending task should return the same resolved | |
| 1518 // "newUnit", so all clients will get it using the usual way. | |
| 1519 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); | |
| 1520 ChangeNotice notice = analysisResult.changeNotices[0]; | |
| 1521 expect(notice.compilationUnit, same(newUnit)); | |
| 1522 // Resolve "newCode" from scratch. | |
| 1523 if (compareWithFull) { | |
| 1524 _resetWithIncremental(false); | |
| 1525 source = addSource(newCode); | |
| 1526 LibraryElement library = resolve(source); | |
| 1527 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); | |
| 1528 // Validate that "incremental" and "full" units have the same resolution. | |
| 1529 _SameResolutionValidator.assertSameResolution(newUnit, fullNewUnit); | |
| 1530 } | |
| 1531 } | |
| 1532 } | |
| 1533 | |
| 1534 | |
| 1365 class ScopeBuilderTest extends EngineTestCase { | 1535 class ScopeBuilderTest extends EngineTestCase { |
| 1366 void test_scopeFor_ClassDeclaration() { | 1536 void test_scopeFor_ClassDeclaration() { |
| 1367 GatheringErrorListener listener = new GatheringErrorListener(); | 1537 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1368 Scope scope = | 1538 Scope scope = |
| 1369 ScopeBuilder.scopeFor(_createResolvedClassDeclaration(), listener); | 1539 ScopeBuilder.scopeFor(_createResolvedClassDeclaration(), listener); |
| 1370 EngineTestCase.assertInstanceOf( | 1540 EngineTestCase.assertInstanceOf( |
| 1371 (obj) => obj is LibraryScope, | 1541 (obj) => obj is LibraryScope, |
| 1372 LibraryScope, | 1542 LibraryScope, |
| 1373 scope); | 1543 scope); |
| 1374 } | 1544 } |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2439 _visitList(node.metadata, other.metadata); | 2609 _visitList(node.metadata, other.metadata); |
| 2440 _visitNode(node.identifier, other.identifier); | 2610 _visitNode(node.identifier, other.identifier); |
| 2441 } | 2611 } |
| 2442 | 2612 |
| 2443 static void assertSameResolution(CompilationUnit actual, | 2613 static void assertSameResolution(CompilationUnit actual, |
| 2444 CompilationUnit expected) { | 2614 CompilationUnit expected) { |
| 2445 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 2615 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 2446 actual.accept(validator); | 2616 actual.accept(validator); |
| 2447 } | 2617 } |
| 2448 } | 2618 } |
| OLD | NEW |