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

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

Issue 2986983002: Resynthesize metadata from Kernel, when already supported. (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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 class _KernelLibraryResynthesizerContextImpl 377 class _KernelLibraryResynthesizerContextImpl
378 implements KernelLibraryResynthesizerContext { 378 implements KernelLibraryResynthesizerContext {
379 final KernelResynthesizer _resynthesizer; 379 final KernelResynthesizer _resynthesizer;
380 380
381 @override 381 @override
382 final kernel.Library library; 382 final kernel.Library library;
383 383
384 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library); 384 _KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library);
385 385
386 @override 386 @override
387 List<ElementAnnotation> buildAnnotations(
388 CompilationUnitElementImpl unit, List<kernel.Expression> expressions) {
389 int length = expressions.length;
390 if (length != 0) {
391 var annotations = new List<ElementAnnotation>(length);
392 for (int i = 0; i < length; i++) {
393 annotations[i] = _buildAnnotation(unit, expressions[i]);
394 }
395 return annotations;
396 } else {
397 return const <ElementAnnotation>[];
398 }
399 }
400
401 @override
387 UnitExplicitTopLevelAccessors buildTopLevelAccessors( 402 UnitExplicitTopLevelAccessors buildTopLevelAccessors(
388 CompilationUnitElementImpl unit) { 403 CompilationUnitElementImpl unit) {
389 var accessorsData = new UnitExplicitTopLevelAccessors(); 404 var accessorsData = new UnitExplicitTopLevelAccessors();
390 var implicitVariables = <String, TopLevelVariableElementImpl>{}; 405 var implicitVariables = <String, TopLevelVariableElementImpl>{};
391 // Build explicit property accessors and implicit fields. 406 // Build explicit property accessors and implicit fields.
392 for (var procedure in library.procedures) { 407 for (var procedure in library.procedures) {
393 bool isGetter = procedure.kind == kernel.ProcedureKind.Getter; 408 bool isGetter = procedure.kind == kernel.ProcedureKind.Getter;
394 bool isSetter = procedure.kind == kernel.ProcedureKind.Setter; 409 bool isSetter = procedure.kind == kernel.ProcedureKind.Setter;
395 if (isGetter || isSetter) { 410 if (isGetter || isSetter) {
396 var accessor = 411 var accessor =
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 552
538 functionElement.returnType = 553 functionElement.returnType =
539 getType(functionElement, kernelType.returnType); 554 getType(functionElement, kernelType.returnType);
540 return functionElement.type; 555 return functionElement.type;
541 } 556 }
542 557
543 // TODO(scheglov) Support other kernel types. 558 // TODO(scheglov) Support other kernel types.
544 throw new UnimplementedError('For ${kernelType.runtimeType}'); 559 throw new UnimplementedError('For ${kernelType.runtimeType}');
545 } 560 }
546 561
562 ElementAnnotationImpl _buildAnnotation(
563 CompilationUnitElementImpl unit, kernel.Expression expression) {
564 ElementAnnotationImpl elementAnnotation = new ElementAnnotationImpl(unit);
565 Expression constExpr = getExpression(expression);
566 if (constExpr is Identifier) {
567 elementAnnotation.element = constExpr.staticElement;
568 elementAnnotation.annotationAst = AstTestFactory.annotation(constExpr);
569 } else if (constExpr is InstanceCreationExpression) {
570 elementAnnotation.element = constExpr.staticElement;
571 Identifier typeName = constExpr.constructorName.type.name;
572 SimpleIdentifier constructorName = constExpr.constructorName.name;
573 elementAnnotation.annotationAst = AstTestFactory.annotation2(
574 typeName, constructorName, constExpr.argumentList)
575 ..element = constExpr.staticElement;
576 } else {
577 throw new StateError(
578 'Unexpected annotation type: ${constExpr.runtimeType}');
579 }
580 return elementAnnotation;
581 }
582
547 /** 583 /**
548 * Return the [ElementImpl] that corresponds to the given [name], or `null` 584 * Return the [ElementImpl] that corresponds to the given [name], or `null`
549 * if the corresponding element cannot be found. 585 * if the corresponding element cannot be found.
550 */ 586 */
551 ElementImpl _getElement(kernel.CanonicalName name) { 587 ElementImpl _getElement(kernel.CanonicalName name) {
552 if (name == null) return null; 588 if (name == null) return null;
553 kernel.CanonicalName parentName = name.parent; 589 kernel.CanonicalName parentName = name.parent;
554 590
555 // If the parent is the root, then this name is a library. 591 // If the parent is the root, then this name is a library.
556 if (parentName.isRoot) { 592 if (parentName.isRoot) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 for (var typeParameter in ctx.typeParameters) { 686 for (var typeParameter in ctx.typeParameters) {
651 if (typeParameter.name == name) { 687 if (typeParameter.name == name) {
652 return typeParameter; 688 return typeParameter;
653 } 689 }
654 } 690 }
655 } 691 }
656 } 692 }
657 throw new StateError('Not found $kernelTypeParameter in $context'); 693 throw new StateError('Not found $kernelTypeParameter in $context');
658 } 694 }
659 } 695 }
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