OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 context = unwrapContext(context); | 206 context = unwrapContext(context); |
207 new MemoryIndexReader(this, context, input).read(); | 207 new MemoryIndexReader(this, context, input).read(); |
208 } | 208 } |
209 | 209 |
210 @Override | 210 @Override |
211 public void recordRelationship(Element element, Relationship relationship, Loc
ation location) { | 211 public void recordRelationship(Element element, Relationship relationship, Loc
ation location) { |
212 if (element == null || location == null) { | 212 if (element == null || location == null) { |
213 return; | 213 return; |
214 } | 214 } |
215 location = location.clone(); | 215 location = location.clone(); |
| 216 // at the index level we don't care about Member(s) |
| 217 if (element instanceof Member) { |
| 218 element = ((Member) element).getBaseElement(); |
| 219 } |
216 // prepare information | 220 // prepare information |
217 AnalysisContext elementContext = element.getContext(); | 221 AnalysisContext elementContext = element.getContext(); |
218 AnalysisContext locationContext = location.getElement().getContext(); | 222 AnalysisContext locationContext = location.getElement().getContext(); |
219 Source elementSource = element.getSource(); | 223 Source elementSource = element.getSource(); |
220 Source locationSource = location.getElement().getSource(); | 224 Source locationSource = location.getElement().getSource(); |
221 // sanity check | 225 // sanity check |
222 if (locationContext == null) { | 226 if (locationContext == null) { |
223 return; | 227 return; |
224 } | 228 } |
| 229 if (locationSource == null) { |
| 230 return; |
| 231 } |
225 if (elementContext == null && !(element instanceof NameElementImpl) | 232 if (elementContext == null && !(element instanceof NameElementImpl) |
226 && !(element instanceof UniverseElementImpl)) { | 233 && !(element instanceof UniverseElementImpl)) { |
227 return; | 234 return; |
228 } | 235 } |
| 236 if (elementSource == null && !(element instanceof NameElementImpl) |
| 237 && !(element instanceof UniverseElementImpl)) { |
| 238 return; |
| 239 } |
229 // may be already removed in other thread | 240 // may be already removed in other thread |
230 if (removedContexts.containsKey(elementContext)) { | 241 if (removedContexts.containsKey(elementContext)) { |
231 return; | 242 return; |
232 } | 243 } |
233 if (removedContexts.containsKey(locationContext)) { | 244 if (removedContexts.containsKey(locationContext)) { |
234 return; | 245 return; |
235 } | 246 } |
236 // at the index level we don't care about Member(s) | |
237 if (element instanceof Member) { | |
238 element = ((Member) element).getBaseElement(); | |
239 } | |
240 // record: key -> location(s) | 247 // record: key -> location(s) |
241 ElementRelationKey key = getCanonicalKey(element, relationship); | 248 ElementRelationKey key = getCanonicalKey(element, relationship); |
242 { | 249 { |
243 Set<Location> locations = keyToLocations.remove(key); | 250 Set<Location> locations = keyToLocations.remove(key); |
244 if (locations == null) { | 251 if (locations == null) { |
245 locations = Sets.newSetFromMap(new IdentityHashMap<Location, Boolean>(4)
); | 252 locations = Sets.newSetFromMap(new IdentityHashMap<Location, Boolean>(4)
); |
246 } else { | 253 } else { |
247 keyCount--; | 254 keyCount--; |
248 } | 255 } |
249 keyToLocations.put(key, locations); | 256 keyToLocations.put(key, locations); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 locations = Lists.newArrayList(); | 288 locations = Lists.newArrayList(); |
282 sourceToLocations.put(locationSource, locations); | 289 sourceToLocations.put(locationSource, locations); |
283 } | 290 } |
284 locations.add(location); | 291 locations.add(location); |
285 } | 292 } |
286 } | 293 } |
287 | 294 |
288 @Override | 295 @Override |
289 public void removeContext(AnalysisContext context) { | 296 public void removeContext(AnalysisContext context) { |
290 context = unwrapContext(context); | 297 context = unwrapContext(context); |
| 298 if (context == null) { |
| 299 return; |
| 300 } |
| 301 // mark as removed |
291 removedContexts.put(context, WEAK_SET_VALUE); | 302 removedContexts.put(context, WEAK_SET_VALUE); |
292 removeSources(context, null); | 303 removeSources(context, null); |
293 // remove context | 304 // remove context |
294 contextToSourceToKeys.remove(context); | 305 contextToSourceToKeys.remove(context); |
295 contextToSourceToLocations.remove(context); | 306 contextToSourceToLocations.remove(context); |
296 } | 307 } |
297 | 308 |
298 @Override | 309 @Override |
299 public void removeSource(AnalysisContext context, Source source) { | 310 public void removeSource(AnalysisContext context, Source source) { |
300 context = unwrapContext(context); | 311 context = unwrapContext(context); |
| 312 if (context == null) { |
| 313 return; |
| 314 } |
301 // remove locations defined in source | 315 // remove locations defined in source |
302 clearSource(context, source); | 316 clearSource(context, source); |
303 // remove keys for elements defined in source | 317 // remove keys for elements defined in source |
304 Map<Source, Set<ElementRelationKey>> sourceToKeys = contextToSourceToKeys.ge
t(context); | 318 Map<Source, Set<ElementRelationKey>> sourceToKeys = contextToSourceToKeys.ge
t(context); |
305 if (sourceToKeys != null) { | 319 if (sourceToKeys != null) { |
306 Set<ElementRelationKey> keys = sourceToKeys.remove(source); | 320 Set<ElementRelationKey> keys = sourceToKeys.remove(source); |
307 if (keys != null) { | 321 if (keys != null) { |
308 for (ElementRelationKey key : keys) { | 322 for (ElementRelationKey key : keys) { |
309 canonicalKeys.remove(key); | 323 canonicalKeys.remove(key); |
310 Set<Location> locations = keyToLocations.remove(key); | 324 Set<Location> locations = keyToLocations.remove(key); |
311 if (locations != null) { | 325 if (locations != null) { |
312 keyCount--; | 326 keyCount--; |
313 locationCount -= locations.size(); | 327 locationCount -= locations.size(); |
314 } | 328 } |
315 } | 329 } |
316 sourceCount--; | 330 sourceCount--; |
317 } | 331 } |
318 } | 332 } |
319 } | 333 } |
320 | 334 |
321 @Override | 335 @Override |
322 public void removeSources(AnalysisContext context, SourceContainer container)
{ | 336 public void removeSources(AnalysisContext context, SourceContainer container)
{ |
323 context = unwrapContext(context); | 337 context = unwrapContext(context); |
| 338 if (context == null) { |
| 339 return; |
| 340 } |
324 // remove sources #1 | 341 // remove sources #1 |
325 Map<Source, Set<ElementRelationKey>> sourceToKeys = contextToSourceToKeys.ge
t(context); | 342 Map<Source, Set<ElementRelationKey>> sourceToKeys = contextToSourceToKeys.ge
t(context); |
326 if (sourceToKeys != null) { | 343 if (sourceToKeys != null) { |
327 List<Source> sources = Lists.newArrayList(sourceToKeys.keySet()); | 344 List<Source> sources = Lists.newArrayList(sourceToKeys.keySet()); |
328 for (Source source : sources) { | 345 for (Source source : sources) { |
329 if (container == null || container.contains(source)) { | 346 if (container == null || container.contains(source)) { |
330 removeSource(context, source); | 347 removeSource(context, source); |
331 } | 348 } |
332 } | 349 } |
333 } | 350 } |
(...skipping 22 matching lines...) Expand all Loading... |
356 private ElementRelationKey getCanonicalKey(Element element, Relationship relat
ionship) { | 373 private ElementRelationKey getCanonicalKey(Element element, Relationship relat
ionship) { |
357 ElementRelationKey key = new ElementRelationKey(element, relationship); | 374 ElementRelationKey key = new ElementRelationKey(element, relationship); |
358 ElementRelationKey canonicalKey = canonicalKeys.get(key); | 375 ElementRelationKey canonicalKey = canonicalKeys.get(key); |
359 if (canonicalKey == null) { | 376 if (canonicalKey == null) { |
360 canonicalKey = key; | 377 canonicalKey = key; |
361 canonicalKeys.put(key, canonicalKey); | 378 canonicalKeys.put(key, canonicalKey); |
362 } | 379 } |
363 return canonicalKey; | 380 return canonicalKey; |
364 } | 381 } |
365 } | 382 } |
OLD | NEW |