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

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

Issue 2977983002: Resynthesize InterfaceType, class type parameters and supertype. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_common.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 analyzer.test.src.summary.resynthesize_kernel_test; 5 library analyzer.test.src.summary.resynthesize_kernel_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/file_system/memory_file_system.dart'; 11 import 'package:analyzer/file_system/memory_file_system.dart';
11 import 'package:analyzer/src/dart/element/element.dart'; 12 import 'package:analyzer/src/dart/element/element.dart';
13 import 'package:analyzer/src/dart/element/type.dart';
14 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
12 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/summary/resynthesize.dart'; 16 import 'package:analyzer/src/summary/resynthesize.dart';
14 import 'package:front_end/file_system.dart'; 17 import 'package:front_end/file_system.dart';
15 import 'package:front_end/src/base/performace_logger.dart'; 18 import 'package:front_end/src/base/performace_logger.dart';
16 import 'package:front_end/src/fasta/uri_translator_impl.dart'; 19 import 'package:front_end/src/fasta/uri_translator_impl.dart';
17 import 'package:front_end/src/incremental/byte_store.dart'; 20 import 'package:front_end/src/incremental/byte_store.dart';
18 import 'package:front_end/src/incremental/kernel_driver.dart'; 21 import 'package:front_end/src/incremental/kernel_driver.dart';
19 import 'package:kernel/kernel.dart' as kernel; 22 import 'package:kernel/kernel.dart' as kernel;
20 import 'package:kernel/target/targets.dart'; 23 import 'package:kernel/target/targets.dart';
21 import 'package:path/path.dart' as pathos; 24 import 'package:path/path.dart' as pathos;
22 import 'package:test/test.dart';
23 import 'package:test_reflective_loader/test_reflective_loader.dart'; 25 import 'package:test_reflective_loader/test_reflective_loader.dart';
24 26
25 import '../context/mock_sdk.dart'; 27 import '../context/mock_sdk.dart';
26 import 'resynthesize_common.dart'; 28 import 'resynthesize_common.dart';
27 29
28 main() { 30 main() {
29 defineReflectiveSuite(() { 31 defineReflectiveSuite(() {
30 defineReflectiveTests(ResynthesizeKernelStrongTest); 32 defineReflectiveTests(ResynthesizeKernelStrongTest);
31 }); 33 });
32 } 34 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 KernelResult kernelResult = await driver.getKernel(testUri); 79 KernelResult kernelResult = await driver.getKernel(testUri);
78 80
79 var libraryMap = <String, kernel.Library>{}; 81 var libraryMap = <String, kernel.Library>{};
80 for (var cycleResult in kernelResult.results) { 82 for (var cycleResult in kernelResult.results) {
81 for (var library in cycleResult.kernelLibraries) { 83 for (var library in cycleResult.kernelLibraries) {
82 String uriStr = library.importUri.toString(); 84 String uriStr = library.importUri.toString();
83 libraryMap[uriStr] = library; 85 libraryMap[uriStr] = library;
84 } 86 }
85 } 87 }
86 88
87 kernel.Library kernelLibrary = libraryMap[testUriStr]; 89 var resynthesizer = new _KernelResynthesizer(context, libraryMap);
88 expect(kernelLibrary, isNotNull); 90 return resynthesizer.getLibrary(testUriStr);
89
90 return new LibraryElementImpl.forKernel(context,
91 new _KernelLibraryResynthesizerContextImpl(libraryMap, kernelLibrary));
92 } 91 }
93 92
94 @override 93 @override
95 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource) { 94 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource) {
96 // TODO(scheglov): implement encodeDecodeLibrarySource 95 // TODO(scheglov): implement encodeDecodeLibrarySource
97 throw new UnimplementedError(); 96 throw new UnimplementedError();
98 } 97 }
99 98
100 @failingTest 99 @failingTest
101 test_class_alias() async { 100 test_class_alias() async {
(...skipping 26 matching lines...) Expand all
128 await super 127 await super
129 .test_class_alias_with_forwarding_constructors_type_substitution_complex (); 128 .test_class_alias_with_forwarding_constructors_type_substitution_complex ();
130 } 129 }
131 130
132 @failingTest 131 @failingTest
133 test_class_alias_with_mixin_members() async { 132 test_class_alias_with_mixin_members() async {
134 await super.test_class_alias_with_mixin_members(); 133 await super.test_class_alias_with_mixin_members();
135 } 134 }
136 135
137 @failingTest 136 @failingTest
138 test_class_constructor_explicit_type_params() async {
139 await super.test_class_constructor_explicit_type_params();
140 }
141
142 @failingTest
143 test_class_constructor_factory() async { 137 test_class_constructor_factory() async {
144 await super.test_class_constructor_factory(); 138 await super.test_class_constructor_factory();
145 } 139 }
146 140
147 @failingTest 141 @failingTest
148 test_class_constructor_field_formal_dynamic_dynamic() async { 142 test_class_constructor_field_formal_dynamic_dynamic() async {
149 await super.test_class_constructor_field_formal_dynamic_dynamic(); 143 await super.test_class_constructor_field_formal_dynamic_dynamic();
150 } 144 }
151 145
152 @failingTest 146 @failingTest
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 test_class_constructor_fieldFormal_optional_noDefault() async { 207 test_class_constructor_fieldFormal_optional_noDefault() async {
214 await super.test_class_constructor_fieldFormal_optional_noDefault(); 208 await super.test_class_constructor_fieldFormal_optional_noDefault();
215 } 209 }
216 210
217 @failingTest 211 @failingTest
218 test_class_constructor_fieldFormal_optional_withDefault() async { 212 test_class_constructor_fieldFormal_optional_withDefault() async {
219 await super.test_class_constructor_fieldFormal_optional_withDefault(); 213 await super.test_class_constructor_fieldFormal_optional_withDefault();
220 } 214 }
221 215
222 @failingTest 216 @failingTest
223 test_class_constructor_implicit_type_params() async {
224 await super.test_class_constructor_implicit_type_params();
225 }
226
227 @failingTest
228 test_class_constructor_params() async { 217 test_class_constructor_params() async {
229 await super.test_class_constructor_params(); 218 await super.test_class_constructor_params();
230 } 219 }
231 220
232 @failingTest 221 @failingTest
233 test_class_documented() async { 222 test_class_documented() async {
234 await super.test_class_documented(); 223 await super.test_class_documented();
235 } 224 }
236 225
237 @failingTest 226 @failingTest
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 test_class_setter_static() async { 367 test_class_setter_static() async {
379 await super.test_class_setter_static(); 368 await super.test_class_setter_static();
380 } 369 }
381 370
382 @failingTest 371 @failingTest
383 test_class_setters() async { 372 test_class_setters() async {
384 await super.test_class_setters(); 373 await super.test_class_setters();
385 } 374 }
386 375
387 @failingTest 376 @failingTest
388 test_class_supertype() async {
389 await super.test_class_supertype();
390 }
391
392 @failingTest
393 test_class_type_parameters() async {
394 await super.test_class_type_parameters();
395 }
396
397 @failingTest
398 test_class_type_parameters_bound() async { 377 test_class_type_parameters_bound() async {
399 await super.test_class_type_parameters_bound(); 378 await super.test_class_type_parameters_bound();
400 } 379 }
401 380
402 @failingTest 381 @failingTest
403 test_class_type_parameters_f_bound_complex() async { 382 test_class_type_parameters_f_bound_complex() async {
404 await super.test_class_type_parameters_f_bound_complex(); 383 await super.test_class_type_parameters_f_bound_complex();
405 } 384 }
406 385
407 @failingTest 386 @failingTest
(...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 } 2639 }
2661 2640
2662 @override 2641 @override
2663 Future<String> readAsString() async { 2642 Future<String> readAsString() async {
2664 return file.readAsStringSync(); 2643 return file.readAsStringSync();
2665 } 2644 }
2666 } 2645 }
2667 2646
2668 class _KernelLibraryResynthesizerContextImpl 2647 class _KernelLibraryResynthesizerContextImpl
2669 implements KernelLibraryResynthesizerContext { 2648 implements KernelLibraryResynthesizerContext {
2670 /// TODO(scheglov) we don't use this yet, make it private later 2649 final _KernelResynthesizer _resynthesizer;
2671 final Map<String, kernel.Library> libraryMap;
2672 2650
2673 @override 2651 @override
2674 final kernel.Library library; 2652 final kernel.Library library;
2675 2653
2676 _KernelLibraryResynthesizerContextImpl(this.libraryMap, this.library); 2654 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library);
2655
2656 @override
2657 InterfaceType getInterfaceType(
2658 ElementImpl context, kernel.Supertype kernelType) {
2659 return _getInterfaceType(
2660 kernelType.className.canonicalName, kernelType.typeArguments);
2661 }
2662
2663 DartType getType(ElementImpl context, kernel.DartType kernelType) {
2664 if (kernelType is kernel.InterfaceType) {
2665 return _getInterfaceType(
2666 kernelType.className.canonicalName, kernelType.typeArguments);
2667 }
2668 // TODO(scheglov) Support other kernel types.
2669 return null;
2670 }
2671
2672 InterfaceType _getInterfaceType(
2673 kernel.CanonicalName className, List<kernel.DartType> kernelArguments) {
2674 var libraryName = className.parent;
2675 var libraryElement = _resynthesizer.getLibrary(libraryName.name);
2676 ClassElementImpl classElement = libraryElement.getType(className.name);
2677
2678 if (kernelArguments.isEmpty) {
2679 return classElement.type;
2680 }
2681
2682 return new InterfaceTypeImpl.elementWithNameAndArgs(
2683 classElement, classElement.name, () {
2684 List<DartType> arguments = kernelArguments
2685 .map((kernel.DartType k) => getType(classElement, k))
2686 .toList(growable: false);
2687 return arguments;
2688 });
2689 }
2677 } 2690 }
2691
2692 class _KernelResynthesizer {
2693 final AnalysisContext _analysisContext;
2694 final Map<String, kernel.Library> _kernelMap;
2695 final Map<String, LibraryElementImpl> _libraryMap = {};
2696
2697 _KernelResynthesizer(this._analysisContext, this._kernelMap);
2698
2699 LibraryElementImpl getLibrary(String uriStr) {
2700 return _libraryMap.putIfAbsent(uriStr, () {
2701 var kernel = _kernelMap[uriStr];
2702 if (kernel == null) return null;
2703 var libraryContext =
2704 new _KernelLibraryResynthesizerContextImpl(this, kernel);
2705 return new LibraryElementImpl.forKernel(_analysisContext, libraryContext);
2706 });
2707 }
2708 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_common.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698