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

Unified Diff: pkg/analyzer/lib/src/kernel/resynthesize.dart

Issue 2987883003: Resynthesize top-level accessors and variables 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/element_text.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/kernel/resynthesize.dart
diff --git a/pkg/analyzer/lib/src/kernel/resynthesize.dart b/pkg/analyzer/lib/src/kernel/resynthesize.dart
index 3c097f155cafdb8fbb9fd4d3dcd60ca1dac8c2b7..aa383c06054bf0ad74bfef5ab5ba8576d2d79eee 100644
--- a/pkg/analyzer/lib/src/kernel/resynthesize.dart
+++ b/pkg/analyzer/lib/src/kernel/resynthesize.dart
@@ -384,6 +384,73 @@ class _KernelLibraryResynthesizerContextImpl
_KernelLibraryResynthesizerContextImpl(this._resynthesizer, this.library);
@override
+ UnitExplicitTopLevelAccessors buildTopLevelAccessors(
+ CompilationUnitElementImpl unit) {
+ var accessorsData = new UnitExplicitTopLevelAccessors();
+ var implicitVariables = <String, TopLevelVariableElementImpl>{};
+ // Build explicit property accessors and implicit fields.
+ for (var k in library.procedures) {
Brian Wilkerson 2017/07/26 18:17:11 "k" --> "procedure"? ("k" seems like a strange nam
+ bool isGetter = k.kind == kernel.ProcedureKind.Getter;
+ bool isSetter = k.kind == kernel.ProcedureKind.Setter;
+ if (isGetter || isSetter) {
+ var accessor = new PropertyAccessorElementImpl.forKernel(unit, k);
+ accessorsData.accessors.add(accessor);
+
+ // Create or update the implicit variable.
+ String name = accessor.displayName;
+ TopLevelVariableElementImpl variable = implicitVariables[name];
+ if (variable == null) {
+ variable = new TopLevelVariableElementImpl(name, -1);
+ implicitVariables[name] = variable;
+ variable.enclosingElement = unit;
+ variable.isSynthetic = true;
+ variable.isFinal = isGetter;
+ } else {
+ variable.isFinal = false;
+ }
+
+ // Attach the accessor to the variable.
+ accessor.variable = variable;
+ if (isGetter) {
+ variable.getter = accessor;
+ } else {
+ variable.setter = accessor;
+ }
+ }
+ }
+ accessorsData.implicitVariables.addAll(implicitVariables.values);
+ return accessorsData;
+ }
+
+ @override
+ UnitExplicitTopLevelVariables buildTopLevelVariables(
+ CompilationUnitElementImpl unit) {
+ int numberOfVariables = library.fields.length;
+ var variablesData = new UnitExplicitTopLevelVariables(numberOfVariables);
+ for (int i = 0; i < numberOfVariables; i++) {
+ kernel.Field kField = library.fields[i];
Brian Wilkerson 2017/07/26 18:17:11 "kField" --> "field"?
+
+ // Add the explicit variables.
+ TopLevelVariableElementImpl variable;
+ if (kField.isConst && kField.initializer != null) {
+ variable = new ConstTopLevelVariableElementImpl.forKernel(unit, kField);
+ } else {
+ variable = new TopLevelVariableElementImpl.forKernel(unit, kField);
+ }
+ variablesData.variables[i] = variable;
+
+ // Add the implicit accessors.
+ variablesData.implicitAccessors
+ .add(new PropertyAccessorElementImpl_ImplicitGetter(variable));
+ if (!(variable.isConst || variable.isFinal)) {
+ variablesData.implicitAccessors
+ .add(new PropertyAccessorElementImpl_ImplicitSetter(variable));
+ }
+ }
+ return variablesData;
+ }
+
+ @override
ConstructorInitializer getConstructorInitializer(
ConstructorElementImpl constructor, kernel.Initializer k) {
if (k is kernel.LocalInitializer ||
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/element_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698