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.element.builder; | 5 library analyzer.src.dart.element.builder; |
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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 class LocalElementBuilder extends _BaseElementBuilder { | 1071 class LocalElementBuilder extends _BaseElementBuilder { |
1072 /** | 1072 /** |
1073 * Initialize a newly created element builder to build the elements for a | 1073 * Initialize a newly created element builder to build the elements for a |
1074 * compilation unit. The [initialHolder] is the element holder to which the | 1074 * compilation unit. The [initialHolder] is the element holder to which the |
1075 * children of the visited compilation unit node will be added. | 1075 * children of the visited compilation unit node will be added. |
1076 */ | 1076 */ |
1077 LocalElementBuilder(ElementHolder initialHolder, | 1077 LocalElementBuilder(ElementHolder initialHolder, |
1078 CompilationUnitElementImpl compilationUnitElement) | 1078 CompilationUnitElementImpl compilationUnitElement) |
1079 : super(initialHolder, compilationUnitElement); | 1079 : super(initialHolder, compilationUnitElement); |
1080 | 1080 |
1081 @override | 1081 /** |
1082 Object visitCatchClause(CatchClause node) { | 1082 * Builds the variable elements associated with [node] and stores them in |
| 1083 * the element holder. |
| 1084 */ |
| 1085 void buildCatchVariableElements(CatchClause node) { |
1083 SimpleIdentifier exceptionParameter = node.exceptionParameter; | 1086 SimpleIdentifier exceptionParameter = node.exceptionParameter; |
1084 if (exceptionParameter != null) { | 1087 if (exceptionParameter != null) { |
1085 // exception | 1088 // exception |
1086 LocalVariableElementImpl exception = | 1089 LocalVariableElementImpl exception = |
1087 new LocalVariableElementImpl.forNode(exceptionParameter); | 1090 new LocalVariableElementImpl.forNode(exceptionParameter); |
1088 if (node.exceptionType == null) { | 1091 if (node.exceptionType == null) { |
1089 exception.hasImplicitType = true; | 1092 exception.hasImplicitType = true; |
1090 } | 1093 } |
1091 exception.setVisibleRange(node.offset, node.length); | 1094 exception.setVisibleRange(node.offset, node.length); |
1092 _currentHolder.addLocalVariable(exception); | 1095 _currentHolder.addLocalVariable(exception); |
1093 exceptionParameter.staticElement = exception; | 1096 exceptionParameter.staticElement = exception; |
1094 // stack trace | 1097 // stack trace |
1095 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; | 1098 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; |
1096 if (stackTraceParameter != null) { | 1099 if (stackTraceParameter != null) { |
1097 LocalVariableElementImpl stackTrace = | 1100 LocalVariableElementImpl stackTrace = |
1098 new LocalVariableElementImpl.forNode(stackTraceParameter); | 1101 new LocalVariableElementImpl.forNode(stackTraceParameter); |
1099 _setCodeRange(stackTrace, stackTraceParameter); | 1102 _setCodeRange(stackTrace, stackTraceParameter); |
1100 stackTrace.setVisibleRange(node.offset, node.length); | 1103 stackTrace.setVisibleRange(node.offset, node.length); |
1101 _currentHolder.addLocalVariable(stackTrace); | 1104 _currentHolder.addLocalVariable(stackTrace); |
1102 stackTraceParameter.staticElement = stackTrace; | 1105 stackTraceParameter.staticElement = stackTrace; |
1103 } | 1106 } |
1104 } | 1107 } |
| 1108 } |
| 1109 |
| 1110 /** |
| 1111 * Builds the label elements associated with [labels] and stores them in the |
| 1112 * element holder. |
| 1113 */ |
| 1114 void buildLabelElements( |
| 1115 NodeList<Label> labels, bool onSwitchStatement, bool onSwitchMember) { |
| 1116 for (Label label in labels) { |
| 1117 SimpleIdentifier labelName = label.label; |
| 1118 LabelElementImpl element = new LabelElementImpl.forNode( |
| 1119 labelName, onSwitchStatement, onSwitchMember); |
| 1120 labelName.staticElement = element; |
| 1121 _currentHolder.addLabel(element); |
| 1122 } |
| 1123 } |
| 1124 |
| 1125 @override |
| 1126 Object visitCatchClause(CatchClause node) { |
| 1127 buildCatchVariableElements(node); |
1105 return super.visitCatchClause(node); | 1128 return super.visitCatchClause(node); |
1106 } | 1129 } |
1107 | 1130 |
1108 @override | 1131 @override |
1109 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 1132 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
1110 SimpleIdentifier variableName = node.identifier; | 1133 SimpleIdentifier variableName = node.identifier; |
1111 LocalVariableElementImpl element = | 1134 LocalVariableElementImpl element = |
1112 new LocalVariableElementImpl.forNode(variableName); | 1135 new LocalVariableElementImpl.forNode(variableName); |
1113 _setCodeRange(element, node); | 1136 _setCodeRange(element, node); |
1114 element.metadata = _createElementAnnotations(node.metadata); | 1137 element.metadata = _createElementAnnotations(node.metadata); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 element.hasImplicitReturnType = true; | 1242 element.hasImplicitReturnType = true; |
1220 _currentHolder.addFunction(element); | 1243 _currentHolder.addFunction(element); |
1221 node.element = element; | 1244 node.element = element; |
1222 holder.validate(); | 1245 holder.validate(); |
1223 return null; | 1246 return null; |
1224 } | 1247 } |
1225 | 1248 |
1226 @override | 1249 @override |
1227 Object visitLabeledStatement(LabeledStatement node) { | 1250 Object visitLabeledStatement(LabeledStatement node) { |
1228 bool onSwitchStatement = node.statement is SwitchStatement; | 1251 bool onSwitchStatement = node.statement is SwitchStatement; |
1229 for (Label label in node.labels) { | 1252 buildLabelElements(node.labels, onSwitchStatement, false); |
1230 SimpleIdentifier labelName = label.label; | |
1231 LabelElementImpl element = | |
1232 new LabelElementImpl.forNode(labelName, onSwitchStatement, false); | |
1233 _currentHolder.addLabel(element); | |
1234 labelName.staticElement = element; | |
1235 } | |
1236 return super.visitLabeledStatement(node); | 1253 return super.visitLabeledStatement(node); |
1237 } | 1254 } |
1238 | 1255 |
1239 @override | 1256 @override |
1240 Object visitSwitchCase(SwitchCase node) { | 1257 Object visitSwitchCase(SwitchCase node) { |
1241 for (Label label in node.labels) { | 1258 buildLabelElements(node.labels, false, true); |
1242 SimpleIdentifier labelName = label.label; | |
1243 LabelElementImpl element = | |
1244 new LabelElementImpl.forNode(labelName, false, true); | |
1245 _currentHolder.addLabel(element); | |
1246 labelName.staticElement = element; | |
1247 } | |
1248 return super.visitSwitchCase(node); | 1259 return super.visitSwitchCase(node); |
1249 } | 1260 } |
1250 | 1261 |
1251 @override | 1262 @override |
1252 Object visitSwitchDefault(SwitchDefault node) { | 1263 Object visitSwitchDefault(SwitchDefault node) { |
1253 for (Label label in node.labels) { | 1264 buildLabelElements(node.labels, false, true); |
1254 SimpleIdentifier labelName = label.label; | |
1255 LabelElementImpl element = | |
1256 new LabelElementImpl.forNode(labelName, false, true); | |
1257 _currentHolder.addLabel(element); | |
1258 labelName.staticElement = element; | |
1259 } | |
1260 return super.visitSwitchDefault(node); | 1265 return super.visitSwitchDefault(node); |
1261 } | 1266 } |
1262 | 1267 |
1263 @override | 1268 @override |
1264 Object visitVariableDeclaration(VariableDeclaration node) { | 1269 Object visitVariableDeclaration(VariableDeclaration node) { |
1265 bool isConst = node.isConst; | 1270 bool isConst = node.isConst; |
1266 bool isFinal = node.isFinal; | 1271 bool isFinal = node.isFinal; |
1267 Expression initializerNode = node.initializer; | 1272 Expression initializerNode = node.initializer; |
1268 VariableDeclarationList varList = node.parent; | 1273 VariableDeclarationList varList = node.parent; |
1269 SimpleIdentifier variableName = node.name; | 1274 SimpleIdentifier variableName = node.name; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 return null; | 1614 return null; |
1610 } | 1615 } |
1611 | 1616 |
1612 /** | 1617 /** |
1613 * Return the lexical identifiers associated with the given [identifiers]. | 1618 * Return the lexical identifiers associated with the given [identifiers]. |
1614 */ | 1619 */ |
1615 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1620 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
1616 return identifiers.map((identifier) => identifier.name).toList(); | 1621 return identifiers.map((identifier) => identifier.name).toList(); |
1617 } | 1622 } |
1618 } | 1623 } |
OLD | NEW |