Skip to content

Commit 1970298

Browse files
committed
Get rid of _inFunction in ApiElementBuilder.
This visitor does not enter into function bodies. [email protected] BUG= Review URL: https://codereview.chromium.org/2430513004 .
1 parent 7e6d8f5 commit 1970298

File tree

2 files changed

+8
-61
lines changed

2 files changed

+8
-61
lines changed

pkg/analyzer/lib/src/dart/element/builder.dart

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ import 'package:analyzer/src/generated/utilities_dart.dart';
2727
* build elements outside of function bodies and initializers.
2828
*/
2929
class ApiElementBuilder extends _BaseElementBuilder {
30-
/**
31-
* A flag indicating whether a variable declaration is within the body of a method or function.
32-
*/
33-
bool _inFunction = false;
34-
3530
/**
3631
* A table mapping field names to field elements for the fields defined in the current class, or
3732
* `null` if we are not in the scope of a class.
@@ -47,13 +42,6 @@ class ApiElementBuilder extends _BaseElementBuilder {
4742
CompilationUnitElementImpl compilationUnitElement)
4843
: super(initialHolder, compilationUnitElement);
4944

50-
/**
51-
* Prepares for incremental resolution of a function body.
52-
*/
53-
void initForFunctionBodyIncrementalResolution() {
54-
_inFunction = true;
55-
}
56-
5745
@override
5846
Object visitAnnotation(Annotation node) {
5947
// Although it isn't valid to do so because closures are not constant
@@ -149,13 +137,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
149137
@override
150138
Object visitConstructorDeclaration(ConstructorDeclaration node) {
151139
ElementHolder holder = new ElementHolder();
152-
bool wasInFunction = _inFunction;
153-
_inFunction = true;
154-
try {
155-
_visitChildren(holder, node);
156-
} finally {
157-
_inFunction = wasInFunction;
158-
}
140+
_visitChildren(holder, node);
159141
FunctionBody body = node.body;
160142
SimpleIdentifier constructorName = node.name;
161143
ConstructorElementImpl element =
@@ -281,16 +263,10 @@ class ApiElementBuilder extends _BaseElementBuilder {
281263
FunctionExpression expression = node.functionExpression;
282264
if (expression != null) {
283265
ElementHolder holder = new ElementHolder();
284-
bool wasInFunction = _inFunction;
285-
_inFunction = true;
286-
try {
287-
_visitChildren(holder, node);
288-
} finally {
289-
_inFunction = wasInFunction;
290-
}
266+
_visitChildren(holder, node);
291267
FunctionBody body = expression.body;
292268
Token property = node.propertyKeyword;
293-
if (property == null || _inFunction) {
269+
if (property == null) {
294270
SimpleIdentifier functionName = node.name;
295271
FunctionElementImpl element =
296272
new FunctionElementImpl.forNode(functionName);
@@ -311,13 +287,6 @@ class ApiElementBuilder extends _BaseElementBuilder {
311287
if (body.isGenerator) {
312288
element.generator = true;
313289
}
314-
if (_inFunction) {
315-
Block enclosingBlock = node.getAncestor((node) => node is Block);
316-
if (enclosingBlock != null) {
317-
element.setVisibleRange(
318-
enclosingBlock.offset, enclosingBlock.length);
319-
}
320-
}
321290
if (node.returnType == null) {
322291
element.hasImplicitReturnType = true;
323292
}
@@ -412,13 +381,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
412381
return super.visitFunctionExpression(node);
413382
}
414383
ElementHolder holder = new ElementHolder();
415-
bool wasInFunction = _inFunction;
416-
_inFunction = true;
417-
try {
418-
_visitChildren(holder, node);
419-
} finally {
420-
_inFunction = wasInFunction;
421-
}
384+
_visitChildren(holder, node);
422385
FunctionBody body = node.body;
423386
FunctionElementImpl element =
424387
new FunctionElementImpl.forOffset(node.beginToken.offset);
@@ -434,12 +397,6 @@ class ApiElementBuilder extends _BaseElementBuilder {
434397
if (body.isGenerator) {
435398
element.generator = true;
436399
}
437-
if (_inFunction) {
438-
Block enclosingBlock = node.getAncestor((node) => node is Block);
439-
if (enclosingBlock != null) {
440-
element.setVisibleRange(enclosingBlock.offset, enclosingBlock.length);
441-
}
442-
}
443400
element.type = new FunctionTypeImpl(element);
444401
element.hasImplicitReturnType = true;
445402
_currentHolder.addFunction(element);
@@ -490,13 +447,7 @@ class ApiElementBuilder extends _BaseElementBuilder {
490447
Object visitMethodDeclaration(MethodDeclaration node) {
491448
try {
492449
ElementHolder holder = new ElementHolder();
493-
bool wasInFunction = _inFunction;
494-
_inFunction = true;
495-
try {
496-
_visitChildren(holder, node);
497-
} finally {
498-
_inFunction = wasInFunction;
499-
}
450+
_visitChildren(holder, node);
500451
bool isStatic = node.isStatic;
501452
Token property = node.propertyKeyword;
502453
FunctionBody body = node.body;
@@ -726,10 +677,8 @@ class ApiElementBuilder extends _BaseElementBuilder {
726677
}
727678

728679
/**
729-
* Build the table mapping field names to field elements for the fields defined in the current
730-
* class.
731-
*
732-
* @param fields the field elements defined in the current class
680+
* Build the table mapping field names to field elements for the [fields]
681+
* defined in the current class.
733682
*/
734683
void _buildFieldMap(List<FieldElement> fields) {
735684
_fieldMap = new HashMap<String, FieldElement>();

pkg/analyzer/lib/src/generated/incremental_resolver.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ class IncrementalResolver {
274274
LoggingTimer timer = logger.startTimer();
275275
try {
276276
ElementHolder holder = new ElementHolder();
277-
ElementBuilder builder = new ElementBuilder(holder, _definingUnit);
278-
builder.initForFunctionBodyIncrementalResolution();
279-
node.accept(builder);
277+
node.accept(new LocalElementBuilder(holder, _definingUnit));
280278
// Move local elements into the ExecutableElementImpl.
281279
ExecutableElementImpl executableElement =
282280
executable.element as ExecutableElementImpl;

0 commit comments

Comments
 (0)