Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: pkg/analyzer/lib/src/generated/engine.dart

Issue 243263004: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 String extension = FileNameUtilities.getExtension(fileName); 80 String extension = FileNameUtilities.getExtension(fileName);
81 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM); 81 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM);
82 } 82 }
83 83
84 /** 84 /**
85 * The logger that should receive information about errors within the analysis engine. 85 * The logger that should receive information about errors within the analysis engine.
86 */ 86 */
87 Logger _logger = Logger.NULL; 87 Logger _logger = Logger.NULL;
88 88
89 /** 89 /**
90 * The partition manager being used to manage the shared partitions.
91 */
92 final PartitionManager partitionManager = new PartitionManager();
93
94 /**
90 * Create a new context in which analysis can be performed. 95 * Create a new context in which analysis can be performed.
91 * 96 *
92 * @return the analysis context that was created 97 * @return the analysis context that was created
93 */ 98 */
94 AnalysisContext createAnalysisContext() { 99 AnalysisContext createAnalysisContext() {
95 // 100 //
96 // If instrumentation is ignoring data, return an uninstrumented analysis co ntext. 101 // If instrumentation is ignoring data, return an uninstrumented analysis co ntext.
97 // 102 //
98 if (Instrumentation.isNullLogger) { 103 if (Instrumentation.isNullLogger) {
99 return new DelegatingAnalysisContextImpl(); 104 return new AnalysisContextImpl();
100 } 105 }
101 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl()); 106 return new InstrumentedAnalysisContextImpl.con1(new AnalysisContextImpl());
102 } 107 }
103 108
104 /** 109 /**
105 * Return the logger that should receive information about errors within the a nalysis engine. 110 * Return the logger that should receive information about errors within the a nalysis engine.
106 * 111 *
107 * @return the logger that should receive information about errors within the analysis engine 112 * @return the logger that should receive information about errors within the analysis engine
108 */ 113 */
109 Logger get logger => _logger; 114 Logger get logger => _logger;
110 115
111 /** 116 /**
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 957
953 /** 958 /**
954 * Return the source for which the result is being reported. 959 * Return the source for which the result is being reported.
955 * 960 *
956 * @return the source for which the result is being reported 961 * @return the source for which the result is being reported
957 */ 962 */
958 Source get source; 963 Source get source;
959 } 964 }
960 965
961 /** 966 /**
962 * Instances of the class `ChangeSet` indicate what sources have been added, cha nged, or 967 * Instances of the class `ChangeSet` indicate which sources have been added, ch anged,
963 * removed. 968 * removed, or deleted. In the case of a changed source, there are multiple ways of indicating the
969 * nature of the change.
970 *
971 * No source should be added to the change set more than once, either with the s ame or a different
972 * kind of change. It does not make sense, for example, for a source to be both added and removed,
973 * and it is redundant for a source to be marked as changed in its entirety and changed in some
974 * specific range.
964 */ 975 */
965 class ChangeSet { 976 class ChangeSet {
966 /** 977 /**
967 * A list containing the sources that have been added. 978 * A list containing the sources that have been added.
968 */ 979 */
969 List<Source> _added = new List<Source>(); 980 final List<Source> addedSources = new List<Source>();
970 981
971 /** 982 /**
972 * A list containing the sources that have been changed. 983 * A list containing the sources that have been changed.
973 */ 984 */
974 List<Source> _changed = new List<Source>(); 985 final List<Source> changedSources = new List<Source>();
986
987 /**
988 * A table mapping the sources whose content has been changed to the current c ontent of those
989 * sources.
990 */
991 Map<Source, String> _changedContent = new Map<Source, String>();
992
993 /**
994 * A table mapping the sources whose content has been changed within a single range to the current
995 * content of those sources and information about the affected range.
996 */
997 final Map<Source, ChangeSet_ContentChange> changedRanges = new Map<Source, Cha ngeSet_ContentChange>();
975 998
976 /** 999 /**
977 * A list containing the sources that have been removed. 1000 * A list containing the sources that have been removed.
978 */ 1001 */
979 List<Source> _removed = new List<Source>(); 1002 final List<Source> removedSources = new List<Source>();
980 1003
981 /** 1004 /**
982 * A list containing the source containers specifying additional sources that have been removed. 1005 * A list containing the source containers specifying additional sources that have been removed.
983 */ 1006 */
984 final List<SourceContainer> removedContainers = new List<SourceContainer>(); 1007 final List<SourceContainer> removedContainers = new List<SourceContainer>();
985 1008
986 /** 1009 /**
987 * Record that the specified source has been added and that it's content is th e default contents 1010 * A list containing the sources that have been deleted.
988 * of the source. 1011 */
1012 final List<Source> deletedSources = new List<Source>();
1013
1014 /**
1015 * Record that the specified source has been added and that its content is the default contents of
1016 * the source.
989 * 1017 *
990 * @param source the source that was added 1018 * @param source the source that was added
991 */ 1019 */
992 void addedSource(Source source) { 1020 void addedSource(Source source) {
993 _added.add(source); 1021 addedSources.add(source);
994 } 1022 }
995 1023
996 /** 1024 /**
997 * Record that the specified source has been changed and that it's content is the default contents 1025 * Record that the specified source has been changed and that its content is t he given contents.
998 * of the source. 1026 *
1027 * @param source the source that was changed
1028 * @param contents the new contents of the source, or `null` if the default co ntents of the
1029 * source are to be used
1030 */
1031 void changedContent(Source source, String contents) {
1032 _changedContent[source] = contents;
1033 }
1034
1035 /**
1036 * Record that the specified source has been changed and that its content is t he given contents.
1037 *
1038 * @param source the source that was changed
1039 * @param contents the new contents of the source
1040 * @param offset the offset into the current contents
1041 * @param oldLength the number of characters in the original contents that wer e replaced
1042 * @param newLength the number of characters in the replacement text
1043 */
1044 void changedRange(Source source, String contents, int offset, int oldLength, i nt newLength) {
1045 changedRanges[source] = new ChangeSet_ContentChange(contents, offset, oldLen gth, newLength);
1046 }
1047
1048 /**
1049 * Record that the specified source has been changed. If the content of the so urce was previously
1050 * overridden, use [changedContent] instead.
999 * 1051 *
1000 * @param source the source that was changed 1052 * @param source the source that was changed
1001 */ 1053 */
1002 void changedSource(Source source) { 1054 void changedSource(Source source) {
1003 _changed.add(source); 1055 changedSources.add(source);
1004 } 1056 }
1005 1057
1006 /** 1058 /**
1007 * Return a collection of the sources that have been added. 1059 * Record that the specified source has been deleted.
1008 * 1060 *
1009 * @return a collection of the sources that have been added 1061 * @param source the source that was deleted
1010 */ 1062 */
1011 List<Source> get addedSources => _added; 1063 void deletedSource(Source source) {
1064 deletedSources.add(source);
1065 }
1012 1066
1013 /** 1067 /**
1014 * Return a collection of sources that have been changed. 1068 * Return a table mapping the sources whose content has been changed to the cu rrent content of
1069 * those sources.
1015 * 1070 *
1016 * @return a collection of sources that have been changed 1071 * @return a table mapping the sources whose content has been changed to the c urrent content of
1072 * those sources
1017 */ 1073 */
1018 List<Source> get changedSources => _changed; 1074 Map<Source, String> get changedContents => _changedContent;
1019
1020 /**
1021 * Return a list containing the sources that were removed.
1022 *
1023 * @return a list containing the sources that were removed
1024 */
1025 List<Source> get removedSources => _removed;
1026 1075
1027 /** 1076 /**
1028 * Return `true` if this change set does not contain any changes. 1077 * Return `true` if this change set does not contain any changes.
1029 * 1078 *
1030 * @return `true` if this change set does not contain any changes 1079 * @return `true` if this change set does not contain any changes
1031 */ 1080 */
1032 bool get isEmpty => _added.isEmpty && _changed.isEmpty && _removed.isEmpty && removedContainers.isEmpty; 1081 bool get isEmpty => addedSources.isEmpty && changedSources.isEmpty && _changed Content.isEmpty && changedRanges.isEmpty && removedSources.isEmpty && removedCon tainers.isEmpty && deletedSources.isEmpty;
1033 1082
1034 /** 1083 /**
1035 * Record that the specified source container has been removed. 1084 * Record that the specified source container has been removed.
1036 * 1085 *
1037 * @param container the source container that was removed 1086 * @param container the source container that was removed
1038 */ 1087 */
1039 void removedContainer(SourceContainer container) { 1088 void removedContainer(SourceContainer container) {
1040 if (container != null) { 1089 if (container != null) {
1041 removedContainers.add(container); 1090 removedContainers.add(container);
1042 } 1091 }
1043 } 1092 }
1044 1093
1045 /** 1094 /**
1046 * Record that the specified source has been removed. 1095 * Record that the specified source has been removed.
1047 * 1096 *
1048 * @param source the source that was removed 1097 * @param source the source that was removed
1049 */ 1098 */
1050 void removedSource(Source source) { 1099 void removedSource(Source source) {
1051 if (source != null) { 1100 if (source != null) {
1052 _removed.add(source); 1101 removedSources.add(source);
1053 } 1102 }
1054 } 1103 }
1055 1104
1056 @override 1105 @override
1057 String toString() { 1106 String toString() {
1058 JavaStringBuilder builder = new JavaStringBuilder(); 1107 JavaStringBuilder builder = new JavaStringBuilder();
1059 bool needsSeparator = _appendSources(builder, _added, false, "added"); 1108 bool needsSeparator = _appendSources(builder, addedSources, false, "addedSou rces");
1060 needsSeparator = _appendSources(builder, _changed, needsSeparator, "changed" ); 1109 needsSeparator = _appendSources(builder, changedSources, needsSeparator, "ch angedSources");
1061 _appendSources(builder, _removed, needsSeparator, "removed"); 1110 needsSeparator = _appendSources2(builder, _changedContent, needsSeparator, " changedContent");
1111 needsSeparator = _appendSources2(builder, changedRanges, needsSeparator, "ch angedRanges");
1112 needsSeparator = _appendSources(builder, deletedSources, needsSeparator, "de letedSources");
1113 needsSeparator = _appendSources(builder, removedSources, needsSeparator, "re movedSources");
1062 int count = removedContainers.length; 1114 int count = removedContainers.length;
1063 if (count > 0) { 1115 if (count > 0) {
1064 if (_removed.isEmpty) { 1116 if (removedSources.isEmpty) {
1065 if (needsSeparator) { 1117 if (needsSeparator) {
1066 builder.append("; "); 1118 builder.append("; ");
1067 } 1119 }
1068 builder.append("removed: from "); 1120 builder.append("removed: from ");
1069 builder.append(count); 1121 builder.append(count);
1070 builder.append(" containers"); 1122 builder.append(" containers");
1071 } else { 1123 } else {
1072 builder.append(", and more from "); 1124 builder.append(", and more from ");
1073 builder.append(count); 1125 builder.append(count);
1074 builder.append(" containers"); 1126 builder.append(" containers");
(...skipping 21 matching lines...) Expand all
1096 } 1148 }
1097 builder.append(label); 1149 builder.append(label);
1098 String prefix = " "; 1150 String prefix = " ";
1099 for (Source source in sources) { 1151 for (Source source in sources) {
1100 builder.append(prefix); 1152 builder.append(prefix);
1101 builder.append(source.fullName); 1153 builder.append(source.fullName);
1102 prefix = ", "; 1154 prefix = ", ";
1103 } 1155 }
1104 return true; 1156 return true;
1105 } 1157 }
1158
1159 /**
1160 * Append the given sources to the given builder, prefixed with the given labe l and possibly a
1161 * separator.
1162 *
1163 * @param builder the builder to which the sources are to be appended
1164 * @param sources the sources to be appended
1165 * @param needsSeparator `true` if a separator is needed before the label
1166 * @param label the label used to prefix the sources
1167 * @return `true` if future lists of sources will need a separator
1168 */
1169 bool _appendSources2(JavaStringBuilder builder, Map<Source, dynamic> sources, bool needsSeparator, String label) {
1170 if (sources.isEmpty) {
1171 return needsSeparator;
1172 }
1173 if (needsSeparator) {
1174 builder.append("; ");
1175 }
1176 builder.append(label);
1177 String prefix = " ";
1178 for (Source source in sources.keys.toSet()) {
1179 builder.append(prefix);
1180 builder.append(source.fullName);
1181 prefix = ", ";
1182 }
1183 return true;
1184 }
1106 } 1185 }
1107 1186
1108 /** 1187 /**
1188 * Instances of the class `ContentChange` represent a change to the content of a source.
1189 */
1190 class ChangeSet_ContentChange {
1191 /**
1192 * The new contents of the source.
1193 */
1194 final String contents;
1195
1196 /**
1197 * The offset into the current contents.
1198 */
1199 final int offset;
1200
1201 /**
1202 * The number of characters in the original contents that were replaced
1203 */
1204 final int oldLength;
1205
1206 /**
1207 * The number of characters in the replacement text.
1208 */
1209 final int newLength;
1210
1211 /**
1212 * Initialize a newly created change object to represent a change to the conte nt of a source.
1213 *
1214 * @param contents the new contents of the source
1215 * @param offset the offset into the current contents
1216 * @param oldLength the number of characters in the original contents that wer e replaced
1217 * @param newLength the number of characters in the replacement text
1218 */
1219 ChangeSet_ContentChange(this.contents, this.offset, this.oldLength, this.newLe ngth);
1220 }
1221
1222 /**
1109 * Instances of the class `ObsoleteSourceAnalysisException` represent an analysi s attempt that 1223 * Instances of the class `ObsoleteSourceAnalysisException` represent an analysi s attempt that
1110 * failed because a source was deleted between the time the analysis started and the time the 1224 * failed because a source was deleted between the time the analysis started and the time the
1111 * results of the analysis were ready to be recorded. 1225 * results of the analysis were ready to be recorded.
1112 */ 1226 */
1113 class ObsoleteSourceAnalysisException extends AnalysisException { 1227 class ObsoleteSourceAnalysisException extends AnalysisException {
1114 /** 1228 /**
1115 * The source that was removed while it was being analyzed. 1229 * The source that was removed while it was being analyzed.
1116 */ 1230 */
1117 Source _source; 1231 Source _source;
1118 1232
(...skipping 13 matching lines...) Expand all
1132 */ 1246 */
1133 Source get source => _source; 1247 Source get source => _source;
1134 } 1248 }
1135 1249
1136 /** 1250 /**
1137 * Instances of the class `AnalysisCache` implement an LRU cache of information related to 1251 * Instances of the class `AnalysisCache` implement an LRU cache of information related to
1138 * analysis. 1252 * analysis.
1139 */ 1253 */
1140 class AnalysisCache { 1254 class AnalysisCache {
1141 /** 1255 /**
1256 * An array containing the partitions of which this cache is comprised.
1257 */
1258 final List<CachePartition> _partitions;
1259
1260 /**
1261 * Initialize a newly created cache to have the given partitions. The partitio ns will be searched
1262 * in the order in which they appear in the array, so the most specific partit ion (usually an
1263 * [SdkCachePartition]) should be first and the most general (usually a
1264 * [UniversalCachePartition]) last.
1265 *
1266 * @param partitions the partitions for the newly created cache
1267 */
1268 AnalysisCache(this._partitions);
1269
1270 /**
1271 * Record that the AST associated with the given source was just read from the cache.
1272 *
1273 * @param source the source whose AST was accessed
1274 */
1275 void accessedAst(Source source) {
1276 int count = _partitions.length;
1277 for (int i = 0; i < count; i++) {
1278 if (_partitions[i].contains(source)) {
1279 _partitions[i].accessedAst(source);
1280 return;
1281 }
1282 }
1283 }
1284
1285 /**
1286 * Return the entry associated with the given source.
1287 *
1288 * @param source the source whose entry is to be returned
1289 * @return the entry associated with the given source
1290 */
1291 SourceEntry get(Source source) {
1292 int count = _partitions.length;
1293 for (int i = 0; i < count; i++) {
1294 if (_partitions[i].contains(source)) {
1295 return _partitions[i].get(source);
1296 }
1297 }
1298 return null;
1299 }
1300
1301 /**
1302 * Return an iterator returning all of the map entries mapping sources to cach e entries.
1303 *
1304 * @return an iterator returning all of the map entries mapping sources to cac he entries
1305 */
1306 MapIterator<Source, SourceEntry> iterator() {
1307 int count = _partitions.length;
1308 List<Map<Source, SourceEntry>> maps = new List<Map>(count);
1309 for (int i = 0; i < count; i++) {
1310 maps[i] = _partitions[i].map;
1311 }
1312 return new MultipleMapIterator<Source, SourceEntry>(maps);
1313 }
1314
1315 /**
1316 * Associate the given entry with the given source.
1317 *
1318 * @param source the source with which the entry is to be associated
1319 * @param entry the entry to be associated with the source
1320 */
1321 void put(Source source, SourceEntry entry) {
1322 (entry as SourceEntryImpl).fixExceptionState();
1323 int count = _partitions.length;
1324 for (int i = 0; i < count; i++) {
1325 if (_partitions[i].contains(source)) {
1326 _partitions[i].put(source, entry);
1327 return;
1328 }
1329 }
1330 }
1331
1332 /**
1333 * Remove all information related to the given source from this cache.
1334 *
1335 * @param source the source to be removed
1336 */
1337 void remove(Source source) {
1338 int count = _partitions.length;
1339 for (int i = 0; i < count; i++) {
1340 if (_partitions[i].contains(source)) {
1341 _partitions[i].remove(source);
1342 return;
1343 }
1344 }
1345 }
1346
1347 /**
1348 * Record that the AST associated with the given source was just removed from the cache.
1349 *
1350 * @param source the source whose AST was removed
1351 */
1352 void removedAst(Source source) {
1353 int count = _partitions.length;
1354 for (int i = 0; i < count; i++) {
1355 if (_partitions[i].contains(source)) {
1356 _partitions[i].removedAst(source);
1357 return;
1358 }
1359 }
1360 }
1361
1362 /**
1363 * Return the number of sources that are mapped to cache entries.
1364 *
1365 * @return the number of sources that are mapped to cache entries
1366 */
1367 int size() {
1368 int size = 0;
1369 int count = _partitions.length;
1370 for (int i = 0; i < count; i++) {
1371 size += _partitions[i].size();
1372 }
1373 return size;
1374 }
1375
1376 /**
1377 * Record that the AST associated with the given source was just stored to the cache.
1378 *
1379 * @param source the source whose AST was stored
1380 */
1381 void storedAst(Source source) {
1382 int count = _partitions.length;
1383 for (int i = 0; i < count; i++) {
1384 if (_partitions[i].contains(source)) {
1385 _partitions[i].storedAst(source);
1386 return;
1387 }
1388 }
1389 }
1390 }
1391
1392 /**
1393 * Instances of the class `CachePartition` implement a single partition in an LR U cache of
1394 * information related to analysis.
1395 */
1396 abstract class CachePartition {
1397 /**
1142 * A table mapping the sources known to the context to the information known a bout the source. 1398 * A table mapping the sources known to the context to the information known a bout the source.
1143 */ 1399 */
1144 Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>(); 1400 Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>();
1145 1401
1146 /** 1402 /**
1147 * The maximum number of sources for which AST structures should be kept in th e cache. 1403 * The maximum number of sources for which AST structures should be kept in th e cache.
1148 */ 1404 */
1149 int _maxCacheSize = 0; 1405 int _maxCacheSize = 0;
1150 1406
1151 /** 1407 /**
(...skipping 10 matching lines...) Expand all
1162 1418
1163 /** 1419 /**
1164 * Initialize a newly created cache to maintain at most the given number of AS T structures in the 1420 * Initialize a newly created cache to maintain at most the given number of AS T structures in the
1165 * cache. 1421 * cache.
1166 * 1422 *
1167 * @param maxCacheSize the maximum number of sources for which AST structures should be kept in 1423 * @param maxCacheSize the maximum number of sources for which AST structures should be kept in
1168 * the cache 1424 * the cache
1169 * @param retentionPolicy the policy used to determine which pieces of data to remove from the 1425 * @param retentionPolicy the policy used to determine which pieces of data to remove from the
1170 * cache 1426 * cache
1171 */ 1427 */
1172 AnalysisCache(int maxCacheSize, this._retentionPolicy) { 1428 CachePartition(int maxCacheSize, this._retentionPolicy) {
1173 this._maxCacheSize = maxCacheSize; 1429 this._maxCacheSize = maxCacheSize;
1174 _recentlyUsed = new List<Source>(); 1430 _recentlyUsed = new List<Source>();
1175 } 1431 }
1176 1432
1177 /** 1433 /**
1178 * Record that the AST associated with the given source was just read from the cache. 1434 * Record that the AST associated with the given source was just read from the cache.
1179 * 1435 *
1180 * @param source the source whose AST was accessed 1436 * @param source the source whose AST was accessed
1181 */ 1437 */
1182 void accessedAst(Source source) { 1438 void accessedAst(Source source) {
1183 if (_recentlyUsed.remove(source)) { 1439 if (_recentlyUsed.remove(source)) {
1184 _recentlyUsed.add(source); 1440 _recentlyUsed.add(source);
1185 return; 1441 return;
1186 } 1442 }
1187 while (_recentlyUsed.length >= _maxCacheSize) { 1443 while (_recentlyUsed.length >= _maxCacheSize) {
1188 if (!_flushAstFromCache()) { 1444 if (!_flushAstFromCache()) {
1189 break; 1445 break;
1190 } 1446 }
1191 } 1447 }
1192 _recentlyUsed.add(source); 1448 _recentlyUsed.add(source);
1193 } 1449 }
1194 1450
1195 /** 1451 /**
1452 * Return `true` if the given source is contained in this partition.
1453 *
1454 * @param source the source being tested
1455 * @return `true` if the source is contained in this partition
1456 */
1457 bool contains(Source source);
1458
1459 /**
1196 * Return the entry associated with the given source. 1460 * Return the entry associated with the given source.
1197 * 1461 *
1198 * @param source the source whose entry is to be returned 1462 * @param source the source whose entry is to be returned
1199 * @return the entry associated with the given source 1463 * @return the entry associated with the given source
1200 */ 1464 */
1201 SourceEntry get(Source source) => _sourceMap[source]; 1465 SourceEntry get(Source source) => _sourceMap[source];
1202 1466
1203 /** 1467 /**
1468 * Return a table mapping the sources known to the context to the information known about the
1469 * source.
1470 *
1471 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and sho uld not be
1472 * used for any other purpose.
1473 *
1474 * @return a table mapping the sources known to the context to the information known about the
1475 * source
1476 */
1477 Map<Source, SourceEntry> get map => _sourceMap;
1478
1479 /**
1204 * Return an iterator returning all of the map entries mapping sources to cach e entries. 1480 * Return an iterator returning all of the map entries mapping sources to cach e entries.
1205 * 1481 *
1206 * @return an iterator returning all of the map entries mapping sources to cac he entries 1482 * @return an iterator returning all of the map entries mapping sources to cac he entries
1207 */ 1483 */
1208 MapIterator<Source, SourceEntry> iterator() => new SingleMapIterator<Source, S ourceEntry>(_sourceMap); 1484 MapIterator<Source, SourceEntry> iterator() => new SingleMapIterator<Source, S ourceEntry>(_sourceMap);
1209 1485
1210 /** 1486 /**
1211 * Associate the given entry with the given source. 1487 * Associate the given entry with the given source.
1212 * 1488 *
1213 * @param source the source with which the entry is to be associated 1489 * @param source the source with which the entry is to be associated
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 _sourceMap[removedSource] = dartCopy; 1572 _sourceMap[removedSource] = dartCopy;
1297 } 1573 }
1298 return true; 1574 return true;
1299 } 1575 }
1300 1576
1301 /** 1577 /**
1302 * Remove and return one source from the list of recently used sources whose A ST structure can be 1578 * Remove and return one source from the list of recently used sources whose A ST structure can be
1303 * flushed from the cache. The source that will be returned will be the source that has been 1579 * flushed from the cache. The source that will be returned will be the source that has been
1304 * unreferenced for the longest period of time but that is not a priority for analysis. 1580 * unreferenced for the longest period of time but that is not a priority for analysis.
1305 * 1581 *
1306 * It is possible for there to be no AST that can be flushed, in which case `n ull` will be
1307 * returned. This happens, for example, if the context is reserving the AST's needed to resolve a
1308 * cycle of libraries and the number of AST's being reserved is larger than th e current cache
1309 * size.
1310 *
1311 * @return the source that was removed 1582 * @return the source that was removed
1312 */ 1583 */
1313 Source _removeAstToFlush() { 1584 Source _removeAstToFlush() {
1314 int sourceToRemove = -1; 1585 int sourceToRemove = -1;
1315 for (int i = 0; i < _recentlyUsed.length; i++) { 1586 for (int i = 0; i < _recentlyUsed.length; i++) {
1316 Source source = _recentlyUsed[i]; 1587 Source source = _recentlyUsed[i];
1317 RetentionPriority priority = _retentionPolicy.getAstPriority(source, _sour ceMap[source]); 1588 RetentionPriority priority = _retentionPolicy.getAstPriority(source, _sour ceMap[source]);
1318 if (priority == RetentionPriority.LOW) { 1589 if (priority == RetentionPriority.LOW) {
1319 return _recentlyUsed.removeAt(i); 1590 return _recentlyUsed.removeAt(i);
1320 } else if (priority == RetentionPriority.MEDIUM && sourceToRemove < 0) { 1591 } else if (priority == RetentionPriority.MEDIUM && sourceToRemove < 0) {
1321 sourceToRemove = i; 1592 sourceToRemove = i;
1322 } 1593 }
1323 } 1594 }
1324 if (sourceToRemove < 0) { 1595 if (sourceToRemove < 0) {
1596 AnalysisEngine.instance.logger.logError2("Internal error: Could not flush data from the cache", new JavaException());
1325 return null; 1597 return null;
1326 } 1598 }
1327 return _recentlyUsed.removeAt(sourceToRemove); 1599 return _recentlyUsed.removeAt(sourceToRemove);
1328 } 1600 }
1329 } 1601 }
1330 1602
1331 /** 1603 /**
1332 * Instances of the class `CacheRetentionPolicy` define the behavior of objects that determine 1604 * Instances of the class `CacheRetentionPolicy` define the behavior of objects that determine
1333 * how important it is for data to be retained in the analysis cache. 1605 * how important it is for data to be retained in the analysis cache.
1334 */ 1606 */
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 * 3088 *
2817 * @param name the name of the descriptor 3089 * @param name the name of the descriptor
2818 */ 3090 */
2819 DataDescriptor(this._name); 3091 DataDescriptor(this._name);
2820 3092
2821 @override 3093 @override
2822 String toString() => _name; 3094 String toString() => _name;
2823 } 3095 }
2824 3096
2825 /** 3097 /**
3098 * Instances of the class `DefaultRetentionPolicy` implement a retention policy that will keep
3099 * AST's in the cache if there is analysis information that needs to be computed for a source, where
3100 * the computation is dependent on having the AST.
3101 */
3102 class DefaultRetentionPolicy implements CacheRetentionPolicy {
3103 /**
3104 * An instance of this class that can be shared.
3105 */
3106 static DefaultRetentionPolicy POLICY = new DefaultRetentionPolicy();
3107
3108 @override
3109 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) {
3110 if (sourceEntry is DartEntry) {
3111 DartEntry dartEntry = sourceEntry;
3112 if (astIsNeeded(dartEntry)) {
3113 return RetentionPriority.MEDIUM;
3114 }
3115 }
3116 return RetentionPriority.LOW;
3117 }
3118
3119 /**
3120 * Return `true` if there is analysis information in the given entry that need s to be
3121 * computed, where the computation is dependent on having the AST.
3122 *
3123 * @param dartEntry the entry being tested
3124 * @return `true` if there is analysis information that needs to be computed f rom the AST
3125 */
3126 bool astIsNeeded(DartEntry dartEntry) => dartEntry.hasInvalidData(DartEntry.HI NTS) || dartEntry.hasInvalidData(DartEntry.VERIFICATION_ERRORS) || dartEntry.has InvalidData(DartEntry.RESOLUTION_ERRORS);
3127 }
3128
3129 /**
2826 * The interface `HtmlEntry` defines the behavior of objects that maintain the i nformation 3130 * The interface `HtmlEntry` defines the behavior of objects that maintain the i nformation
2827 * cached by an analysis context about an individual HTML file. 3131 * cached by an analysis context about an individual HTML file.
2828 */ 3132 */
2829 abstract class HtmlEntry implements SourceEntry { 3133 abstract class HtmlEntry implements SourceEntry {
2830 /** 3134 /**
2831 * The data descriptor representing the information about an Angular applicati on this source is 3135 * The data descriptor representing the information about an Angular applicati on this source is
2832 * used in. 3136 * used in.
2833 */ 3137 */
2834 static final DataDescriptor<AngularApplication> ANGULAR_APPLICATION = new Data Descriptor<AngularApplication>("HtmlEntry.ANGULAR_APPLICATION"); 3138 static final DataDescriptor<AngularApplication> ANGULAR_APPLICATION = new Data Descriptor<AngularApplication>("HtmlEntry.ANGULAR_APPLICATION");
2835 3139
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 builder.append("; angularErrors = "); 3723 builder.append("; angularErrors = ");
3420 builder.append(_angularErrorsState); 3724 builder.append(_angularErrorsState);
3421 builder.append("; polymerBuildErrors = "); 3725 builder.append("; polymerBuildErrors = ");
3422 builder.append(_polymerBuildErrorsState); 3726 builder.append(_polymerBuildErrorsState);
3423 builder.append("; polymerResolutionErrors = "); 3727 builder.append("; polymerResolutionErrors = ");
3424 builder.append(_polymerResolutionErrorsState); 3728 builder.append(_polymerResolutionErrorsState);
3425 } 3729 }
3426 } 3730 }
3427 3731
3428 /** 3732 /**
3733 * Instances of the class `PartitionManager` manage the partitions that can be s hared between
3734 * analysis contexts.
3735 */
3736 class PartitionManager {
3737 /**
3738 * A table mapping SDK's to the partitions used for those SDK's.
3739 */
3740 Map<DartSdk, SdkCachePartition> _sdkPartitions = new Map<DartSdk, SdkCachePart ition>();
3741
3742 /**
3743 * The default cache size for a Dart SDK partition.
3744 */
3745 static int _DEFAULT_SDK_CACHE_SIZE = 256;
3746
3747 /**
3748 * Return the partition being used for the given SDK, creating the partition i f necessary.
3749 *
3750 * @param sdk the SDK for which a partition is being requested
3751 * @return the partition being used for the given SDK
3752 */
3753 SdkCachePartition forSdk(DartSdk sdk) {
3754 SdkCachePartition partition = _sdkPartitions[sdk];
3755 if (partition == null) {
3756 partition = new SdkCachePartition(_DEFAULT_SDK_CACHE_SIZE);
3757 _sdkPartitions[sdk] = partition;
3758 }
3759 return partition;
3760 }
3761 }
3762
3763 /**
3429 * The enumerated type `RetentionPriority` represents the priority of data in th e cache in 3764 * The enumerated type `RetentionPriority` represents the priority of data in th e cache in
3430 * terms of the desirability of retaining some specified data about a specified source. 3765 * terms of the desirability of retaining some specified data about a specified source.
3431 */ 3766 */
3432 class RetentionPriority extends Enum<RetentionPriority> { 3767 class RetentionPriority extends Enum<RetentionPriority> {
3433 /** 3768 /**
3434 * A priority indicating that a given piece of data can be removed from the ca che without 3769 * A priority indicating that a given piece of data can be removed from the ca che without
3435 * reservation. 3770 * reservation.
3436 */ 3771 */
3437 static const RetentionPriority LOW = const RetentionPriority('LOW', 0); 3772 static const RetentionPriority LOW = const RetentionPriority('LOW', 0);
3438 3773
3439 /** 3774 /**
3440 * A priority indicating that a given piece of data should not be removed from the cache unless 3775 * A priority indicating that a given piece of data should not be removed from the cache unless
3441 * there are no sources for which the corresponding data has a lower priority. Currently used for 3776 * there are no sources for which the corresponding data has a lower priority. Currently used for
3442 * data that is needed in order to finish some outstanding analysis task. 3777 * data that is needed in order to finish some outstanding analysis task.
3443 */ 3778 */
3444 static const RetentionPriority MEDIUM = const RetentionPriority('MEDIUM', 1); 3779 static const RetentionPriority MEDIUM = const RetentionPriority('MEDIUM', 1);
3445 3780
3446 /** 3781 /**
3447 * A priority indicating that a given piece of data should not be removed from the cache. 3782 * A priority indicating that a given piece of data should not be removed from the cache.
3448 * Currently used for data related to a priority source. 3783 * Currently used for data related to a priority source.
3449 */ 3784 */
3450 static const RetentionPriority HIGH = const RetentionPriority('HIGH', 2); 3785 static const RetentionPriority HIGH = const RetentionPriority('HIGH', 2);
3451 3786
3452 static const List<RetentionPriority> values = const [LOW, MEDIUM, HIGH]; 3787 static const List<RetentionPriority> values = const [LOW, MEDIUM, HIGH];
3453 3788
3454 const RetentionPriority(String name, int ordinal) : super(name, ordinal); 3789 const RetentionPriority(String name, int ordinal) : super(name, ordinal);
3455 } 3790 }
3456 3791
3457 /** 3792 /**
3793 * Instances of the class `SdkCachePartition` implement a cache partition that c ontains all of
3794 * the sources in the SDK.
3795 */
3796 class SdkCachePartition extends CachePartition {
3797 /**
3798 * Initialize a newly created partition.
3799 *
3800 * @param maxCacheSize the maximum number of sources for which AST structures should be kept in
3801 * the cache
3802 */
3803 SdkCachePartition(int maxCacheSize) : super(maxCacheSize, DefaultRetentionPoli cy.POLICY);
3804
3805 @override
3806 bool contains(Source source) => source.isInSystemLibrary;
3807 }
3808
3809 /**
3458 * The interface `SourceEntry` defines the behavior of objects that maintain the information 3810 * The interface `SourceEntry` defines the behavior of objects that maintain the information
3459 * cached by an analysis context about an individual source, no matter what kind of source it is. 3811 * cached by an analysis context about an individual source, no matter what kind of source it is.
3460 * 3812 *
3461 * Source entries should be treated as if they were immutable unless a writable copy of the entry 3813 * Source entries should be treated as if they were immutable unless a writable copy of the entry
3462 * has been obtained and has not yet been made visible to other threads. 3814 * has been obtained and has not yet been made visible to other threads.
3463 */ 3815 */
3464 abstract class SourceEntry { 3816 abstract class SourceEntry {
3465 /** 3817 /**
3466 * The data descriptor representing the contents of the source. 3818 * The data descriptor representing the contents of the source.
3467 */ 3819 */
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3626 } else { 3978 } else {
3627 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 3979 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
3628 } 3980 }
3629 } 3981 }
3630 3982
3631 /** 3983 /**
3632 * Invalidate all of the information associated with this source. 3984 * Invalidate all of the information associated with this source.
3633 */ 3985 */
3634 void invalidateAllInformation() { 3986 void invalidateAllInformation() {
3635 _content = null; 3987 _content = null;
3636 _contentState = CacheState.INVALID; 3988 _contentState = _checkContentState(CacheState.INVALID);
3637 _lineInfo = null; 3989 _lineInfo = null;
3638 _lineInfoState = CacheState.INVALID; 3990 _lineInfoState = CacheState.INVALID;
3639 } 3991 }
3640 3992
3641 /** 3993 /**
3642 * Record that an error occurred while attempting to get the contents of the s ource represented by 3994 * Record that an error occurred while attempting to get the contents of the s ource represented by
3643 * this entry. This will set the state of all information, including any resol ution-based 3995 * this entry. This will set the state of all information, including any resol ution-based
3644 * information, as being in error. 3996 * information, as being in error.
3645 */ 3997 */
3646 void recordContentError() { 3998 void recordContentError() {
(...skipping 22 matching lines...) Expand all
3669 4021
3670 /** 4022 /**
3671 * Set the state of the data represented by the given descriptor to the given state. 4023 * Set the state of the data represented by the given descriptor to the given state.
3672 * 4024 *
3673 * @param descriptor the descriptor representing the data whose state is to be set 4025 * @param descriptor the descriptor representing the data whose state is to be set
3674 * @param the new state of the data represented by the given descriptor 4026 * @param the new state of the data represented by the given descriptor
3675 */ 4027 */
3676 void setState(DataDescriptor descriptor, CacheState state) { 4028 void setState(DataDescriptor descriptor, CacheState state) {
3677 if (identical(descriptor, SourceEntry.CONTENT)) { 4029 if (identical(descriptor, SourceEntry.CONTENT)) {
3678 _content = updatedValue(state, _content, null); 4030 _content = updatedValue(state, _content, null);
3679 _contentState = state; 4031 _contentState = _checkContentState(state);
3680 } else if (identical(descriptor, SourceEntry.LINE_INFO)) { 4032 } else if (identical(descriptor, SourceEntry.LINE_INFO)) {
3681 _lineInfo = updatedValue(state, _lineInfo, null); 4033 _lineInfo = updatedValue(state, _lineInfo, null);
3682 _lineInfoState = state; 4034 _lineInfoState = state;
3683 } else { 4035 } else {
3684 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 4036 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
3685 } 4037 }
3686 } 4038 }
3687 4039
3688 /** 4040 /**
3689 * Set the value of the data represented by the given descriptor to the given value. 4041 * Set the value of the data represented by the given descriptor to the given value.
3690 * 4042 *
3691 * @param descriptor the descriptor representing the data whose value is to be set 4043 * @param descriptor the descriptor representing the data whose value is to be set
3692 * @param value the new value of the data represented by the given descriptor 4044 * @param value the new value of the data represented by the given descriptor
3693 */ 4045 */
3694 void setValue(DataDescriptor descriptor, Object value) { 4046 void setValue(DataDescriptor descriptor, Object value) {
3695 if (identical(descriptor, SourceEntry.CONTENT)) { 4047 if (identical(descriptor, SourceEntry.CONTENT)) {
3696 _content = value as String; 4048 _content = value as String;
3697 _contentState = CacheState.VALID; 4049 _contentState = _checkContentState(CacheState.VALID);
3698 } else if (identical(descriptor, SourceEntry.LINE_INFO)) { 4050 } else if (identical(descriptor, SourceEntry.LINE_INFO)) {
3699 _lineInfo = value as LineInfo; 4051 _lineInfo = value as LineInfo;
3700 _lineInfoState = CacheState.VALID; 4052 _lineInfoState = CacheState.VALID;
3701 } else { 4053 } else {
3702 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 4054 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
3703 } 4055 }
3704 } 4056 }
3705 4057
3706 @override 4058 @override
3707 String toString() { 4059 String toString() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 * @param builder the builder to which the text should be written 4141 * @param builder the builder to which the text should be written
3790 */ 4142 */
3791 void writeOn(JavaStringBuilder builder) { 4143 void writeOn(JavaStringBuilder builder) {
3792 builder.append("time = "); 4144 builder.append("time = ");
3793 builder.append(_modificationTime); 4145 builder.append(_modificationTime);
3794 builder.append("; content = "); 4146 builder.append("; content = ");
3795 builder.append(_contentState); 4147 builder.append(_contentState);
3796 builder.append("; lineInfo = "); 4148 builder.append("; lineInfo = ");
3797 builder.append(_lineInfoState); 4149 builder.append(_lineInfoState);
3798 } 4150 }
4151
4152 /**
4153 * If the state is changing from ERROR to anything else, capture the informati on. This is an
4154 * attempt to discover the underlying cause of a long-standing bug.
4155 *
4156 * @param newState the new state of the content
4157 * @return the new state of the content
4158 */
4159 CacheState _checkContentState(CacheState newState) {
4160 if (_contentState == CacheState.ERROR) {
4161 InstrumentationBuilder builder = Instrumentation.builder2("SourceEntryImpl -checkContentState");
4162 builder.data3("message", "contentState changing from ${_contentState} to $ {newState}");
4163 //builder.data("source", source.getFullName());
4164 builder.record(new AnalysisException());
4165 builder.log();
4166 }
4167 return newState;
4168 }
3799 } 4169 }
3800 4170
3801 /** 4171 /**
4172 * Instances of the class `UniversalCachePartition` implement a cache partition that contains
4173 * all sources not contained in other partitions.
4174 */
4175 class UniversalCachePartition extends CachePartition {
4176 /**
4177 * Initialize a newly created partition.
4178 *
4179 * @param maxCacheSize the maximum number of sources for which AST structures should be kept in
4180 * the cache
4181 * @param retentionPolicy the policy used to determine which pieces of data to remove from the
4182 * cache
4183 */
4184 UniversalCachePartition(int maxCacheSize, CacheRetentionPolicy retentionPolicy ) : super(maxCacheSize, retentionPolicy);
4185
4186 @override
4187 bool contains(Source source) => true;
4188 }
4189
4190 /**
3802 * Implementation of the [AnalysisContentStatistics]. 4191 * Implementation of the [AnalysisContentStatistics].
3803 */ 4192 */
3804 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics { 4193 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics {
3805 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>(); 4194 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>();
3806 4195
3807 List<Source> _sources = new List<Source>(); 4196 List<Source> _sources = new List<Source>();
3808 4197
3809 Set<AnalysisException> _exceptions = new Set<AnalysisException>(); 4198 Set<AnalysisException> _exceptions = new Set<AnalysisException>();
3810 4199
3811 void addSource(Source source) { 4200 void addSource(Source source) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3947 * The source factory used to create the sources that can be analyzed in this context. 4336 * The source factory used to create the sources that can be analyzed in this context.
3948 */ 4337 */
3949 SourceFactory _sourceFactory; 4338 SourceFactory _sourceFactory;
3950 4339
3951 /** 4340 /**
3952 * A source representing the core library. 4341 * A source representing the core library.
3953 */ 4342 */
3954 Source _coreLibrarySource; 4343 Source _coreLibrarySource;
3955 4344
3956 /** 4345 /**
4346 * The partition that contains analysis results that are not shared with other contexts.
4347 */
4348 CachePartition _privatePartition;
4349
4350 /**
3957 * A table mapping the sources known to the context to the information known a bout the source. 4351 * A table mapping the sources known to the context to the information known a bout the source.
3958 */ 4352 */
3959 AnalysisCache _cache; 4353 AnalysisCache _cache;
3960 4354
3961 /** 4355 /**
3962 * An array containing sources for which data should not be flushed. 4356 * An array containing sources for which data should not be flushed.
3963 */ 4357 */
3964 List<Source> _priorityOrder = Source.EMPTY_ARRAY; 4358 List<Source> _priorityOrder = Source.EMPTY_ARRAY;
3965 4359
3966 /** 4360 /**
(...skipping 15 matching lines...) Expand all
3982 Set<String> _recentTasks = new Set<String>(); 4376 Set<String> _recentTasks = new Set<String>();
3983 4377
3984 /** 4378 /**
3985 * The object used to synchronize access to all of the caches. The rules relat ed to the use of 4379 * The object used to synchronize access to all of the caches. The rules relat ed to the use of
3986 * this lock object are 4380 * this lock object are
3987 * * no analysis work is done while holding the lock, and 4381 * * no analysis work is done while holding the lock, and
3988 * * no analysis results can be recorded unless we have obtained the lock and validated that the 4382 * * no analysis results can be recorded unless we have obtained the lock and validated that the
3989 * results are for the same version (modification time) of the source as our c urrent cache 4383 * results are for the same version (modification time) of the source as our c urrent cache
3990 * content. 4384 * content.
3991 */ 4385 */
3992 Object _cacheLock = new Object(); 4386 static Object _cacheLock = new Object();
3993 4387
3994 /** 4388 /**
3995 * The object used to record the results of performing an analysis task. 4389 * The object used to record the results of performing an analysis task.
3996 */ 4390 */
3997 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder; 4391 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder;
3998 4392
3999 /** 4393 /**
4000 * Cached information used in incremental analysis or `null` if none. Synchron ize against 4394 * Cached information used in incremental analysis or `null` if none. Synchron ize against
4001 * [cacheLock] before accessing this field. 4395 * [cacheLock] before accessing this field.
4002 */ 4396 */
4003 IncrementalAnalysisCache _incrementalAnalysisCache; 4397 IncrementalAnalysisCache _incrementalAnalysisCache;
4004 4398
4005 /** 4399 /**
4006 * The object used to manage the list of sources that need to be analyzed. 4400 * The object used to manage the list of sources that need to be analyzed.
4007 */ 4401 */
4008 WorkManager _workManager = new WorkManager(); 4402 WorkManager _workManager = new WorkManager();
4009 4403
4010 /** 4404 /**
4011 * The set of [AngularApplication] in this context. 4405 * The set of [AngularApplication] in this context.
4012 */ 4406 */
4013 Set<AngularApplication> _angularApplications = new Set(); 4407 Set<AngularApplication> _angularApplications = new Set();
4014 4408
4015 /** 4409 /**
4016 * Initialize a newly created analysis context. 4410 * Initialize a newly created analysis context.
4017 */ 4411 */
4018 AnalysisContextImpl() : super() { 4412 AnalysisContextImpl() : super() {
4019 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); 4413 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this);
4020 _cache = new AnalysisCache(AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, new Analy sisContextImpl_ContextRetentionPolicy(this)); 4414 _privatePartition = new UniversalCachePartition(AnalysisOptionsImpl.DEFAULT_ CACHE_SIZE, new AnalysisContextImpl_ContextRetentionPolicy(this));
4415 _cache = _createCacheFromSourceFactory(null);
4021 } 4416 }
4022 4417
4023 @override 4418 @override
4024 void addSourceInfo(Source source, SourceEntry info) { 4419 void addSourceInfo(Source source, SourceEntry info) {
4025 // This implementation assumes that the access to the cache does not need to be synchronized 4420 // This implementation assumes that the access to the cache does not need to be synchronized
4026 // because no other object can have access to this context while this method is being invoked. 4421 // because no other object can have access to this context while this method is being invoked.
4027 _cache.put(source, info); 4422 _cache.put(source, info);
4028 } 4423 }
4029 4424
4030 @override 4425 @override
(...skipping 14 matching lines...) Expand all
4045 // 4440 //
4046 bool addedDartSource = false; 4441 bool addedDartSource = false;
4047 for (Source source in changeSet.addedSources) { 4442 for (Source source in changeSet.addedSources) {
4048 if (_sourceAvailable(source)) { 4443 if (_sourceAvailable(source)) {
4049 addedDartSource = true; 4444 addedDartSource = true;
4050 } 4445 }
4051 } 4446 }
4052 for (Source source in changeSet.changedSources) { 4447 for (Source source in changeSet.changedSources) {
4053 _sourceChanged(source); 4448 _sourceChanged(source);
4054 } 4449 }
4450 for (MapEntry<Source, String> entry in getMapEntrySet(changeSet.changedConte nts)) {
4451 setContents(entry.getKey(), entry.getValue());
4452 }
4453 for (MapEntry<Source, ChangeSet_ContentChange> entry in getMapEntrySet(chang eSet.changedRanges)) {
4454 ChangeSet_ContentChange change = entry.getValue();
4455 setChangedContents(entry.getKey(), change.contents, change.offset, change. oldLength, change.newLength);
4456 }
4457 for (Source source in changeSet.deletedSources) {
4458 _sourceDeleted(source);
4459 }
4055 for (Source source in removedSources) { 4460 for (Source source in removedSources) {
4056 _sourceRemoved(source); 4461 _sourceRemoved(source);
4057 } 4462 }
4058 if (addedDartSource) { 4463 if (addedDartSource) {
4059 // TODO(brianwilkerson) This is hugely inefficient, but we need to re-anal yze any libraries 4464 // TODO(brianwilkerson) This is hugely inefficient, but we need to re-anal yze any libraries
4060 // that might have been referencing the not-yet-existing source that was j ust added. Longer 4465 // that might have been referencing the not-yet-existing source that was j ust added. Longer
4061 // term we need to keep track of which libraries are referencing non-exist ing sources and 4466 // term we need to keep track of which libraries are referencing non-exist ing sources and
4062 // only re-analyze those libraries. 4467 // only re-analyze those libraries.
4063 // logInformation("Added Dart sources, invalidating all resolution information"); 4468 // logInformation("Added Dart sources, invalidating all resolution information");
4064 List<Source> sourcesToInvalidate = new List<Source>(); 4469 List<Source> sourcesToInvalidate = new List<Source>();
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception); 5149 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
4745 } 5150 }
4746 } 5151 }
4747 int performEnd = JavaSystem.currentTimeMillis(); 5152 int performEnd = JavaSystem.currentTimeMillis();
4748 return new AnalysisResult(_getChangeNotices(false), getEnd - getStart, task. runtimeType.toString(), performEnd - performStart); 5153 return new AnalysisResult(_getChangeNotices(false), getEnd - getStart, task. runtimeType.toString(), performEnd - performStart);
4749 } 5154 }
4750 5155
4751 @override 5156 @override
4752 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 5157 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
4753 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); 5158 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
4754 for (MapIterator<Source, LibraryElement> iter = SingleMapIterator.forMap(ele mentMap); iter.moveNext();) { 5159 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
4755 Source librarySource = iter.key; 5160 Source librarySource = entry.getKey();
4756 LibraryElement library = iter.value; 5161 LibraryElement library = entry.getValue();
4757 // 5162 //
4758 // Cache the element in the library's info. 5163 // Cache the element in the library's info.
4759 // 5164 //
4760 DartEntry dartEntry = _getReadableDartEntry(librarySource); 5165 DartEntry dartEntry = _getReadableDartEntry(librarySource);
4761 if (dartEntry != null) { 5166 if (dartEntry != null) {
4762 DartEntryImpl dartCopy = dartEntry.writableCopy; 5167 DartEntryImpl dartCopy = dartEntry.writableCopy;
4763 _recordElementData(dartCopy, library, library.source, htmlSource); 5168 _recordElementData(dartCopy, library, library.source, htmlSource);
5169 dartCopy.setValue(DartEntry.SCAN_ERRORS, AnalysisError.NO_ERRORS);
5170 dartCopy.setValue(DartEntry.PARSE_ERRORS, AnalysisError.NO_ERRORS);
5171 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
5172 dartCopy.setValueInLibrary(DartEntry.BUILD_ELEMENT_ERRORS, librarySource , AnalysisError.NO_ERRORS);
5173 dartCopy.setValueInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource, A nalysisError.NO_ERRORS);
5174 dartCopy.setStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource, Cache State.FLUSHED);
5175 dartCopy.setValueInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource, AnalysisError.NO_ERRORS);
5176 dartCopy.setValue(DartEntry.ANGULAR_ERRORS, AnalysisError.NO_ERRORS);
5177 dartCopy.setValueInLibrary(DartEntry.HINTS, librarySource, AnalysisError .NO_ERRORS);
4764 _cache.put(librarySource, dartCopy); 5178 _cache.put(librarySource, dartCopy);
4765 } 5179 }
4766 } 5180 }
4767 } 5181 }
4768 5182
4769 @override 5183 @override
4770 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) { 5184 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
4771 if (library == null) { 5185 if (library == null) {
4772 return null; 5186 return null;
4773 } 5187 }
4774 return resolveCompilationUnit2(unitSource, library.source); 5188 return resolveCompilationUnit2(unitSource, library.source);
4775 } 5189 }
4776 5190
4777 @override 5191 @override
4778 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => _getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT , null); 5192 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => _getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT , null);
4779 5193
4780 @override 5194 @override
4781 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { 5195 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
4782 computeHtmlElement(htmlSource); 5196 computeHtmlElement(htmlSource);
4783 return parseHtmlUnit(htmlSource); 5197 return parseHtmlUnit(htmlSource);
4784 } 5198 }
4785 5199
4786 @override 5200 @override
4787 void set analysisOptions(AnalysisOptions options) { 5201 void set analysisOptions(AnalysisOptions options) {
4788 bool needsRecompute = this._options.analyzeFunctionBodies != options.analyze FunctionBodies || this._options.generateSdkErrors != options.generateSdkErrors | | this._options.dart2jsHint != options.dart2jsHint || (this._options.hint && !op tions.hint) || this._options.preserveComments != options.preserveComments; 5202 bool needsRecompute = this._options.analyzeFunctionBodies != options.analyze FunctionBodies || this._options.generateSdkErrors != options.generateSdkErrors | | this._options.dart2jsHint != options.dart2jsHint || (this._options.hint && !op tions.hint) || this._options.preserveComments != options.preserveComments;
4789 int cacheSize = options.cacheSize; 5203 int cacheSize = options.cacheSize;
4790 if (this._options.cacheSize != cacheSize) { 5204 if (this._options.cacheSize != cacheSize) {
4791 this._options.cacheSize = cacheSize; 5205 this._options.cacheSize = cacheSize;
4792 _cache.maxCacheSize = cacheSize; 5206 //cache.setMaxCacheSize(cacheSize);
5207 _privatePartition.maxCacheSize = cacheSize;
4793 // 5208 //
4794 // Cap the size of the priority list to being less than the cache size. Fa ilure to do so can 5209 // Cap the size of the priority list to being less than the cache size. Fa ilure to do so can
4795 // result in an infinite loop in performAnalysisTask() because re-caching one AST structure 5210 // result in an infinite loop in performAnalysisTask() because re-caching one AST structure
4796 // can cause another priority source's AST structure to be flushed. 5211 // can cause another priority source's AST structure to be flushed.
4797 // 5212 //
4798 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; 5213 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA;
4799 if (_priorityOrder.length > maxPriorityOrderSize) { 5214 if (_priorityOrder.length > maxPriorityOrderSize) {
4800 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize); 5215 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize);
4801 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriority OrderSize); 5216 JavaSystem.arraycopy(_priorityOrder, 0, newPriorityOrder, 0, maxPriority OrderSize);
4802 _priorityOrder = newPriorityOrder; 5217 _priorityOrder = newPriorityOrder;
4803 } 5218 }
4804 } 5219 }
4805 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies; 5220 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies;
4806 this._options.generateSdkErrors = options.generateSdkErrors; 5221 this._options.generateSdkErrors = options.generateSdkErrors;
4807 this._options.dart2jsHint = options.dart2jsHint; 5222 this._options.dart2jsHint = options.dart2jsHint;
4808 this._options.hint = options.hint; 5223 this._options.hint = options.hint;
4809 this._options.incremental = options.incremental; 5224 this._options.incremental = options.incremental;
4810 this._options.preserveComments = options.preserveComments; 5225 this._options.preserveComments = options.preserveComments;
4811 _generateSdkErrors = options.generateSdkErrors; 5226 _generateSdkErrors = options.generateSdkErrors;
4812 if (needsRecompute) { 5227 if (needsRecompute) {
4813 _invalidateAllResolutionInformation(); 5228 _invalidateAllLocalResolutionInformation();
4814 } 5229 }
4815 } 5230 }
4816 5231
4817 @override 5232 @override
4818 void set analysisPriorityOrder(List<Source> sources) { 5233 void set analysisPriorityOrder(List<Source> sources) {
4819 if (sources == null || sources.isEmpty) { 5234 if (sources == null || sources.isEmpty) {
4820 _priorityOrder = Source.EMPTY_ARRAY; 5235 _priorityOrder = Source.EMPTY_ARRAY;
4821 } else { 5236 } else {
4822 while (sources.remove(null)) { 5237 while (sources.remove(null)) {
4823 } 5238 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4889 return; 5304 return;
4890 } else if (factory.context != null) { 5305 } else if (factory.context != null) {
4891 throw new IllegalStateException("Source factories cannot be shared between contexts"); 5306 throw new IllegalStateException("Source factories cannot be shared between contexts");
4892 } 5307 }
4893 if (_sourceFactory != null) { 5308 if (_sourceFactory != null) {
4894 _sourceFactory.context = null; 5309 _sourceFactory.context = null;
4895 } 5310 }
4896 factory.context = this; 5311 factory.context = this;
4897 _sourceFactory = factory; 5312 _sourceFactory = factory;
4898 _coreLibrarySource = _sourceFactory.forUri(DartSdk.DART_CORE); 5313 _coreLibrarySource = _sourceFactory.forUri(DartSdk.DART_CORE);
4899 _invalidateAllResolutionInformation(); 5314 _cache = _createCacheFromSourceFactory(factory);
5315 _invalidateAllLocalResolutionInformation();
4900 } 5316 }
4901 5317
4902 /** 5318 /**
4903 * Record the results produced by performing a [ResolveDartLibraryCycleTask]. If the results 5319 * Record the results produced by performing a [ResolveDartLibraryCycleTask]. If the results
4904 * were computed from data that is now out-of-date, then the results will not be recorded. 5320 * were computed from data that is now out-of-date, then the results will not be recorded.
4905 * 5321 *
4906 * @param task the task that was performed 5322 * @param task the task that was performed
4907 * @return an entry containing the computed results 5323 * @return an entry containing the computed results
4908 * @throws AnalysisException if the results could not be recorded 5324 * @throws AnalysisException if the results could not be recorded
4909 */ 5325 */
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
5412 // 5828 //
5413 // Check to see whether we already have the information being requested. 5829 // Check to see whether we already have the information being requested.
5414 // 5830 //
5415 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource); 5831 CacheState state = dartEntry.getStateInLibrary(descriptor, librarySource);
5416 while (state != CacheState.ERROR && state != CacheState.VALID) { 5832 while (state != CacheState.ERROR && state != CacheState.VALID) {
5417 // 5833 //
5418 // If not, compute the information. Unless the modification date of the so urce continues to 5834 // If not, compute the information. Unless the modification date of the so urce continues to
5419 // change, this loop will eventually terminate. 5835 // change, this loop will eventually terminate.
5420 // 5836 //
5421 LibraryElement library = computeLibraryElement(librarySource); 5837 LibraryElement library = computeLibraryElement(librarySource);
5422 dartEntry = new GenerateDartErrorsTask(this, unitSource, dartEntry.modific ationTime, resolveCompilationUnit(unitSource, library), library).perform(_result Recorder) as DartEntry; 5838 CompilationUnit unit = resolveCompilationUnit(unitSource, library);
5839 if (unit == null) {
5840 throw new AnalysisException.con1("Could not resolve compilation unit ${u nitSource.fullName} in ${librarySource.fullName}");
5841 }
5842 dartEntry = new GenerateDartErrorsTask(this, unitSource, dartEntry.modific ationTime, unit, library).perform(_resultRecorder) as DartEntry;
5423 state = dartEntry.getStateInLibrary(descriptor, librarySource); 5843 state = dartEntry.getStateInLibrary(descriptor, librarySource);
5424 } 5844 }
5425 return dartEntry; 5845 return dartEntry;
5426 } 5846 }
5427 5847
5428 /** 5848 /**
5429 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by 5849 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
5430 * the state of the given descriptors is either [CacheState#VALID] or 5850 * the state of the given descriptors is either [CacheState#VALID] or
5431 * [CacheState#ERROR]. This method assumes that the data can be produced by pa rsing the 5851 * [CacheState#ERROR]. This method assumes that the data can be produced by pa rsing the
5432 * source if it is not already cached. 5852 * source if it is not already cached.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
5537 bool _containsAny(List<Source> sources, List<Source> targetSources) { 5957 bool _containsAny(List<Source> sources, List<Source> targetSources) {
5538 for (Source targetSource in targetSources) { 5958 for (Source targetSource in targetSources) {
5539 if (_contains(sources, targetSource)) { 5959 if (_contains(sources, targetSource)) {
5540 return true; 5960 return true;
5541 } 5961 }
5542 } 5962 }
5543 return false; 5963 return false;
5544 } 5964 }
5545 5965
5546 /** 5966 /**
5967 * Create an analysis cache based on the given source factory.
5968 *
5969 * @param factory the source factory containing the information needed to crea te the cache
5970 * @return the cache that was created
5971 */
5972 AnalysisCache _createCacheFromSourceFactory(SourceFactory factory) {
5973 if (factory == null) {
5974 return new AnalysisCache(<CachePartition> [_privatePartition]);
5975 }
5976 DartSdk sdk = factory.dartSdk;
5977 if (sdk == null) {
5978 return new AnalysisCache(<CachePartition> [_privatePartition]);
5979 }
5980 return new AnalysisCache(<CachePartition> [
5981 AnalysisEngine.instance.partitionManager.forSdk(sdk),
5982 _privatePartition]);
5983 }
5984
5985 /**
5547 * Create a [GenerateDartErrorsTask] for the given source, marking the verific ation errors 5986 * Create a [GenerateDartErrorsTask] for the given source, marking the verific ation errors
5548 * as being in-process. The compilation unit and the library can be the same i f the compilation 5987 * as being in-process. The compilation unit and the library can be the same i f the compilation
5549 * unit is the defining compilation unit of the library. 5988 * unit is the defining compilation unit of the library.
5550 * 5989 *
5551 * @param unitSource the source for the compilation unit to be verified 5990 * @param unitSource the source for the compilation unit to be verified
5552 * @param unitEntry the entry for the compilation unit 5991 * @param unitEntry the entry for the compilation unit
5553 * @param librarySource the source for the library containing the compilation unit 5992 * @param librarySource the source for the library containing the compilation unit
5554 * @param libraryEntry the entry for the library 5993 * @param libraryEntry the entry for the library
5555 * @return task data representing the created task 5994 * @return task data representing the created task
5556 */ 5995 */
5557 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) { 5996 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) {
5558 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != C acheState.VALID || libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { 5997 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != C acheState.VALID || libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) {
5559 return _createResolveDartLibraryTask(librarySource, libraryEntry); 5998 return _createResolveDartLibraryTask(librarySource, libraryEntry);
5560 } 5999 }
5561 CompilationUnit unit = unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); 6000 CompilationUnit unit = unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource);
6001 if (unit == null) {
6002 AnalysisEngine.instance.logger.logInformation2("Entry has VALID state for RESOLVED_UNIT but null value for ${unitSource.fullName} in ${librarySource.fullN ame}", new AnalysisException());
6003 DartEntryImpl dartCopy = unitEntry.writableCopy;
6004 dartCopy.recordResolutionError();
6005 _cache.put(unitSource, dartCopy);
6006 return new AnalysisContextImpl_TaskData(null, false);
6007 }
5562 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); 6008 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT);
5563 DartEntryImpl dartCopy = unitEntry.writableCopy; 6009 DartEntryImpl dartCopy = unitEntry.writableCopy;
5564 dartCopy.setStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource, Cac heState.IN_PROCESS); 6010 dartCopy.setStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource, Cac heState.IN_PROCESS);
5565 _cache.put(unitSource, dartCopy); 6011 _cache.put(unitSource, dartCopy);
5566 return new AnalysisContextImpl_TaskData(new GenerateDartErrorsTask(this, uni tSource, dartCopy.modificationTime, unit, libraryElement), false); 6012 return new AnalysisContextImpl_TaskData(new GenerateDartErrorsTask(this, uni tSource, dartCopy.modificationTime, unit, libraryElement), false);
5567 } 6013 }
5568 6014
5569 /** 6015 /**
5570 * Create a [GenerateDartHintsTask] for the given source, marking the hints as being 6016 * Create a [GenerateDartHintsTask] for the given source, marking the hints as being
5571 * in-process. 6017 * in-process.
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
6585 } 7031 }
6586 } 7032 }
6587 } 7033 }
6588 } 7034 }
6589 7035
6590 /** 7036 /**
6591 * Invalidate all of the resolution results computed by this context. 7037 * Invalidate all of the resolution results computed by this context.
6592 * 7038 *
6593 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 7039 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6594 */ 7040 */
6595 void _invalidateAllResolutionInformation() { 7041 void _invalidateAllLocalResolutionInformation() {
6596 Map<Source, List<Source>> oldPartMap = new Map<Source, List<Source>>(); 7042 Map<Source, List<Source>> oldPartMap = new Map<Source, List<Source>>();
6597 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); 7043 MapIterator<Source, SourceEntry> iterator = _privatePartition.iterator();
6598 while (iterator.moveNext()) { 7044 while (iterator.moveNext()) {
6599 Source source = iterator.key; 7045 Source source = iterator.key;
6600 SourceEntry sourceEntry = iterator.value; 7046 SourceEntry sourceEntry = iterator.value;
6601 if (sourceEntry is HtmlEntry) { 7047 if (sourceEntry is HtmlEntry) {
6602 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy; 7048 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy;
6603 htmlCopy.invalidateAllResolutionInformation(); 7049 htmlCopy.invalidateAllResolutionInformation();
6604 iterator.value = htmlCopy; 7050 iterator.value = htmlCopy;
6605 } else if (sourceEntry is DartEntry) { 7051 } else if (sourceEntry is DartEntry) {
6606 DartEntry dartEntry = sourceEntry; 7052 DartEntry dartEntry = sourceEntry;
6607 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS); 7053 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
7020 } 7466 }
7021 if (thrownException == null) { 7467 if (thrownException == null) {
7022 thrownException = new AnalysisException.con1("GenerateDartHintsTask retu rned a null hint map without throwing an exception: ${librarySource.fullName}"); 7468 thrownException = new AnalysisException.con1("GenerateDartHintsTask retu rned a null hint map without throwing an exception: ${librarySource.fullName}");
7023 } 7469 }
7024 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy; 7470 DartEntryImpl dartCopy = (sourceEntry as DartEntry).writableCopy;
7025 dartCopy.setStateInLibrary(DartEntry.HINTS, librarySource, CacheState.ERRO R); 7471 dartCopy.setStateInLibrary(DartEntry.HINTS, librarySource, CacheState.ERRO R);
7026 dartCopy.exception = thrownException; 7472 dartCopy.exception = thrownException;
7027 _cache.put(librarySource, dartCopy); 7473 _cache.put(librarySource, dartCopy);
7028 throw thrownException; 7474 throw thrownException;
7029 } 7475 }
7030 for (MapIterator<Source, TimestampedData<List<AnalysisError>>> iter = Single MapIterator.forMap(hintMap); iter.moveNext();) { 7476 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) {
7031 Source unitSource = iter.key; 7477 Source unitSource = entry.getKey();
7032 TimestampedData<List<AnalysisError>> results = iter.value; 7478 TimestampedData<List<AnalysisError>> results = entry.getValue();
7033 SourceEntry sourceEntry = _cache.get(unitSource); 7479 SourceEntry sourceEntry = _cache.get(unitSource);
7034 if (sourceEntry is! DartEntry) { 7480 if (sourceEntry is! DartEntry) {
7035 // This shouldn't be possible because we should never have performed the task if the source 7481 // This shouldn't be possible because we should never have performed the task if the source
7036 // didn't represent a Dart file, but check to be safe. 7482 // didn't represent a Dart file, but check to be safe.
7037 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${unitSource.fullName}"); 7483 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${unitSource.fullName}");
7038 } 7484 }
7039 DartEntry dartEntry = sourceEntry as DartEntry; 7485 DartEntry dartEntry = sourceEntry as DartEntry;
7040 if (unitSource == librarySource) { 7486 if (unitSource == librarySource) {
7041 libraryEntry = dartEntry; 7487 libraryEntry = dartEntry;
7042 } 7488 }
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
7936 8382
7937 /** 8383 /**
7938 * Remove the given libraries that are keys in the given map from the list of containing libraries 8384 * Remove the given libraries that are keys in the given map from the list of containing libraries
7939 * for each of the parts in the corresponding value. 8385 * for each of the parts in the corresponding value.
7940 * 8386 *
7941 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 8387 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
7942 * 8388 *
7943 * @param oldPartMap the table containing the parts associated with each libra ry 8389 * @param oldPartMap the table containing the parts associated with each libra ry
7944 */ 8390 */
7945 void _removeFromPartsUsingMap(Map<Source, List<Source>> oldPartMap) { 8391 void _removeFromPartsUsingMap(Map<Source, List<Source>> oldPartMap) {
7946 for (MapIterator<Source, List<Source>> iter = SingleMapIterator.forMap(oldPa rtMap); iter.moveNext();) { 8392 for (MapEntry<Source, List<Source>> entry in getMapEntrySet(oldPartMap)) {
7947 Source librarySource = iter.key; 8393 Source librarySource = entry.getKey();
7948 List<Source> oldParts = iter.value; 8394 List<Source> oldParts = entry.getValue();
7949 for (int i = 0; i < oldParts.length; i++) { 8395 for (int i = 0; i < oldParts.length; i++) {
7950 Source partSource = oldParts[i]; 8396 Source partSource = oldParts[i];
7951 if (partSource != librarySource) { 8397 if (partSource != librarySource) {
7952 DartEntry partEntry = _getReadableDartEntry(partSource); 8398 DartEntry partEntry = _getReadableDartEntry(partSource);
7953 if (partEntry != null) { 8399 if (partEntry != null) {
7954 DartEntryImpl partCopy = partEntry.writableCopy; 8400 DartEntryImpl partCopy = partEntry.writableCopy;
7955 partCopy.removeContainingLibrary(librarySource); 8401 partCopy.removeContainingLibrary(librarySource);
7956 if (partCopy.containingLibraries.length == 0 && !exists(partSource)) { 8402 if (partCopy.containingLibraries.length == 0 && !exists(partSource)) {
7957 _cache.remove(partSource); 8403 _cache.remove(partSource);
7958 } else { 8404 } else {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
8052 _cache.removedAst(source); 8498 _cache.removedAst(source);
8053 _workManager.add(source, SourcePriority.UNKNOWN); 8499 _workManager.add(source, SourcePriority.UNKNOWN);
8054 } 8500 }
8055 } 8501 }
8056 8502
8057 /** 8503 /**
8058 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 8504 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
8059 * 8505 *
8060 * @param source the source that has been deleted 8506 * @param source the source that has been deleted
8061 */ 8507 */
8508 void _sourceDeleted(Source source) {
8509 SourceEntry sourceEntry = _cache.get(source);
8510 if (sourceEntry is HtmlEntry) {
8511 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy;
8512 _invalidateAngularResolution(htmlCopy);
8513 htmlCopy.recordContentError();
8514 _cache.put(source, htmlCopy);
8515 } else if (sourceEntry is DartEntry) {
8516 Set<Source> libraries = new Set<Source>();
8517 for (Source librarySource in getLibrariesContaining(source)) {
8518 libraries.add(librarySource);
8519 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) {
8520 libraries.add(dependentLibrary);
8521 }
8522 }
8523 for (Source librarySource in libraries) {
8524 _invalidateLibraryResolution(librarySource);
8525 }
8526 DartEntryImpl dartCopy = sourceEntry.writableCopy;
8527 dartCopy.recordContentError();
8528 _cache.put(source, dartCopy);
8529 }
8530 _workManager.remove(source);
8531 _removeFromPriorityOrder(source);
8532 }
8533
8534 /**
8535 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
8536 *
8537 * @param source the source that has been removed
8538 */
8062 void _sourceRemoved(Source source) { 8539 void _sourceRemoved(Source source) {
8063 SourceEntry sourceEntry = _cache.get(source); 8540 SourceEntry sourceEntry = _cache.get(source);
8064 if (sourceEntry is HtmlEntry) { 8541 if (sourceEntry is HtmlEntry) {
8065 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy; 8542 HtmlEntryImpl htmlCopy = sourceEntry.writableCopy;
8066 _invalidateAngularResolution(htmlCopy); 8543 _invalidateAngularResolution(htmlCopy);
8067 } else if (sourceEntry is DartEntry) { 8544 } else if (sourceEntry is DartEntry) {
8068 Set<Source> libraries = new Set<Source>(); 8545 Set<Source> libraries = new Set<Source>();
8069 for (Source librarySource in getLibrariesContaining(source)) { 8546 for (Source librarySource in getLibrariesContaining(source)) {
8070 libraries.add(librarySource); 8547 libraries.add(librarySource);
8071 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) { 8548 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
8677 return pairs; 9154 return pairs;
8678 } 9155 }
8679 9156
8680 /** 9157 /**
8681 * Ensure that there is a resolvable compilation unit available for the given source. 9158 * Ensure that there is a resolvable compilation unit available for the given source.
8682 * 9159 *
8683 * @param source the source for which a resolvable compilation unit must be av ailable 9160 * @param source the source for which a resolvable compilation unit must be av ailable
8684 * @param dartEntry the entry associated with the source 9161 * @param dartEntry the entry associated with the source
8685 */ 9162 */
8686 void _ensureResolvableCompilationUnit(Source source, DartEntry dartEntry) { 9163 void _ensureResolvableCompilationUnit(Source source, DartEntry dartEntry) {
8687 if (!dartEntry.hasResolvableCompilationUnit) { 9164 // The entry will be null if the source represents a non-Dart file.
9165 if (dartEntry != null && !dartEntry.hasResolvableCompilationUnit) {
8688 if (_taskData == null) { 9166 if (_taskData == null) {
8689 _taskData = AnalysisContextImpl_this._createParseDartTask(source, dartEn try); 9167 _taskData = AnalysisContextImpl_this._createParseDartTask(source, dartEn try);
8690 } 9168 }
8691 } 9169 }
8692 } 9170 }
8693 9171
8694 Set<Source> _gatherSources(List<CycleBuilder_LibraryPair> libraryData) { 9172 Set<Source> _gatherSources(List<CycleBuilder_LibraryPair> libraryData) {
8695 int libraryCount = libraryData.length; 9173 int libraryCount = libraryData.length;
8696 Set<Source> sources = new Set<Source>(); 9174 Set<Source> sources = new Set<Source>();
8697 for (int i = 0; i < libraryCount; i++) { 9175 for (int i = 0; i < libraryCount; i++) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
8957 if (lineInfo == null) { 9435 if (lineInfo == null) {
8958 AnalysisEngine.instance.logger.logInformation2("No line info: ${source}", new JavaException()); 9436 AnalysisEngine.instance.logger.logInformation2("No line info: ${source}", new JavaException());
8959 } 9437 }
8960 } 9438 }
8961 9439
8962 @override 9440 @override
8963 String toString() => "Changes for ${source.fullName}"; 9441 String toString() => "Changes for ${source.fullName}";
8964 } 9442 }
8965 9443
8966 /** 9444 /**
8967 * Instances of the class `DelegatingAnalysisContextImpl` extend [AnalysisContex tImpl
8968 ] to delegate sources to the appropriate analysis context. For instance, if the
8969 * source is in a system library then the analysis context from the [DartSdk] is used.
8970 */
8971 class DelegatingAnalysisContextImpl extends AnalysisContextImpl {
8972 /**
8973 * This references the [InternalAnalysisContext] held onto by the [DartSdk] wh ich is
8974 * used (instead of this [AnalysisContext]) for SDK sources. This field is set when
8975 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the
8976 * [DartUriResolver] in the [SourceFactory], this analysis context assumes tha t there
8977 * will be such a resolver.
8978 */
8979 InternalAnalysisContext _sdkAnalysisContext;
8980
8981 @override
8982 void addSourceInfo(Source source, SourceEntry info) {
8983 if (source.isInSystemLibrary) {
8984 _sdkAnalysisContext.addSourceInfo(source, info);
8985 } else {
8986 super.addSourceInfo(source, info);
8987 }
8988 }
8989
8990 @override
8991 List<AnalysisError> computeErrors(Source source) {
8992 if (source.isInSystemLibrary) {
8993 return _sdkAnalysisContext.computeErrors(source);
8994 } else {
8995 return super.computeErrors(source);
8996 }
8997 }
8998
8999 @override
9000 List<Source> computeExportedLibraries(Source source) {
9001 if (source.isInSystemLibrary) {
9002 return _sdkAnalysisContext.computeExportedLibraries(source);
9003 } else {
9004 return super.computeExportedLibraries(source);
9005 }
9006 }
9007
9008 @override
9009 HtmlElement computeHtmlElement(Source source) {
9010 if (source.isInSystemLibrary) {
9011 return _sdkAnalysisContext.computeHtmlElement(source);
9012 } else {
9013 return super.computeHtmlElement(source);
9014 }
9015 }
9016
9017 @override
9018 List<Source> computeImportedLibraries(Source source) {
9019 if (source.isInSystemLibrary) {
9020 return _sdkAnalysisContext.computeImportedLibraries(source);
9021 } else {
9022 return super.computeImportedLibraries(source);
9023 }
9024 }
9025
9026 @override
9027 SourceKind computeKindOf(Source source) {
9028 if (source.isInSystemLibrary) {
9029 return _sdkAnalysisContext.computeKindOf(source);
9030 } else {
9031 return super.computeKindOf(source);
9032 }
9033 }
9034
9035 @override
9036 LibraryElement computeLibraryElement(Source source) {
9037 if (source.isInSystemLibrary) {
9038 return _sdkAnalysisContext.computeLibraryElement(source);
9039 } else {
9040 return super.computeLibraryElement(source);
9041 }
9042 }
9043
9044 @override
9045 LineInfo computeLineInfo(Source source) {
9046 if (source.isInSystemLibrary) {
9047 return _sdkAnalysisContext.computeLineInfo(source);
9048 } else {
9049 return super.computeLineInfo(source);
9050 }
9051 }
9052
9053 @override
9054 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
9055 if (source.isInSystemLibrary) {
9056 return _sdkAnalysisContext.computeResolvableCompilationUnit(source);
9057 } else {
9058 return super.computeResolvableCompilationUnit(source);
9059 }
9060 }
9061
9062 @override
9063 AnalysisErrorInfo getErrors(Source source) {
9064 if (source.isInSystemLibrary) {
9065 return _sdkAnalysisContext.getErrors(source);
9066 } else {
9067 return super.getErrors(source);
9068 }
9069 }
9070
9071 @override
9072 HtmlElement getHtmlElement(Source source) {
9073 if (source.isInSystemLibrary) {
9074 return _sdkAnalysisContext.getHtmlElement(source);
9075 } else {
9076 return super.getHtmlElement(source);
9077 }
9078 }
9079
9080 @override
9081 List<Source> getHtmlFilesReferencing(Source source) {
9082 if (source.isInSystemLibrary) {
9083 return _sdkAnalysisContext.getHtmlFilesReferencing(source);
9084 } else {
9085 return super.getHtmlFilesReferencing(source);
9086 }
9087 }
9088
9089 @override
9090 SourceKind getKindOf(Source source) {
9091 if (source.isInSystemLibrary) {
9092 return _sdkAnalysisContext.getKindOf(source);
9093 } else {
9094 return super.getKindOf(source);
9095 }
9096 }
9097
9098 @override
9099 List<Source> getLibrariesContaining(Source source) {
9100 if (source.isInSystemLibrary) {
9101 return _sdkAnalysisContext.getLibrariesContaining(source);
9102 } else {
9103 return super.getLibrariesContaining(source);
9104 }
9105 }
9106
9107 @override
9108 List<Source> getLibrariesDependingOn(Source librarySource) {
9109 if (librarySource.isInSystemLibrary) {
9110 return _sdkAnalysisContext.getLibrariesDependingOn(librarySource);
9111 } else {
9112 return super.getLibrariesDependingOn(librarySource);
9113 }
9114 }
9115
9116 @override
9117 LibraryElement getLibraryElement(Source source) {
9118 if (source.isInSystemLibrary) {
9119 return _sdkAnalysisContext.getLibraryElement(source);
9120 } else {
9121 return super.getLibraryElement(source);
9122 }
9123 }
9124
9125 @override
9126 List<Source> get librarySources => ArrayUtils.addAll(super.librarySources, _sd kAnalysisContext.librarySources);
9127
9128 @override
9129 LineInfo getLineInfo(Source source) {
9130 if (source.isInSystemLibrary) {
9131 return _sdkAnalysisContext.getLineInfo(source);
9132 } else {
9133 return super.getLineInfo(source);
9134 }
9135 }
9136
9137 @override
9138 Namespace getPublicNamespace(LibraryElement library) {
9139 Source source = library.source;
9140 if (source.isInSystemLibrary) {
9141 return _sdkAnalysisContext.getPublicNamespace(library);
9142 } else {
9143 return super.getPublicNamespace(library);
9144 }
9145 }
9146
9147 @override
9148 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
9149 if (unitSource.isInSystemLibrary) {
9150 return _sdkAnalysisContext.getResolvedCompilationUnit(unitSource, library) ;
9151 } else {
9152 return super.getResolvedCompilationUnit(unitSource, library);
9153 }
9154 }
9155
9156 @override
9157 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
9158 if (unitSource.isInSystemLibrary) {
9159 return _sdkAnalysisContext.getResolvedCompilationUnit2(unitSource, library Source);
9160 } else {
9161 return super.getResolvedCompilationUnit2(unitSource, librarySource);
9162 }
9163 }
9164
9165 @override
9166 bool isClientLibrary(Source librarySource) {
9167 if (librarySource.isInSystemLibrary) {
9168 return _sdkAnalysisContext.isClientLibrary(librarySource);
9169 } else {
9170 return super.isClientLibrary(librarySource);
9171 }
9172 }
9173
9174 @override
9175 bool isServerLibrary(Source librarySource) {
9176 if (librarySource.isInSystemLibrary) {
9177 return _sdkAnalysisContext.isServerLibrary(librarySource);
9178 } else {
9179 return super.isServerLibrary(librarySource);
9180 }
9181 }
9182
9183 @override
9184 CompilationUnit parseCompilationUnit(Source source) {
9185 if (source.isInSystemLibrary) {
9186 return _sdkAnalysisContext.parseCompilationUnit(source);
9187 } else {
9188 return super.parseCompilationUnit(source);
9189 }
9190 }
9191
9192 @override
9193 ht.HtmlUnit parseHtmlUnit(Source source) {
9194 if (source.isInSystemLibrary) {
9195 return _sdkAnalysisContext.parseHtmlUnit(source);
9196 } else {
9197 return super.parseHtmlUnit(source);
9198 }
9199 }
9200
9201 @override
9202 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
9203 if (elementMap.isEmpty) {
9204 return;
9205 }
9206 // TODO(jwren) we are making the assumption here that the elementMap will ha ve sources from only
9207 // one library, while this is true with our use of the Analysis Engine, it i s not required by
9208 // the API, revisit to fix cases where the elementMap can have sources both in the sdk and other
9209 // libraries
9210 Source source = new JavaIterator(elementMap.keys.toSet()).next();
9211 if (source.isInSystemLibrary) {
9212 _sdkAnalysisContext.recordLibraryElements(elementMap);
9213 } else {
9214 super.recordLibraryElements(elementMap);
9215 }
9216 }
9217
9218 @override
9219 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
9220 if (source.isInSystemLibrary) {
9221 return _sdkAnalysisContext.resolveCompilationUnit(source, library);
9222 } else {
9223 return super.resolveCompilationUnit(source, library);
9224 }
9225 }
9226
9227 @override
9228 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
9229 if (unitSource.isInSystemLibrary) {
9230 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce);
9231 } else {
9232 return super.resolveCompilationUnit2(unitSource, librarySource);
9233 }
9234 }
9235
9236 @override
9237 ht.HtmlUnit resolveHtmlUnit(Source unitSource) {
9238 if (unitSource.isInSystemLibrary) {
9239 return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
9240 } else {
9241 return super.resolveHtmlUnit(unitSource);
9242 }
9243 }
9244
9245 @override
9246 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) {
9247 if (source.isInSystemLibrary) {
9248 _sdkAnalysisContext.setChangedContents(source, contents, offset, oldLength , newLength);
9249 } else {
9250 super.setChangedContents(source, contents, offset, oldLength, newLength);
9251 }
9252 }
9253
9254 @override
9255 void setContents(Source source, String contents) {
9256 if (source.isInSystemLibrary) {
9257 _sdkAnalysisContext.setContents(source, contents);
9258 } else {
9259 super.setContents(source, contents);
9260 }
9261 }
9262
9263 @override
9264 void set sourceFactory(SourceFactory factory) {
9265 super.sourceFactory = factory;
9266 DartSdk sdk = factory.dartSdk;
9267 if (sdk != null) {
9268 _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
9269 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl) {
9270 _sdkAnalysisContext = null;
9271 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context");
9272 }
9273 } else {
9274 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
9275 }
9276 }
9277 }
9278
9279 /**
9280 * Instances of the class `IncrementalAnalysisCache` hold information used to pe rform 9445 * Instances of the class `IncrementalAnalysisCache` hold information used to pe rform
9281 * incremental analysis. 9446 * incremental analysis.
9282 * 9447 *
9283 * @see AnalysisContextImpl#setChangedContents(Source, String, int, int, int) 9448 * @see AnalysisContextImpl#setChangedContents(Source, String, int, int, int)
9284 */ 9449 */
9285 class IncrementalAnalysisCache { 9450 class IncrementalAnalysisCache {
9286 /** 9451 /**
9287 * Determine if the incremental analysis result can be cached for the next inc remental analysis. 9452 * Determine if the incremental analysis result can be cached for the next inc remental analysis.
9288 * 9453 *
9289 * @param cache the prior incremental analysis cache 9454 * @param cache the prior incremental analysis cache
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
9375 * equivalent to the fully parsed unit. 9540 * equivalent to the fully parsed unit.
9376 * 9541 *
9377 * @param cache the prior cache or `null` if none 9542 * @param cache the prior cache or `null` if none
9378 * @param source the source of the compilation unit that was parsed (not `null `) 9543 * @param source the source of the compilation unit that was parsed (not `null `)
9379 * @param unit the compilation unit that was just parsed 9544 * @param unit the compilation unit that was just parsed
9380 * @return the cache used for incremental analysis or `null` if incremental an alysis results 9545 * @return the cache used for incremental analysis or `null` if incremental an alysis results
9381 * cannot be cached for the next incremental analysis 9546 * cannot be cached for the next incremental analysis
9382 */ 9547 */
9383 static IncrementalAnalysisCache verifyStructure(IncrementalAnalysisCache cache , Source source, CompilationUnit unit) { 9548 static IncrementalAnalysisCache verifyStructure(IncrementalAnalysisCache cache , Source source, CompilationUnit unit) {
9384 if (cache != null && unit != null && cache.source == source) { 9549 if (cache != null && unit != null && cache.source == source) {
9385 if (!AstComparator.equalUnits(cache.resolvedUnit, unit)) { 9550 if (!AstComparator.equalNodes(cache.resolvedUnit, unit)) {
9386 return null; 9551 return null;
9387 } 9552 }
9388 } 9553 }
9389 return cache; 9554 return cache;
9390 } 9555 }
9391 9556
9392 final Source librarySource; 9557 final Source librarySource;
9393 9558
9394 final Source source; 9559 final Source source;
9395 9560
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
9480 9645
9481 /** 9646 /**
9482 * The analysis context to which all of the non-instrumentation work is delega ted. 9647 * The analysis context to which all of the non-instrumentation work is delega ted.
9483 */ 9648 */
9484 InternalAnalysisContext _basis; 9649 InternalAnalysisContext _basis;
9485 9650
9486 /** 9651 /**
9487 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new 9652 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new
9488 * [AnalysisContextImpl] as the basis context. 9653 * [AnalysisContextImpl] as the basis context.
9489 */ 9654 */
9490 InstrumentedAnalysisContextImpl() : this.con1(new DelegatingAnalysisContextImp l()); 9655 InstrumentedAnalysisContextImpl() : this.con1(new AnalysisContextImpl());
9491 9656
9492 /** 9657 /**
9493 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the 9658 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the
9494 * context to wrap and instrument. 9659 * context to wrap and instrument.
9495 * 9660 *
9496 * @param context some [InstrumentedAnalysisContext] to wrap and instrument 9661 * @param context some [InstrumentedAnalysisContext] to wrap and instrument
9497 */ 9662 */
9498 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) { 9663 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) {
9499 _basis = context; 9664 _basis = context;
9500 } 9665 }
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
10353 onError(error); 10518 onError(error);
10354 } 10519 }
10355 } 10520 }
10356 10521
10357 /** 10522 /**
10358 * Answer the errors collected by the listener. 10523 * Answer the errors collected by the listener.
10359 * 10524 *
10360 * @return an array of errors (not `null`, contains no `null`s) 10525 * @return an array of errors (not `null`, contains no `null`s)
10361 */ 10526 */
10362 List<AnalysisError> get errors { 10527 List<AnalysisError> get errors {
10363 Iterable<Set<AnalysisError>> errorsSets = _errors.values; 10528 Iterable<MapEntry<Source, Set<AnalysisError>>> entrySet = getMapEntrySet(_er rors);
10364 int numEntries = errorsSets.length; 10529 int numEntries = entrySet.length;
10365 if (numEntries == 0) { 10530 if (numEntries == 0) {
10366 return AnalysisError.NO_ERRORS; 10531 return AnalysisError.NO_ERRORS;
10367 } 10532 }
10368 List<AnalysisError> resultList = new List<AnalysisError>(); 10533 List<AnalysisError> resultList = new List<AnalysisError>();
10369 for (Set<AnalysisError> errorsSet in errorsSets) { 10534 for (MapEntry<Source, Set<AnalysisError>> entry in entrySet) {
10370 resultList.addAll(errorsSet); 10535 resultList.addAll(entry.getValue());
10371 } 10536 }
10372 return new List.from(resultList); 10537 return new List.from(resultList);
10373 } 10538 }
10374 10539
10375 /** 10540 /**
10376 * Answer the errors collected by the listener for some passed [Source]. 10541 * Answer the errors collected by the listener for some passed [Source].
10377 * 10542 *
10378 * @param source some [Source] for which the caller wants the set of [Analysis Error]s 10543 * @param source some [Source] for which the caller wants the set of [Analysis Error]s
10379 * collected by this listener 10544 * collected by this listener
10380 * @return the errors collected by the listener for the passed [Source] 10545 * @return the errors collected by the listener for the passed [Source]
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
11267 11432
11268 AngularExpression _parseAngularExpressionInToken(Token token) { 11433 AngularExpression _parseAngularExpressionInToken(Token token) {
11269 List<Token> tokens = _splitAtBar(token); 11434 List<Token> tokens = _splitAtBar(token);
11270 Expression mainExpression = _parseDartExpressionInToken(tokens[0]); 11435 Expression mainExpression = _parseDartExpressionInToken(tokens[0]);
11271 // parse filters 11436 // parse filters
11272 List<AngularFilterNode> filters = []; 11437 List<AngularFilterNode> filters = [];
11273 for (int i = 1; i < tokens.length; i++) { 11438 for (int i = 1; i < tokens.length; i++) {
11274 Token filterToken = tokens[i]; 11439 Token filterToken = tokens[i];
11275 Token barToken = filterToken; 11440 Token barToken = filterToken;
11276 filterToken = filterToken.next; 11441 filterToken = filterToken.next;
11277 // TODO(scheglov) report missing identifier 11442 // parse name
11278 SimpleIdentifier name = _parseDartExpressionInToken(filterToken) as Simple Identifier; 11443 Expression nameExpression = _parseDartExpressionInToken(filterToken);
11444 if (nameExpression is! SimpleIdentifier) {
11445 _reportErrorForNode(AngularCode.INVALID_FILTER_NAME, nameExpression, []) ;
11446 continue;
11447 }
11448 SimpleIdentifier name = nameExpression as SimpleIdentifier;
11279 filterToken = name.endToken.next; 11449 filterToken = name.endToken.next;
11280 // parse arguments 11450 // parse arguments
11281 List<AngularFilterArgument> arguments = []; 11451 List<AngularFilterArgument> arguments = [];
11282 while (filterToken.type != TokenType.EOF) { 11452 while (filterToken.type != TokenType.EOF) {
11283 // skip ":" 11453 // skip ":"
11284 Token colonToken = filterToken; 11454 Token colonToken = filterToken;
11285 if (colonToken.type == TokenType.COLON) { 11455 if (colonToken.type == TokenType.COLON) {
11286 filterToken = filterToken.next; 11456 filterToken = filterToken.next;
11287 } else { 11457 } else {
11288 _reportErrorForToken(AngularCode.MISSING_FILTER_COLON, colonToken, []) ; 11458 _reportErrorForToken(AngularCode.MISSING_FILTER_COLON, colonToken, []) ;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
11563 // simulate imports for injects 11733 // simulate imports for injects
11564 { 11734 {
11565 List<ImportElement> imports = []; 11735 List<ImportElement> imports = [];
11566 for (LibraryElement injectedLibrary in _injectedLibraries) { 11736 for (LibraryElement injectedLibrary in _injectedLibraries) {
11567 ImportElementImpl importElement = new ImportElementImpl(-1); 11737 ImportElementImpl importElement = new ImportElementImpl(-1);
11568 importElement.importedLibrary = injectedLibrary; 11738 importElement.importedLibrary = injectedLibrary;
11569 imports.add(importElement); 11739 imports.add(importElement);
11570 } 11740 }
11571 _libraryElement.imports = new List.from(imports); 11741 _libraryElement.imports = new List.from(imports);
11572 } 11742 }
11573 // push conditional errors
11574 for (ProxyConditionalAnalysisError conditionalCode in _resolver.proxyConditi onalAnalysisErrors) {
11575 _resolver.reportError(conditionalCode.analysisError);
11576 }
11577 } 11743 }
11578 11744
11579 void _resolveXmlExpression(AngularXmlExpression angularXmlExpression) { 11745 void _resolveXmlExpression(AngularXmlExpression angularXmlExpression) {
11580 AngularExpression angularExpression = angularXmlExpression.expression; 11746 AngularExpression angularExpression = angularXmlExpression.expression;
11581 _resolveExpression(angularExpression); 11747 _resolveExpression(angularExpression);
11582 } 11748 }
11583 11749
11584 List<Token> _splitAtBar(Token token) { 11750 List<Token> _splitAtBar(Token token) {
11585 List<Token> tokens = []; 11751 List<Token> tokens = [];
11586 tokens.add(token); 11752 tokens.add(token);
(...skipping 2685 matching lines...) Expand 10 before | Expand all | Expand 10 after
14272 // 14438 //
14273 RecordingErrorListener errorListener = new RecordingErrorListener(); 14439 RecordingErrorListener errorListener = new RecordingErrorListener();
14274 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener); 14440 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener);
14275 unit.accept(typeResolverVisitor); 14441 unit.accept(typeResolverVisitor);
14276 // 14442 //
14277 // Resolve the rest of the structure 14443 // Resolve the rest of the structure
14278 // 14444 //
14279 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt); 14445 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt);
14280 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener); 14446 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener);
14281 unit.accept(resolverVisitor); 14447 unit.accept(resolverVisitor);
14282 // TODO (jwren) Move this logic/ loop into the ResolverVisitor and then make the reportError protected again.
14283 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) {
14284 if (conditionalCode.shouldIncludeErrorCode()) {
14285 resolverVisitor.reportError(conditionalCode.analysisError);
14286 }
14287 }
14288 // 14448 //
14289 // Perform additional error checking. 14449 // Perform additional error checking.
14290 // 14450 //
14291 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er rors.start(); 14451 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er rors.start();
14292 try { 14452 try {
14293 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 14453 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
14294 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle ment, typeProvider, inheritanceManager); 14454 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEle ment, typeProvider, inheritanceManager);
14295 unit.accept(errorVerifier); 14455 unit.accept(errorVerifier);
14296 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider); 14456 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, ty peProvider);
14297 unit.accept(constantVerifier); 14457 unit.accept(constantVerifier);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
14597 } 14757 }
14598 14758
14599 @override 14759 @override
14600 void logInformation(String message) { 14760 void logInformation(String message) {
14601 } 14761 }
14602 14762
14603 @override 14763 @override
14604 void logInformation2(String message, Exception exception) { 14764 void logInformation2(String message, Exception exception) {
14605 } 14765 }
14606 } 14766 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698