| 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 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/constant/value.dart'; | 9 import 'package:analyzer/dart/constant/value.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 reason: desc); | 675 reason: desc); |
| 676 } | 676 } |
| 677 expect(resynthesized.compilationUnit, isNotNull, reason: desc); | 677 expect(resynthesized.compilationUnit, isNotNull, reason: desc); |
| 678 expect(resynthesized.compilationUnit.location, | 678 expect(resynthesized.compilationUnit.location, |
| 679 original.compilationUnit.location, | 679 original.compilationUnit.location, |
| 680 reason: desc); | 680 reason: desc); |
| 681 expect(resynthesized.annotationAst, isNotNull, reason: desc); | 681 expect(resynthesized.annotationAst, isNotNull, reason: desc); |
| 682 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc); | 682 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc); |
| 683 } | 683 } |
| 684 | 684 |
| 685 void compareElementLocations( |
| 686 Element resynthesized, Element original, String desc) { |
| 687 bool hasFunctionElementByValue(Element e) { |
| 688 if (e == null) { |
| 689 return false; |
| 690 } |
| 691 if (e is FunctionElementImpl_forLUB) { |
| 692 return true; |
| 693 } |
| 694 return hasFunctionElementByValue(e.enclosingElement); |
| 695 } |
| 696 |
| 697 if (hasFunctionElementByValue(resynthesized)) { |
| 698 // We resynthesize elements representing types of local functions |
| 699 // without corresponding name offsets, so their locations don't have |
| 700 // corresponding valid @offset components. Also, we don't put |
| 701 // resynthesized local functions into initializers of variables. |
| 702 return; |
| 703 } |
| 704 expect(resynthesized.location, original.location, reason: desc); |
| 705 } |
| 706 |
| 685 void compareElements(Element resynthesized, Element original, String desc) { | 707 void compareElements(Element resynthesized, Element original, String desc) { |
| 686 ElementImpl rImpl = getActualElement(resynthesized, desc); | 708 ElementImpl rImpl = getActualElement(resynthesized, desc); |
| 687 ElementImpl oImpl = getActualElement(original, desc); | 709 ElementImpl oImpl = getActualElement(original, desc); |
| 688 if (oImpl == null && rImpl == null) { | 710 if (oImpl == null && rImpl == null) { |
| 689 return; | 711 return; |
| 690 } | 712 } |
| 691 if (oImpl is PrefixElement) { | 713 if (oImpl is PrefixElement) { |
| 692 // TODO(scheglov) prefixes cannot be resynthesized | 714 // TODO(scheglov) prefixes cannot be resynthesized |
| 693 return; | 715 return; |
| 694 } | 716 } |
| 695 expect(original, isNotNull); | 717 expect(original, isNotNull); |
| 696 expect(resynthesized, isNotNull, reason: desc); | 718 expect(resynthesized, isNotNull, reason: desc); |
| 697 if (rImpl is DefaultParameterElementImpl && oImpl is ParameterElementImpl) { | 719 if (rImpl is DefaultParameterElementImpl && oImpl is ParameterElementImpl) { |
| 698 // This is ok provided the resynthesized parameter element doesn't have | 720 // This is ok provided the resynthesized parameter element doesn't have |
| 699 // any evaluation result. | 721 // any evaluation result. |
| 700 expect(rImpl.evaluationResult, isNull); | 722 expect(rImpl.evaluationResult, isNull); |
| 701 } else { | 723 } else { |
| 702 Type rRuntimeType; | 724 Type rRuntimeType; |
| 703 if (rImpl is ConstFieldElementImpl) { | 725 if (rImpl is ConstFieldElementImpl) { |
| 704 rRuntimeType = ConstFieldElementImpl; | 726 rRuntimeType = ConstFieldElementImpl; |
| 705 } else if (rImpl is FunctionElementImpl) { | 727 } else if (rImpl is FunctionElementImpl) { |
| 706 rRuntimeType = FunctionElementImpl; | 728 rRuntimeType = FunctionElementImpl; |
| 707 } else { | 729 } else { |
| 708 rRuntimeType = rImpl.runtimeType; | 730 rRuntimeType = rImpl.runtimeType; |
| 709 } | 731 } |
| 710 expect(rRuntimeType, oImpl.runtimeType); | 732 expect(rRuntimeType, oImpl.runtimeType); |
| 711 } | 733 } |
| 712 expect(resynthesized.kind, original.kind); | 734 expect(resynthesized.kind, original.kind); |
| 713 expect(resynthesized.location, original.location, reason: desc); | 735 compareElementLocations(resynthesized, original, desc); |
| 714 expect(resynthesized.name, original.name); | 736 expect(resynthesized.name, original.name); |
| 715 expect(resynthesized.nameOffset, original.nameOffset, | 737 expect(resynthesized.nameOffset, original.nameOffset, |
| 716 reason: '$desc.nameOffset'); | 738 reason: '$desc.nameOffset'); |
| 717 expect(rImpl.codeOffset, oImpl.codeOffset, reason: desc); | 739 expect(rImpl.codeOffset, oImpl.codeOffset, reason: desc); |
| 718 expect(rImpl.codeLength, oImpl.codeLength, reason: desc); | 740 expect(rImpl.codeLength, oImpl.codeLength, reason: desc); |
| 719 expect(resynthesized.documentationComment, original.documentationComment, | 741 expect(resynthesized.documentationComment, original.documentationComment, |
| 720 reason: desc); | 742 reason: desc); |
| 721 compareMetadata(resynthesized.metadata, original.metadata, desc); | 743 compareMetadata(resynthesized.metadata, original.metadata, desc); |
| 722 | 744 |
| 723 // Validate modifiers. | 745 // Validate modifiers. |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1045 |
| 1024 void compareTopLevelVariableElements( | 1046 void compareTopLevelVariableElements( |
| 1025 TopLevelVariableElementImpl resynthesized, | 1047 TopLevelVariableElementImpl resynthesized, |
| 1026 TopLevelVariableElementImpl original, | 1048 TopLevelVariableElementImpl original, |
| 1027 String desc) { | 1049 String desc) { |
| 1028 comparePropertyInducingElements(resynthesized, original, desc); | 1050 comparePropertyInducingElements(resynthesized, original, desc); |
| 1029 } | 1051 } |
| 1030 | 1052 |
| 1031 void compareTypeImpls( | 1053 void compareTypeImpls( |
| 1032 TypeImpl resynthesized, TypeImpl original, String desc) { | 1054 TypeImpl resynthesized, TypeImpl original, String desc) { |
| 1033 expect(resynthesized.element.location, original.element.location, | 1055 compareElementLocations( |
| 1034 reason: '$desc.element.location'); | 1056 resynthesized.element, original.element, '$desc.element.location'); |
| 1035 expect(resynthesized.name, original.name, reason: '$desc.name'); | 1057 expect(resynthesized.name, original.name, reason: '$desc.name'); |
| 1036 } | 1058 } |
| 1037 | 1059 |
| 1038 void compareTypeParameterElementLists( | 1060 void compareTypeParameterElementLists( |
| 1039 List<TypeParameterElement> resynthesized, | 1061 List<TypeParameterElement> resynthesized, |
| 1040 List<TypeParameterElement> original, | 1062 List<TypeParameterElement> original, |
| 1041 String desc) { | 1063 String desc) { |
| 1042 int length = original.length; | 1064 int length = original.length; |
| 1043 expect(resynthesized.length, length, reason: '$desc.length'); | 1065 expect(resynthesized.length, length, reason: '$desc.length'); |
| 1044 for (int i = 0; i < length; i++) { | 1066 for (int i = 0; i < length; i++) { |
| (...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3155 } else { | 3177 } else { |
| 3156 checkElementText( | 3178 checkElementText( |
| 3157 library, | 3179 library, |
| 3158 r''' | 3180 r''' |
| 3159 dynamic f() {} | 3181 dynamic f() {} |
| 3160 '''); | 3182 '''); |
| 3161 } | 3183 } |
| 3162 } | 3184 } |
| 3163 | 3185 |
| 3164 test_closure_generic() { | 3186 test_closure_generic() { |
| 3165 var library = checkLibrary('final f = <U, V>(U x, V y) => y;'); | 3187 var library = checkLibrary('final f = <U, V extends int>(U x, V y) => y;'); |
| 3166 if (isStrongMode) { | 3188 if (isStrongMode) { |
| 3167 checkElementText( | 3189 checkElementText( |
| 3168 library, | 3190 library, |
| 3169 r''' | 3191 r''' |
| 3170 final <U,V>(U, V) → V f; | 3192 final <U,V extends int>(U, V) → V f; |
| 3171 '''); | 3193 '''); |
| 3172 } else { | 3194 } else { |
| 3173 checkElementText( | 3195 checkElementText( |
| 3174 library, | 3196 library, |
| 3175 r''' | 3197 r''' |
| 3176 final dynamic f; | 3198 final dynamic f; |
| 3177 '''); | 3199 '''); |
| 3178 } | 3200 } |
| 3179 } | 3201 } |
| 3180 | 3202 |
| (...skipping 11983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15164 fail('Unexpectedly tried to get unlinked summary for $uri'); | 15186 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 15165 } | 15187 } |
| 15166 return serializedUnit; | 15188 return serializedUnit; |
| 15167 } | 15189 } |
| 15168 | 15190 |
| 15169 @override | 15191 @override |
| 15170 bool hasLibrarySummary(String uri) { | 15192 bool hasLibrarySummary(String uri) { |
| 15171 return true; | 15193 return true; |
| 15172 } | 15194 } |
| 15173 } | 15195 } |
| OLD | NEW |