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

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2983413002: Resynthesize constructor initializers from Kernel. (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 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 643343deb880ad5faaa8c7938b02bf20029f5c88..37a013c80199142df93368d45ad8e1d830690144 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -2215,10 +2215,19 @@ class ConstructorElementImpl extends ExecutableElementImpl
* there are no initializers, or `null` if there was an error in the source.
*/
List<ConstructorInitializer> get constantInitializers {
- if (serializedExecutable != null && _constantInitializers == null) {
- _constantInitializers ??= serializedExecutable.constantInitializers
- .map((i) => _buildConstructorInitializer(i))
- .toList(growable: false);
+ if (_constantInitializers == null) {
+ if (_kernelConstructor != null) {
+ var context = enclosingUnit._kernelContext;
+ _constantInitializers = _kernelConstructor.initializers
+ .map((k) => context.getConstructorInitializer(this, k))
+ .where((i) => i != null)
+ .toList();
+ }
+ if (serializedExecutable != null) {
+ _constantInitializers = serializedExecutable.constantInitializers
+ .map((i) => _buildConstructorInitializer(i))
+ .toList(growable: false);
+ }
}
return _constantInitializers;
}
@@ -2349,18 +2358,29 @@ class ConstructorElementImpl extends ExecutableElementImpl
@override
ConstructorElement get redirectedConstructor {
- if (serializedExecutable != null && _redirectedConstructor == null) {
- if (serializedExecutable.isRedirectedConstructor) {
- if (serializedExecutable.isFactory) {
- _redirectedConstructor = enclosingUnit.resynthesizerContext
- .resolveConstructorRef(
- enclosingElement, serializedExecutable.redirectedConstructor);
+ if (_redirectedConstructor == null) {
+ if (_kernelConstructor != null) {
+ for (var initializer in _kernelConstructor.initializers) {
+ if (initializer is kernel.RedirectingInitializer) {
+ return _redirectedConstructor = enclosingUnit._kernelContext
+ .getElement(initializer.targetReference)
+ as ConstructorElementImpl;
+ }
+ }
+ }
+ if (serializedExecutable != null) {
+ if (serializedExecutable.isRedirectedConstructor) {
+ if (serializedExecutable.isFactory) {
+ _redirectedConstructor = enclosingUnit.resynthesizerContext
+ .resolveConstructorRef(enclosingElement,
+ serializedExecutable.redirectedConstructor);
+ } else {
+ _redirectedConstructor = enclosingElement.getNamedConstructor(
+ serializedExecutable.redirectedConstructorName);
+ }
} else {
- _redirectedConstructor = enclosingElement.getNamedConstructor(
- serializedExecutable.redirectedConstructorName);
+ return null;
}
- } else {
- return null;
}
}
return _redirectedConstructor;
@@ -5865,6 +5885,18 @@ abstract class KernelLibraryResynthesizerContext {
kernel.Library get library;
/**
+ * Return the resynthesized [ConstructorInitializer] for the given Kernel
+ * [initializer], or `null` if synthetic.
+ */
+ ConstructorInitializer getConstructorInitializer(
+ ConstructorElementImpl constructor, kernel.Initializer initializer);
+
+ /**
+ * Return the [Element] referenced by the given [reference].
+ */
+ ElementImpl getElement(kernel.Reference reference);
+
+ /**
* Return the [Expression] for the given kernel.
*/
Expression getExpression(kernel.Expression expression);

Powered by Google App Engine
This is Rietveld 408576698