| 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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 } | 635 } |
| 636 | 636 |
| 637 // Validate members. | 637 // Validate members. |
| 638 if (oImpl is Member) { | 638 if (oImpl is Member) { |
| 639 expect(rImpl, new isInstanceOf<Member>(), reason: desc); | 639 expect(rImpl, new isInstanceOf<Member>(), reason: desc); |
| 640 } else { | 640 } else { |
| 641 expect(rImpl, isNot(new isInstanceOf<Member>()), reason: desc); | 641 expect(rImpl, isNot(new isInstanceOf<Member>()), reason: desc); |
| 642 } | 642 } |
| 643 } | 643 } |
| 644 | 644 |
| 645 void compareExecutableElements(ExecutableElement resynthesized, | 645 void compareExecutableElements( |
| 646 ExecutableElement original, String desc) { | 646 ExecutableElement resynthesized, ExecutableElement original, String desc, |
| 647 {bool shallow: false}) { |
| 647 compareElements(resynthesized, original, desc); | 648 compareElements(resynthesized, original, desc); |
| 648 compareParameterElementLists( | 649 compareParameterElementLists( |
| 649 resynthesized.parameters, original.parameters, desc); | 650 resynthesized.parameters, original.parameters, desc); |
| 650 compareTypes( | 651 compareTypes( |
| 651 resynthesized.returnType, original.returnType, '$desc return type'); | 652 resynthesized.returnType, original.returnType, '$desc return type'); |
| 652 compareTypes(resynthesized.type, original.type, desc); | 653 if (!shallow) { |
| 654 compareTypes(resynthesized.type, original.type, desc); |
| 655 } |
| 653 expect(resynthesized.typeParameters.length, original.typeParameters.length); | 656 expect(resynthesized.typeParameters.length, original.typeParameters.length); |
| 654 for (int i = 0; i < resynthesized.typeParameters.length; i++) { | 657 for (int i = 0; i < resynthesized.typeParameters.length; i++) { |
| 655 compareTypeParameterElements( | 658 compareTypeParameterElements( |
| 656 resynthesized.typeParameters[i], | 659 resynthesized.typeParameters[i], |
| 657 original.typeParameters[i], | 660 original.typeParameters[i], |
| 658 '$desc type parameter ${original.typeParameters[i].name}'); | 661 '$desc type parameter ${original.typeParameters[i].name}'); |
| 659 } | 662 } |
| 660 if (original is! Member) { | 663 if (original is! Member) { |
| 661 List<FunctionElement> rFunctions = resynthesized.functions; | 664 List<FunctionElement> rFunctions = resynthesized.functions; |
| 662 List<FunctionElement> oFunctions = original.functions; | 665 List<FunctionElement> oFunctions = original.functions; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 resynthesized.combinators[i], original.combinators[i]); | 700 resynthesized.combinators[i], original.combinators[i]); |
| 698 } | 701 } |
| 699 } | 702 } |
| 700 | 703 |
| 701 void compareFieldElements( | 704 void compareFieldElements( |
| 702 FieldElementImpl resynthesized, FieldElementImpl original, String desc) { | 705 FieldElementImpl resynthesized, FieldElementImpl original, String desc) { |
| 703 comparePropertyInducingElements(resynthesized, original, desc); | 706 comparePropertyInducingElements(resynthesized, original, desc); |
| 704 } | 707 } |
| 705 | 708 |
| 706 void compareFunctionElements( | 709 void compareFunctionElements( |
| 707 FunctionElement resynthesized, FunctionElement original, String desc) { | 710 FunctionElement resynthesized, FunctionElement original, String desc, |
| 711 {bool shallow: false}) { |
| 708 if (original == null && resynthesized == null) { | 712 if (original == null && resynthesized == null) { |
| 709 return; | 713 return; |
| 710 } | 714 } |
| 711 expect(resynthesized, isNotNull, reason: desc); | 715 expect(resynthesized, isNotNull, reason: desc); |
| 712 compareExecutableElements(resynthesized, original, desc); | 716 compareExecutableElements(resynthesized, original, desc, shallow: shallow); |
| 713 checkPossibleLocalElements(resynthesized, original); | 717 checkPossibleLocalElements(resynthesized, original); |
| 714 } | 718 } |
| 715 | 719 |
| 716 void compareFunctionTypeAliasElements( | 720 void compareFunctionTypeAliasElements( |
| 717 FunctionTypeAliasElementImpl resynthesized, | 721 FunctionTypeAliasElementImpl resynthesized, |
| 718 FunctionTypeAliasElementImpl original, | 722 FunctionTypeAliasElementImpl original, |
| 719 String desc) { | 723 String desc) { |
| 720 compareElements(resynthesized, original, desc); | 724 compareElements(resynthesized, original, desc); |
| 721 compareParameterElementLists( | 725 compareParameterElementLists( |
| 722 resynthesized.parameters, original.parameters, desc); | 726 resynthesized.parameters, original.parameters, desc); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 original is FunctionTypeImpl) { | 934 original is FunctionTypeImpl) { |
| 931 compareTypeImpls(resynthesized, original, desc); | 935 compareTypeImpls(resynthesized, original, desc); |
| 932 expect(resynthesized.isInstantiated, original.isInstantiated, | 936 expect(resynthesized.isInstantiated, original.isInstantiated, |
| 933 reason: desc); | 937 reason: desc); |
| 934 if (original.element.isSynthetic && | 938 if (original.element.isSynthetic && |
| 935 original.element is FunctionTypeAliasElementImpl && | 939 original.element is FunctionTypeAliasElementImpl && |
| 936 resynthesized.element is FunctionTypeAliasElementImpl) { | 940 resynthesized.element is FunctionTypeAliasElementImpl) { |
| 937 compareFunctionTypeAliasElements( | 941 compareFunctionTypeAliasElements( |
| 938 resynthesized.element, original.element, desc); | 942 resynthesized.element, original.element, desc); |
| 939 } | 943 } |
| 944 if (original.element.enclosingElement == null && |
| 945 original.element is FunctionElement) { |
| 946 expect(resynthesized.element, new isInstanceOf<FunctionElement>()); |
| 947 expect(resynthesized.element.enclosingElement, isNull, reason: desc); |
| 948 compareFunctionElements( |
| 949 resynthesized.element, original.element, '$desc element', |
| 950 shallow: true); |
| 951 expect(resynthesized.element.type, same(resynthesized)); |
| 952 } |
| 940 expect(resynthesized.typeArguments.length, original.typeArguments.length, | 953 expect(resynthesized.typeArguments.length, original.typeArguments.length, |
| 941 reason: desc); | 954 reason: desc); |
| 942 for (int i = 0; i < resynthesized.typeArguments.length; i++) { | 955 for (int i = 0; i < resynthesized.typeArguments.length; i++) { |
| 943 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], | 956 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], |
| 944 '$desc type argument ${original.typeArguments[i].name}'); | 957 '$desc type argument ${original.typeArguments[i].name}'); |
| 945 } | 958 } |
| 946 if (original.typeParameters == null) { | 959 if (original.typeParameters == null) { |
| 947 expect(resynthesized.typeParameters, isNull, reason: desc); | 960 expect(resynthesized.typeParameters, isNull, reason: desc); |
| 948 } else { | 961 } else { |
| 949 expect(resynthesized.typeParameters, isNotNull, reason: desc); | 962 expect(resynthesized.typeParameters, isNotNull, reason: desc); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 999 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 987 } | 1000 } |
| 988 | 1001 |
| 989 void compareVariableElements( | 1002 void compareVariableElements( |
| 990 VariableElement resynthesized, VariableElement original, String desc) { | 1003 VariableElement resynthesized, VariableElement original, String desc) { |
| 991 compareElements(resynthesized, original, desc); | 1004 compareElements(resynthesized, original, desc); |
| 992 compareTypes(resynthesized.type, original.type, desc); | 1005 compareTypes(resynthesized.type, original.type, desc); |
| 993 VariableElementImpl resynthesizedActual = | 1006 VariableElementImpl resynthesizedActual = |
| 994 getActualElement(resynthesized, desc); | 1007 getActualElement(resynthesized, desc); |
| 995 VariableElementImpl originalActual = getActualElement(original, desc); | 1008 VariableElementImpl originalActual = getActualElement(original, desc); |
| 996 compareFunctionElements( | 1009 compareFunctionElements(resynthesizedActual.initializer, |
| 997 resynthesizedActual.initializer, originalActual.initializer, desc); | 1010 originalActual.initializer, '$desc initializer'); |
| 998 if (originalActual is ConstVariableElement) { | 1011 if (originalActual is ConstVariableElement) { |
| 999 Element oEnclosing = original.enclosingElement; | 1012 Element oEnclosing = original.enclosingElement; |
| 1000 if (oEnclosing is ClassElement && oEnclosing.isEnum) { | 1013 if (oEnclosing is ClassElement && oEnclosing.isEnum) { |
| 1001 compareConstValues( | 1014 compareConstValues( |
| 1002 resynthesized.constantValue, original.constantValue, desc); | 1015 resynthesized.constantValue, original.constantValue, desc); |
| 1003 } else { | 1016 } else { |
| 1004 Expression initializer = resynthesizedActual.constantInitializer; | 1017 Expression initializer = resynthesizedActual.constantInitializer; |
| 1005 if (constantInitializersAreInvalid) { | 1018 if (constantInitializersAreInvalid) { |
| 1006 _assertUnresolvedIdentifier(initializer, desc); | 1019 _assertUnresolvedIdentifier(initializer, desc); |
| 1007 } else { | 1020 } else { |
| (...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3625 } | 3638 } |
| 3626 | 3639 |
| 3627 test_setter_inferred_type_top_level_implicit_return() { | 3640 test_setter_inferred_type_top_level_implicit_return() { |
| 3628 checkLibrary('set f(int value) {}'); | 3641 checkLibrary('set f(int value) {}'); |
| 3629 } | 3642 } |
| 3630 | 3643 |
| 3631 test_setters() { | 3644 test_setters() { |
| 3632 checkLibrary('void set x(int value) {} set y(value) {}'); | 3645 checkLibrary('void set x(int value) {} set y(value) {}'); |
| 3633 } | 3646 } |
| 3634 | 3647 |
| 3648 test_syntheticFunctionType_genericClosure() { |
| 3649 if (!options.strongMode) { |
| 3650 // The test below uses generic comment syntax because proper generic |
| 3651 // method syntax doesn't support generic closures. So it can only run in |
| 3652 // strong mode. |
| 3653 // TODO(paulberry): once proper generic method syntax supports generic |
| 3654 // closures, rewrite the test below without using generic comment syntax, |
| 3655 // and remove this hack. See dartbug.com/25819 |
| 3656 return; |
| 3657 } |
| 3658 checkLibrary(''' |
| 3659 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1; |
| 3660 bool f() => true; |
| 3661 '''); |
| 3662 } |
| 3663 |
| 3664 test_syntheticFunctionType_genericClosure_inGenericFunction() { |
| 3665 if (!options.strongMode) { |
| 3666 // The test below uses generic comment syntax because proper generic |
| 3667 // method syntax doesn't support generic closures. So it can only run in |
| 3668 // strong mode. |
| 3669 // TODO(paulberry): once proper generic method syntax supports generic |
| 3670 // closures, rewrite the test below without using generic comment syntax, |
| 3671 // and remove this hack. See dartbug.com/25819 |
| 3672 return; |
| 3673 } |
| 3674 checkLibrary(''' |
| 3675 void f<T, U>(bool b) { |
| 3676 final v = b ? /*<V>*/(T t, U u, V v) => 0 : /*<V>*/(T t, U u, V v) => 1; |
| 3677 } |
| 3678 '''); |
| 3679 } |
| 3680 |
| 3681 test_syntheticFunctionType_inGenericClass() { |
| 3682 checkLibrary(''' |
| 3683 class C<T, U> { |
| 3684 var v = f() ? (T t, U u) => 0 : (T t, U u) => 1; |
| 3685 } |
| 3686 bool f() => false; |
| 3687 '''); |
| 3688 } |
| 3689 |
| 3690 test_syntheticFunctionType_inGenericFunction() { |
| 3691 checkLibrary(''' |
| 3692 void f<T, U>(bool b) { |
| 3693 var v = b ? (T t, U u) => 0 : (T t, U u) => 1; |
| 3694 } |
| 3695 '''); |
| 3696 } |
| 3697 |
| 3698 test_syntheticFunctionType_noArguments() { |
| 3699 checkLibrary(''' |
| 3700 final v = f() ? () => 0 : () => 1; |
| 3701 bool f() => true; |
| 3702 '''); |
| 3703 } |
| 3704 |
| 3705 test_syntheticFunctionType_withArguments() { |
| 3706 checkLibrary(''' |
| 3707 final v = f() ? (int x, String y) => 0 : (int x, String y) => 1; |
| 3708 bool f() => true; |
| 3709 '''); |
| 3710 } |
| 3711 |
| 3635 test_type_arguments_explicit_dynamic_dynamic() { | 3712 test_type_arguments_explicit_dynamic_dynamic() { |
| 3636 checkLibrary('Map<dynamic, dynamic> m;'); | 3713 checkLibrary('Map<dynamic, dynamic> m;'); |
| 3637 } | 3714 } |
| 3638 | 3715 |
| 3639 test_type_arguments_explicit_dynamic_int() { | 3716 test_type_arguments_explicit_dynamic_int() { |
| 3640 checkLibrary('Map<dynamic, int> m;'); | 3717 checkLibrary('Map<dynamic, int> m;'); |
| 3641 } | 3718 } |
| 3642 | 3719 |
| 3643 test_type_arguments_explicit_String_dynamic() { | 3720 test_type_arguments_explicit_String_dynamic() { |
| 3644 checkLibrary('Map<String, dynamic> m;'); | 3721 checkLibrary('Map<String, dynamic> m;'); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3991 fail('Unexpectedly tried to get unlinked summary for $uri'); | 4068 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 3992 } | 4069 } |
| 3993 return serializedUnit; | 4070 return serializedUnit; |
| 3994 } | 4071 } |
| 3995 | 4072 |
| 3996 @override | 4073 @override |
| 3997 bool hasLibrarySummary(String uri) { | 4074 bool hasLibrarySummary(String uri) { |
| 3998 return true; | 4075 return true; |
| 3999 } | 4076 } |
| 4000 } | 4077 } |
| OLD | NEW |