Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1686283002: Ensure that element handles never refer to Member objects. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 } 781 }
782 expect(resynthesized.typeFormals.length, original.typeFormals.length, 782 expect(resynthesized.typeFormals.length, original.typeFormals.length,
783 reason: desc); 783 reason: desc);
784 for (int i = 0; i < resynthesized.typeFormals.length; i++) { 784 for (int i = 0; i < resynthesized.typeFormals.length; i++) {
785 compareTypeParameterElements(resynthesized.typeFormals[i], 785 compareTypeParameterElements(resynthesized.typeFormals[i],
786 original.typeFormals[i], '$desc bound type parameter $i'); 786 original.typeFormals[i], '$desc bound type parameter $i');
787 } 787 }
788 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { 788 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) {
789 expect(resynthesized, same(original)); 789 expect(resynthesized, same(original));
790 } else if (resynthesized.runtimeType != original.runtimeType) { 790 } else if (resynthesized.runtimeType != original.runtimeType) {
791 fail( 791 fail('Type mismatch: expected ${original.runtimeType},'
792 'Type mismatch: expected ${original.runtimeType}, got ${resynthesized. runtimeType}'); 792 ' got ${resynthesized.runtimeType} ($desc)');
793 } else { 793 } else {
794 fail('Unimplemented comparison for ${original.runtimeType}'); 794 fail('Unimplemented comparison for ${original.runtimeType}');
795 } 795 }
796 } 796 }
797 797
798 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, 798 void compareUriReferencedElements(UriReferencedElementImpl resynthesized,
799 UriReferencedElementImpl original, String desc) { 799 UriReferencedElementImpl original, String desc) {
800 compareElements(resynthesized, original, desc); 800 compareElements(resynthesized, original, desc);
801 expect(resynthesized.uri, original.uri); 801 expect(resynthesized.uri, original.uri);
802 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); 802 expect(resynthesized.uriOffset, original.uriOffset, reason: desc);
803 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); 803 expect(resynthesized.uriEnd, original.uriEnd, reason: desc);
804 } 804 }
805 805
806 void compareVariableElements( 806 void compareVariableElements(
807 VariableElement resynthesized, VariableElement original, String desc) { 807 VariableElement resynthesized, VariableElement original, String desc) {
808 compareElements(resynthesized, original, desc); 808 compareElements(resynthesized, original, desc);
809 compareTypes(resynthesized.type, original.type, desc); 809 compareTypes(resynthesized.type, original.type, desc);
810 VariableElementImpl originalActual = getActualElement(original, desc); 810 VariableElementImpl originalActual = getActualElement(original, desc);
811 if (originalActual is ConstVariableElement) { 811 if (originalActual is ConstVariableElement) {
812 VariableElementImpl resynthesizedActual = 812 VariableElementImpl resynthesizedActual =
813 getActualElement(resynthesized, desc); 813 getActualElement(resynthesized, desc);
814 Expression initializer = resynthesizedActual.constantInitializer; 814 Expression initializer = resynthesizedActual.constantInitializer;
815 if (constantInitializersAreInvalid) { 815 if (constantInitializersAreInvalid) {
816 _assertUnresolvedIdentifier(initializer, desc); 816 _assertUnresolvedIdentifier(initializer, desc);
817 } else { 817 } else {
818 compareConstAsts(initializer, originalActual.constantInitializer, desc); 818 compareConstAsts(initializer, originalActual.constantInitializer,
819 '$desc initializer');
819 } 820 }
820 } 821 }
821 checkPossibleMember(resynthesized, original, desc); 822 checkPossibleMember(resynthesized, original, desc);
822 } 823 }
823 824
824 /** 825 /**
825 * Serialize the given [library] into a summary. Then create a 826 * Serialize the given [library] into a summary. Then create a
826 * [_TestSummaryResynthesizer] which can deserialize it, along with any 827 * [_TestSummaryResynthesizer] which can deserialize it, along with any
827 * references it makes to `dart:core`. 828 * references it makes to `dart:core`.
828 * 829 *
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 } 884 }
884 885
885 fail_library_hasExtUri() { 886 fail_library_hasExtUri() {
886 checkLibrary('import "dart-ext:doesNotExist.dart";'); 887 checkLibrary('import "dart-ext:doesNotExist.dart";');
887 } 888 }
888 889
889 ElementImpl getActualElement(Element element, String desc) { 890 ElementImpl getActualElement(Element element, String desc) {
890 if (element is ElementImpl) { 891 if (element is ElementImpl) {
891 return element; 892 return element;
892 } else if (element is ElementHandle) { 893 } else if (element is ElementHandle) {
893 return getActualElement(element.actualElement, desc); 894 Element actualElement = element.actualElement;
895 // A handle should never point to a member, because if it did, then
896 // "is Member" checks on the handle would produce the wrong result.
897 expect(actualElement, isNot(new isInstanceOf<Member>()), reason: desc);
898 return getActualElement(actualElement, desc);
894 } else if (element is Member) { 899 } else if (element is Member) {
895 return getActualElement(element.baseElement, desc); 900 return getActualElement(element.baseElement, desc);
896 } else { 901 } else {
897 fail('Unexpected type for resynthesized ($desc):' 902 fail('Unexpected type for resynthesized ($desc):'
898 ' ${element.runtimeType}'); 903 ' ${element.runtimeType}');
899 return null; 904 return null;
900 } 905 }
901 } 906 }
902 907
903 /** 908 /**
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 fail('Unexpectedly tried to get unlinked summary for $uri'); 3276 fail('Unexpectedly tried to get unlinked summary for $uri');
3272 } 3277 }
3273 return serializedUnit; 3278 return serializedUnit;
3274 } 3279 }
3275 3280
3276 @override 3281 @override
3277 bool hasLibrarySummary(String uri) { 3282 bool hasLibrarySummary(String uri) {
3278 return true; 3283 return true;
3279 } 3284 }
3280 } 3285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698