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

Side by Side Diff: pkg/analyzer/lib/src/kernel/resynthesize.dart

Issue 2991723002: Resynthesize FunctionType(s) from Kernel. (Closed)
Patch Set: Created 3 years, 4 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) 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.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';
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 411 }
412 412
413 @override 413 @override
414 LibraryElement getLibrary(String uriStr) { 414 LibraryElement getLibrary(String uriStr) {
415 return _resynthesizer.getLibrary(uriStr); 415 return _resynthesizer.getLibrary(uriStr);
416 } 416 }
417 417
418 DartType getType(ElementImpl context, kernel.DartType kernelType) { 418 DartType getType(ElementImpl context, kernel.DartType kernelType) {
419 if (kernelType is kernel.DynamicType) return DynamicTypeImpl.instance; 419 if (kernelType is kernel.DynamicType) return DynamicTypeImpl.instance;
420 if (kernelType is kernel.VoidType) return VoidTypeImpl.instance; 420 if (kernelType is kernel.VoidType) return VoidTypeImpl.instance;
421
421 if (kernelType is kernel.InterfaceType) { 422 if (kernelType is kernel.InterfaceType) {
422 return _getInterfaceType(context, kernelType.className.canonicalName, 423 return _getInterfaceType(context, kernelType.className.canonicalName,
423 kernelType.typeArguments); 424 kernelType.typeArguments);
424 } 425 }
426
425 if (kernelType is kernel.TypeParameterType) { 427 if (kernelType is kernel.TypeParameterType) {
426 kernel.TypeParameter kTypeParameter = kernelType.parameter; 428 kernel.TypeParameter kTypeParameter = kernelType.parameter;
427 return _getTypeParameter(context, kTypeParameter).type; 429 return _getTypeParameter(context, kTypeParameter).type;
428 } 430 }
431
432 if (kernelType is kernel.FunctionType) {
433 var functionElement = new FunctionElementImpl.synthetic([], null);
434 functionElement.enclosingElement = context;
435
436 functionElement.typeParameters = kernelType.typeParameters.map((k) {
437 return new TypeParameterElementImpl.forKernel(functionElement, k);
438 }).toList(growable: false);
439
440 functionElement.parameters = ParameterElementImpl.forKernelParameters(
441 functionElement,
442 kernelType.requiredParameterCount,
443 kernelType.positionalParameters
444 .map((t) => new kernel.VariableDeclaration(null, type: t))
445 .toList(),
446 kernelType.namedParameters
447 .map((t) => new kernel.VariableDeclaration(t.name, type: t.type))
448 .toList());
449
450 functionElement.returnType =
451 getType(functionElement, kernelType.returnType);
452 return functionElement.type;
453 }
454
429 // TODO(scheglov) Support other kernel types. 455 // TODO(scheglov) Support other kernel types.
430 throw new UnimplementedError('For ${kernelType.runtimeType}'); 456 throw new UnimplementedError('For ${kernelType.runtimeType}');
431 } 457 }
432 458
433 /** 459 /**
434 * Return the [ElementImpl] that corresponds to the given [name], or `null` 460 * Return the [ElementImpl] that corresponds to the given [name], or `null`
435 * if the corresponding element cannot be found. 461 * if the corresponding element cannot be found.
436 */ 462 */
437 ElementImpl _getElement(kernel.CanonicalName name) { 463 ElementImpl _getElement(kernel.CanonicalName name) {
438 if (name == null) return null; 464 if (name == null) return null;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 for (var typeParameter in ctx.typeParameters) { 562 for (var typeParameter in ctx.typeParameters) {
537 if (typeParameter.name == name) { 563 if (typeParameter.name == name) {
538 return typeParameter; 564 return typeParameter;
539 } 565 }
540 } 566 }
541 } 567 }
542 } 568 }
543 throw new StateError('Not found $kernelTypeParameter in $context'); 569 throw new StateError('Not found $kernelTypeParameter in $context');
544 } 570 }
545 } 571 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698