| 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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 compareElements(resynthesized, original, desc); | 858 compareElements(resynthesized, original, desc); |
| 859 expect(resynthesized.uri, original.uri); | 859 expect(resynthesized.uri, original.uri); |
| 860 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); | 860 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 861 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 861 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 862 } | 862 } |
| 863 | 863 |
| 864 void compareVariableElements( | 864 void compareVariableElements( |
| 865 VariableElement resynthesized, VariableElement original, String desc) { | 865 VariableElement resynthesized, VariableElement original, String desc) { |
| 866 compareElements(resynthesized, original, desc); | 866 compareElements(resynthesized, original, desc); |
| 867 compareTypes(resynthesized.type, original.type, desc); | 867 compareTypes(resynthesized.type, original.type, desc); |
| 868 // TODO(scheglov) VariableMember.initializer is not implemented |
| 869 if (original is! VariableMember) { |
| 870 compareVariableInitializers( |
| 871 resynthesized.initializer, original.initializer, desc); |
| 872 } |
| 868 VariableElementImpl originalActual = getActualElement(original, desc); | 873 VariableElementImpl originalActual = getActualElement(original, desc); |
| 869 if (originalActual is ConstVariableElement) { | 874 if (originalActual is ConstVariableElement) { |
| 870 VariableElementImpl resynthesizedActual = | 875 VariableElementImpl resynthesizedActual = |
| 871 getActualElement(resynthesized, desc); | 876 getActualElement(resynthesized, desc); |
| 872 Expression initializer = resynthesizedActual.constantInitializer; | 877 Expression initializer = resynthesizedActual.constantInitializer; |
| 873 if (constantInitializersAreInvalid) { | 878 if (constantInitializersAreInvalid) { |
| 874 _assertUnresolvedIdentifier(initializer, desc); | 879 _assertUnresolvedIdentifier(initializer, desc); |
| 875 } else { | 880 } else { |
| 876 compareConstAsts(initializer, originalActual.constantInitializer, | 881 compareConstAsts(initializer, originalActual.constantInitializer, |
| 877 '$desc initializer'); | 882 '$desc initializer'); |
| 878 } | 883 } |
| 879 } | 884 } |
| 880 checkPossibleMember(resynthesized, original, desc); | 885 checkPossibleMember(resynthesized, original, desc); |
| 881 checkPossibleLocalElements(resynthesized, original); | 886 checkPossibleLocalElements(resynthesized, original); |
| 882 } | 887 } |
| 883 | 888 |
| 889 void compareVariableInitializers( |
| 890 FunctionElement resynthesized, FunctionElement original, String desc) { |
| 891 if (original == null && resynthesized == null) { |
| 892 return; |
| 893 } |
| 894 expect(resynthesized, isNotNull, reason: desc); |
| 895 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); |
| 896 expect(resynthesized.name, original.name, reason: desc); |
| 897 // TODO(scheglov) replace this method with compareFunctionElements() |
| 898 // once we resynthesize initializers return types. |
| 899 } |
| 900 |
| 884 /** | 901 /** |
| 885 * Serialize the given [library] into a summary. Then create a | 902 * Serialize the given [library] into a summary. Then create a |
| 886 * [_TestSummaryResynthesizer] which can deserialize it, along with any | 903 * [_TestSummaryResynthesizer] which can deserialize it, along with any |
| 887 * references it makes to `dart:core`. | 904 * references it makes to `dart:core`. |
| 888 * | 905 * |
| 889 * Errors will lead to a test failure unless [allowErrors] is `true`. | 906 * Errors will lead to a test failure unless [allowErrors] is `true`. |
| 890 */ | 907 */ |
| 891 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, | 908 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, |
| 892 {bool allowErrors: false, bool dumpSummaries: false}) { | 909 {bool allowErrors: false, bool dumpSummaries: false}) { |
| 893 if (!allowErrors) { | 910 if (!allowErrors) { |
| (...skipping 2784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3678 fail('Unexpectedly tried to get unlinked summary for $uri'); | 3695 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 3679 } | 3696 } |
| 3680 return serializedUnit; | 3697 return serializedUnit; |
| 3681 } | 3698 } |
| 3682 | 3699 |
| 3683 @override | 3700 @override |
| 3684 bool hasLibrarySummary(String uri) { | 3701 bool hasLibrarySummary(String uri) { |
| 3685 return true; | 3702 return true; |
| 3686 } | 3703 } |
| 3687 } | 3704 } |
| OLD | NEW |