use of com.google.common.collect.ForwardingMap in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImpl method clearCache.
protected void clearCache(IJavaProject project, Set<PackageFragmentRootData> toBeKept) {
Collection<PackageFragmentRootData> values;
synchronized (cachedPackageFragmentRootData) {
values = newArrayList(cachedPackageFragmentRootData.values());
}
List<PackageFragmentRootData> toBeRemoved = newArrayList();
for (PackageFragmentRootData data : values) {
if (toBeKept.contains(data)) {
continue;
}
Map<String, IPackageFragmentRoot> associatedRoots = data.associatedRoots;
synchronized (associatedRoots) {
Iterator<IPackageFragmentRoot> i = associatedRoots.values().iterator();
IPackageFragmentRoot someRoot = null;
boolean didChange = false;
while (i.hasNext()) {
IPackageFragmentRoot root = i.next();
if (project.equals(root.getJavaProject())) {
i.remove();
didChange = true;
} else if (someRoot == null) {
someRoot = root;
}
}
if (associatedRoots.size() == 0) {
toBeRemoved.add(data);
} else if (didChange) {
// get rid of cached storages that still point to roots / projects that are no longer available
// and recompute them lazily on demand
final IPackageFragmentRoot rootToProcess = someRoot;
data.uri2Storage = new ForwardingMap<URI, IStorage>() {
Map<URI, IStorage> delegate;
@Override
protected Map<URI, IStorage> delegate() {
if (delegate == null) {
return delegate = initializeData(rootToProcess).uri2Storage;
}
return delegate;
}
};
}
}
}
if (!toBeRemoved.isEmpty()) {
synchronized (cachedPackageFragmentRootData) {
cachedPackageFragmentRootData.values().removeAll(toBeRemoved);
}
}
}
use of com.google.common.collect.ForwardingMap in project xtext-eclipse by eclipse.
the class DefaultReferenceFinder method createExportedElementsMap.
@Deprecated
protected Map<EObject, URI> createExportedElementsMap(final Resource resource) {
return new ForwardingMap<EObject, URI>() {
private Map<EObject, URI> delegate;
@Override
protected Map<EObject, URI> delegate() {
if (delegate != null) {
return delegate;
}
URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(resource);
IResourceServiceProvider resourceServiceProvider = getServiceProviderRegistry().getResourceServiceProvider(uri);
if (resourceServiceProvider == null) {
return delegate = Collections.emptyMap();
}
IResourceDescription.Manager resourceDescriptionManager = resourceServiceProvider.getResourceDescriptionManager();
if (resourceDescriptionManager == null) {
return delegate = Collections.emptyMap();
}
IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
Map<EObject, URI> exportedElementMap = newIdentityHashMap();
if (resourceDescription != null) {
for (IEObjectDescription exportedEObjectDescription : resourceDescription.getExportedObjects()) {
EObject eObject = resource.getEObject(exportedEObjectDescription.getEObjectURI().fragment());
if (eObject != null)
exportedElementMap.put(eObject, exportedEObjectDescription.getEObjectURI());
}
}
return delegate = exportedElementMap;
}
};
}
Aggregations