OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.dart.constant.utilities; | 5 library analyzer.src.dart.constant.utilities; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/resolution_accessors.dart'; |
10 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
11 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/src/dart/ast/utilities.dart'; | 13 import 'package:analyzer/src/dart/ast/utilities.dart'; |
13 import 'package:analyzer/src/dart/element/element.dart'; | 14 import 'package:analyzer/src/dart/element/element.dart'; |
14 import 'package:analyzer/src/dart/element/handle.dart' | 15 import 'package:analyzer/src/dart/element/handle.dart' |
15 show ConstructorElementHandle; | 16 show ConstructorElementHandle; |
16 import 'package:analyzer/src/dart/element/member.dart'; | 17 import 'package:analyzer/src/dart/element/member.dart'; |
17 import 'package:analyzer/src/task/dart.dart'; | 18 import 'package:analyzer/src/task/dart.dart'; |
18 | 19 |
19 ConstructorElementImpl getConstructorImpl(ConstructorElement constructor) { | 20 ConstructorElementImpl getConstructorImpl(ConstructorElement constructor) { |
(...skipping 12 matching lines...) Expand all Loading... |
32 typedef void ReferenceFinderCallback(ConstantEvaluationTarget dependency); | 33 typedef void ReferenceFinderCallback(ConstantEvaluationTarget dependency); |
33 | 34 |
34 /** | 35 /** |
35 * An [AstCloner] that copies the necessary information from the AST to allow | 36 * An [AstCloner] that copies the necessary information from the AST to allow |
36 * constants to be evaluated. | 37 * constants to be evaluated. |
37 */ | 38 */ |
38 class ConstantAstCloner extends AstCloner { | 39 class ConstantAstCloner extends AstCloner { |
39 ConstantAstCloner() : super(true); | 40 ConstantAstCloner() : super(true); |
40 | 41 |
41 @override | 42 @override |
42 ConstructorName visitConstructorName(ConstructorName node) { | |
43 ConstructorName name = super.visitConstructorName(node); | |
44 name.staticElement = node.staticElement; | |
45 return name; | |
46 } | |
47 | |
48 @override | |
49 Annotation visitAnnotation(Annotation node) { | 43 Annotation visitAnnotation(Annotation node) { |
50 Annotation annotation = super.visitAnnotation(node); | 44 Annotation annotation = super.visitAnnotation(node); |
51 annotation.element = node.element; | 45 annotation.element = node.element; |
52 return annotation; | 46 return annotation; |
53 } | 47 } |
54 | 48 |
55 @override | 49 @override |
| 50 ConstructorName visitConstructorName(ConstructorName node) { |
| 51 ConstructorName name = super.visitConstructorName(node); |
| 52 name.staticElement = node.staticElement; |
| 53 return name; |
| 54 } |
| 55 |
| 56 @override |
56 FunctionExpression visitFunctionExpression(FunctionExpression node) { | 57 FunctionExpression visitFunctionExpression(FunctionExpression node) { |
57 FunctionExpression expression = super.visitFunctionExpression(node); | 58 FunctionExpression expression = super.visitFunctionExpression(node); |
58 expression.element = node.element; | 59 expression.element = node.element; |
59 return expression; | 60 return expression; |
60 } | 61 } |
61 | 62 |
62 @override | 63 @override |
63 InstanceCreationExpression visitInstanceCreationExpression( | 64 InstanceCreationExpression visitInstanceCreationExpression( |
64 InstanceCreationExpression node) { | 65 InstanceCreationExpression node) { |
65 InstanceCreationExpression expression = | 66 InstanceCreationExpression expression = |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 node.parent is EnumConstantDeclaration); | 185 node.parent is EnumConstantDeclaration); |
185 } else { | 186 } else { |
186 constantsToCompute.add(elementAnnotation); | 187 constantsToCompute.add(elementAnnotation); |
187 } | 188 } |
188 return null; | 189 return null; |
189 } | 190 } |
190 | 191 |
191 @override | 192 @override |
192 Object visitClassDeclaration(ClassDeclaration node) { | 193 Object visitClassDeclaration(ClassDeclaration node) { |
193 bool prevTreatFinalInstanceVarAsConst = treatFinalInstanceVarAsConst; | 194 bool prevTreatFinalInstanceVarAsConst = treatFinalInstanceVarAsConst; |
194 if (node.element.constructors.any((ConstructorElement e) => e.isConst)) { | 195 if (elementForClassDeclaration(node) |
| 196 .constructors |
| 197 .any((ConstructorElement e) => e.isConst)) { |
195 // Instance vars marked "final" need to be included in the dependency | 198 // Instance vars marked "final" need to be included in the dependency |
196 // graph, since constant constructors implicitly use the values in their | 199 // graph, since constant constructors implicitly use the values in their |
197 // initializers. | 200 // initializers. |
198 treatFinalInstanceVarAsConst = true; | 201 treatFinalInstanceVarAsConst = true; |
199 } | 202 } |
200 try { | 203 try { |
201 return super.visitClassDeclaration(node); | 204 return super.visitClassDeclaration(node); |
202 } finally { | 205 } finally { |
203 treatFinalInstanceVarAsConst = prevTreatFinalInstanceVarAsConst; | 206 treatFinalInstanceVarAsConst = prevTreatFinalInstanceVarAsConst; |
204 } | 207 } |
(...skipping 10 matching lines...) Expand all Loading... |
215 } | 218 } |
216 } | 219 } |
217 return null; | 220 return null; |
218 } | 221 } |
219 | 222 |
220 @override | 223 @override |
221 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 224 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
222 super.visitDefaultFormalParameter(node); | 225 super.visitDefaultFormalParameter(node); |
223 Expression defaultValue = node.defaultValue; | 226 Expression defaultValue = node.defaultValue; |
224 if (defaultValue != null && node.element != null) { | 227 if (defaultValue != null && node.element != null) { |
225 constantsToCompute.add(node.element); | 228 constantsToCompute.add(elementForFormalParameter(node)); |
226 } | 229 } |
227 return null; | 230 return null; |
228 } | 231 } |
229 | 232 |
230 @override | 233 @override |
231 Object visitVariableDeclaration(VariableDeclaration node) { | 234 Object visitVariableDeclaration(VariableDeclaration node) { |
232 super.visitVariableDeclaration(node); | 235 super.visitVariableDeclaration(node); |
233 Expression initializer = node.initializer; | 236 Expression initializer = node.initializer; |
234 VariableElement element = node.element; | 237 VariableElement element = node.element; |
235 if (initializer != null && | 238 if (initializer != null && |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 @override | 314 @override |
312 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 315 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
313 super.visitSuperConstructorInvocation(node); | 316 super.visitSuperConstructorInvocation(node); |
314 ConstructorElement constructor = getConstructorImpl(node.staticElement); | 317 ConstructorElement constructor = getConstructorImpl(node.staticElement); |
315 if (constructor != null) { | 318 if (constructor != null) { |
316 _callback(constructor); | 319 _callback(constructor); |
317 } | 320 } |
318 return null; | 321 return null; |
319 } | 322 } |
320 } | 323 } |
OLD | NEW |