Chromium Code Reviews| 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.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1078 * A table mapping the offset of a directive to the annotations associated | 1078 * A table mapping the offset of a directive to the annotations associated |
| 1079 * with that directive, or `null` if none of the annotations in the | 1079 * with that directive, or `null` if none of the annotations in the |
| 1080 * compilation unit have annotations. | 1080 * compilation unit have annotations. |
| 1081 */ | 1081 */ |
| 1082 Map<int, List<ElementAnnotation>> annotationMap = null; | 1082 Map<int, List<ElementAnnotation>> annotationMap = null; |
| 1083 | 1083 |
| 1084 /** | 1084 /** |
| 1085 * A list containing all of the top-level accessors (getters and setters) | 1085 * A list containing all of the top-level accessors (getters and setters) |
| 1086 * contained in this compilation unit. | 1086 * contained in this compilation unit. |
| 1087 */ | 1087 */ |
| 1088 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; | 1088 List<PropertyAccessorElement> _accessors; |
| 1089 | 1089 |
| 1090 /** | 1090 /** |
| 1091 * A list containing all of the enums contained in this compilation unit. | 1091 * A list containing all of the enums contained in this compilation unit. |
| 1092 */ | 1092 */ |
| 1093 List<ClassElement> _enums = ClassElement.EMPTY_LIST; | 1093 List<ClassElement> _enums = ClassElement.EMPTY_LIST; |
| 1094 | 1094 |
| 1095 /** | 1095 /** |
| 1096 * A list containing all of the top-level functions contained in this | 1096 * A list containing all of the top-level functions contained in this |
| 1097 * compilation unit. | 1097 * compilation unit. |
| 1098 */ | 1098 */ |
| 1099 List<FunctionElement> _functions = FunctionElement.EMPTY_LIST; | 1099 List<FunctionElement> _functions = FunctionElement.EMPTY_LIST; |
| 1100 | 1100 |
| 1101 /** | 1101 /** |
| 1102 * A list containing all of the function type aliases contained in this | 1102 * A list containing all of the function type aliases contained in this |
| 1103 * compilation unit. | 1103 * compilation unit. |
| 1104 */ | 1104 */ |
| 1105 List<FunctionTypeAliasElement> _typeAliases = | 1105 List<FunctionTypeAliasElement> _typeAliases = |
| 1106 FunctionTypeAliasElement.EMPTY_LIST; | 1106 FunctionTypeAliasElement.EMPTY_LIST; |
| 1107 | 1107 |
| 1108 /** | 1108 /** |
| 1109 * A list containing all of the types contained in this compilation unit. | 1109 * A list containing all of the types contained in this compilation unit. |
| 1110 */ | 1110 */ |
| 1111 List<ClassElement> _types = ClassElement.EMPTY_LIST; | 1111 List<ClassElement> _types = ClassElement.EMPTY_LIST; |
| 1112 | 1112 |
| 1113 /** | 1113 /** |
| 1114 * A list containing all of the variables contained in this compilation unit. | 1114 * A list containing all of the variables contained in this compilation unit. |
| 1115 */ | 1115 */ |
| 1116 List<TopLevelVariableElement> _variables = TopLevelVariableElement.EMPTY_LIST; | 1116 List<TopLevelVariableElement> _variables; |
| 1117 | 1117 |
| 1118 /** | 1118 /** |
| 1119 * A map from offsets to elements of this unit at these offsets. | 1119 * A map from offsets to elements of this unit at these offsets. |
| 1120 */ | 1120 */ |
| 1121 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>(); | 1121 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>(); |
| 1122 | 1122 |
| 1123 /** | 1123 /** |
| 1124 * Resynthesized explicit top-level property accessors. | |
| 1125 */ | |
| 1126 UnitExplicitTopLevelAccessors _explicitTopLevelAccessors; | |
| 1127 | |
| 1128 /** | |
| 1129 * Resynthesized explicit top-level variables. | |
| 1130 */ | |
| 1131 UnitExplicitTopLevelVariables _explicitTopLevelVariables; | |
| 1132 | |
| 1133 /** | |
| 1134 * Description of top-level variable replacements that should be applied | |
| 1135 * to implicit top-level variables because of re-linking top-level property | |
| 1136 * accessors between different unit of the same library. | |
| 1137 */ | |
| 1138 Map<TopLevelVariableElement, TopLevelVariableElement> | |
| 1139 _topLevelVariableReplaceMap; | |
| 1140 | |
| 1141 /** | |
| 1124 * Initialize a newly created compilation unit element to have the given | 1142 * Initialize a newly created compilation unit element to have the given |
| 1125 * [name]. | 1143 * [name]. |
| 1126 */ | 1144 */ |
| 1127 CompilationUnitElementImpl(String name) | 1145 CompilationUnitElementImpl(String name) |
| 1128 : resynthesizerContext = null, | 1146 : resynthesizerContext = null, |
| 1129 _unlinkedUnit = null, | 1147 _unlinkedUnit = null, |
| 1130 _unlinkedPart = null, | 1148 _unlinkedPart = null, |
| 1131 super(name, -1); | 1149 super(name, -1); |
| 1132 | 1150 |
| 1133 /** | 1151 /** |
| 1134 * Initialize using the given serialized information. | 1152 * Initialize using the given serialized information. |
| 1135 */ | 1153 */ |
| 1136 CompilationUnitElementImpl.forSerialized( | 1154 CompilationUnitElementImpl.forSerialized( |
| 1137 LibraryElementImpl enclosingLibrary, | 1155 LibraryElementImpl enclosingLibrary, |
| 1138 this.resynthesizerContext, | 1156 this.resynthesizerContext, |
| 1139 this._unlinkedUnit, | 1157 this._unlinkedUnit, |
| 1140 this._unlinkedPart, | 1158 this._unlinkedPart, |
| 1141 String name) | 1159 String name) |
| 1142 : super.forSerialized(null) { | 1160 : super.forSerialized(null) { |
| 1143 _enclosingElement = enclosingLibrary; | 1161 _enclosingElement = enclosingLibrary; |
| 1144 _name = name; | 1162 _name = name; |
| 1145 _nameOffset = -1; | 1163 _nameOffset = -1; |
| 1146 } | 1164 } |
| 1147 | 1165 |
| 1148 @override | 1166 @override |
| 1149 List<PropertyAccessorElement> get accessors => _accessors; | 1167 List<PropertyAccessorElement> get accessors { |
| 1168 if (_unlinkedUnit != null) { | |
| 1169 if (_accessors == null) { | |
| 1170 _explicitTopLevelAccessors ??= | |
| 1171 resynthesizerContext.buildTopLevelAccessors(); | |
| 1172 _explicitTopLevelVariables ??= | |
| 1173 resynthesizerContext.buildTopLevelVariables(); | |
| 1174 List<PropertyAccessorElementImpl> accessors = | |
| 1175 <PropertyAccessorElementImpl>[]; | |
| 1176 accessors.addAll(_explicitTopLevelAccessors.accessors); | |
| 1177 for (TopLevelVariableElementImpl implicitVariable | |
| 1178 in _explicitTopLevelAccessors.implicitVariables) { | |
| 1179 implicitVariable.enclosingElement = this; | |
| 1180 } | |
| 1181 for (PropertyAccessorElementImpl implicitAccessors | |
| 1182 in _explicitTopLevelVariables.implicitAccessors) { | |
| 1183 implicitAccessors.enclosingElement = this; | |
| 1184 accessors.add(implicitAccessors); | |
| 1185 } | |
| 1186 _accessors = accessors; | |
| 1187 } | |
| 1188 } | |
| 1189 return _accessors ?? PropertyAccessorElement.EMPTY_LIST; | |
| 1190 } | |
| 1150 | 1191 |
| 1151 /** | 1192 /** |
| 1152 * Set the top-level accessors (getters and setters) contained in this | 1193 * Set the top-level accessors (getters and setters) contained in this |
| 1153 * compilation unit to the given [accessors]. | 1194 * compilation unit to the given [accessors]. |
| 1154 */ | 1195 */ |
| 1155 void set accessors(List<PropertyAccessorElement> accessors) { | 1196 void set accessors(List<PropertyAccessorElement> accessors) { |
| 1156 for (PropertyAccessorElement accessor in accessors) { | 1197 for (PropertyAccessorElement accessor in accessors) { |
| 1157 (accessor as PropertyAccessorElementImpl).enclosingElement = this; | 1198 (accessor as PropertyAccessorElementImpl).enclosingElement = this; |
| 1158 } | 1199 } |
| 1159 this._accessors = accessors; | 1200 this._accessors = accessors; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 for (int i = 0; i < _functions.length; i++) { | 1263 for (int i = 0; i < _functions.length; i++) { |
| 1223 if (_functions[i].name == FunctionElement.LOAD_LIBRARY_NAME) { | 1264 if (_functions[i].name == FunctionElement.LOAD_LIBRARY_NAME) { |
| 1224 return true; | 1265 return true; |
| 1225 } | 1266 } |
| 1226 } | 1267 } |
| 1227 return false; | 1268 return false; |
| 1228 } | 1269 } |
| 1229 | 1270 |
| 1230 @override | 1271 @override |
| 1231 String get identifier => source.encoding; | 1272 String get identifier => source.encoding; |
| 1232 | |
|
Paul Berry
2016/05/19 11:27:29
Nit: restore this blank line.
| |
| 1233 @override | 1273 @override |
| 1234 ElementKind get kind => ElementKind.COMPILATION_UNIT; | 1274 ElementKind get kind => ElementKind.COMPILATION_UNIT; |
| 1235 | 1275 |
| 1236 @override | 1276 @override |
| 1237 List<ElementAnnotation> get metadata { | 1277 List<ElementAnnotation> get metadata { |
| 1238 if (_unlinkedPart != null) { | 1278 if (_unlinkedPart != null) { |
| 1239 CompilationUnitElementImpl definingUnit = | 1279 CompilationUnitElementImpl definingUnit = |
| 1240 library.definingCompilationUnit as CompilationUnitElementImpl; | 1280 library.definingCompilationUnit as CompilationUnitElementImpl; |
| 1241 return _metadata ??= _unlinkedPart.annotations | 1281 return _metadata ??= _unlinkedPart.annotations |
| 1242 .map(definingUnit.resynthesizerContext.buildAnnotation) | 1282 .map(definingUnit.resynthesizerContext.buildAnnotation) |
| 1243 .toList(); | 1283 .toList(); |
| 1244 } | 1284 } |
| 1245 return super.metadata; | 1285 return super.metadata; |
| 1246 } | 1286 } |
| 1247 | 1287 |
| 1248 @override | 1288 @override |
| 1249 List<TopLevelVariableElement> get topLevelVariables => _variables; | 1289 List<TopLevelVariableElement> get topLevelVariables { |
| 1290 if (_unlinkedUnit != null) { | |
| 1291 if (_variables == null) { | |
| 1292 _explicitTopLevelAccessors ??= | |
| 1293 resynthesizerContext.buildTopLevelAccessors(); | |
| 1294 _explicitTopLevelVariables ??= | |
| 1295 resynthesizerContext.buildTopLevelVariables(); | |
| 1296 List<TopLevelVariableElementImpl> variables = | |
| 1297 <TopLevelVariableElementImpl>[]; | |
| 1298 variables.addAll(_explicitTopLevelVariables.variables); | |
| 1299 for (PropertyAccessorElementImpl implicitAccessor | |
| 1300 in _explicitTopLevelVariables.implicitAccessors) { | |
| 1301 implicitAccessor.enclosingElement = this; | |
|
Paul Berry
2016/05/19 11:27:30
If `.accessors` is called and then `.topLevelVaria
scheglov
2016/05/19 16:54:57
Done.
| |
| 1302 } | |
| 1303 for (TopLevelVariableElementImpl implicitVariable | |
| 1304 in _explicitTopLevelAccessors.implicitVariables) { | |
| 1305 implicitVariable.enclosingElement = this; | |
| 1306 variables.add(implicitVariable); | |
| 1307 } | |
| 1308 _variables = variables; | |
| 1309 } | |
| 1310 (enclosingElement as LibraryElementImpl) | |
| 1311 .resynthesizerContext | |
| 1312 .patchTopLevelAccessors(); | |
| 1313 _topLevelVariableReplaceMap?.forEach((from, to) { | |
| 1314 int index = _variables.indexOf(from); | |
| 1315 _variables[index] = to; | |
| 1316 }); | |
| 1317 _topLevelVariableReplaceMap = null; | |
| 1318 } | |
| 1319 return _variables ?? TopLevelVariableElement.EMPTY_LIST; | |
| 1320 } | |
| 1250 | 1321 |
| 1251 /** | 1322 /** |
| 1252 * Set the top-level variables contained in this compilation unit to the given | 1323 * Set the top-level variables contained in this compilation unit to the given |
| 1253 * [variables]. | 1324 * [variables]. |
| 1254 */ | 1325 */ |
| 1255 void set topLevelVariables(List<TopLevelVariableElement> variables) { | 1326 void set topLevelVariables(List<TopLevelVariableElement> variables) { |
| 1327 assert(!isResynthesized); | |
| 1256 for (TopLevelVariableElement field in variables) { | 1328 for (TopLevelVariableElement field in variables) { |
| 1257 (field as TopLevelVariableElementImpl).enclosingElement = this; | 1329 (field as TopLevelVariableElementImpl).enclosingElement = this; |
| 1258 } | 1330 } |
| 1259 this._variables = variables; | 1331 this._variables = variables; |
| 1260 } | 1332 } |
| 1261 | 1333 |
| 1262 /** | 1334 /** |
| 1263 * Set the function type aliases contained in this compilation unit to the | 1335 * Set the function type aliases contained in this compilation unit to the |
| 1264 * given [typeAliases]. | 1336 * given [typeAliases]. |
| 1265 */ | 1337 */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 return annotationMap[offset] ?? const <ElementAnnotation>[]; | 1399 return annotationMap[offset] ?? const <ElementAnnotation>[]; |
| 1328 } | 1400 } |
| 1329 | 1401 |
| 1330 @override | 1402 @override |
| 1331 ElementImpl getChild(String identifier) { | 1403 ElementImpl getChild(String identifier) { |
| 1332 // | 1404 // |
| 1333 // The casts in this method are safe because the set methods would have | 1405 // The casts in this method are safe because the set methods would have |
| 1334 // thrown a CCE if any of the elements in the arrays were not of the | 1406 // thrown a CCE if any of the elements in the arrays were not of the |
| 1335 // expected types. | 1407 // expected types. |
| 1336 // | 1408 // |
| 1337 for (PropertyAccessorElement accessor in _accessors) { | 1409 for (PropertyAccessorElement accessor in accessors) { |
| 1338 PropertyAccessorElementImpl accessorImpl = accessor; | 1410 PropertyAccessorElementImpl accessorImpl = accessor; |
| 1339 if (accessorImpl.identifier == identifier) { | 1411 if (accessorImpl.identifier == identifier) { |
| 1340 return accessorImpl; | 1412 return accessorImpl; |
| 1341 } | 1413 } |
| 1342 } | 1414 } |
| 1343 for (TopLevelVariableElement variable in _variables) { | 1415 for (TopLevelVariableElement variable in topLevelVariables) { |
| 1344 TopLevelVariableElementImpl variableImpl = variable; | 1416 TopLevelVariableElementImpl variableImpl = variable; |
| 1345 if (variableImpl.identifier == identifier) { | 1417 if (variableImpl.identifier == identifier) { |
| 1346 return variableImpl; | 1418 return variableImpl; |
| 1347 } | 1419 } |
| 1348 } | 1420 } |
| 1349 for (FunctionElement function in _functions) { | 1421 for (FunctionElement function in _functions) { |
| 1350 FunctionElementImpl functionImpl = function; | 1422 FunctionElementImpl functionImpl = function; |
| 1351 if (functionImpl.identifier == identifier) { | 1423 if (functionImpl.identifier == identifier) { |
| 1352 return functionImpl; | 1424 return functionImpl; |
| 1353 } | 1425 } |
| 1354 } | 1426 } |
| 1355 for (FunctionTypeAliasElement typeAlias in _typeAliases) { | 1427 for (FunctionTypeAliasElement typeAlias in _typeAliases) { |
| 1356 FunctionTypeAliasElementImpl typeAliasImpl = typeAlias; | 1428 FunctionTypeAliasElementImpl typeAliasImpl = typeAlias; |
| 1357 if (typeAliasImpl.identifier == identifier) { | 1429 if (typeAliasImpl.identifier == identifier) { |
| 1358 return typeAliasImpl; | 1430 return typeAliasImpl; |
| 1359 } | 1431 } |
| 1360 } | 1432 } |
| 1361 for (ClassElement type in _types) { | 1433 for (ClassElement type in _types) { |
| 1362 ClassElementImpl typeImpl = type; | 1434 ClassElementImpl typeImpl = type; |
| 1363 if (typeImpl.identifier == identifier) { | 1435 if (typeImpl.name == identifier) { |
| 1364 return typeImpl; | 1436 return typeImpl; |
| 1365 } | 1437 } |
| 1366 } | 1438 } |
| 1367 for (ClassElement type in _enums) { | 1439 for (ClassElement type in _enums) { |
| 1368 ClassElementImpl typeImpl = type; | 1440 ClassElementImpl typeImpl = type; |
| 1369 if (typeImpl.identifier == identifier) { | 1441 if (typeImpl.identifier == identifier) { |
| 1442 return typeImpl; | |
| 1443 } | |
| 1444 } | |
| 1445 return null; | |
| 1446 } | |
| 1447 | |
| 1448 /** | |
| 1449 * TODO(scheglov) When `_DeferredClassElement` is replaced with | |
|
Paul Berry
2016/05/19 11:27:30
In addition to the TODO, I would appreciate a long
scheglov
2016/05/19 16:54:57
Done.
| |
| 1450 * [ClassElementImpl] remove this method. | |
| 1451 */ | |
| 1452 Element getChildNotImpl(String identifier) { | |
| 1453 // | |
| 1454 // The casts in this method are safe because the set methods would have | |
| 1455 // thrown a CCE if any of the elements in the arrays were not of the | |
| 1456 // expected types. | |
| 1457 // | |
| 1458 for (PropertyAccessorElement accessor in accessors) { | |
| 1459 PropertyAccessorElementImpl accessorImpl = accessor; | |
| 1460 if (accessorImpl.identifier == identifier) { | |
| 1461 return accessorImpl; | |
| 1462 } | |
| 1463 } | |
| 1464 for (TopLevelVariableElement variable in topLevelVariables) { | |
| 1465 TopLevelVariableElementImpl variableImpl = variable; | |
| 1466 if (variableImpl.identifier == identifier) { | |
| 1467 return variableImpl; | |
| 1468 } | |
| 1469 } | |
| 1470 for (FunctionElement function in _functions) { | |
| 1471 FunctionElementImpl functionImpl = function; | |
| 1472 if (functionImpl.identifier == identifier) { | |
| 1473 return functionImpl; | |
| 1474 } | |
| 1475 } | |
| 1476 for (FunctionTypeAliasElement typeAlias in _typeAliases) { | |
| 1477 FunctionTypeAliasElementImpl typeAliasImpl = typeAlias; | |
| 1478 if (typeAliasImpl.identifier == identifier) { | |
| 1479 return typeAliasImpl; | |
| 1480 } | |
| 1481 } | |
| 1482 for (ClassElement type in _types) { | |
| 1483 if (type.name == identifier) { | |
| 1484 return type; | |
| 1485 } | |
| 1486 } | |
| 1487 for (ClassElement type in _enums) { | |
| 1488 ClassElementImpl typeImpl = type; | |
| 1489 if (typeImpl.identifier == identifier) { | |
| 1370 return typeImpl; | 1490 return typeImpl; |
| 1371 } | 1491 } |
| 1372 } | 1492 } |
| 1373 return null; | 1493 return null; |
| 1374 } | 1494 } |
| 1375 | 1495 |
| 1376 @override | 1496 @override |
| 1377 Element getElementAt(int offset) { | 1497 Element getElementAt(int offset) { |
| 1378 if (_offsetToElementMap.isEmpty) { | 1498 if (_offsetToElementMap.isEmpty) { |
| 1379 accept(new _BuildOffsetToElementMap(_offsetToElementMap)); | 1499 accept(new _BuildOffsetToElementMap(_offsetToElementMap)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1399 } | 1519 } |
| 1400 } | 1520 } |
| 1401 return null; | 1521 return null; |
| 1402 } | 1522 } |
| 1403 | 1523 |
| 1404 /** | 1524 /** |
| 1405 * Replace the given [from] top-level variable with [to] in this compilation u nit. | 1525 * Replace the given [from] top-level variable with [to] in this compilation u nit. |
| 1406 */ | 1526 */ |
| 1407 void replaceTopLevelVariable( | 1527 void replaceTopLevelVariable( |
| 1408 TopLevelVariableElement from, TopLevelVariableElement to) { | 1528 TopLevelVariableElement from, TopLevelVariableElement to) { |
| 1409 int index = _variables.indexOf(from); | 1529 if (_unlinkedUnit != null) { |
| 1410 _variables[index] = to; | 1530 _topLevelVariableReplaceMap ??= |
|
Paul Berry
2016/05/19 11:27:29
This will only have the desired effect if the `top
scheglov
2016/05/19 16:54:57
Done.
| |
| 1531 <TopLevelVariableElement, TopLevelVariableElement>{}; | |
| 1532 _topLevelVariableReplaceMap[from] = to; | |
| 1533 } else { | |
| 1534 int index = _variables.indexOf(from); | |
| 1535 _variables[index] = to; | |
| 1536 } | |
| 1411 } | 1537 } |
| 1412 | 1538 |
| 1413 /** | 1539 /** |
| 1414 * Set the annotations associated with the directive at the given [offset] to | 1540 * Set the annotations associated with the directive at the given [offset] to |
| 1415 * the given list of [annotations]. | 1541 * the given list of [annotations]. |
| 1416 */ | 1542 */ |
| 1417 void setAnnotations(int offset, List<ElementAnnotation> annotations) { | 1543 void setAnnotations(int offset, List<ElementAnnotation> annotations) { |
| 1418 annotationMap ??= new HashMap<int, List<ElementAnnotation>>(); | 1544 annotationMap ??= new HashMap<int, List<ElementAnnotation>>(); |
| 1419 annotationMap[offset] = annotations; | 1545 annotationMap[offset] = annotations; |
| 1420 } | 1546 } |
| 1421 | 1547 |
| 1422 @override | 1548 @override |
| 1423 void visitChildren(ElementVisitor visitor) { | 1549 void visitChildren(ElementVisitor visitor) { |
| 1424 super.visitChildren(visitor); | 1550 super.visitChildren(visitor); |
| 1425 safelyVisitChildren(_accessors, visitor); | 1551 safelyVisitChildren(accessors, visitor); |
| 1426 safelyVisitChildren(_enums, visitor); | 1552 safelyVisitChildren(_enums, visitor); |
| 1427 safelyVisitChildren(_functions, visitor); | 1553 safelyVisitChildren(_functions, visitor); |
| 1428 safelyVisitChildren(_typeAliases, visitor); | 1554 safelyVisitChildren(_typeAliases, visitor); |
| 1429 safelyVisitChildren(_types, visitor); | 1555 safelyVisitChildren(_types, visitor); |
| 1430 safelyVisitChildren(_variables, visitor); | 1556 safelyVisitChildren(topLevelVariables, visitor); |
| 1431 } | 1557 } |
| 1432 } | 1558 } |
| 1433 | 1559 |
| 1434 /** | 1560 /** |
| 1435 * A [FieldElement] for a 'const' or 'final' field that has an initializer. | 1561 * A [FieldElement] for a 'const' or 'final' field that has an initializer. |
| 1436 * | 1562 * |
| 1437 * TODO(paulberry): we should rename this class to reflect the fact that it's | 1563 * TODO(paulberry): we should rename this class to reflect the fact that it's |
| 1438 * used for both const and final fields. However, we shouldn't do so until | 1564 * used for both const and final fields. However, we shouldn't do so until |
| 1439 * we've created an API for reading the values of constants; until that API is | 1565 * we've created an API for reading the values of constants; until that API is |
| 1440 * available, clients are likely to read constant values by casting to | 1566 * available, clients are likely to read constant values by casting to |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1632 */ | 1758 */ |
| 1633 ConstTopLevelVariableElementImpl(String name, int offset) | 1759 ConstTopLevelVariableElementImpl(String name, int offset) |
| 1634 : super(name, offset); | 1760 : super(name, offset); |
| 1635 | 1761 |
| 1636 /** | 1762 /** |
| 1637 * Initialize a newly created top-level variable element to have the given | 1763 * Initialize a newly created top-level variable element to have the given |
| 1638 * [name]. | 1764 * [name]. |
| 1639 */ | 1765 */ |
| 1640 ConstTopLevelVariableElementImpl.forNode(Identifier name) | 1766 ConstTopLevelVariableElementImpl.forNode(Identifier name) |
| 1641 : super.forNode(name); | 1767 : super.forNode(name); |
| 1768 | |
| 1769 /** | |
| 1770 * Initialize using the given serialized information. | |
| 1771 */ | |
| 1772 ConstTopLevelVariableElementImpl.forSerialized( | |
| 1773 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) | |
| 1774 : super.forSerialized(unlinkedVariable, enclosingElement); | |
| 1642 } | 1775 } |
| 1643 | 1776 |
| 1644 /** | 1777 /** |
| 1645 * Mixin used by elements that represent constant variables and have | 1778 * Mixin used by elements that represent constant variables and have |
| 1646 * initializers. | 1779 * initializers. |
| 1647 * | 1780 * |
| 1648 * Note that in correct Dart code, all constant variables must have | 1781 * Note that in correct Dart code, all constant variables must have |
| 1649 * initializers. However, analyzer also needs to handle incorrect Dart code, | 1782 * initializers. However, analyzer also needs to handle incorrect Dart code, |
| 1650 * in which case there might be some constant variables that lack initializers. | 1783 * in which case there might be some constant variables that lack initializers. |
| 1651 * This interface is only used for constant variables that have initializers. | 1784 * This interface is only used for constant variables that have initializers. |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3637 | 3770 |
| 3638 /** | 3771 /** |
| 3639 * A concrete implementation of a [LibraryElement]. | 3772 * A concrete implementation of a [LibraryElement]. |
| 3640 */ | 3773 */ |
| 3641 class LibraryElementImpl extends ElementImpl implements LibraryElement { | 3774 class LibraryElementImpl extends ElementImpl implements LibraryElement { |
| 3642 /** | 3775 /** |
| 3643 * The analysis context in which this library is defined. | 3776 * The analysis context in which this library is defined. |
| 3644 */ | 3777 */ |
| 3645 final AnalysisContext context; | 3778 final AnalysisContext context; |
| 3646 | 3779 |
| 3780 final LibraryResynthesizerContext resynthesizerContext; | |
| 3781 | |
| 3782 final UnlinkedUnit _unlinkedDefiningUnit; | |
| 3783 | |
| 3647 /** | 3784 /** |
| 3648 * The compilation unit that defines this library. | 3785 * The compilation unit that defines this library. |
| 3649 */ | 3786 */ |
| 3650 CompilationUnitElement _definingCompilationUnit; | 3787 CompilationUnitElement _definingCompilationUnit; |
| 3651 | 3788 |
| 3652 /** | 3789 /** |
| 3653 * The entry point for this library, or `null` if this library does not have | 3790 * The entry point for this library, or `null` if this library does not have |
| 3654 * an entry point. | 3791 * an entry point. |
| 3655 */ | 3792 */ |
| 3656 FunctionElement entryPoint; | 3793 FunctionElement _entryPoint; |
| 3657 | 3794 |
| 3658 /** | 3795 /** |
| 3659 * A list containing specifications of all of the imports defined in this | 3796 * A list containing specifications of all of the imports defined in this |
| 3660 * library. | 3797 * library. |
| 3661 */ | 3798 */ |
| 3662 List<ImportElement> _imports = ImportElement.EMPTY_LIST; | 3799 List<ImportElement> _imports = ImportElement.EMPTY_LIST; |
| 3663 | 3800 |
| 3664 /** | 3801 /** |
| 3665 * A list containing specifications of all of the exports defined in this | 3802 * A list containing specifications of all of the exports defined in this |
| 3666 * library. | 3803 * library. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 3688 */ | 3825 */ |
| 3689 FunctionElement _loadLibraryFunction; | 3826 FunctionElement _loadLibraryFunction; |
| 3690 | 3827 |
| 3691 @override | 3828 @override |
| 3692 final int nameLength; | 3829 final int nameLength; |
| 3693 | 3830 |
| 3694 /** | 3831 /** |
| 3695 * The export [Namespace] of this library, `null` if it has not been | 3832 * The export [Namespace] of this library, `null` if it has not been |
| 3696 * computed yet. | 3833 * computed yet. |
| 3697 */ | 3834 */ |
| 3698 @override | 3835 Namespace _exportNamespace; |
| 3699 Namespace exportNamespace; | |
| 3700 | 3836 |
| 3701 /** | 3837 /** |
| 3702 * The public [Namespace] of this library, `null` if it has not been | 3838 * The public [Namespace] of this library, `null` if it has not been |
| 3703 * computed yet. | 3839 * computed yet. |
| 3704 */ | 3840 */ |
| 3705 @override | 3841 Namespace _publicNamespace; |
| 3706 Namespace publicNamespace; | |
| 3707 | 3842 |
| 3708 /** | 3843 /** |
| 3709 * Initialize a newly created library element in the given [context] to have | 3844 * Initialize a newly created library element in the given [context] to have |
| 3710 * the given [name] and [offset]. | 3845 * the given [name] and [offset]. |
| 3711 */ | 3846 */ |
| 3712 LibraryElementImpl(this.context, String name, int offset, this.nameLength) | 3847 LibraryElementImpl(this.context, String name, int offset, this.nameLength) |
| 3713 : super(name, offset); | 3848 : resynthesizerContext = null, |
| 3849 _unlinkedDefiningUnit = null, | |
| 3850 super(name, offset); | |
| 3714 | 3851 |
| 3715 /** | 3852 /** |
| 3716 * Initialize a newly created library element in the given [context] to have | 3853 * Initialize a newly created library element in the given [context] to have |
| 3717 * the given [name]. | 3854 * the given [name]. |
| 3718 */ | 3855 */ |
| 3719 LibraryElementImpl.forNode(this.context, LibraryIdentifier name) | 3856 LibraryElementImpl.forNode(this.context, LibraryIdentifier name) |
| 3720 : nameLength = name != null ? name.length : 0, | 3857 : nameLength = name != null ? name.length : 0, |
| 3858 resynthesizerContext = null, | |
| 3859 _unlinkedDefiningUnit = null, | |
| 3721 super.forNode(name); | 3860 super.forNode(name); |
| 3722 | 3861 |
| 3862 /** | |
| 3863 * Initialize using the given serialized information. | |
| 3864 */ | |
| 3865 LibraryElementImpl.forSerialized(this.context, String name, int offset, | |
| 3866 this.nameLength, this.resynthesizerContext, this._unlinkedDefiningUnit) | |
| 3867 : super.forSerialized(null) { | |
| 3868 _name = name; | |
| 3869 _nameOffset = offset; | |
| 3870 } | |
| 3871 | |
| 3723 @override | 3872 @override |
| 3724 int get codeLength { | 3873 int get codeLength { |
| 3725 CompilationUnitElement unit = _definingCompilationUnit; | 3874 CompilationUnitElement unit = _definingCompilationUnit; |
| 3726 if (unit is CompilationUnitElementImpl) { | 3875 if (unit is CompilationUnitElementImpl) { |
| 3727 return unit.codeLength; | 3876 return unit.codeLength; |
| 3728 } | 3877 } |
| 3729 return null; | 3878 return null; |
| 3730 } | 3879 } |
| 3731 | 3880 |
| 3732 @override | 3881 @override |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3746 * Set the compilation unit that defines this library to the given compilation | 3895 * Set the compilation unit that defines this library to the given compilation |
| 3747 * [unit]. | 3896 * [unit]. |
| 3748 */ | 3897 */ |
| 3749 void set definingCompilationUnit(CompilationUnitElement unit) { | 3898 void set definingCompilationUnit(CompilationUnitElement unit) { |
| 3750 assert((unit as CompilationUnitElementImpl).librarySource == unit.source); | 3899 assert((unit as CompilationUnitElementImpl).librarySource == unit.source); |
| 3751 (unit as CompilationUnitElementImpl).enclosingElement = this; | 3900 (unit as CompilationUnitElementImpl).enclosingElement = this; |
| 3752 this._definingCompilationUnit = unit; | 3901 this._definingCompilationUnit = unit; |
| 3753 } | 3902 } |
| 3754 | 3903 |
| 3755 @override | 3904 @override |
| 3905 SourceRange get docRange { | |
| 3906 if (_unlinkedDefiningUnit != null) { | |
| 3907 UnlinkedDocumentationComment comment = | |
| 3908 _unlinkedDefiningUnit.libraryDocumentationComment; | |
| 3909 return comment != null | |
| 3910 ? new SourceRange(comment.offset, comment.length) | |
| 3911 : null; | |
| 3912 } | |
| 3913 return super.docRange; | |
| 3914 } | |
| 3915 | |
| 3916 @override | |
| 3917 String get documentationComment { | |
| 3918 if (_unlinkedDefiningUnit != null) { | |
| 3919 return _unlinkedDefiningUnit?.libraryDocumentationComment?.text; | |
| 3920 } | |
| 3921 return super.documentationComment; | |
| 3922 } | |
| 3923 | |
| 3924 FunctionElement get entryPoint { | |
| 3925 if (resynthesizerContext != null) { | |
| 3926 _entryPoint ??= resynthesizerContext.findEntryPoint(); | |
| 3927 } | |
| 3928 return _entryPoint; | |
| 3929 } | |
| 3930 | |
| 3931 void set entryPoint(FunctionElement entryPoint) { | |
| 3932 _entryPoint = entryPoint; | |
| 3933 } | |
| 3934 | |
| 3935 @override | |
| 3756 List<LibraryElement> get exportedLibraries { | 3936 List<LibraryElement> get exportedLibraries { |
| 3757 HashSet<LibraryElement> libraries = new HashSet<LibraryElement>(); | 3937 HashSet<LibraryElement> libraries = new HashSet<LibraryElement>(); |
| 3758 for (ExportElement element in _exports) { | 3938 for (ExportElement element in _exports) { |
| 3759 LibraryElement library = element.exportedLibrary; | 3939 LibraryElement library = element.exportedLibrary; |
| 3760 if (library != null) { | 3940 if (library != null) { |
| 3761 libraries.add(library); | 3941 libraries.add(library); |
| 3762 } | 3942 } |
| 3763 } | 3943 } |
| 3764 return new List.from(libraries); | 3944 return new List.from(libraries); |
| 3765 } | 3945 } |
| 3766 | 3946 |
| 3767 @override | 3947 @override |
| 3948 Namespace get exportNamespace { | |
| 3949 if (resynthesizerContext != null) { | |
| 3950 _exportNamespace ??= resynthesizerContext.buildExportNamespace(); | |
| 3951 } | |
| 3952 return _exportNamespace; | |
| 3953 } | |
| 3954 | |
| 3955 void set exportNamespace(Namespace exportNamespace) { | |
| 3956 _exportNamespace = exportNamespace; | |
| 3957 } | |
| 3958 | |
| 3959 @override | |
| 3768 List<ExportElement> get exports => _exports; | 3960 List<ExportElement> get exports => _exports; |
| 3769 | 3961 |
| 3770 /** | 3962 /** |
| 3771 * Set the specifications of all of the exports defined in this library to the | 3963 * Set the specifications of all of the exports defined in this library to the |
| 3772 * given list of [exports]. | 3964 * given list of [exports]. |
| 3773 */ | 3965 */ |
| 3774 void set exports(List<ExportElement> exports) { | 3966 void set exports(List<ExportElement> exports) { |
| 3775 for (ExportElement exportElement in exports) { | 3967 for (ExportElement exportElement in exports) { |
| 3776 (exportElement as ExportElementImpl).enclosingElement = this; | 3968 (exportElement as ExportElementImpl).enclosingElement = this; |
| 3777 } | 3969 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3871 if (!visited.contains(exportedLibrary)) { | 4063 if (!visited.contains(exportedLibrary)) { |
| 3872 visited.add(exportedLibrary); | 4064 visited.add(exportedLibrary); |
| 3873 } | 4065 } |
| 3874 } | 4066 } |
| 3875 } | 4067 } |
| 3876 return false; | 4068 return false; |
| 3877 } | 4069 } |
| 3878 | 4070 |
| 3879 @override | 4071 @override |
| 3880 bool get isResynthesized { | 4072 bool get isResynthesized { |
| 3881 CompilationUnitElement definingUnit = _definingCompilationUnit; | 4073 return resynthesizerContext != null; |
| 3882 return definingUnit is CompilationUnitElementImpl && | |
| 3883 definingUnit.resynthesizerContext != null; | |
| 3884 } | 4074 } |
| 3885 | 4075 |
| 3886 @override | 4076 @override |
| 3887 ElementKind get kind => ElementKind.LIBRARY; | 4077 ElementKind get kind => ElementKind.LIBRARY; |
| 3888 | 4078 |
| 3889 @override | 4079 @override |
| 3890 LibraryElement get library => this; | 4080 LibraryElement get library => this; |
| 3891 | 4081 |
| 3892 @override | 4082 @override |
| 3893 List<LibraryElement> get libraryCycle { | 4083 List<LibraryElement> get libraryCycle { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3966 return _libraryCycle; | 4156 return _libraryCycle; |
| 3967 } | 4157 } |
| 3968 | 4158 |
| 3969 @override | 4159 @override |
| 3970 FunctionElement get loadLibraryFunction { | 4160 FunctionElement get loadLibraryFunction { |
| 3971 assert(_loadLibraryFunction != null); | 4161 assert(_loadLibraryFunction != null); |
| 3972 return _loadLibraryFunction; | 4162 return _loadLibraryFunction; |
| 3973 } | 4163 } |
| 3974 | 4164 |
| 3975 @override | 4165 @override |
| 4166 List<ElementAnnotation> get metadata { | |
| 4167 if (_unlinkedDefiningUnit != null) { | |
| 4168 if (_metadata == null) { | |
| 4169 CompilationUnitElementImpl definingUnit = | |
| 4170 _definingCompilationUnit as CompilationUnitElementImpl; | |
| 4171 _metadata ??= _unlinkedDefiningUnit.libraryAnnotations | |
| 4172 .map(definingUnit.resynthesizerContext.buildAnnotation) | |
| 4173 .toList(); | |
| 4174 } | |
| 4175 return _metadata; | |
| 4176 } | |
| 4177 return super.metadata; | |
| 4178 } | |
| 4179 | |
| 4180 @override | |
| 3976 List<CompilationUnitElement> get parts => _parts; | 4181 List<CompilationUnitElement> get parts => _parts; |
| 3977 | 4182 |
| 3978 /** | 4183 /** |
| 3979 * Set the compilation units that are included in this library using a `part` | 4184 * Set the compilation units that are included in this library using a `part` |
| 3980 * directive to the given list of [parts]. | 4185 * directive to the given list of [parts]. |
| 3981 */ | 4186 */ |
| 3982 void set parts(List<CompilationUnitElement> parts) { | 4187 void set parts(List<CompilationUnitElement> parts) { |
| 3983 for (CompilationUnitElement compilationUnit in parts) { | 4188 for (CompilationUnitElement compilationUnit in parts) { |
| 3984 assert((compilationUnit as CompilationUnitElementImpl).librarySource == | 4189 assert((compilationUnit as CompilationUnitElementImpl).librarySource == |
| 3985 source); | 4190 source); |
| 3986 (compilationUnit as CompilationUnitElementImpl).enclosingElement = this; | 4191 (compilationUnit as CompilationUnitElementImpl).enclosingElement = this; |
| 3987 } | 4192 } |
| 3988 this._parts = parts; | 4193 this._parts = parts; |
| 3989 } | 4194 } |
| 3990 | 4195 |
| 3991 @override | 4196 @override |
| 3992 List<PrefixElement> get prefixes { | 4197 List<PrefixElement> get prefixes { |
| 3993 HashSet<PrefixElement> prefixes = new HashSet<PrefixElement>(); | 4198 HashSet<PrefixElement> prefixes = new HashSet<PrefixElement>(); |
| 3994 for (ImportElement element in _imports) { | 4199 for (ImportElement element in _imports) { |
| 3995 PrefixElement prefix = element.prefix; | 4200 PrefixElement prefix = element.prefix; |
| 3996 if (prefix != null) { | 4201 if (prefix != null) { |
| 3997 prefixes.add(prefix); | 4202 prefixes.add(prefix); |
| 3998 } | 4203 } |
| 3999 } | 4204 } |
| 4000 return new List.from(prefixes); | 4205 return new List.from(prefixes); |
| 4001 } | 4206 } |
| 4002 | 4207 |
| 4003 @override | 4208 @override |
| 4209 Namespace get publicNamespace { | |
| 4210 if (resynthesizerContext != null) { | |
| 4211 _publicNamespace ??= resynthesizerContext.buildPublicNamespace(); | |
| 4212 } | |
| 4213 return _publicNamespace; | |
| 4214 } | |
| 4215 | |
| 4216 void set publicNamespace(Namespace publicNamespace) { | |
| 4217 _publicNamespace = publicNamespace; | |
| 4218 } | |
| 4219 | |
| 4220 @override | |
| 4004 Source get source { | 4221 Source get source { |
| 4005 if (_definingCompilationUnit == null) { | 4222 if (_definingCompilationUnit == null) { |
| 4006 return null; | 4223 return null; |
| 4007 } | 4224 } |
| 4008 return _definingCompilationUnit.source; | 4225 return _definingCompilationUnit.source; |
| 4009 } | 4226 } |
| 4010 | 4227 |
| 4011 @override | 4228 @override |
| 4012 List<CompilationUnitElement> get units { | 4229 List<CompilationUnitElement> get units { |
| 4013 List<CompilationUnitElement> units = new List<CompilationUnitElement>(); | 4230 List<CompilationUnitElement> units = new List<CompilationUnitElement>(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4226 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { | 4443 if (!_safeIsUpToDate(exportedLibrary, timeStamp, visitedLibraries)) { |
| 4227 return false; | 4444 return false; |
| 4228 } | 4445 } |
| 4229 } | 4446 } |
| 4230 } | 4447 } |
| 4231 return true; | 4448 return true; |
| 4232 } | 4449 } |
| 4233 } | 4450 } |
| 4234 | 4451 |
| 4235 /** | 4452 /** |
| 4453 * TODO(scheglov) document | |
|
Paul Berry
2016/05/19 11:27:29
Did you intend to address this before sending out
scheglov
2016/05/19 16:54:57
Done.
| |
| 4454 */ | |
| 4455 abstract class LibraryResynthesizerContext { | |
| 4456 Namespace buildExportNamespace(); | |
| 4457 Namespace buildPublicNamespace(); | |
| 4458 FunctionElement findEntryPoint(); | |
| 4459 void patchTopLevelAccessors(); | |
| 4460 } | |
| 4461 | |
| 4462 /** | |
| 4236 * A concrete implementation of a [LocalVariableElement]. | 4463 * A concrete implementation of a [LocalVariableElement]. |
| 4237 */ | 4464 */ |
| 4238 class LocalVariableElementImpl extends NonParameterVariableElementImpl | 4465 class LocalVariableElementImpl extends NonParameterVariableElementImpl |
| 4239 implements LocalVariableElement { | 4466 implements LocalVariableElement { |
| 4240 /** | 4467 /** |
| 4241 * The offset to the beginning of the visible range for this element. | 4468 * The offset to the beginning of the visible range for this element. |
| 4242 */ | 4469 */ |
| 4243 int _visibleRangeOffset = 0; | 4470 int _visibleRangeOffset = 0; |
| 4244 | 4471 |
| 4245 /** | 4472 /** |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4849 return super.codeOffset; | 5076 return super.codeOffset; |
| 4850 } | 5077 } |
| 4851 | 5078 |
| 4852 @override | 5079 @override |
| 4853 void set const3(bool isConst) { | 5080 void set const3(bool isConst) { |
| 4854 assert(_unlinkedVariable == null); | 5081 assert(_unlinkedVariable == null); |
| 4855 super.const3 = isConst; | 5082 super.const3 = isConst; |
| 4856 } | 5083 } |
| 4857 | 5084 |
| 4858 @override | 5085 @override |
| 5086 SourceRange get docRange { | |
| 5087 if (_unlinkedVariable != null) { | |
| 5088 UnlinkedDocumentationComment comment = | |
| 5089 _unlinkedVariable.documentationComment; | |
| 5090 return comment != null | |
| 5091 ? new SourceRange(comment.offset, comment.length) | |
| 5092 : null; | |
| 5093 } | |
| 5094 return super.docRange; | |
| 5095 } | |
| 5096 | |
| 5097 @override | |
| 5098 String get documentationComment { | |
| 5099 if (_unlinkedVariable != null) { | |
| 5100 return _unlinkedVariable?.documentationComment?.text; | |
| 5101 } | |
| 5102 return super.documentationComment; | |
| 5103 } | |
| 5104 | |
| 5105 @override | |
| 4859 void set final2(bool isFinal) { | 5106 void set final2(bool isFinal) { |
| 4860 assert(_unlinkedVariable == null); | 5107 assert(_unlinkedVariable == null); |
| 4861 super.final2 = isFinal; | 5108 super.final2 = isFinal; |
| 4862 } | 5109 } |
| 4863 | 5110 |
| 4864 @override | 5111 @override |
| 4865 bool get hasImplicitType { | 5112 bool get hasImplicitType { |
| 4866 if (_unlinkedVariable != null) { | 5113 if (_unlinkedVariable != null) { |
| 4867 return _unlinkedVariable.type == null; | 5114 return _unlinkedVariable.type == null; |
| 4868 } | 5115 } |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5483 /** | 5730 /** |
| 5484 * Initialize a newly created synthetic element to have the given [name] and | 5731 * Initialize a newly created synthetic element to have the given [name] and |
| 5485 * [offset]. | 5732 * [offset]. |
| 5486 */ | 5733 */ |
| 5487 PropertyInducingElementImpl(String name, int offset) : super(name, offset); | 5734 PropertyInducingElementImpl(String name, int offset) : super(name, offset); |
| 5488 | 5735 |
| 5489 /** | 5736 /** |
| 5490 * Initialize a newly created element to have the given [name]. | 5737 * Initialize a newly created element to have the given [name]. |
| 5491 */ | 5738 */ |
| 5492 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); | 5739 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); |
| 5740 | |
| 5741 /** | |
| 5742 * Initialize using the given serialized information. | |
| 5743 */ | |
| 5744 PropertyInducingElementImpl.forSerialized( | |
| 5745 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) | |
| 5746 : super.forSerialized(unlinkedVariable, enclosingElement); | |
| 5493 } | 5747 } |
| 5494 | 5748 |
| 5495 /** | 5749 /** |
| 5496 * The context in which elements are resynthesized. | 5750 * The context in which elements are resynthesized. |
| 5497 */ | 5751 */ |
| 5498 abstract class ResynthesizerContext { | 5752 abstract class ResynthesizerContext { |
| 5499 /** | 5753 /** |
| 5500 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. | 5754 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. |
| 5501 */ | 5755 */ |
| 5502 ElementAnnotationImpl buildAnnotation(UnlinkedConst uc); | 5756 ElementAnnotationImpl buildAnnotation(UnlinkedConst uc); |
| 5503 | 5757 |
| 5504 /** | 5758 /** |
| 5505 * Build [Expression] for the given [UnlinkedConst]. | 5759 * Build [Expression] for the given [UnlinkedConst]. |
| 5506 */ | 5760 */ |
| 5507 Expression buildExpression(UnlinkedConst uc); | 5761 Expression buildExpression(UnlinkedConst uc); |
| 5508 | 5762 |
| 5509 /** | 5763 /** |
| 5764 * Build explicit top-level property accessors. | |
| 5765 */ | |
| 5766 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); | |
| 5767 | |
| 5768 /** | |
| 5769 * Build explicit top-level variables. | |
| 5770 */ | |
| 5771 UnitExplicitTopLevelVariables buildTopLevelVariables(); | |
| 5772 | |
| 5773 /** | |
| 5510 * Resolve an [EntityRef] into a type. If the reference is | 5774 * Resolve an [EntityRef] into a type. If the reference is |
| 5511 * unresolved, return [DynamicTypeImpl.instance]. | 5775 * unresolved, return [DynamicTypeImpl.instance]. |
| 5512 * | 5776 * |
| 5513 * TODO(paulberry): or should we have a class representing an | 5777 * TODO(paulberry): or should we have a class representing an |
| 5514 * unresolved type, for consistency with the full element model? | 5778 * unresolved type, for consistency with the full element model? |
| 5515 */ | 5779 */ |
| 5516 DartType resolveTypeRef( | 5780 DartType resolveTypeRef( |
| 5517 EntityRef type, TypeParameterizedElementMixin typeParameterContext, | 5781 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 5518 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); | 5782 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); |
| 5519 } | 5783 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5564 * given [name] and [offset]. | 5828 * given [name] and [offset]. |
| 5565 */ | 5829 */ |
| 5566 TopLevelVariableElementImpl(String name, int offset) : super(name, offset); | 5830 TopLevelVariableElementImpl(String name, int offset) : super(name, offset); |
| 5567 | 5831 |
| 5568 /** | 5832 /** |
| 5569 * Initialize a newly created top-level variable element to have the given | 5833 * Initialize a newly created top-level variable element to have the given |
| 5570 * [name]. | 5834 * [name]. |
| 5571 */ | 5835 */ |
| 5572 TopLevelVariableElementImpl.forNode(Identifier name) : super.forNode(name); | 5836 TopLevelVariableElementImpl.forNode(Identifier name) : super.forNode(name); |
| 5573 | 5837 |
| 5838 /** | |
| 5839 * Initialize using the given serialized information. | |
| 5840 */ | |
| 5841 TopLevelVariableElementImpl.forSerialized( | |
| 5842 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) | |
| 5843 : super.forSerialized(unlinkedVariable, enclosingElement); | |
| 5844 | |
| 5574 @override | 5845 @override |
| 5575 bool get isStatic => true; | 5846 bool get isStatic => true; |
| 5576 | 5847 |
| 5577 @override | 5848 @override |
| 5578 ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE; | 5849 ElementKind get kind => ElementKind.TOP_LEVEL_VARIABLE; |
| 5579 | 5850 |
| 5580 @override | 5851 @override |
| 5581 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this); | 5852 accept(ElementVisitor visitor) => visitor.visitTopLevelVariableElement(this); |
| 5582 | 5853 |
| 5583 @override | 5854 @override |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5844 } else if (enclosingTypeParameterContext != null) { | 6115 } else if (enclosingTypeParameterContext != null) { |
| 5845 return enclosingTypeParameterContext | 6116 return enclosingTypeParameterContext |
| 5846 .isTypeParameterInScope(typeParameter); | 6117 .isTypeParameterInScope(typeParameter); |
| 5847 } else { | 6118 } else { |
| 5848 return false; | 6119 return false; |
| 5849 } | 6120 } |
| 5850 } | 6121 } |
| 5851 } | 6122 } |
| 5852 | 6123 |
| 5853 /** | 6124 /** |
| 6125 * Container with information about explicit top-level property accessors and | |
| 6126 * corresponding implicit top-level variables. | |
| 6127 */ | |
| 6128 class UnitExplicitTopLevelAccessors { | |
| 6129 final List<PropertyAccessorElementImpl> accessors = | |
| 6130 <PropertyAccessorElementImpl>[]; | |
| 6131 final List<TopLevelVariableElementImpl> implicitVariables = | |
| 6132 <TopLevelVariableElementImpl>[]; | |
| 6133 } | |
| 6134 | |
| 6135 /** | |
| 6136 * Container with information about explicit top-level variables and | |
| 6137 * corresponding implicit top-level property accessors. | |
| 6138 */ | |
| 6139 class UnitExplicitTopLevelVariables { | |
| 6140 final List<TopLevelVariableElementImpl> variables = | |
| 6141 <TopLevelVariableElementImpl>[]; | |
| 6142 final List<PropertyAccessorElementImpl> implicitAccessors = | |
| 6143 <PropertyAccessorElementImpl>[]; | |
| 6144 } | |
| 6145 | |
| 6146 /** | |
| 5854 * A concrete implementation of a [UriReferencedElement]. | 6147 * A concrete implementation of a [UriReferencedElement]. |
| 5855 */ | 6148 */ |
| 5856 abstract class UriReferencedElementImpl extends ElementImpl | 6149 abstract class UriReferencedElementImpl extends ElementImpl |
| 5857 implements UriReferencedElement { | 6150 implements UriReferencedElement { |
| 5858 /** | 6151 /** |
| 5859 * The offset of the URI in the file, may be `-1` if synthetic. | 6152 * The offset of the URI in the file, may be `-1` if synthetic. |
| 5860 */ | 6153 */ |
| 5861 int uriOffset = -1; | 6154 int uriOffset = -1; |
| 5862 | 6155 |
| 5863 /** | 6156 /** |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6037 | 6330 |
| 6038 @override | 6331 @override |
| 6039 void visitElement(Element element) { | 6332 void visitElement(Element element) { |
| 6040 int offset = element.nameOffset; | 6333 int offset = element.nameOffset; |
| 6041 if (offset != -1) { | 6334 if (offset != -1) { |
| 6042 map[offset] = element; | 6335 map[offset] = element; |
| 6043 } | 6336 } |
| 6044 super.visitElement(element); | 6337 super.visitElement(element); |
| 6045 } | 6338 } |
| 6046 } | 6339 } |
| OLD | NEW |