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

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

Issue 1696793003: Don't use _inFieldContext tracking. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | no next file » | 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 31d99a251ddb5deea5b7af0eb247001c625ee473..b844770c7712c06313787737d948fa94b1b29e20 100644
--- a/pkg/analyzer/lib/src/dart/element/builder.dart
+++ b/pkg/analyzer/lib/src/dart/element/builder.dart
@@ -303,11 +303,6 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
ElementHolder _currentHolder;
/**
- * A flag indicating whether a variable declaration is in the context of a field declaration.
- */
- bool _inFieldContext = false;
-
- /**
* A flag indicating whether a variable declaration is within the body of a method or function.
*/
bool _inFunction = false;
@@ -336,18 +331,6 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
}
@override
- Object visitBlock(Block node) {
- bool wasInField = _inFieldContext;
- _inFieldContext = false;
- try {
- node.visitChildren(this);
- } finally {
- _inFieldContext = wasInField;
- }
- return null;
- }
-
- @override
Object visitCatchClause(CatchClause node) {
SimpleIdentifier exceptionParameter = node.exceptionParameter;
if (exceptionParameter != null) {
@@ -603,18 +586,6 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
}
@override
- Object visitFieldDeclaration(FieldDeclaration node) {
- bool wasInField = _inFieldContext;
- _inFieldContext = true;
- try {
- node.visitChildren(this);
- } finally {
- _inFieldContext = wasInField;
- }
- return null;
- }
-
- @override
Object visitFieldFormalParameter(FieldFormalParameter node) {
if (node.parent is! DefaultFormalParameter) {
SimpleIdentifier parameterName = node.identifier;
@@ -1111,22 +1082,22 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
bool isConst = node.isConst;
bool isFinal = node.isFinal;
bool hasInitializer = node.initializer != null;
+ VariableDeclarationList varList = node.parent;
+ FieldDeclaration fieldNode =
+ varList.parent is FieldDeclaration ? varList.parent : null;
VariableElementImpl element;
- if (_inFieldContext) {
+ if (fieldNode != null) {
SimpleIdentifier fieldName = node.name;
FieldElementImpl field;
- if ((isConst || isFinal) && hasInitializer) {
+ if ((isConst || isFinal && !fieldNode.isStatic) && hasInitializer) {
field = new ConstFieldElementImpl.forNode(fieldName);
} else {
field = new FieldElementImpl.forNode(fieldName);
}
element = field;
- if (node.parent.parent is FieldDeclaration) {
- setElementDocumentationComment(element, node.parent.parent);
- }
- if ((node.parent as VariableDeclarationList).type == null) {
- field.hasImplicitType = true;
- }
+ field.static = fieldNode.isStatic;
+ setElementDocumentationComment(element, fieldNode);
+ field.hasImplicitType = varList.type == null;
_currentHolder.addField(field);
fieldName.staticElement = field;
} else if (_inFunction) {
@@ -1142,9 +1113,7 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
// TODO(brianwilkerson) This isn't right for variables declared in a for
// loop.
variable.setVisibleRange(enclosingBlock.offset, enclosingBlock.length);
- if ((node.parent as VariableDeclarationList).type == null) {
- variable.hasImplicitType = true;
- }
+ variable.hasImplicitType = varList.type == null;
_currentHolder.addLocalVariable(variable);
variableName.staticElement = element;
} else {
@@ -1156,12 +1125,10 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
variable = new TopLevelVariableElementImpl.forNode(variableName);
}
element = variable;
- if (node.parent.parent is TopLevelVariableDeclaration) {
- setElementDocumentationComment(element, node.parent.parent);
- }
- if ((node.parent as VariableDeclarationList).type == null) {
- variable.hasImplicitType = true;
+ if (varList.parent is TopLevelVariableDeclaration) {
+ setElementDocumentationComment(element, varList.parent);
}
+ variable.hasImplicitType = varList.type == null;
_currentHolder.addTopLevelVariable(variable);
variableName.staticElement = element;
}
@@ -1169,13 +1136,7 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
element.final2 = isFinal;
if (hasInitializer) {
ElementHolder holder = new ElementHolder();
- bool wasInFieldContext = _inFieldContext;
- _inFieldContext = false;
- try {
- _visit(holder, node.initializer);
- } finally {
- _inFieldContext = wasInFieldContext;
- }
+ _visit(holder, node.initializer);
FunctionElementImpl initializer =
new FunctionElementImpl.forOffset(node.initializer.beginToken.offset);
initializer.functions = holder.functions;
@@ -1186,10 +1147,6 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
holder.validate();
}
if (element is PropertyInducingElementImpl) {
- if (_inFieldContext) {
- (element as FieldElementImpl).static =
- (node.parent.parent as FieldDeclaration).isStatic;
- }
PropertyAccessorElementImpl getter =
new PropertyAccessorElementImpl.forVariable(element);
getter.getter = true;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698