Chromium Code Reviews| 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 if (original is! Member) { | |
|
Paul Berry
2016/02/17 21:15:30
Again, why should we skip this code if original is
scheglov
2016/02/17 21:27:51
I've added the explanation comment.
| |
| 869 compareVariableInitializers( | |
| 870 resynthesized.initializer, original.initializer, desc); | |
| 871 } | |
| 868 VariableElementImpl originalActual = getActualElement(original, desc); | 872 VariableElementImpl originalActual = getActualElement(original, desc); |
| 869 if (originalActual is ConstVariableElement) { | 873 if (originalActual is ConstVariableElement) { |
| 870 VariableElementImpl resynthesizedActual = | 874 VariableElementImpl resynthesizedActual = |
| 871 getActualElement(resynthesized, desc); | 875 getActualElement(resynthesized, desc); |
| 872 Expression initializer = resynthesizedActual.constantInitializer; | 876 Expression initializer = resynthesizedActual.constantInitializer; |
| 873 if (constantInitializersAreInvalid) { | 877 if (constantInitializersAreInvalid) { |
| 874 _assertUnresolvedIdentifier(initializer, desc); | 878 _assertUnresolvedIdentifier(initializer, desc); |
| 875 } else { | 879 } else { |
| 876 compareConstAsts(initializer, originalActual.constantInitializer, | 880 compareConstAsts(initializer, originalActual.constantInitializer, |
| 877 '$desc initializer'); | 881 '$desc initializer'); |
| 878 } | 882 } |
| 879 } | 883 } |
| 880 checkPossibleMember(resynthesized, original, desc); | 884 checkPossibleMember(resynthesized, original, desc); |
| 881 checkPossibleLocalElements(resynthesized, original); | 885 checkPossibleLocalElements(resynthesized, original); |
| 882 } | 886 } |
| 883 | 887 |
| 888 void compareVariableInitializers( | |
| 889 FunctionElement resynthesized, FunctionElement original, String desc) { | |
| 890 if (original == null && resynthesized == null) { | |
| 891 return; | |
| 892 } | |
| 893 expect(resynthesized, isNotNull, reason: desc); | |
| 894 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); | |
| 895 expect(resynthesized.name, original.name, reason: desc); | |
| 896 // TODO(scheglov) replace this method with compareFunctionElements() | |
| 897 // once we resynthesize initializers return types. | |
| 898 } | |
| 899 | |
| 884 /** | 900 /** |
| 885 * Serialize the given [library] into a summary. Then create a | 901 * Serialize the given [library] into a summary. Then create a |
| 886 * [_TestSummaryResynthesizer] which can deserialize it, along with any | 902 * [_TestSummaryResynthesizer] which can deserialize it, along with any |
| 887 * references it makes to `dart:core`. | 903 * references it makes to `dart:core`. |
| 888 * | 904 * |
| 889 * Errors will lead to a test failure unless [allowErrors] is `true`. | 905 * Errors will lead to a test failure unless [allowErrors] is `true`. |
| 890 */ | 906 */ |
| 891 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, | 907 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, |
| 892 {bool allowErrors: false, bool dumpSummaries: false}) { | 908 {bool allowErrors: false, bool dumpSummaries: false}) { |
| 893 if (!allowErrors) { | 909 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'); | 3694 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 3679 } | 3695 } |
| 3680 return serializedUnit; | 3696 return serializedUnit; |
| 3681 } | 3697 } |
| 3682 | 3698 |
| 3683 @override | 3699 @override |
| 3684 bool hasLibrarySummary(String uri) { | 3700 bool hasLibrarySummary(String uri) { |
| 3685 return true; | 3701 return true; |
| 3686 } | 3702 } |
| 3687 } | 3703 } |
| OLD | NEW |