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

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

Issue 3008453002: Build / resynthesize final fields as ConstFieldElementImpl only if the enclosing class has a consta… (Closed)
Patch Set: Created 3 years, 4 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/dart/element/element.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 f05c401bc228fb9e0e03439be75d346e07b12597..8c5e1b1a772965c66056a43335e41173154665d3 100644
--- a/pkg/analyzer/lib/src/dart/element/builder.dart
+++ b/pkg/analyzer/lib/src/dart/element/builder.dart
@@ -34,6 +34,11 @@ class ApiElementBuilder extends _BaseElementBuilder {
*/
HashMap<String, FieldElement> _fieldMap;
+ /**
+ * Whether the class being built has a constant constructor.
+ */
+ bool _enclosingClassHasConstConstructor = false;
+
/**
* Initialize a newly created element builder to build the elements for a
* compilation unit. The [initialHolder] is the element holder to which the
@@ -68,6 +73,15 @@ class ApiElementBuilder extends _BaseElementBuilder {
@override
Object visitClassDeclaration(ClassDeclaration node) {
+ _enclosingClassHasConstConstructor = false;
+ for (var constructor in node.members) {
+ if (constructor is ConstructorDeclaration &&
+ constructor.constKeyword != null) {
+ _enclosingClassHasConstConstructor = true;
+ break;
+ }
+ }
+
ElementHolder holder = new ElementHolder();
//
// Process field declarations before constructors and methods so that field
@@ -606,7 +620,11 @@ class ApiElementBuilder extends _BaseElementBuilder {
if (fieldNode != null) {
SimpleIdentifier fieldName = node.name;
FieldElementImpl field;
- if ((isConst || isFinal && !fieldNode.isStatic) && hasInitializer) {
+ if ((isConst ||
+ isFinal &&
+ !fieldNode.isStatic &&
+ _enclosingClassHasConstConstructor) &&
+ hasInitializer) {
field = new ConstFieldElementImpl.forNode(fieldName);
} else {
field = new FieldElementImpl.forNode(fieldName);
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698