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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2016543002: Resynthesize FieldFormalParameterElementImpl(s) lazily. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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) 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 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 * [nameOffset]. 1791 * [nameOffset].
1792 */ 1792 */
1793 DefaultFieldFormalParameterElementImpl(String name, int nameOffset) 1793 DefaultFieldFormalParameterElementImpl(String name, int nameOffset)
1794 : super(name, nameOffset); 1794 : super(name, nameOffset);
1795 1795
1796 /** 1796 /**
1797 * Initialize a newly created parameter element to have the given [name]. 1797 * Initialize a newly created parameter element to have the given [name].
1798 */ 1798 */
1799 DefaultFieldFormalParameterElementImpl.forNode(Identifier name) 1799 DefaultFieldFormalParameterElementImpl.forNode(Identifier name)
1800 : super.forNode(name); 1800 : super.forNode(name);
1801
1802 /**
1803 * Initialize using the given serialized information.
1804 */
1805 DefaultFieldFormalParameterElementImpl.forSerialized(
1806 UnlinkedParam unlinkedParam, ElementImpl enclosingElement)
1807 : super.forSerialized(unlinkedParam, enclosingElement);
1808
1809 @override
1810 Expression get constantInitializer {
1811 if (_unlinkedParam != null) {
1812 UnlinkedConst defaultValue = _unlinkedParam.defaultValue;
1813 if (defaultValue == null) {
1814 return null;
1815 }
1816 return super.constantInitializer ??= enclosingUnit.resynthesizerContext
1817 .buildExpression(this, defaultValue);
1818 }
1819 return super.constantInitializer;
1820 }
1821
1822 @override
1823 void set constantInitializer(Expression initializer) {
1824 assert(_unlinkedParam == null);
1825 super.constantInitializer = initializer;
1826 }
1801 } 1827 }
1802 1828
1803 /** 1829 /**
1804 * A [ParameterElement] for parameters that have an initializer. 1830 * A [ParameterElement] for parameters that have an initializer.
1805 */ 1831 */
1806 class DefaultParameterElementImpl extends ParameterElementImpl 1832 class DefaultParameterElementImpl extends ParameterElementImpl
1807 with ConstVariableElement { 1833 with ConstVariableElement {
1808 /** 1834 /**
1809 * Initialize a newly created parameter element to have the given [name] and 1835 * Initialize a newly created parameter element to have the given [name] and
1810 * [nameOffset]. 1836 * [nameOffset].
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 3357
3332 /** 3358 /**
3333 * A [ParameterElementImpl] that has the additional information of the 3359 * A [ParameterElementImpl] that has the additional information of the
3334 * [FieldElement] associated with the parameter. 3360 * [FieldElement] associated with the parameter.
3335 */ 3361 */
3336 class FieldFormalParameterElementImpl extends ParameterElementImpl 3362 class FieldFormalParameterElementImpl extends ParameterElementImpl
3337 implements FieldFormalParameterElement { 3363 implements FieldFormalParameterElement {
3338 /** 3364 /**
3339 * The field associated with this field formal parameter. 3365 * The field associated with this field formal parameter.
3340 */ 3366 */
3341 FieldElement field; 3367 FieldElement _field;
3342 3368
3343 /** 3369 /**
3344 * Initialize a newly created parameter element to have the given [name] and 3370 * Initialize a newly created parameter element to have the given [name] and
3345 * [nameOffset]. 3371 * [nameOffset].
3346 */ 3372 */
3347 FieldFormalParameterElementImpl(String name, int nameOffset) 3373 FieldFormalParameterElementImpl(String name, int nameOffset)
3348 : super(name, nameOffset); 3374 : super(name, nameOffset);
3349 3375
3350 /** 3376 /**
3351 * Initialize a newly created parameter element to have the given [name]. 3377 * Initialize a newly created parameter element to have the given [name].
3352 */ 3378 */
3353 FieldFormalParameterElementImpl.forNode(Identifier name) 3379 FieldFormalParameterElementImpl.forNode(Identifier name)
3354 : super.forNode(name); 3380 : super.forNode(name);
3355 3381
3382 /**
3383 * Initialize using the given serialized information.
3384 */
3385 FieldFormalParameterElementImpl.forSerialized(
3386 UnlinkedParam unlinkedParam, ElementImpl enclosingElement)
3387 : super.forSerialized(unlinkedParam, enclosingElement);
3388
3389 @override
3390 FieldElement get field {
3391 if (_unlinkedParam != null && _field == null) {
3392 Element enclosingClass = enclosingElement?.enclosingElement;
3393 if (enclosingClass is ClassElement) {
3394 _field = enclosingClass.getField(_unlinkedParam.name);
3395 }
3396 }
3397 return _field;
3398 }
3399
3400 void set field(FieldElement field) {
3401 assert(_unlinkedParam == null);
3402 _field = field;
3403 }
3404
3356 @override 3405 @override
3357 bool get isInitializingFormal => true; 3406 bool get isInitializingFormal => true;
3358 3407
3359 @override 3408 @override
3409 DartType get type {
3410 if (_unlinkedParam != null && _unlinkedParam.type == null) {
3411 _type ??= field?.type ?? DynamicTypeImpl.instance;
3412 }
3413 return super.type;
3414 }
3415
3416 @override
3417 void set type(DartType type) {
3418 assert(_unlinkedParam == null);
3419 _type = type;
3420 }
3421
3422 @override
3360 accept(ElementVisitor visitor) => 3423 accept(ElementVisitor visitor) =>
3361 visitor.visitFieldFormalParameterElement(this); 3424 visitor.visitFieldFormalParameterElement(this);
3362 } 3425 }
3363 3426
3364 /** 3427 /**
3365 * Indicates that an ElementImpl's hashCode cannot currently be changed. 3428 * Indicates that an ElementImpl's hashCode cannot currently be changed.
3366 */ 3429 */
3367 class FrozenHashCodeException implements Exception { 3430 class FrozenHashCodeException implements Exception {
3368 final String _message; 3431 final String _message;
3369 3432
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3499 * [parameters] without becoming the parent of the parameters. This should 3562 * [parameters] without becoming the parent of the parameters. This should
3500 * only be used by the [TypeResolverVisitor] when creating a synthetic type 3563 * only be used by the [TypeResolverVisitor] when creating a synthetic type
3501 * alias. 3564 * alias.
3502 */ 3565 */
3503 void shareTypeParameters(List<TypeParameterElement> typeParameters) { 3566 void shareTypeParameters(List<TypeParameterElement> typeParameters) {
3504 this._typeParameters = typeParameters; 3567 this._typeParameters = typeParameters;
3505 } 3568 }
3506 } 3569 }
3507 3570
3508 /** 3571 /**
3572 * Implementation of [FunctionElementImpl] for a function typed parameter.
3573 */
3574 class FunctionElementImpl_forFunctionTypedParameter
3575 extends FunctionElementImpl {
3576 @override
3577 final CompilationUnitElementImpl enclosingUnit;
3578
3579 /**
3580 * The enclosing function typed [ParameterElementImpl].
3581 */
3582 final ParameterElementImpl _parameter;
3583
3584 FunctionElementImpl_forFunctionTypedParameter(
3585 this.enclosingUnit, this._parameter)
3586 : super('', -1);
3587
3588 @override
3589 TypeParameterizedElementMixin get enclosingTypeParameterContext =>
3590 _parameter.typeParameterContext;
3591
3592 @override
3593 bool get isSynthetic => true;
3594 }
3595
3596 /**
3597 * Implementation of [FunctionElementImpl] for a synthetic function element
3598 * that was synthesized by a LUB computation.
3599 */
3600 class FunctionElementImpl_forLUB extends FunctionElementImpl {
3601 @override
3602 final CompilationUnitElementImpl enclosingUnit;
3603
3604 @override
3605 final TypeParameterizedElementMixin enclosingTypeParameterContext;
3606
3607 FunctionElementImpl_forLUB(
3608 this.enclosingUnit, this.enclosingTypeParameterContext)
3609 : super('', -1);
3610
3611 @override
3612 bool get isSynthetic => true;
3613 }
3614
3615 /**
3509 * A concrete implementation of a [FunctionTypeAliasElement]. 3616 * A concrete implementation of a [FunctionTypeAliasElement].
3510 */ 3617 */
3511 class FunctionTypeAliasElementImpl extends ElementImpl 3618 class FunctionTypeAliasElementImpl extends ElementImpl
3512 with TypeParameterizedElementMixin 3619 with TypeParameterizedElementMixin
3513 implements FunctionTypeAliasElement { 3620 implements FunctionTypeAliasElement {
3514 /** 3621 /**
3515 * The unlinked representation of the type in the summary. 3622 * The unlinked representation of the type in the summary.
3516 */ 3623 */
3517 final UnlinkedTypedef _unlinkedTypedef; 3624 final UnlinkedTypedef _unlinkedTypedef;
3518 3625
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after
5848 * [parameters]. 5955 * [parameters].
5849 */ 5956 */
5850 void set parameters(List<ParameterElement> parameters) { 5957 void set parameters(List<ParameterElement> parameters) {
5851 for (ParameterElement parameter in parameters) { 5958 for (ParameterElement parameter in parameters) {
5852 (parameter as ParameterElementImpl).enclosingElement = this; 5959 (parameter as ParameterElementImpl).enclosingElement = this;
5853 } 5960 }
5854 this._parameters = parameters; 5961 this._parameters = parameters;
5855 } 5962 }
5856 5963
5857 @override 5964 @override
5965 DartType get type {
5966 if (_unlinkedParam != null && _type == null) {
5967 _type = enclosingUnit.resynthesizerContext.resolveLinkedType(
5968 _unlinkedParam.inferredTypeSlot, typeParameterContext) ??
5969 enclosingUnit.resynthesizerContext
5970 .resolveTypeRef(_unlinkedParam.type, typeParameterContext);
5971 }
5972 return super.type;
5973 }
5974
5975 @override
5858 List<TypeParameterElement> get typeParameters => _typeParameters; 5976 List<TypeParameterElement> get typeParameters => _typeParameters;
5859 5977
5860 /** 5978 /**
5861 * Set the type parameters defined by this parameter element to the given 5979 * Set the type parameters defined by this parameter element to the given
5862 * [typeParameters]. 5980 * [typeParameters].
5863 */ 5981 */
5864 void set typeParameters(List<TypeParameterElement> typeParameters) { 5982 void set typeParameters(List<TypeParameterElement> typeParameters) {
5865 for (TypeParameterElement parameter in typeParameters) { 5983 for (TypeParameterElement parameter in typeParameters) {
5866 (parameter as TypeParameterElementImpl).enclosingElement = this; 5984 (parameter as TypeParameterElementImpl).enclosingElement = this;
5867 } 5985 }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
6287 * Build top-level functions. 6405 * Build top-level functions.
6288 */ 6406 */
6289 List<FunctionElementImpl> buildTopLevelFunctions(); 6407 List<FunctionElementImpl> buildTopLevelFunctions();
6290 6408
6291 /** 6409 /**
6292 * Build explicit top-level variables. 6410 * Build explicit top-level variables.
6293 */ 6411 */
6294 UnitExplicitTopLevelVariables buildTopLevelVariables(); 6412 UnitExplicitTopLevelVariables buildTopLevelVariables();
6295 6413
6296 /** 6414 /**
6415 * Build the appropriate [DartType] object corresponding to a slot id in the
6416 * [LinkedUnit.types] table.
6417 */
6418 DartType resolveLinkedType(
6419 int slot, TypeParameterizedElementMixin typeParameterContext);
6420
6421 /**
6297 * Resolve an [EntityRef] into a type. If the reference is 6422 * Resolve an [EntityRef] into a type. If the reference is
6298 * unresolved, return [DynamicTypeImpl.instance]. 6423 * unresolved, return [DynamicTypeImpl.instance].
6299 * 6424 *
6300 * TODO(paulberry): or should we have a class representing an 6425 * TODO(paulberry): or should we have a class representing an
6301 * unresolved type, for consistency with the full element model? 6426 * unresolved type, for consistency with the full element model?
6302 */ 6427 */
6303 DartType resolveTypeRef( 6428 DartType resolveTypeRef(
6304 EntityRef type, TypeParameterizedElementMixin typeParameterContext, 6429 EntityRef type, TypeParameterizedElementMixin typeParameterContext,
6305 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); 6430 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true});
6306 } 6431 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
6770 } 6895 }
6771 6896
6772 /** 6897 /**
6773 * A concrete implementation of a [VariableElement]. 6898 * A concrete implementation of a [VariableElement].
6774 */ 6899 */
6775 abstract class VariableElementImpl extends ElementImpl 6900 abstract class VariableElementImpl extends ElementImpl
6776 implements VariableElement { 6901 implements VariableElement {
6777 /** 6902 /**
6778 * The declared type of this variable. 6903 * The declared type of this variable.
6779 */ 6904 */
6780 DartType type; 6905 DartType _type;
6781 6906
6782 /** 6907 /**
6783 * A synthetic function representing this variable's initializer, or `null` if 6908 * A synthetic function representing this variable's initializer, or `null` if
6784 * this variable does not have an initializer. 6909 * this variable does not have an initializer.
6785 */ 6910 */
6786 FunctionElement _initializer; 6911 FunctionElement _initializer;
6787 6912
6788 /** 6913 /**
6789 * Initialize a newly created variable element to have the given [name] and 6914 * Initialize a newly created variable element to have the given [name] and
6790 * [offset]. 6915 * [offset].
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
6889 @override 7014 @override
6890 bool get isPotentiallyMutatedInClosure => false; 7015 bool get isPotentiallyMutatedInClosure => false;
6891 7016
6892 @override 7017 @override
6893 bool get isPotentiallyMutatedInScope => false; 7018 bool get isPotentiallyMutatedInScope => false;
6894 7019
6895 @override 7020 @override
6896 bool get isStatic => hasModifier(Modifier.STATIC); 7021 bool get isStatic => hasModifier(Modifier.STATIC);
6897 7022
6898 @override 7023 @override
7024 DartType get type => _type;
7025
7026 void set type(DartType type) {
7027 _type = type;
7028 }
7029
7030 @override
6899 void appendTo(StringBuffer buffer) { 7031 void appendTo(StringBuffer buffer) {
6900 buffer.write(type); 7032 buffer.write(type);
6901 buffer.write(" "); 7033 buffer.write(" ");
6902 buffer.write(displayName); 7034 buffer.write(displayName);
6903 } 7035 }
6904 7036
6905 @override 7037 @override
6906 DartObject computeConstantValue() => null; 7038 DartObject computeConstantValue() => null;
6907 7039
6908 @override 7040 @override
(...skipping 13 matching lines...) Expand all
6922 7054
6923 @override 7055 @override
6924 void visitElement(Element element) { 7056 void visitElement(Element element) {
6925 int offset = element.nameOffset; 7057 int offset = element.nameOffset;
6926 if (offset != -1) { 7058 if (offset != -1) {
6927 map[offset] = element; 7059 map[offset] = element;
6928 } 7060 }
6929 super.visitElement(element); 7061 super.visitElement(element);
6930 } 7062 }
6931 } 7063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698