| 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/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/src/dart/ast/utilities.dart'; | 12 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/element/handle.dart' | 14 import 'package:analyzer/src/dart/element/handle.dart' |
| 15 show ConstructorElementHandle; | 15 show ConstructorElementHandle; |
| 16 import 'package:analyzer/src/dart/element/member.dart'; | 16 import 'package:analyzer/src/dart/element/member.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | |
| 18 import 'package:analyzer/src/generated/source.dart' show Source; | |
| 19 import 'package:analyzer/src/task/dart.dart'; | 17 import 'package:analyzer/src/task/dart.dart'; |
| 20 | 18 |
| 21 ConstructorElementImpl getConstructorImpl(ConstructorElement constructor) { | 19 ConstructorElementImpl getConstructorImpl(ConstructorElement constructor) { |
| 22 while (constructor is ConstructorMember) { | 20 while (constructor is ConstructorMember) { |
| 23 constructor = (constructor as ConstructorMember).baseElement; | 21 constructor = (constructor as ConstructorMember).baseElement; |
| 24 } | 22 } |
| 25 if (constructor is ConstructorElementHandle) { | 23 if (constructor is ConstructorElementHandle) { |
| 26 constructor = (constructor as ConstructorElementHandle).actualElement; | 24 constructor = (constructor as ConstructorElementHandle).actualElement; |
| 27 } | 25 } |
| 28 return constructor; | 26 return constructor; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 | 149 |
| 152 /** | 150 /** |
| 153 * A visitor used to traverse the AST structures of all of the compilation units | 151 * A visitor used to traverse the AST structures of all of the compilation units |
| 154 * being resolved and build tables of the constant variables, constant | 152 * being resolved and build tables of the constant variables, constant |
| 155 * constructors, constant constructor invocations, and annotations found in | 153 * constructors, constant constructor invocations, and annotations found in |
| 156 * those compilation units. | 154 * those compilation units. |
| 157 */ | 155 */ |
| 158 class ConstantFinder extends RecursiveAstVisitor<Object> { | 156 class ConstantFinder extends RecursiveAstVisitor<Object> { |
| 159 final AnalysisContext context; | |
| 160 final Source source; | |
| 161 final Source librarySource; | |
| 162 | |
| 163 /** | 157 /** |
| 164 * The elements and AST nodes whose constant values need to be computed. | 158 * The elements and AST nodes whose constant values need to be computed. |
| 165 */ | 159 */ |
| 166 List<ConstantEvaluationTarget> constantsToCompute = | 160 List<ConstantEvaluationTarget> constantsToCompute = |
| 167 <ConstantEvaluationTarget>[]; | 161 <ConstantEvaluationTarget>[]; |
| 168 | 162 |
| 169 /** | 163 /** |
| 170 * A flag indicating whether instance variables marked as "final" should be | 164 * A flag indicating whether instance variables marked as "final" should be |
| 171 * treated as "const". | 165 * treated as "const". |
| 172 */ | 166 */ |
| 173 bool treatFinalInstanceVarAsConst = false; | 167 bool treatFinalInstanceVarAsConst = false; |
| 174 | 168 |
| 175 ConstantFinder(this.context, this.source, this.librarySource); | |
| 176 | |
| 177 @override | 169 @override |
| 178 Object visitAnnotation(Annotation node) { | 170 Object visitAnnotation(Annotation node) { |
| 179 super.visitAnnotation(node); | 171 super.visitAnnotation(node); |
| 180 ElementAnnotation elementAnnotation = node.elementAnnotation; | 172 ElementAnnotation elementAnnotation = node.elementAnnotation; |
| 181 if (elementAnnotation == null) { | 173 if (elementAnnotation == null) { |
| 182 // Analyzer ignores annotations on "part of" directives and on enum | 174 // Analyzer ignores annotations on "part of" directives and on enum |
| 183 // constant declarations. | 175 // constant declarations. |
| 184 assert(node.parent is PartOfDirective || | 176 assert(node.parent is PartOfDirective || |
| 185 node.parent is EnumConstantDeclaration); | 177 node.parent is EnumConstantDeclaration); |
| 186 } else { | 178 } else { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 @override | 304 @override |
| 313 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 305 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 314 super.visitSuperConstructorInvocation(node); | 306 super.visitSuperConstructorInvocation(node); |
| 315 ConstructorElement constructor = getConstructorImpl(node.staticElement); | 307 ConstructorElement constructor = getConstructorImpl(node.staticElement); |
| 316 if (constructor != null) { | 308 if (constructor != null) { |
| 317 _callback(constructor); | 309 _callback(constructor); |
| 318 } | 310 } |
| 319 return null; | 311 return null; |
| 320 } | 312 } |
| 321 } | 313 } |
| OLD | NEW |