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

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

Issue 1771243002: Change when enum constant elements are created to fix bug in re-creating ASTs from existing element… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/element/builder.dart
diff --git a/pkg/analyzer/lib/src/dart/element/builder.dart b/pkg/analyzer/lib/src/dart/element/builder.dart
index 058c10d4b5d62560b2a6fb9f091e612d19f4a35d..8dfc781ddc143e4e2de2524f1f63d315f495a47b 100644
--- a/pkg/analyzer/lib/src/dart/element/builder.dart
+++ b/pkg/analyzer/lib/src/dart/element/builder.dart
@@ -621,6 +621,27 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
// to subclass, mix-in, implement, or explicitly instantiate an enum). So
// we represent this as having no constructors.
enumElement.constructors = ConstructorElement.EMPTY_LIST;
+ //
+ // Build the elements for the constants. These are minimal elements; the
+ // rest of the constant elements (and elements for other fields) must be
+ // built later after we can access the type provider.
+ //
+ List<FieldElement> fields = new List<FieldElement>();
+ NodeList<EnumConstantDeclaration> constants = node.constants;
+ for (EnumConstantDeclaration constant in constants) {
+ SimpleIdentifier constantName = constant.name;
+ FieldElementImpl constantField =
+ new ConstFieldElementImpl.forNode(constantName);
+ constantField.static = true;
+ constantField.const3 = true;
+ constantField.type = enumType;
+ setElementDocumentationComment(constantField, constant);
+ fields.add(constantField);
+ _createGetter(constantField);
+ constantName.staticElement = constantField;
+ }
+ enumElement.fields = fields;
+
_currentHolder.addEnum(enumElement);
enumName.staticElement = enumElement;
return super.visitEnumDeclaration(node);
@@ -1316,6 +1337,18 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
}
/**
+ * Create a getter that corresponds to the given [field].
+ */
+ void _createGetter(FieldElementImpl field) {
+ PropertyAccessorElementImpl getter =
+ new PropertyAccessorElementImpl.forVariable(field);
+ getter.getter = true;
+ getter.returnType = field.type;
+ getter.type = new FunctionTypeImpl(getter);
+ field.getter = getter;
+ }
+
+ /**
* Create the types associated with the given type parameters, setting the type of each type
* parameter, and return an array of types corresponding to the given parameters.
*
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698