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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.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 | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 804 }
805 for (ConstructorElement constructor in constructors) { 805 for (ConstructorElement constructor in constructors) {
806 if (!constructor.isSynthetic && !constructor.isFactory) { 806 if (!constructor.isSynthetic && !constructor.isFactory) {
807 return false; 807 return false;
808 } 808 }
809 } 809 }
810 return true; 810 return true;
811 } 811 }
812 812
813 @override 813 @override
814 List<kernel.TypeParameter> get kernelTypeParams => _kernel?.typeParameters;
815
816 @override
814 List<ElementAnnotation> get metadata { 817 List<ElementAnnotation> get metadata {
815 if (_unlinkedClass != null) { 818 if (_unlinkedClass != null) {
816 return _metadata ??= 819 return _metadata ??=
817 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations); 820 _buildAnnotations(enclosingUnit, _unlinkedClass.annotations);
818 } 821 }
819 return super.metadata; 822 return super.metadata;
820 } 823 }
821 824
822 @override 825 @override
823 List<MethodElement> get methods { 826 List<MethodElement> get methods {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 int get nameOffset { 884 int get nameOffset {
882 int offset = super.nameOffset; 885 int offset = super.nameOffset;
883 if (offset == 0 && _unlinkedClass != null) { 886 if (offset == 0 && _unlinkedClass != null) {
884 return _unlinkedClass.nameOffset; 887 return _unlinkedClass.nameOffset;
885 } 888 }
886 return offset; 889 return offset;
887 } 890 }
888 891
889 @override 892 @override
890 InterfaceType get supertype { 893 InterfaceType get supertype {
891 if (_unlinkedClass != null && _supertype == null) { 894 if (_supertype == null) {
892 if (_unlinkedClass.supertype != null) { 895 if (_kernel != null) {
893 DartType type = enclosingUnit.resynthesizerContext 896 if (_kernel.supertype != null) {
894 .resolveTypeRef(this, _unlinkedClass.supertype); 897 _supertype = enclosingUnit._kernelContext
895 if (_isClassInterfaceType(type)) { 898 .getInterfaceType(this, _kernel.supertype);
896 _supertype = type; 899 _supertype ??= context.typeProvider.objectType;
900 } else {
901 return null;
902 }
903 }
904 if (_unlinkedClass != null) {
905 if (_unlinkedClass.supertype != null) {
906 DartType type = enclosingUnit.resynthesizerContext
907 .resolveTypeRef(this, _unlinkedClass.supertype);
908 if (_isClassInterfaceType(type)) {
909 _supertype = type;
910 } else {
911 _supertype = context.typeProvider.objectType;
912 }
913 } else if (_unlinkedClass.hasNoSupertype) {
914 return null;
897 } else { 915 } else {
898 _supertype = context.typeProvider.objectType; 916 _supertype = context.typeProvider.objectType;
899 } 917 }
900 } else if (_unlinkedClass.hasNoSupertype) {
901 return null;
902 } else {
903 _supertype = context.typeProvider.objectType;
904 } 918 }
905 } 919 }
906 return _supertype; 920 return _supertype;
907 } 921 }
908 922
909 void set supertype(InterfaceType supertype) { 923 void set supertype(InterfaceType supertype) {
910 _assertNotResynthesized(_unlinkedClass); 924 _assertNotResynthesized(_unlinkedClass);
911 _supertype = supertype; 925 _supertype = supertype;
912 } 926 }
913 927
(...skipping 2910 matching lines...) Expand 10 before | Expand all | Expand 10 after
3824 return hasModifier(Modifier.GENERATOR); 3838 return hasModifier(Modifier.GENERATOR);
3825 } 3839 }
3826 3840
3827 @override 3841 @override
3828 bool get isOperator => false; 3842 bool get isOperator => false;
3829 3843
3830 @override 3844 @override
3831 bool get isSynchronous => !isAsynchronous; 3845 bool get isSynchronous => !isAsynchronous;
3832 3846
3833 @override 3847 @override
3848 List<kernel.TypeParameter> get kernelTypeParams => null;
3849
3850 @override
3834 List<ElementAnnotation> get metadata { 3851 List<ElementAnnotation> get metadata {
3835 if (serializedExecutable != null) { 3852 if (serializedExecutable != null) {
3836 return _metadata ??= 3853 return _metadata ??=
3837 _buildAnnotations(enclosingUnit, serializedExecutable.annotations); 3854 _buildAnnotations(enclosingUnit, serializedExecutable.annotations);
3838 } 3855 }
3839 return super.metadata; 3856 return super.metadata;
3840 } 3857 }
3841 3858
3842 @override 3859 @override
3843 String get name { 3860 String get name {
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 super.enclosingElement as CompilationUnitElement; 4675 super.enclosingElement as CompilationUnitElement;
4659 4676
4660 @override 4677 @override
4661 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; 4678 TypeParameterizedElementMixin get enclosingTypeParameterContext => null;
4662 4679
4663 @override 4680 @override
4664 CompilationUnitElementImpl get enclosingUnit => 4681 CompilationUnitElementImpl get enclosingUnit =>
4665 _enclosingElement as CompilationUnitElementImpl; 4682 _enclosingElement as CompilationUnitElementImpl;
4666 4683
4667 @override 4684 @override
4685 List<kernel.TypeParameter> get kernelTypeParams => null;
4686
4687 @override
4668 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; 4688 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS;
4669 4689
4670 @override 4690 @override
4671 List<ElementAnnotation> get metadata { 4691 List<ElementAnnotation> get metadata {
4672 if (_unlinkedTypedef != null) { 4692 if (_unlinkedTypedef != null) {
4673 return _metadata ??= 4693 return _metadata ??=
4674 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); 4694 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations);
4675 } 4695 }
4676 return super.metadata; 4696 return super.metadata;
4677 } 4697 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
4872 4892
4873 @override 4893 @override
4874 TypeParameterizedElementMixin get enclosingTypeParameterContext { 4894 TypeParameterizedElementMixin get enclosingTypeParameterContext {
4875 return _enclosingElement.typeParameterContext; 4895 return _enclosingElement.typeParameterContext;
4876 } 4896 }
4877 4897
4878 @override 4898 @override
4879 String get identifier => '-'; 4899 String get identifier => '-';
4880 4900
4881 @override 4901 @override
4902 List<kernel.TypeParameter> get kernelTypeParams => null;
4903
4904 @override
4882 ElementKind get kind => ElementKind.GENERIC_FUNCTION_TYPE; 4905 ElementKind get kind => ElementKind.GENERIC_FUNCTION_TYPE;
4883 4906
4884 @override 4907 @override
4885 List<ParameterElement> get parameters { 4908 List<ParameterElement> get parameters {
4886 if (_entityRef != null) { 4909 if (_entityRef != null) {
4887 _parameters ??= ParameterElementImpl.resynthesizeList( 4910 _parameters ??= ParameterElementImpl.resynthesizeList(
4888 _entityRef.syntheticParams, this); 4911 _entityRef.syntheticParams, this);
4889 } 4912 }
4890 return _parameters ?? const <ParameterElement>[]; 4913 return _parameters ?? const <ParameterElement>[];
4891 } 4914 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
5099 */ 5122 */
5100 void set function(GenericFunctionTypeElement function) { 5123 void set function(GenericFunctionTypeElement function) {
5101 _assertNotResynthesized(_unlinkedTypedef); 5124 _assertNotResynthesized(_unlinkedTypedef);
5102 if (function != null) { 5125 if (function != null) {
5103 (function as GenericFunctionTypeElementImpl).enclosingElement = this; 5126 (function as GenericFunctionTypeElementImpl).enclosingElement = this;
5104 } 5127 }
5105 _function = function; 5128 _function = function;
5106 } 5129 }
5107 5130
5108 @override 5131 @override
5132 List<kernel.TypeParameter> get kernelTypeParams => null;
5133
5134 @override
5109 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; 5135 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS;
5110 5136
5111 @override 5137 @override
5112 List<ElementAnnotation> get metadata { 5138 List<ElementAnnotation> get metadata {
5113 if (_unlinkedTypedef != null) { 5139 if (_unlinkedTypedef != null) {
5114 return _metadata ??= 5140 return _metadata ??=
5115 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations); 5141 _buildAnnotations(enclosingUnit, _unlinkedTypedef.annotations);
5116 } 5142 }
5117 return super.metadata; 5143 return super.metadata;
5118 } 5144 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
5556 return const <NamespaceCombinator>[]; 5582 return const <NamespaceCombinator>[];
5557 } 5583 }
5558 } 5584 }
5559 } 5585 }
5560 5586
5561 /** 5587 /**
5562 * The kernel context in which a library is resynthesized. 5588 * The kernel context in which a library is resynthesized.
5563 */ 5589 */
5564 abstract class KernelLibraryResynthesizerContext { 5590 abstract class KernelLibraryResynthesizerContext {
5565 kernel.Library get library; 5591 kernel.Library get library;
5592
5593 /**
5594 * Return the [InterfaceType] for the given Kernel [type], or `null` if the
5595 * [type] does not correspond to an [InterfaceType].
5596 */
5597 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type);
5598
5599 /**
5600 * Return the [DartType] for the given Kernel [type], or `null` if the [type]
5601 * does not correspond to a [DartType].
5602 */
5603 DartType getType(ElementImpl context, kernel.DartType type);
5566 } 5604 }
5567 5605
5568 /** 5606 /**
5569 * A concrete implementation of a [LabelElement]. 5607 * A concrete implementation of a [LabelElement].
5570 */ 5608 */
5571 class LabelElementImpl extends ElementImpl implements LabelElement { 5609 class LabelElementImpl extends ElementImpl implements LabelElement {
5572 /** 5610 /**
5573 * A flag indicating whether this label is associated with a `switch` 5611 * A flag indicating whether this label is associated with a `switch`
5574 * statement. 5612 * statement.
5575 */ 5613 */
(...skipping 2868 matching lines...) Expand 10 before | Expand all | Expand 10 after
8444 8482
8445 /** 8483 /**
8446 * The number of type parameters whose scope overlaps this one, and which are 8484 * The number of type parameters whose scope overlaps this one, and which are
8447 * declared earlier in the file. 8485 * declared earlier in the file.
8448 * 8486 *
8449 * TODO(scheglov) make private? 8487 * TODO(scheglov) make private?
8450 */ 8488 */
8451 final int nestingLevel; 8489 final int nestingLevel;
8452 8490
8453 /** 8491 /**
8492 * The kernel of the element.
8493 */
8494 final kernel.TypeParameter _kernel;
8495
8496 /**
8454 * The type defined by this type parameter. 8497 * The type defined by this type parameter.
8455 */ 8498 */
8456 TypeParameterType _type; 8499 TypeParameterType _type;
8457 8500
8458 /** 8501 /**
8459 * The type representing the bound associated with this parameter, or `null` 8502 * The type representing the bound associated with this parameter, or `null`
8460 * if this parameter does not have an explicit bound. 8503 * if this parameter does not have an explicit bound.
8461 */ 8504 */
8462 DartType _bound; 8505 DartType _bound;
8463 8506
8464 /** 8507 /**
8465 * Initialize a newly created method element to have the given [name] and 8508 * Initialize a newly created method element to have the given [name] and
8466 * [offset]. 8509 * [offset].
8467 */ 8510 */
8468 TypeParameterElementImpl(String name, int offset) 8511 TypeParameterElementImpl(String name, int offset)
8469 : _unlinkedTypeParam = null, 8512 : _unlinkedTypeParam = null,
8470 nestingLevel = null, 8513 nestingLevel = null,
8514 _kernel = null,
8471 super(name, offset); 8515 super(name, offset);
8472 8516
8473 /** 8517 /**
8518 * Initialize using the given kernel.
8519 */
8520 TypeParameterElementImpl.forKernel(
8521 TypeParameterizedElementMixin enclosingElement, this._kernel)
8522 : _unlinkedTypeParam = null,
8523 nestingLevel = null,
8524 super.forSerialized(enclosingElement);
8525
8526 /**
8474 * Initialize a newly created type parameter element to have the given [name]. 8527 * Initialize a newly created type parameter element to have the given [name].
8475 */ 8528 */
8476 TypeParameterElementImpl.forNode(Identifier name) 8529 TypeParameterElementImpl.forNode(Identifier name)
8477 : _unlinkedTypeParam = null, 8530 : _unlinkedTypeParam = null,
8478 nestingLevel = null, 8531 nestingLevel = null,
8532 _kernel = null,
8479 super.forNode(name); 8533 super.forNode(name);
8480 8534
8481 /** 8535 /**
8482 * Initialize using the given serialized information. 8536 * Initialize using the given serialized information.
8483 */ 8537 */
8484 TypeParameterElementImpl.forSerialized(this._unlinkedTypeParam, 8538 TypeParameterElementImpl.forSerialized(this._unlinkedTypeParam,
8485 TypeParameterizedElementMixin enclosingElement, this.nestingLevel) 8539 TypeParameterizedElementMixin enclosingElement, this.nestingLevel)
8486 : super.forSerialized(enclosingElement); 8540 : _kernel = null,
8541 super.forSerialized(enclosingElement);
8487 8542
8488 /** 8543 /**
8489 * Initialize a newly created synthetic type parameter element to have the 8544 * Initialize a newly created synthetic type parameter element to have the
8490 * given [name], and with [synthetic] set to true. 8545 * given [name], and with [synthetic] set to true.
8491 */ 8546 */
8492 TypeParameterElementImpl.synthetic(String name) 8547 TypeParameterElementImpl.synthetic(String name)
8493 : _unlinkedTypeParam = null, 8548 : _unlinkedTypeParam = null,
8494 nestingLevel = null, 8549 nestingLevel = null,
8550 _kernel = null,
8495 super(name, -1) { 8551 super(name, -1) {
8496 isSynthetic = true; 8552 isSynthetic = true;
8497 } 8553 }
8498 8554
8499 DartType get bound { 8555 DartType get bound {
8500 if (_unlinkedTypeParam != null) { 8556 if (_bound == null) {
8501 if (_unlinkedTypeParam.bound == null) { 8557 if (_kernel != null) {
8502 return null; 8558 _bound = enclosingUnit._kernelContext.getType(this, _kernel.bound);
8559 // TODO(scheglov) Add a flag for explicit bound.
8560 if (_bound != null && _bound.isObject) _bound = null;
8503 } 8561 }
8504 return _bound ??= enclosingUnit.resynthesizerContext.resolveTypeRef( 8562 if (_unlinkedTypeParam != null) {
8505 this, _unlinkedTypeParam.bound, 8563 if (_unlinkedTypeParam.bound == null) {
8506 instantiateToBoundsAllowed: false, declaredType: true); 8564 return null;
8565 }
8566 _bound = enclosingUnit.resynthesizerContext.resolveTypeRef(
8567 this, _unlinkedTypeParam.bound,
8568 instantiateToBoundsAllowed: false, declaredType: true);
8569 }
8507 } 8570 }
8508 return _bound; 8571 return _bound;
8509 } 8572 }
8510 8573
8511 void set bound(DartType bound) { 8574 void set bound(DartType bound) {
8512 _assertNotResynthesized(_unlinkedTypeParam); 8575 _assertNotResynthesized(_unlinkedTypeParam);
8513 _bound = _checkElementOfType(bound); 8576 _bound = _checkElementOfType(bound);
8514 } 8577 }
8515 8578
8516 @override 8579 @override
(...skipping 22 matching lines...) Expand all
8539 List<ElementAnnotation> get metadata { 8602 List<ElementAnnotation> get metadata {
8540 if (_unlinkedTypeParam != null) { 8603 if (_unlinkedTypeParam != null) {
8541 return _metadata ??= 8604 return _metadata ??=
8542 _buildAnnotations(enclosingUnit, _unlinkedTypeParam.annotations); 8605 _buildAnnotations(enclosingUnit, _unlinkedTypeParam.annotations);
8543 } 8606 }
8544 return super.metadata; 8607 return super.metadata;
8545 } 8608 }
8546 8609
8547 @override 8610 @override
8548 String get name { 8611 String get name {
8612 if (_kernel != null) {
8613 return _kernel.name;
8614 }
8549 if (_unlinkedTypeParam != null) { 8615 if (_unlinkedTypeParam != null) {
8550 return _unlinkedTypeParam.name; 8616 return _unlinkedTypeParam.name;
8551 } 8617 }
8552 return super.name; 8618 return super.name;
8553 } 8619 }
8554 8620
8555 @override 8621 @override
8556 int get nameOffset { 8622 int get nameOffset {
8557 int offset = super.nameOffset; 8623 int offset = super.nameOffset;
8558 if (offset == 0 && _unlinkedTypeParam != null) { 8624 if (offset == 0 && _unlinkedTypeParam != null) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
8644 /** 8710 /**
8645 * Get the type parameter context enclosing this one, if any. 8711 * Get the type parameter context enclosing this one, if any.
8646 */ 8712 */
8647 TypeParameterizedElementMixin get enclosingTypeParameterContext; 8713 TypeParameterizedElementMixin get enclosingTypeParameterContext;
8648 8714
8649 /** 8715 /**
8650 * The unit in which this element is resynthesized. 8716 * The unit in which this element is resynthesized.
8651 */ 8717 */
8652 CompilationUnitElementImpl get enclosingUnit; 8718 CompilationUnitElementImpl get enclosingUnit;
8653 8719
8720 /**
8721 * Get the [kernel.TypeParameter]s declared by this element, or `null` if
8722 * this elements isn't from a kernel.
8723 */
8724 List<kernel.TypeParameter> get kernelTypeParams;
8725
8654 @override 8726 @override
8655 TypeParameterizedElementMixin get typeParameterContext => this; 8727 TypeParameterizedElementMixin get typeParameterContext => this;
8656 8728
8657 /** 8729 /**
8658 * Find out how many type parameters are in scope in this context. 8730 * Find out how many type parameters are in scope in this context.
8659 */ 8731 */
8660 int get typeParameterNestingLevel => 8732 int get typeParameterNestingLevel =>
8661 _nestingLevel ??= unlinkedTypeParams.length + 8733 _nestingLevel ??= unlinkedTypeParams.length +
8662 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); 8734 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0);
8663 8735
8664 @override 8736 @override
8665 List<TypeParameterElement> get typeParameters { 8737 List<TypeParameterElement> get typeParameters {
8666 if (_typeParameterElements == null) { 8738 if (_typeParameterElements == null) {
8739 List<kernel.TypeParameter> kernelParams = kernelTypeParams;
8740 if (kernelParams != null) {
8741 int numTypeParameters = kernelParams.length;
8742 _typeParameterElements =
8743 new List<TypeParameterElement>(numTypeParameters);
8744 for (int i = 0; i < numTypeParameters; i++) {
8745 _typeParameterElements[i] =
8746 new TypeParameterElementImpl.forKernel(this, kernelParams[i]);
8747 }
8748 }
8749
8667 List<UnlinkedTypeParam> unlinkedParams = unlinkedTypeParams; 8750 List<UnlinkedTypeParam> unlinkedParams = unlinkedTypeParams;
8668 if (unlinkedParams != null) { 8751 if (unlinkedParams != null) {
8669 int enclosingNestingLevel = 8752 int enclosingNestingLevel =
8670 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0; 8753 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0;
8671 int numTypeParameters = unlinkedParams.length; 8754 int numTypeParameters = unlinkedParams.length;
8672 _typeParameterElements = 8755 _typeParameterElements =
8673 new List<TypeParameterElement>(numTypeParameters); 8756 new List<TypeParameterElement>(numTypeParameters);
8674 for (int i = 0; i < numTypeParameters; i++) { 8757 for (int i = 0; i < numTypeParameters; i++) {
8675 _typeParameterElements[i] = 8758 _typeParameterElements[i] =
8676 new TypeParameterElementImpl.forSerialized( 8759 new TypeParameterElementImpl.forSerialized(
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
9000 9083
9001 @override 9084 @override
9002 DartObject computeConstantValue() => null; 9085 DartObject computeConstantValue() => null;
9003 9086
9004 @override 9087 @override
9005 void visitChildren(ElementVisitor visitor) { 9088 void visitChildren(ElementVisitor visitor) {
9006 super.visitChildren(visitor); 9089 super.visitChildren(visitor);
9007 _initializer?.accept(visitor); 9090 _initializer?.accept(visitor);
9008 } 9091 }
9009 } 9092 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698