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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 78d0f5f496275bf18d56e98cef9fd068b33ae782..93652e9e52a649de106c10baf12e4b730f074113 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -1798,6 +1798,32 @@ class DefaultFieldFormalParameterElementImpl
*/
DefaultFieldFormalParameterElementImpl.forNode(Identifier name)
: super.forNode(name);
+
+ /**
+ * Initialize using the given serialized information.
+ */
+ DefaultFieldFormalParameterElementImpl.forSerialized(
+ UnlinkedParam unlinkedParam, ElementImpl enclosingElement)
+ : super.forSerialized(unlinkedParam, enclosingElement);
+
+ @override
+ Expression get constantInitializer {
+ if (_unlinkedParam != null) {
+ UnlinkedConst defaultValue = _unlinkedParam.defaultValue;
+ if (defaultValue == null) {
+ return null;
+ }
+ return super.constantInitializer ??= enclosingUnit.resynthesizerContext
+ .buildExpression(this, defaultValue);
+ }
+ return super.constantInitializer;
+ }
+
+ @override
+ void set constantInitializer(Expression initializer) {
+ assert(_unlinkedParam == null);
+ super.constantInitializer = initializer;
+ }
}
/**
@@ -3338,7 +3364,7 @@ class FieldFormalParameterElementImpl extends ParameterElementImpl
/**
* The field associated with this field formal parameter.
*/
- FieldElement field;
+ FieldElement _field;
/**
* Initialize a newly created parameter element to have the given [name] and
@@ -3353,10 +3379,47 @@ class FieldFormalParameterElementImpl extends ParameterElementImpl
FieldFormalParameterElementImpl.forNode(Identifier name)
: super.forNode(name);
+ /**
+ * Initialize using the given serialized information.
+ */
+ FieldFormalParameterElementImpl.forSerialized(
+ UnlinkedParam unlinkedParam, ElementImpl enclosingElement)
+ : super.forSerialized(unlinkedParam, enclosingElement);
+
+ @override
+ FieldElement get field {
+ if (_unlinkedParam != null && _field == null) {
+ Element enclosingClass = enclosingElement?.enclosingElement;
+ if (enclosingClass is ClassElement) {
+ _field = enclosingClass.getField(_unlinkedParam.name);
+ }
+ }
+ return _field;
+ }
+
+ void set field(FieldElement field) {
+ assert(_unlinkedParam == null);
+ _field = field;
+ }
+
@override
bool get isInitializingFormal => true;
@override
+ DartType get type {
+ if (_unlinkedParam != null && _unlinkedParam.type == null) {
+ _type ??= field?.type ?? DynamicTypeImpl.instance;
+ }
+ return super.type;
+ }
+
+ @override
+ void set type(DartType type) {
+ assert(_unlinkedParam == null);
+ _type = type;
+ }
+
+ @override
accept(ElementVisitor visitor) =>
visitor.visitFieldFormalParameterElement(this);
}
@@ -3506,6 +3569,50 @@ class FunctionElementImpl extends ExecutableElementImpl
}
/**
+ * Implementation of [FunctionElementImpl] for a function typed parameter.
+ */
+class FunctionElementImpl_forFunctionTypedParameter
+ extends FunctionElementImpl {
+ @override
+ final CompilationUnitElementImpl enclosingUnit;
+
+ /**
+ * The enclosing function typed [ParameterElementImpl].
+ */
+ final ParameterElementImpl _parameter;
+
+ FunctionElementImpl_forFunctionTypedParameter(
+ this.enclosingUnit, this._parameter)
+ : super('', -1);
+
+ @override
+ TypeParameterizedElementMixin get enclosingTypeParameterContext =>
+ _parameter.typeParameterContext;
+
+ @override
+ bool get isSynthetic => true;
+}
+
+/**
+ * Implementation of [FunctionElementImpl] for a synthetic function element
+ * that was synthesized by a LUB computation.
+ */
+class FunctionElementImpl_forLUB extends FunctionElementImpl {
+ @override
+ final CompilationUnitElementImpl enclosingUnit;
+
+ @override
+ final TypeParameterizedElementMixin enclosingTypeParameterContext;
+
+ FunctionElementImpl_forLUB(
+ this.enclosingUnit, this.enclosingTypeParameterContext)
+ : super('', -1);
+
+ @override
+ bool get isSynthetic => true;
+}
+
+/**
* A concrete implementation of a [FunctionTypeAliasElement].
*/
class FunctionTypeAliasElementImpl extends ElementImpl
@@ -5855,6 +5962,17 @@ class ParameterElementImpl extends VariableElementImpl
}
@override
+ DartType get type {
+ if (_unlinkedParam != null && _type == null) {
+ _type = enclosingUnit.resynthesizerContext.resolveLinkedType(
+ _unlinkedParam.inferredTypeSlot, typeParameterContext) ??
+ enclosingUnit.resynthesizerContext
+ .resolveTypeRef(_unlinkedParam.type, typeParameterContext);
+ }
+ return super.type;
+ }
+
+ @override
List<TypeParameterElement> get typeParameters => _typeParameters;
/**
@@ -6294,6 +6412,13 @@ abstract class ResynthesizerContext {
UnitExplicitTopLevelVariables buildTopLevelVariables();
/**
+ * Build the appropriate [DartType] object corresponding to a slot id in the
+ * [LinkedUnit.types] table.
+ */
+ DartType resolveLinkedType(
+ int slot, TypeParameterizedElementMixin typeParameterContext);
+
+ /**
* Resolve an [EntityRef] into a type. If the reference is
* unresolved, return [DynamicTypeImpl.instance].
*
@@ -6777,7 +6902,7 @@ abstract class VariableElementImpl extends ElementImpl
/**
* The declared type of this variable.
*/
- DartType type;
+ DartType _type;
/**
* A synthetic function representing this variable's initializer, or `null` if
@@ -6896,6 +7021,13 @@ abstract class VariableElementImpl extends ElementImpl
bool get isStatic => hasModifier(Modifier.STATIC);
@override
+ DartType get type => _type;
+
+ void set type(DartType type) {
+ _type = type;
+ }
+
+ @override
void appendTo(StringBuffer buffer) {
buffer.write(type);
buffer.write(" ");

Powered by Google App Engine
This is Rietveld 408576698