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/incremental_resolver.dart'; | 11 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
| 11 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; | |
| 12 import 'package:analyzer/src/generated/resolver.dart'; | 14 import 'package:analyzer/src/generated/resolver.dart'; |
| 15 import 'package:analyzer/src/generated/scanner.dart'; | |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 16 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 17 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 15 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 17 | 20 |
| 18 import '../reflective_tests.dart'; | 21 import '../reflective_tests.dart'; |
| 19 import 'parser_test.dart'; | 22 import 'parser_test.dart'; |
| 20 import 'resolver_test.dart'; | 23 import 'resolver_test.dart'; |
| 21 import 'test_support.dart'; | 24 import 'test_support.dart'; |
| 22 | 25 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 DeclarationMatcher matcher = new DeclarationMatcher(); | 239 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 237 expect(matcher.matches(newMethod, element), expectMatch); | 240 expect(matcher.matches(newMethod, element), expectMatch); |
| 238 } | 241 } |
| 239 | 242 |
| 240 MethodDeclaration _getFirstMethod(CompilationUnit unit) { | 243 MethodDeclaration _getFirstMethod(CompilationUnit unit) { |
| 241 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | 244 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; |
| 242 return classNode.members[0] as MethodDeclaration; | 245 return classNode.members[0] as MethodDeclaration; |
| 243 } | 246 } |
| 244 } | 247 } |
| 245 | 248 |
| 249 | |
| 246 class IncrementalResolverTest extends ResolverTestCase { | 250 class IncrementalResolverTest extends ResolverTestCase { |
| 247 void test_resolve() { | 251 Source source; |
| 248 MethodDeclaration method = _resolveMethod(r''' | 252 String code; |
| 249 class C { | 253 LibraryElement library; |
| 250 int m(int a) { | 254 CompilationUnit unit; |
| 251 return a + a; | 255 |
| 252 } | 256 void fail_test_functionBody_addLocalVariable() { |
| 253 }'''); | 257 // TODO(scheglov) this test fails, because we don't create element models |
| 254 BlockFunctionBody body = method.body as BlockFunctionBody; | 258 // for new local variables |
| 255 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 259 _resolveUnit(r''' |
| 256 BinaryExpression expression = statement.expression as BinaryExpression; | 260 main(int a, int b) { |
| 257 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; | 261 return a + b; |
| 258 Element leftElement = left.staticElement; | 262 } |
| 259 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; | 263 '''); |
| 260 Element rightElement = right.staticElement; | 264 _resolve(_editString(' return a + b;', r''' |
| 261 expect(leftElement, isNotNull); | 265 int res = a + b; |
| 262 expect(rightElement, same(leftElement)); | 266 return res; |
| 267 '''), _isBlock); | |
| 263 } | 268 } |
| 264 | 269 |
| 265 MethodDeclaration _resolveMethod(String content) { | 270 void test_functionBody_body() { |
| 266 Source source = addSource(content); | 271 _resolveUnit(r''' |
| 267 LibraryElement library = resolve(source); | 272 main(int a, int b) { |
| 268 CompilationUnit unit = resolveCompilationUnit(source, library); | 273 return a + b; |
| 269 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | 274 }'''); |
| 270 MethodDeclaration method = classNode.members[0] as MethodDeclaration; | 275 _resolve(_editString('+', '*'), _isFunctionBody); |
| 271 method.body.accept(new ResolutionEraser()); | 276 } |
| 277 | |
| 278 void test_functionBody_statement() { | |
| 279 _resolveUnit(r''' | |
| 280 main(int a, int b) { | |
| 281 return a + b; | |
| 282 }'''); | |
| 283 _resolve(_editString('+', '*'), _isStatement); | |
| 284 } | |
| 285 | |
| 286 _Edit _editString(String search, String replacement, [int length]) { | |
| 287 int offset = code.indexOf(search); | |
| 288 expect(offset, isNot(-1)); | |
| 289 if (length == null) { | |
| 290 length = search.length; | |
| 291 } | |
| 292 return new _Edit(offset, length, replacement); | |
| 293 } | |
| 294 | |
| 295 // _Edit _editMethodBody(String className, String methodName, | |
| 296 // String replacement) { | |
| 297 // ClassDeclaration clazz = _findClass(unit, className); | |
| 298 // MethodDeclaration method = clazz.getMethod(methodName); | |
| 299 // FunctionBody body = method.body; | |
| 300 // return new _Edit(body.offset, body.length, replacement); | |
| 301 // } | |
| 302 | |
| 303 /** | |
| 304 * Applies [edit] to [code], find the [AstNode] specified by [predicate] | |
| 305 * and incrementally resolves it. | |
| 306 * | |
| 307 * Then resolves the new code from scratch and validates that results of | |
| 308 * the incremental resolution and non-incremental resolutions are the same. | |
| 309 */ | |
| 310 void _resolve(_Edit edit, Predicate<AstNode> predicate) { | |
| 311 int offset = edit.offset; | |
| 312 // parse "newCode" | |
| 313 String newCode = | |
| 314 code.substring(0, offset) + | |
| 315 edit.replacement + | |
| 316 code.substring(offset + edit.length); | |
| 317 CompilationUnit newUnit = _parseUnit(newCode); | |
| 318 // replace the node | |
| 319 AstNode oldNode = _findNodeAt(unit, offset, predicate); | |
|
Brian Wilkerson
2014/11/20 15:38:39
This concerns me because it doesn't necessarily ma
scheglov
2014/11/20 16:13:17
We need to discuss this offline.
| |
| 320 AstNode newNode = _findNodeAt(newUnit, offset, predicate); | |
| 321 bool success = NodeReplacer.replace(oldNode, newNode); | |
| 322 expect(success, isTrue); | |
| 323 // do incremental resolution | |
| 272 GatheringErrorListener errorListener = new GatheringErrorListener(); | 324 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 325 // TODO(scheglov) use 'replacement' to update elements offsets | |
| 273 IncrementalResolver resolver = | 326 IncrementalResolver resolver = |
| 274 new IncrementalResolver(library, source, typeProvider, errorListener); | 327 new IncrementalResolver(library, source, typeProvider, errorListener); |
| 275 resolver.resolve(method.body); | 328 resolver.resolve(newNode); |
| 276 return method; | 329 // resolve "newCode" from scratch |
| 330 CompilationUnit fullNewUnit; | |
| 331 { | |
| 332 source = addSource(newCode); | |
| 333 LibraryElement library = resolve(source); | |
| 334 fullNewUnit = resolveCompilationUnit(source, library); | |
| 335 } | |
| 336 _SameResolutionValidator.assertSameResolution(unit, fullNewUnit); | |
| 337 } | |
| 338 | |
| 339 void _resolveUnit(String code) { | |
| 340 this.code = code; | |
| 341 source = addSource(code); | |
| 342 library = resolve(source); | |
| 343 unit = resolveCompilationUnit(source, library); | |
| 344 } | |
| 345 | |
| 346 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset, | |
| 347 Predicate<AstNode> predicate) { | |
| 348 NodeLocator locator = new NodeLocator.con1(offset); | |
| 349 AstNode node = locator.searchWithin(oldUnit); | |
| 350 return node.getAncestor(predicate); | |
| 351 } | |
| 352 | |
| 353 static bool _isBlock(AstNode node) => node is Block; | |
| 354 | |
| 355 static bool _isFunctionBody(AstNode node) => node is FunctionBody; | |
| 356 | |
| 357 static bool _isStatement(AstNode node) => node is Statement; | |
| 358 | |
| 359 static CompilationUnit _parseUnit(String code) { | |
| 360 var errorListener = new BooleanErrorListener(); | |
| 361 var reader = new CharSequenceReader(code); | |
| 362 var scanner = new Scanner(null, reader, errorListener); | |
| 363 var token = scanner.tokenize(); | |
| 364 var parser = new Parser(null, errorListener); | |
| 365 return parser.parseCompilationUnit(token); | |
| 277 } | 366 } |
| 278 } | 367 } |
| 279 | 368 |
| 369 | |
| 280 class ScopeBuilderTest extends EngineTestCase { | 370 class ScopeBuilderTest extends EngineTestCase { |
| 281 void test_scopeFor_ClassDeclaration() { | 371 void test_scopeFor_ClassDeclaration() { |
| 282 GatheringErrorListener listener = new GatheringErrorListener(); | 372 GatheringErrorListener listener = new GatheringErrorListener(); |
| 283 Scope scope = | 373 Scope scope = |
| 284 ScopeBuilder.scopeFor(_createResolvedClassDeclaration(), listener); | 374 ScopeBuilder.scopeFor(_createResolvedClassDeclaration(), listener); |
| 285 EngineTestCase.assertInstanceOf( | 375 EngineTestCase.assertInstanceOf( |
| 286 (obj) => obj is LibraryScope, | 376 (obj) => obj is LibraryScope, |
| 287 LibraryScope, | 377 LibraryScope, |
| 288 scope); | 378 scope); |
| 289 } | 379 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 AstFactory.formalParameterList()); | 617 AstFactory.formalParameterList()); |
| 528 classNode.members.add(methodNode); | 618 classNode.members.add(methodNode); |
| 529 MethodElement methodElement = | 619 MethodElement methodElement = |
| 530 ElementFactory.methodElement(methodName, null); | 620 ElementFactory.methodElement(methodName, null); |
| 531 methodNode.name.staticElement = methodElement; | 621 methodNode.name.staticElement = methodElement; |
| 532 (classNode.element as ClassElementImpl).methods = | 622 (classNode.element as ClassElementImpl).methods = |
| 533 <MethodElement>[methodElement]; | 623 <MethodElement>[methodElement]; |
| 534 return methodNode; | 624 return methodNode; |
| 535 } | 625 } |
| 536 } | 626 } |
| 627 | |
| 628 | |
| 629 class _Edit { | |
| 630 final int offset; | |
| 631 final int length; | |
| 632 final String replacement; | |
| 633 _Edit(this.offset, this.length, this.replacement); | |
| 634 } | |
| 635 | |
| 636 class _SameResolutionValidator implements AstVisitor { | |
| 637 AstNode other; | |
| 638 | |
| 639 _SameResolutionValidator(this.other); | |
| 640 | |
| 641 @override | |
| 642 visitAdjacentStrings(AdjacentStrings node) { | |
| 643 } | |
| 644 | |
| 645 @override | |
| 646 visitAnnotation(Annotation node) { | |
| 647 Annotation other = this.other; | |
| 648 _vN(node.name, other.name); | |
| 649 _vN(node.constructorName, other.constructorName); | |
| 650 _vN(node.arguments, other.arguments); | |
| 651 _vE(node.element, other.element); | |
| 652 } | |
| 653 | |
| 654 @override | |
| 655 visitArgumentList(ArgumentList node) { | |
| 656 ArgumentList other = this.other; | |
| 657 _vL(node.arguments, other.arguments); | |
| 658 } | |
| 659 | |
| 660 @override | |
| 661 visitAsExpression(AsExpression node) { | |
| 662 AsExpression other = this.other; | |
| 663 _vEP(node, other); | |
| 664 _vN(node.expression, other.expression); | |
| 665 _vN(node.type, other.type); | |
| 666 } | |
| 667 | |
| 668 @override | |
| 669 visitAssertStatement(AssertStatement node) { | |
| 670 AssertStatement other = this.other; | |
| 671 _vN(node.condition, other.condition); | |
| 672 } | |
| 673 | |
| 674 @override | |
| 675 visitAssignmentExpression(AssignmentExpression node) { | |
| 676 AssignmentExpression other = this.other; | |
| 677 _vEP(node, other); | |
| 678 _vE(node.staticElement, other.staticElement); | |
| 679 _vE(node.propagatedElement, other.propagatedElement); | |
| 680 _vN(node.leftHandSide, other.leftHandSide); | |
| 681 _vN(node.rightHandSide, other.rightHandSide); | |
| 682 } | |
| 683 | |
| 684 @override | |
| 685 visitAwaitExpression(AwaitExpression node) { | |
| 686 AwaitExpression other = this.other; | |
| 687 _vEP(node, other); | |
| 688 _vN(node.expression, other.expression); | |
| 689 } | |
| 690 | |
| 691 @override | |
| 692 visitBinaryExpression(BinaryExpression node) { | |
| 693 BinaryExpression other = this.other; | |
| 694 _vEP(node, other); | |
| 695 _vE(node.staticElement, other.staticElement); | |
| 696 _vE(node.propagatedElement, other.propagatedElement); | |
| 697 _vN(node.leftOperand, other.leftOperand); | |
| 698 _vN(node.rightOperand, other.rightOperand); | |
| 699 } | |
| 700 | |
| 701 @override | |
| 702 visitBlock(Block node) { | |
| 703 Block other = this.other; | |
| 704 _vL(node.statements, other.statements); | |
| 705 } | |
| 706 | |
| 707 @override | |
| 708 visitBlockFunctionBody(BlockFunctionBody node) { | |
| 709 BlockFunctionBody other = this.other; | |
| 710 _vN(node.block, other.block); | |
| 711 } | |
| 712 | |
| 713 @override | |
| 714 visitBooleanLiteral(BooleanLiteral node) { | |
| 715 BooleanLiteral other = this.other; | |
| 716 _vEP(node, other); | |
| 717 } | |
| 718 | |
| 719 @override | |
| 720 visitBreakStatement(BreakStatement node) { | |
| 721 BreakStatement other = this.other; | |
| 722 _vN(node.label, other.label); | |
| 723 } | |
| 724 | |
| 725 @override | |
| 726 visitCascadeExpression(CascadeExpression node) { | |
| 727 CascadeExpression other = this.other; | |
| 728 _vEP(node, other); | |
| 729 _vN(node.target, other.target); | |
| 730 _vL(node.cascadeSections, other.cascadeSections); | |
| 731 } | |
| 732 | |
| 733 @override | |
| 734 visitCatchClause(CatchClause node) { | |
| 735 CatchClause other = this.other; | |
| 736 _vN(node.exceptionType, other.exceptionType); | |
| 737 _vN(node.exceptionParameter, other.exceptionParameter); | |
| 738 _vN(node.stackTraceParameter, other.stackTraceParameter); | |
| 739 _vN(node.body, other.body); | |
| 740 } | |
| 741 | |
| 742 @override | |
| 743 visitClassDeclaration(ClassDeclaration node) { | |
| 744 ClassDeclaration other = this.other; | |
| 745 _vN(node.name, other.name); | |
| 746 _vN(node.typeParameters, other.typeParameters); | |
| 747 _vN(node.extendsClause, other.extendsClause); | |
| 748 _vN(node.implementsClause, other.implementsClause); | |
| 749 _vN(node.withClause, other.withClause); | |
| 750 _vL(node.members, other.members); | |
| 751 } | |
| 752 | |
| 753 @override | |
| 754 visitClassTypeAlias(ClassTypeAlias node) { | |
| 755 ClassTypeAlias other = this.other; | |
| 756 _vE(node.element, other.element); | |
| 757 _vN(node.name, other.name); | |
| 758 _vN(node.typeParameters, other.typeParameters); | |
| 759 _vN(node.superclass, other.superclass); | |
| 760 _vN(node.withClause, other.withClause); | |
| 761 } | |
| 762 | |
| 763 @override | |
| 764 visitComment(Comment node) { | |
| 765 Comment other = this.other; | |
| 766 _vL(node.references, other.references); | |
| 767 } | |
| 768 | |
| 769 @override | |
| 770 visitCommentReference(CommentReference node) { | |
| 771 CommentReference other = this.other; | |
| 772 _vN(node.identifier, other.identifier); | |
| 773 } | |
| 774 | |
| 775 @override | |
| 776 visitCompilationUnit(CompilationUnit node) { | |
| 777 CompilationUnit other = this.other; | |
| 778 _vE(node.element, other.element); | |
| 779 _vL(node.directives, other.directives); | |
| 780 _vL(node.declarations, other.declarations); | |
| 781 } | |
| 782 | |
| 783 @override | |
| 784 visitConditionalExpression(ConditionalExpression node) { | |
| 785 ConditionalExpression other = this.other; | |
| 786 _vEP(node, other); | |
| 787 _vN(node.condition, other.condition); | |
| 788 _vN(node.thenExpression, other.thenExpression); | |
| 789 _vN(node.elseExpression, other.elseExpression); | |
| 790 } | |
| 791 | |
| 792 @override | |
| 793 visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 794 ConstructorDeclaration other = this.other; | |
| 795 _vE(node.element, other.element); | |
| 796 _vN(node.returnType, other.returnType); | |
| 797 _vN(node.name, other.name); | |
| 798 _vN(node.parameters, other.parameters); | |
| 799 _vN(node.redirectedConstructor, other.redirectedConstructor); | |
| 800 _vL(node.initializers, other.initializers); | |
| 801 } | |
| 802 | |
| 803 @override | |
| 804 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 805 ConstructorFieldInitializer other = this.other; | |
| 806 _vN(node.fieldName, other.fieldName); | |
| 807 _vN(node.expression, other.expression); | |
| 808 } | |
| 809 | |
| 810 @override | |
| 811 visitConstructorName(ConstructorName node) { | |
| 812 ConstructorName other = this.other; | |
| 813 _vE(node.staticElement, other.staticElement); | |
| 814 _vN(node.type, other.type); | |
| 815 _vN(node.name, other.name); | |
| 816 } | |
| 817 | |
| 818 @override | |
| 819 visitContinueStatement(ContinueStatement node) { | |
| 820 ContinueStatement other = this.other; | |
| 821 _vN(node.label, other.label); | |
| 822 } | |
| 823 | |
| 824 @override | |
| 825 visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 826 DeclaredIdentifier other = this.other; | |
| 827 _vN(node.type, other.type); | |
| 828 _vN(node.identifier, other.identifier); | |
| 829 } | |
| 830 | |
| 831 @override | |
| 832 visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 833 DefaultFormalParameter other = this.other; | |
| 834 _vN(node.parameter, other.parameter); | |
| 835 _vN(node.defaultValue, other.defaultValue); | |
| 836 } | |
| 837 | |
| 838 @override | |
| 839 visitDoStatement(DoStatement node) { | |
| 840 DoStatement other = this.other; | |
| 841 _vN(node.condition, other.condition); | |
| 842 _vN(node.body, other.body); | |
| 843 } | |
| 844 | |
| 845 @override | |
| 846 visitDoubleLiteral(DoubleLiteral node) { | |
| 847 DoubleLiteral other = this.other; | |
| 848 _vEP(node, other); | |
| 849 } | |
| 850 | |
| 851 @override | |
| 852 visitEmptyFunctionBody(EmptyFunctionBody node) { | |
| 853 } | |
| 854 | |
| 855 @override | |
| 856 visitEmptyStatement(EmptyStatement node) { | |
| 857 } | |
| 858 | |
| 859 @override | |
| 860 visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 861 EnumConstantDeclaration other = this.other; | |
| 862 _vDeclaration(node, other); | |
| 863 _vN(node.name, other.name); | |
| 864 } | |
| 865 | |
| 866 @override | |
| 867 visitEnumDeclaration(EnumDeclaration node) { | |
| 868 EnumDeclaration other = this.other; | |
| 869 _vDeclaration(node, other); | |
| 870 _vN(node.name, other.name); | |
| 871 _vL(node.constants, other.constants); | |
| 872 } | |
| 873 | |
| 874 @override | |
| 875 visitExportDirective(ExportDirective node) { | |
| 876 ExportDirective other = this.other; | |
| 877 _vDirective(node, other); | |
| 878 } | |
| 879 | |
| 880 @override | |
| 881 visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 882 ExpressionFunctionBody other = this.other; | |
| 883 _vN(node.expression, other.expression); | |
| 884 } | |
| 885 | |
| 886 @override | |
| 887 visitExpressionStatement(ExpressionStatement node) { | |
| 888 ExpressionStatement other = this.other; | |
| 889 _vN(node.expression, other.expression); | |
| 890 } | |
| 891 | |
| 892 @override | |
| 893 visitExtendsClause(ExtendsClause node) { | |
| 894 ExtendsClause other = this.other; | |
| 895 _vN(node.superclass, other.superclass); | |
| 896 } | |
| 897 | |
| 898 @override | |
| 899 visitFieldDeclaration(FieldDeclaration node) { | |
| 900 FieldDeclaration other = this.other; | |
| 901 _vN(node.fields, other.fields); | |
| 902 } | |
| 903 | |
| 904 @override | |
| 905 visitFieldFormalParameter(FieldFormalParameter node) { | |
| 906 FieldFormalParameter other = this.other; | |
| 907 _visitNormalFormalParameter(node, other); | |
| 908 _vN(node.type, other.type); | |
| 909 _vN(node.parameters, other.parameters); | |
| 910 } | |
| 911 | |
| 912 @override | |
| 913 visitForEachStatement(ForEachStatement node) { | |
| 914 ForEachStatement other = this.other; | |
| 915 _vN(node.identifier, other.identifier); | |
| 916 _vN(node.loopVariable, other.loopVariable); | |
| 917 _vN(node.iterable, other.iterable); | |
| 918 } | |
| 919 | |
| 920 @override | |
| 921 visitFormalParameterList(FormalParameterList node) { | |
| 922 FormalParameterList other = this.other; | |
| 923 _vL(node.parameters, other.parameters); | |
| 924 } | |
| 925 | |
| 926 @override | |
| 927 visitForStatement(ForStatement node) { | |
| 928 ForStatement other = this.other; | |
| 929 _vN(node.variables, other.variables); | |
| 930 _vN(node.initialization, other.initialization); | |
| 931 _vN(node.condition, other.condition); | |
| 932 _vL(node.updaters, other.updaters); | |
| 933 _vN(node.body, other.body); | |
| 934 } | |
| 935 | |
| 936 @override | |
| 937 visitFunctionDeclaration(FunctionDeclaration node) { | |
| 938 FunctionDeclaration other = this.other; | |
| 939 _vDeclaration(node, other); | |
| 940 _vN(node.returnType, other.returnType); | |
| 941 _vN(node.name, other.name); | |
| 942 _vN(node.functionExpression, other.functionExpression); | |
| 943 } | |
| 944 | |
| 945 @override | |
| 946 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 947 FunctionDeclarationStatement other = this.other; | |
| 948 _vN(node.functionDeclaration, other.functionDeclaration); | |
| 949 } | |
| 950 | |
| 951 @override | |
| 952 visitFunctionExpression(FunctionExpression node) { | |
| 953 FunctionExpression other = this.other; | |
| 954 _vEP(node, other); | |
| 955 _vE(node.element, other.element); | |
| 956 _vN(node.parameters, other.parameters); | |
| 957 _vN(node.body, other.body); | |
| 958 } | |
| 959 | |
| 960 @override | |
| 961 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 962 FunctionExpressionInvocation other = this.other; | |
| 963 _vEP(node, other); | |
| 964 _vE(node.staticElement, other.staticElement); | |
| 965 _vE(node.propagatedElement, other.propagatedElement); | |
| 966 _vN(node.function, other.function); | |
| 967 _vN(node.argumentList, other.argumentList); | |
| 968 } | |
| 969 | |
| 970 @override | |
| 971 visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 972 FunctionTypeAlias other = this.other; | |
| 973 _vDeclaration(node, other); | |
| 974 _vN(node.returnType, other.returnType); | |
| 975 _vN(node.name, other.name); | |
| 976 _vN(node.typeParameters, other.typeParameters); | |
| 977 _vN(node.parameters, other.parameters); | |
| 978 } | |
| 979 | |
| 980 @override | |
| 981 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 982 FunctionTypedFormalParameter other = this.other; | |
| 983 _visitNormalFormalParameter(node, other); | |
| 984 _vN(node.returnType, other.returnType); | |
| 985 _vN(node.parameters, other.parameters); | |
| 986 } | |
| 987 | |
| 988 @override | |
| 989 visitHideCombinator(HideCombinator node) { | |
| 990 HideCombinator other = this.other; | |
| 991 _vL(node.hiddenNames, other.hiddenNames); | |
| 992 } | |
| 993 | |
| 994 @override | |
| 995 visitIfStatement(IfStatement node) { | |
| 996 IfStatement other = this.other; | |
| 997 _vN(node.condition, other.condition); | |
| 998 _vN(node.thenStatement, other.thenStatement); | |
| 999 _vN(node.elseStatement, other.elseStatement); | |
| 1000 } | |
| 1001 | |
| 1002 @override | |
| 1003 visitImplementsClause(ImplementsClause node) { | |
| 1004 ImplementsClause other = this.other; | |
| 1005 _vL(node.interfaces, other.interfaces); | |
| 1006 } | |
| 1007 | |
| 1008 @override | |
| 1009 visitImportDirective(ImportDirective node) { | |
| 1010 ImportDirective other = this.other; | |
| 1011 _vDirective(node, other); | |
| 1012 _vN(node.prefix, other.prefix); | |
| 1013 _vE(node.uriElement, other.uriElement); | |
| 1014 } | |
| 1015 | |
| 1016 @override | |
| 1017 visitIndexExpression(IndexExpression node) { | |
| 1018 IndexExpression other = this.other; | |
| 1019 _vEP(node, other); | |
| 1020 _vE(node.staticElement, other.staticElement); | |
| 1021 _vE(node.propagatedElement, other.propagatedElement); | |
| 1022 _vN(node.target, other.target); | |
| 1023 _vN(node.index, other.index); | |
| 1024 } | |
| 1025 | |
| 1026 @override | |
| 1027 visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 1028 InstanceCreationExpression other = this.other; | |
| 1029 _vEP(node, other); | |
| 1030 _vE(node.staticElement, other.staticElement); | |
| 1031 _vN(node.constructorName, other.constructorName); | |
| 1032 _vN(node.argumentList, other.argumentList); | |
| 1033 } | |
| 1034 | |
| 1035 @override | |
| 1036 visitIntegerLiteral(IntegerLiteral node) { | |
| 1037 IntegerLiteral other = this.other; | |
| 1038 _vEP(node, other); | |
| 1039 } | |
| 1040 | |
| 1041 @override | |
| 1042 visitInterpolationExpression(InterpolationExpression node) { | |
| 1043 InterpolationExpression other = this.other; | |
| 1044 _vN(node.expression, other.expression); | |
| 1045 } | |
| 1046 | |
| 1047 @override | |
| 1048 visitInterpolationString(InterpolationString node) { | |
| 1049 } | |
| 1050 | |
| 1051 @override | |
| 1052 visitIsExpression(IsExpression node) { | |
| 1053 IsExpression other = this.other; | |
| 1054 _vEP(node, other); | |
| 1055 _vN(node.expression, other.expression); | |
| 1056 _vN(node.type, other.type); | |
| 1057 } | |
| 1058 | |
| 1059 @override | |
| 1060 visitLabel(Label node) { | |
| 1061 Label other = this.other; | |
| 1062 _vN(node.label, other.label); | |
| 1063 } | |
| 1064 | |
| 1065 @override | |
| 1066 visitLabeledStatement(LabeledStatement node) { | |
| 1067 LabeledStatement other = this.other; | |
| 1068 _vL(node.labels, other.labels); | |
| 1069 _vN(node.statement, other.statement); | |
| 1070 } | |
| 1071 | |
| 1072 @override | |
| 1073 visitLibraryDirective(LibraryDirective node) { | |
| 1074 LibraryDirective other = this.other; | |
| 1075 _vDirective(node, other); | |
| 1076 _vN(node.name, other.name); | |
| 1077 } | |
| 1078 | |
| 1079 @override | |
| 1080 visitLibraryIdentifier(LibraryIdentifier node) { | |
| 1081 LibraryIdentifier other = this.other; | |
| 1082 _vL(node.components, other.components); | |
| 1083 } | |
| 1084 | |
| 1085 @override | |
| 1086 visitListLiteral(ListLiteral node) { | |
| 1087 ListLiteral other = this.other; | |
| 1088 _vEP(node, other); | |
| 1089 _vL(node.elements, other.elements); | |
| 1090 } | |
| 1091 | |
| 1092 @override | |
| 1093 visitMapLiteral(MapLiteral node) { | |
| 1094 MapLiteral other = this.other; | |
| 1095 _vEP(node, other); | |
| 1096 _vL(node.entries, other.entries); | |
| 1097 } | |
| 1098 | |
| 1099 @override | |
| 1100 visitMapLiteralEntry(MapLiteralEntry node) { | |
| 1101 MapLiteralEntry other = this.other; | |
| 1102 _vN(node.key, other.key); | |
| 1103 _vN(node.value, other.value); | |
| 1104 } | |
| 1105 | |
| 1106 @override | |
| 1107 visitMethodDeclaration(MethodDeclaration node) { | |
| 1108 MethodDeclaration other = this.other; | |
| 1109 _vN(node.name, other.name); | |
| 1110 _vN(node.parameters, other.parameters); | |
| 1111 _vN(node.body, other.body); | |
| 1112 } | |
| 1113 | |
| 1114 @override | |
| 1115 visitMethodInvocation(MethodInvocation node) { | |
| 1116 MethodInvocation other = this.other; | |
| 1117 _vN(node.target, other.target); | |
| 1118 _vN(node.methodName, other.methodName); | |
| 1119 _vN(node.argumentList, other.argumentList); | |
| 1120 } | |
| 1121 | |
| 1122 @override | |
| 1123 visitNamedExpression(NamedExpression node) { | |
| 1124 NamedExpression other = this.other; | |
| 1125 _vN(node.name, other.name); | |
| 1126 _vN(node.expression, other.expression); | |
| 1127 } | |
| 1128 | |
| 1129 @override | |
| 1130 visitNativeClause(NativeClause node) { | |
| 1131 } | |
| 1132 | |
| 1133 @override | |
| 1134 visitNativeFunctionBody(NativeFunctionBody node) { | |
| 1135 } | |
| 1136 | |
| 1137 @override | |
| 1138 visitNullLiteral(NullLiteral node) { | |
| 1139 NullLiteral other = this.other; | |
| 1140 _vEP(node, other); | |
| 1141 } | |
| 1142 | |
| 1143 @override | |
| 1144 visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 1145 ParenthesizedExpression other = this.other; | |
| 1146 _vN(node.expression, other.expression); | |
| 1147 } | |
| 1148 | |
| 1149 @override | |
| 1150 visitPartDirective(PartDirective node) { | |
| 1151 PartDirective other = this.other; | |
| 1152 _vDirective(node, other); | |
| 1153 } | |
| 1154 | |
| 1155 @override | |
| 1156 visitPartOfDirective(PartOfDirective node) { | |
| 1157 PartOfDirective other = this.other; | |
| 1158 _vDirective(node, other); | |
| 1159 _vN(node.libraryName, other.libraryName); | |
| 1160 } | |
| 1161 | |
| 1162 @override | |
| 1163 visitPostfixExpression(PostfixExpression node) { | |
| 1164 PostfixExpression other = this.other; | |
| 1165 _vEP(node, other); | |
| 1166 _vE(node.staticElement, other.staticElement); | |
| 1167 _vE(node.propagatedElement, other.propagatedElement); | |
| 1168 _vN(node.operand, other.operand); | |
| 1169 } | |
| 1170 | |
| 1171 @override | |
| 1172 visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 1173 PrefixedIdentifier other = this.other; | |
| 1174 _vEP(node, other); | |
| 1175 _vN(node.prefix, other.prefix); | |
| 1176 _vN(node.identifier, other.identifier); | |
| 1177 } | |
| 1178 | |
| 1179 @override | |
| 1180 visitPrefixExpression(PrefixExpression node) { | |
| 1181 PrefixExpression other = this.other; | |
| 1182 _vEP(node, other); | |
| 1183 _vE(node.staticElement, other.staticElement); | |
| 1184 _vE(node.propagatedElement, other.propagatedElement); | |
| 1185 _vN(node.operand, other.operand); | |
| 1186 } | |
| 1187 | |
| 1188 @override | |
| 1189 visitPropertyAccess(PropertyAccess node) { | |
| 1190 PropertyAccess other = this.other; | |
| 1191 _vEP(node, other); | |
| 1192 _vN(node.target, other.target); | |
| 1193 _vN(node.propertyName, other.propertyName); | |
| 1194 } | |
| 1195 | |
| 1196 @override | |
| 1197 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { | |
| 1198 RedirectingConstructorInvocation other = this.other; | |
| 1199 _vE(node.staticElement, other.staticElement); | |
| 1200 _vN(node.constructorName, other.constructorName); | |
| 1201 _vN(node.argumentList, other.argumentList); | |
| 1202 } | |
| 1203 | |
| 1204 @override | |
| 1205 visitRethrowExpression(RethrowExpression node) { | |
| 1206 RethrowExpression other = this.other; | |
| 1207 _vEP(node, other); | |
| 1208 } | |
| 1209 | |
| 1210 @override | |
| 1211 visitReturnStatement(ReturnStatement node) { | |
| 1212 ReturnStatement other = this.other; | |
| 1213 _vN(node.expression, other.expression); | |
| 1214 } | |
| 1215 | |
| 1216 @override | |
| 1217 visitScriptTag(ScriptTag node) { | |
| 1218 } | |
| 1219 | |
| 1220 @override | |
| 1221 visitShowCombinator(ShowCombinator node) { | |
| 1222 ShowCombinator other = this.other; | |
| 1223 _vL(node.shownNames, other.shownNames); | |
| 1224 } | |
| 1225 | |
| 1226 @override | |
| 1227 visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 1228 SimpleFormalParameter other = this.other; | |
| 1229 _visitNormalFormalParameter(node, other); | |
| 1230 _vN(node.type, other.type); | |
| 1231 } | |
| 1232 | |
| 1233 @override | |
| 1234 visitSimpleIdentifier(SimpleIdentifier node) { | |
| 1235 SimpleIdentifier other = this.other; | |
| 1236 _vE(node.staticElement, other.staticElement); | |
| 1237 _vE(node.propagatedElement, other.propagatedElement); | |
| 1238 _vEP(node, other); | |
| 1239 } | |
| 1240 | |
| 1241 @override | |
| 1242 visitSimpleStringLiteral(SimpleStringLiteral node) { | |
| 1243 } | |
| 1244 | |
| 1245 @override | |
| 1246 visitStringInterpolation(StringInterpolation node) { | |
| 1247 StringInterpolation other = this.other; | |
| 1248 _vL(node.elements, other.elements); | |
| 1249 } | |
| 1250 | |
| 1251 @override | |
| 1252 visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 1253 SuperConstructorInvocation other = this.other; | |
| 1254 _vE(node.staticElement, other.staticElement); | |
| 1255 _vN(node.constructorName, other.constructorName); | |
| 1256 _vN(node.argumentList, other.argumentList); | |
| 1257 } | |
| 1258 | |
| 1259 @override | |
| 1260 visitSuperExpression(SuperExpression node) { | |
| 1261 SuperExpression other = this.other; | |
| 1262 _vEP(node, other); | |
| 1263 } | |
| 1264 | |
| 1265 @override | |
| 1266 visitSwitchCase(SwitchCase node) { | |
| 1267 SwitchCase other = this.other; | |
| 1268 _vL(node.labels, other.labels); | |
| 1269 _vN(node.expression, other.expression); | |
| 1270 _vL(node.statements, other.statements); | |
| 1271 } | |
| 1272 | |
| 1273 @override | |
| 1274 visitSwitchDefault(SwitchDefault node) { | |
| 1275 SwitchDefault other = this.other; | |
| 1276 _vL(node.statements, other.statements); | |
| 1277 } | |
| 1278 | |
| 1279 @override | |
| 1280 visitSwitchStatement(SwitchStatement node) { | |
| 1281 SwitchStatement other = this.other; | |
| 1282 _vN(node.expression, other.expression); | |
| 1283 _vL(node.members, other.members); | |
| 1284 } | |
| 1285 | |
| 1286 @override | |
| 1287 visitSymbolLiteral(SymbolLiteral node) { | |
| 1288 } | |
| 1289 | |
| 1290 @override | |
| 1291 visitThisExpression(ThisExpression node) { | |
| 1292 ThisExpression other = this.other; | |
| 1293 _vEP(node, other); | |
| 1294 } | |
| 1295 | |
| 1296 @override | |
| 1297 visitThrowExpression(ThrowExpression node) { | |
| 1298 ThrowExpression other = this.other; | |
| 1299 _vN(node.expression, other.expression); | |
| 1300 } | |
| 1301 | |
| 1302 @override | |
| 1303 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 1304 TopLevelVariableDeclaration other = this.other; | |
| 1305 _vN(node.variables, other.variables); | |
| 1306 } | |
| 1307 | |
| 1308 @override | |
| 1309 visitTryStatement(TryStatement node) { | |
| 1310 TryStatement other = this.other; | |
| 1311 _vN(node.body, other.body); | |
| 1312 _vL(node.catchClauses, other.catchClauses); | |
| 1313 _vN(node.finallyBlock, other.finallyBlock); | |
| 1314 } | |
| 1315 | |
| 1316 @override | |
| 1317 visitTypeArgumentList(TypeArgumentList node) { | |
| 1318 TypeArgumentList other = this.other; | |
| 1319 _vL(node.arguments, other.arguments); | |
| 1320 } | |
| 1321 | |
| 1322 @override | |
| 1323 visitTypeName(TypeName node) { | |
| 1324 TypeName other = this.other; | |
| 1325 _safeT(node.type, other.type); | |
| 1326 _vN(node.name, node.name); | |
| 1327 _vN(node.typeArguments, other.typeArguments); | |
| 1328 } | |
| 1329 | |
| 1330 @override | |
| 1331 visitTypeParameter(TypeParameter node) { | |
| 1332 TypeParameter other = this.other; | |
| 1333 _vN(node.name, other.name); | |
| 1334 _vN(node.bound, other.bound); | |
| 1335 } | |
| 1336 | |
| 1337 @override | |
| 1338 visitTypeParameterList(TypeParameterList node) { | |
| 1339 TypeParameterList other = this.other; | |
| 1340 _vL(node.typeParameters, other.typeParameters); | |
| 1341 } | |
| 1342 | |
| 1343 @override | |
| 1344 visitVariableDeclaration(VariableDeclaration node) { | |
| 1345 VariableDeclaration other = this.other; | |
| 1346 _vN(node.name, other.name); | |
| 1347 _vN(node.initializer, other.initializer); | |
| 1348 } | |
| 1349 | |
| 1350 @override | |
| 1351 visitVariableDeclarationList(VariableDeclarationList node) { | |
| 1352 VariableDeclarationList other = this.other; | |
| 1353 _vN(node.type, other.type); | |
| 1354 _vL(node.variables, other.variables); | |
| 1355 } | |
| 1356 | |
| 1357 @override | |
| 1358 visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 1359 VariableDeclarationStatement other = this.other; | |
| 1360 _vN(node.variables, other.variables); | |
| 1361 } | |
| 1362 | |
| 1363 @override | |
| 1364 visitWhileStatement(WhileStatement node) { | |
| 1365 WhileStatement other = this.other; | |
| 1366 _vN(node.condition, other.condition); | |
| 1367 _vN(node.body, other.body); | |
| 1368 } | |
| 1369 | |
| 1370 @override | |
| 1371 visitWithClause(WithClause node) { | |
| 1372 WithClause other = this.other; | |
| 1373 _vL(node.mixinTypes, other.mixinTypes); | |
| 1374 } | |
| 1375 | |
| 1376 @override | |
| 1377 visitYieldStatement(YieldStatement node) { | |
| 1378 YieldStatement other = this.other; | |
| 1379 _vN(node.expression, other.expression); | |
| 1380 } | |
| 1381 | |
| 1382 void _safeT(DartType a, DartType b) { | |
|
Brian Wilkerson
2014/11/20 15:38:39
These single letter abbreviations ("T" for type, "
scheglov
2014/11/20 16:13:17
Thank you.
I forgot to rename these.
Fixed.
| |
| 1383 expect(a, equals(b)); | |
| 1384 } | |
| 1385 | |
| 1386 void _vAnnotatedNode(AnnotatedNode node, AnnotatedNode other) { | |
| 1387 _vN(node.documentationComment, other.documentationComment); | |
| 1388 _vL(node.metadata, other.metadata); | |
| 1389 } | |
| 1390 | |
| 1391 _vDeclaration(Declaration node, Declaration other) { | |
| 1392 _vE(node.element, other.element); | |
| 1393 _vAnnotatedNode(node, other); | |
| 1394 } | |
| 1395 | |
| 1396 _vDirective(Directive node, Directive other) { | |
| 1397 _vE(node.element, other.element); | |
| 1398 _vAnnotatedNode(node, other); | |
| 1399 } | |
| 1400 | |
| 1401 void _vE(Element a, Element b) { | |
| 1402 if (a != b) { | |
| 1403 fail('Expected: $b\n Actual: $a'); | |
| 1404 } | |
| 1405 if (a == null && b == null) { | |
| 1406 return; | |
| 1407 } | |
| 1408 // TODO(scheglov) uncomment when implement elements shifting | |
| 1409 // expect(a.nameOffset, b.nameOffset); | |
| 1410 } | |
| 1411 | |
| 1412 void _vEP(Expression a, Expression b) { | |
| 1413 _safeT(a.staticType, b.staticType); | |
| 1414 _safeT(a.propagatedType, b.propagatedType); | |
| 1415 _vE(a.staticParameterElement, b.staticParameterElement); | |
| 1416 _vE(a.propagatedParameterElement, b.propagatedParameterElement); | |
| 1417 } | |
| 1418 | |
| 1419 void _visitNormalFormalParameter(NormalFormalParameter node, | |
| 1420 NormalFormalParameter other) { | |
| 1421 _vN(node.documentationComment, other.documentationComment); | |
| 1422 _vL(node.metadata, other.metadata); | |
| 1423 _vN(node.identifier, other.identifier); | |
| 1424 } | |
| 1425 | |
| 1426 void _vL(NodeList nodeList, NodeList otherList) { | |
| 1427 int length = nodeList.length; | |
| 1428 expect(otherList, hasLength(length)); | |
| 1429 for (int i = 0; i < length; i++) { | |
| 1430 _vN(nodeList[i], otherList[i]); | |
| 1431 } | |
| 1432 } | |
| 1433 | |
| 1434 void _vN(AstNode node, AstNode other) { | |
| 1435 if (node == null) { | |
| 1436 expect(other, isNull); | |
| 1437 } else { | |
| 1438 this.other = other; | |
| 1439 node.accept(this); | |
| 1440 } | |
| 1441 } | |
| 1442 | |
| 1443 static void assertSameResolution(CompilationUnit actual, | |
| 1444 CompilationUnit expected) { | |
| 1445 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | |
| 1446 actual.accept(validator); | |
| 1447 } | |
| 1448 } | |
| OLD | NEW |