| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); | 541 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); |
| 542 } | 542 } |
| 543 // Validate members. | 543 // Validate members. |
| 544 if (oImpl is Member) { | 544 if (oImpl is Member) { |
| 545 expect(rImpl, new isInstanceOf<Member>(), reason: desc); | 545 expect(rImpl, new isInstanceOf<Member>(), reason: desc); |
| 546 } else { | 546 } else { |
| 547 expect(rImpl, isNot(new isInstanceOf<Member>()), reason: desc); | 547 expect(rImpl, isNot(new isInstanceOf<Member>()), reason: desc); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 void compareExecutableElements( | 551 void compareExecutableElements(ExecutableElement resynthesized, |
| 552 ExecutableElement resynthesized, ExecutableElement original, String desc, | 552 ExecutableElement original, String desc) { |
| 553 {bool compareReturnTypes: true}) { | |
| 554 compareElements(resynthesized, original, desc); | 553 compareElements(resynthesized, original, desc); |
| 555 compareParameterElementLists( | 554 compareParameterElementLists( |
| 556 resynthesized.parameters, original.parameters, desc); | 555 resynthesized.parameters, original.parameters, desc); |
| 557 // TODO(scheglov) remove the condition once initializers have return types. | 556 compareTypes( |
| 558 if (compareReturnTypes) { | 557 resynthesized.returnType, original.returnType, '$desc return type'); |
| 559 compareTypes( | |
| 560 resynthesized.returnType, original.returnType, '$desc return type'); | |
| 561 } | |
| 562 compareTypes(resynthesized.type, original.type, desc); | 558 compareTypes(resynthesized.type, original.type, desc); |
| 563 expect(resynthesized.typeParameters.length, original.typeParameters.length); | 559 expect(resynthesized.typeParameters.length, original.typeParameters.length); |
| 564 for (int i = 0; i < resynthesized.typeParameters.length; i++) { | 560 for (int i = 0; i < resynthesized.typeParameters.length; i++) { |
| 565 compareTypeParameterElements( | 561 compareTypeParameterElements( |
| 566 resynthesized.typeParameters[i], | 562 resynthesized.typeParameters[i], |
| 567 original.typeParameters[i], | 563 original.typeParameters[i], |
| 568 '$desc type parameter ${original.typeParameters[i].name}'); | 564 '$desc type parameter ${original.typeParameters[i].name}'); |
| 569 } | 565 } |
| 570 if (original is! Member) { | 566 if (original is! Member) { |
| 571 List<FunctionElement> rFunctions = resynthesized.functions; | 567 List<FunctionElement> rFunctions = resynthesized.functions; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 598 resynthesized.combinators[i], original.combinators[i]); | 594 resynthesized.combinators[i], original.combinators[i]); |
| 599 } | 595 } |
| 600 } | 596 } |
| 601 | 597 |
| 602 void compareFieldElements( | 598 void compareFieldElements( |
| 603 FieldElementImpl resynthesized, FieldElementImpl original, String desc) { | 599 FieldElementImpl resynthesized, FieldElementImpl original, String desc) { |
| 604 comparePropertyInducingElements(resynthesized, original, desc); | 600 comparePropertyInducingElements(resynthesized, original, desc); |
| 605 } | 601 } |
| 606 | 602 |
| 607 void compareFunctionElements( | 603 void compareFunctionElements( |
| 608 FunctionElement resynthesized, FunctionElement original, String desc, | 604 FunctionElement resynthesized, FunctionElement original, String desc) { |
| 609 {bool compareReturnTypes: true}) { | |
| 610 if (original == null && resynthesized == null) { | 605 if (original == null && resynthesized == null) { |
| 611 return; | 606 return; |
| 612 } | 607 } |
| 613 expect(resynthesized, isNotNull, reason: desc); | 608 expect(resynthesized, isNotNull, reason: desc); |
| 614 compareExecutableElements(resynthesized, original, desc, | 609 compareExecutableElements(resynthesized, original, desc); |
| 615 compareReturnTypes: compareReturnTypes); | |
| 616 checkPossibleLocalElements(resynthesized, original); | 610 checkPossibleLocalElements(resynthesized, original); |
| 617 } | 611 } |
| 618 | 612 |
| 619 void compareFunctionTypeAliasElements( | 613 void compareFunctionTypeAliasElements( |
| 620 FunctionTypeAliasElementImpl resynthesized, | 614 FunctionTypeAliasElementImpl resynthesized, |
| 621 FunctionTypeAliasElementImpl original, | 615 FunctionTypeAliasElementImpl original, |
| 622 String desc) { | 616 String desc) { |
| 623 compareElements(resynthesized, original, desc); | 617 compareElements(resynthesized, original, desc); |
| 624 compareParameterElementLists( | 618 compareParameterElementLists( |
| 625 resynthesized.parameters, original.parameters, desc); | 619 resynthesized.parameters, original.parameters, desc); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 compareTypeParameterElements(resynthesized.typeFormals[i], | 840 compareTypeParameterElements(resynthesized.typeFormals[i], |
| 847 original.typeFormals[i], '$desc bound type parameter $i'); | 841 original.typeFormals[i], '$desc bound type parameter $i'); |
| 848 } | 842 } |
| 849 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { | 843 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { |
| 850 expect(resynthesized, same(original)); | 844 expect(resynthesized, same(original)); |
| 851 } else if (resynthesized is DynamicTypeImpl && | 845 } else if (resynthesized is DynamicTypeImpl && |
| 852 original is UndefinedTypeImpl) { | 846 original is UndefinedTypeImpl) { |
| 853 // TODO(scheglov) In the strong mode constant variable like | 847 // TODO(scheglov) In the strong mode constant variable like |
| 854 // `var V = new Unresolved()` gets `UndefinedTypeImpl`, and it gets | 848 // `var V = new Unresolved()` gets `UndefinedTypeImpl`, and it gets |
| 855 // `DynamicTypeImpl` in the spec mode. | 849 // `DynamicTypeImpl` in the spec mode. |
| 850 } else if (resynthesized is BottomTypeImpl && original is BottomTypeImpl) { |
| 851 expect(resynthesized, same(original)); |
| 856 } else if (resynthesized.runtimeType != original.runtimeType) { | 852 } else if (resynthesized.runtimeType != original.runtimeType) { |
| 857 fail('Type mismatch: expected ${original.runtimeType},' | 853 fail('Type mismatch: expected ${original.runtimeType},' |
| 858 ' got ${resynthesized.runtimeType} ($desc)'); | 854 ' got ${resynthesized.runtimeType} ($desc)'); |
| 859 } else { | 855 } else { |
| 860 fail('Unimplemented comparison for ${original.runtimeType}'); | 856 fail('Unimplemented comparison for ${original.runtimeType}'); |
| 861 } | 857 } |
| 862 } | 858 } |
| 863 | 859 |
| 864 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, | 860 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, |
| 865 UriReferencedElementImpl original, String desc) { | 861 UriReferencedElementImpl original, String desc) { |
| 866 compareElements(resynthesized, original, desc); | 862 compareElements(resynthesized, original, desc); |
| 867 expect(resynthesized.uri, original.uri); | 863 expect(resynthesized.uri, original.uri); |
| 868 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); | 864 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 869 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 865 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 870 } | 866 } |
| 871 | 867 |
| 872 void compareVariableElements( | 868 void compareVariableElements( |
| 873 VariableElement resynthesized, VariableElement original, String desc) { | 869 VariableElement resynthesized, VariableElement original, String desc) { |
| 874 compareElements(resynthesized, original, desc); | 870 compareElements(resynthesized, original, desc); |
| 875 compareTypes(resynthesized.type, original.type, desc); | 871 compareTypes(resynthesized.type, original.type, desc); |
| 876 // TODO(scheglov) VariableMember.initializer is not implemented | 872 // TODO(scheglov) VariableMember.initializer is not implemented |
| 877 if (original is! VariableMember) { | 873 if (original is! VariableMember) { |
| 878 compareFunctionElements( | 874 compareFunctionElements( |
| 879 resynthesized.initializer, original.initializer, desc, | 875 resynthesized.initializer, original.initializer, desc); |
| 880 compareReturnTypes: false); | |
| 881 } | 876 } |
| 882 VariableElementImpl originalActual = getActualElement(original, desc); | 877 VariableElementImpl originalActual = getActualElement(original, desc); |
| 883 if (originalActual is ConstVariableElement) { | 878 if (originalActual is ConstVariableElement) { |
| 884 VariableElementImpl resynthesizedActual = | 879 VariableElementImpl resynthesizedActual = |
| 885 getActualElement(resynthesized, desc); | 880 getActualElement(resynthesized, desc); |
| 886 Expression initializer = resynthesizedActual.constantInitializer; | 881 Expression initializer = resynthesizedActual.constantInitializer; |
| 887 if (constantInitializersAreInvalid) { | 882 if (constantInitializersAreInvalid) { |
| 888 _assertUnresolvedIdentifier(initializer, desc); | 883 _assertUnresolvedIdentifier(initializer, desc); |
| 889 } else { | 884 } else { |
| 890 compareConstAsts(initializer, originalActual.constantInitializer, | 885 compareConstAsts(initializer, originalActual.constantInitializer, |
| (...skipping 2801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3692 fail('Unexpectedly tried to get unlinked summary for $uri'); | 3687 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 3693 } | 3688 } |
| 3694 return serializedUnit; | 3689 return serializedUnit; |
| 3695 } | 3690 } |
| 3696 | 3691 |
| 3697 @override | 3692 @override |
| 3698 bool hasLibrarySummary(String uri) { | 3693 bool hasLibrarySummary(String uri) { |
| 3699 return true; | 3694 return true; |
| 3700 } | 3695 } |
| 3701 } | 3696 } |
| OLD | NEW |