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

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

Issue 1660663002: Resynthesize generic class instance creations. (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 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
11 import 'package:analyzer/src/dart/element/member.dart';
11 import 'package:analyzer/src/dart/element/type.dart'; 12 import 'package:analyzer/src/dart/element/type.dart';
12 import 'package:analyzer/src/generated/element_handle.dart'; 13 import 'package:analyzer/src/generated/element_handle.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/resolver.dart' 15 import 'package:analyzer/src/generated/resolver.dart'
15 show Namespace, TypeProvider; 16 show Namespace, TypeProvider;
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/summary/format.dart'; 18 import 'package:analyzer/src/summary/format.dart';
18 import 'package:analyzer/src/summary/resynthesize.dart'; 19 import 'package:analyzer/src/summary/resynthesize.dart';
19 import 'package:analyzer/src/summary/summarize_elements.dart'; 20 import 'package:analyzer/src/summary/summarize_elements.dart';
20 import 'package:unittest/unittest.dart'; 21 import 'package:unittest/unittest.dart';
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 expect(oConstructor, isNotNull, reason: desc); 326 expect(oConstructor, isNotNull, reason: desc);
326 expect(rConstructor, isNotNull, reason: desc); 327 expect(rConstructor, isNotNull, reason: desc);
327 compareElements( 328 compareElements(
328 rConstructor.staticElement, oConstructor.staticElement, desc); 329 rConstructor.staticElement, oConstructor.staticElement, desc);
329 TypeName oType = oConstructor.type; 330 TypeName oType = oConstructor.type;
330 TypeName rType = rConstructor.type; 331 TypeName rType = rConstructor.type;
331 expect(oType, isNotNull, reason: desc); 332 expect(oType, isNotNull, reason: desc);
332 expect(rType, isNotNull, reason: desc); 333 expect(rType, isNotNull, reason: desc);
333 compareConstantExpressions(rType.name, oType.name, desc); 334 compareConstantExpressions(rType.name, oType.name, desc);
334 compareConstantExpressions(rConstructor.name, oConstructor.name, desc); 335 compareConstantExpressions(rConstructor.name, oConstructor.name, desc);
336 compareLists(
337 rType.typeArguments?.arguments, oType.typeArguments?.arguments);
335 compareLists(r.argumentList.arguments, o.argumentList.arguments); 338 compareLists(r.argumentList.arguments, o.argumentList.arguments);
336 } else if (o is ConstructorName && r is ConstructorName) { 339 } else if (o is ConstructorName && r is ConstructorName) {
337 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); 340 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
338 } else { 341 } else {
339 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); 342 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}');
340 } 343 }
341 } 344 }
342 } 345 }
343 346
344 void compareConstructorElements(ConstructorElementImpl resynthesized, 347 void compareConstructorElements(ConstructorElementImpl resynthesized,
(...skipping 14 matching lines...) Expand all
359 // Modifiers are a pain to test via handles. So just test them via the 362 // Modifiers are a pain to test via handles. So just test them via the
360 // actual element. 363 // actual element.
361 ElementImpl actualResynthesized = getActualElement(resynthesized, desc); 364 ElementImpl actualResynthesized = getActualElement(resynthesized, desc);
362 ElementImpl actualOriginal = getActualElement(original, desc); 365 ElementImpl actualOriginal = getActualElement(original, desc);
363 for (Modifier modifier in Modifier.values) { 366 for (Modifier modifier in Modifier.values) {
364 bool got = actualResynthesized.hasModifier(modifier); 367 bool got = actualResynthesized.hasModifier(modifier);
365 bool want = actualOriginal.hasModifier(modifier); 368 bool want = actualOriginal.hasModifier(modifier);
366 expect(got, want, 369 expect(got, want,
367 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 370 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
368 } 371 }
372 // Validate members.
373 if (actualOriginal is Member) {
374 expect(actualResynthesized, new isInstanceOf<Member>(), reason: desc);
375 } else {
376 expect(actualResynthesized, isNot(new isInstanceOf<Member>()),
377 reason: desc);
378 }
369 } 379 }
370 380
371 void compareExecutableElements(ExecutableElement resynthesized, 381 void compareExecutableElements(ExecutableElement resynthesized,
372 ExecutableElement original, String desc) { 382 ExecutableElement original, String desc) {
373 compareElements(resynthesized, original, desc); 383 compareElements(resynthesized, original, desc);
374 expect(resynthesized.parameters.length, original.parameters.length); 384 expect(resynthesized.parameters.length, original.parameters.length);
375 for (int i = 0; i < resynthesized.parameters.length; i++) { 385 for (int i = 0; i < resynthesized.parameters.length; i++) {
376 compareParameterElements( 386 compareParameterElements(
377 resynthesized.parameters[i], 387 resynthesized.parameters[i],
378 original.parameters[i], 388 original.parameters[i],
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 unlinkedSummaries, 724 unlinkedSummaries,
715 linkedSummaries, 725 linkedSummaries,
716 options.strongMode); 726 options.strongMode);
717 } 727 }
718 728
719 fail_library_hasExtUri() { 729 fail_library_hasExtUri() {
720 checkLibrary('import "dart-ext:doesNotExist.dart";'); 730 checkLibrary('import "dart-ext:doesNotExist.dart";');
721 } 731 }
722 732
723 ElementImpl getActualElement(Element element, String desc) { 733 ElementImpl getActualElement(Element element, String desc) {
724 if (element is ElementHandle) { 734 if (element is ElementImpl) {
725 return element.actualElement;
726 } else if (element is ElementImpl) {
727 return element; 735 return element;
736 } else if (element is ElementHandle) {
737 return getActualElement(element.actualElement, desc);
738 } else if (element is Member) {
739 return getActualElement(element.baseElement, desc);
728 } else { 740 } else {
729 fail('Unexpected type for resynthesized ($desc):' 741 fail('Unexpected type for resynthesized ($desc):'
730 ' ${element.runtimeType}'); 742 ' ${element.runtimeType}');
731 return null; 743 return null;
732 } 744 }
733 } 745 }
734 746
735 /** 747 /**
736 * Resynthesize the library element associated with [uri] using 748 * Resynthesize the library element associated with [uri] using
737 * [resynthesizer], and verify that it only had to consult one summary in 749 * [resynthesizer], and verify that it only had to consult one summary in
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1070 }
1059 1071
1060 test_class_type_parameters_f_bound_simple() { 1072 test_class_type_parameters_f_bound_simple() {
1061 checkLibrary('class C<T extends U, U> {}'); 1073 checkLibrary('class C<T extends U, U> {}');
1062 } 1074 }
1063 1075
1064 test_classes() { 1076 test_classes() {
1065 checkLibrary('class C {} class D {}'); 1077 checkLibrary('class C {} class D {}');
1066 } 1078 }
1067 1079
1080 test_const_invokeConstructor_generic_named() {
1081 shouldCompareConstValues = true;
1082 checkLibrary(r'''
1083 class C<K, V> {
1084 const C.named(K k, V v);
1085 }
1086 const V = const C<int, String>.named(1, '222');
1087 ''');
1088 }
1089
1090 test_const_invokeConstructor_generic_named_imported() {
1091 shouldCompareConstValues = true;
1092 addLibrarySource(
1093 '/a.dart',
1094 r'''
1095 class C<K, V> {
1096 const C.named(K k, V v);
1097 }
1098 ''');
1099 checkLibrary(r'''
1100 import 'a.dart';
1101 const V = const C<int, String>.named(1, '222');
1102 ''');
1103 }
1104
1105 test_const_invokeConstructor_generic_named_imported_withPrefix() {
1106 shouldCompareConstValues = true;
1107 addLibrarySource(
1108 '/a.dart',
1109 r'''
1110 class C<K, V> {
1111 const C.named(K k, V v);
1112 }
1113 ''');
1114 checkLibrary(r'''
1115 import 'a.dart' as p;
1116 const V = const p.C<int, String>.named(1, '222');
1117 ''');
1118 }
1119
1120 test_const_invokeConstructor_generic_unnamed() {
1121 shouldCompareConstValues = true;
1122 checkLibrary(r'''
1123 class C<K, V> {
1124 const C();
1125 }
1126 const V = const C<int, String>();
1127 ''');
1128 }
1129
1130 test_const_invokeConstructor_generic_unnamed_imported() {
1131 shouldCompareConstValues = true;
1132 addLibrarySource(
1133 '/a.dart',
1134 r'''
1135 class C<K, V> {
1136 const C();
1137 }
1138 ''');
1139 checkLibrary(r'''
1140 import 'a.dart';
1141 const V = const C<int, String>();
1142 ''');
1143 }
1144
1145 test_const_invokeConstructor_generic_unnamed_imported_withPrefix() {
1146 shouldCompareConstValues = true;
1147 addLibrarySource(
1148 '/a.dart',
1149 r'''
1150 class C<K, V> {
1151 const C();
1152 }
1153 ''');
1154 checkLibrary(r'''
1155 import 'a.dart' as p;
1156 const V = const p.C<int, String>();
1157 ''');
1158 }
1159
1068 test_const_invokeConstructor_named() { 1160 test_const_invokeConstructor_named() {
1069 shouldCompareConstValues = true; 1161 shouldCompareConstValues = true;
1070 checkLibrary(r''' 1162 checkLibrary(r'''
1071 class C { 1163 class C {
1072 const C.named(bool a, int b, int c, {String d, double e}); 1164 const C.named(bool a, int b, int c, {String d, double e});
1073 } 1165 }
1074 const V = const C.named(true, 1, 2, d: 'ccc', e: 3.4); 1166 const V = const C.named(true, 1, 2, d: 'ccc', e: 3.4);
1075 '''); 1167 ''');
1076 } 1168 }
1077 1169
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 fail('Unexpectedly tried to get unlinked summary for $uri'); 2489 fail('Unexpectedly tried to get unlinked summary for $uri');
2398 } 2490 }
2399 return serializedUnit; 2491 return serializedUnit;
2400 } 2492 }
2401 2493
2402 @override 2494 @override
2403 bool hasLibrarySummary(String uri) { 2495 bool hasLibrarySummary(String uri) {
2404 return true; 2496 return true;
2405 } 2497 }
2406 } 2498 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698