com.google.common.collect.ForwardingMap Java Examples
The following examples show how to use
com.google.common.collect.ForwardingMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N4JSResourceDescriptionStrategy.java From n4js with Eclipse Public License 1.0 | 6 votes |
private Map<String, String> createModuleUserData(final TModule module) { // TODO GH-230 consider disallowing serializing reconciled modules to index with fail-safe behavior: // if (module.isPreLinkingPhase() || module.isReconciled()) { if (module.isPreLinkingPhase()) { return UserDataMapper.createTimestampUserData(module); } return new ForwardingMap<>() { private Map<String, String> delegate; @Override protected Map<String, String> delegate() { if (delegate == null) { try { delegate = UserDataMapper.createUserData(module); N4JSResource resource = (N4JSResource) module.eResource(); UserDataMapper.writeDependenciesToUserData(resource, delegate); } catch (Exception e) { throw new IllegalStateException(e); } } return delegate; } }; }
Example #2
Source File: JvmTypesResourceDescriptionStrategy.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected Map<String, String> createLazyUserData(final EObject eObject) { return new ForwardingMap<String, String>() { private Map<String,String> delegate; @Override protected Map<String, String> delegate() { if(delegate == null) { Builder<String, String> userData = ImmutableMap.builder(); createUserData(eObject, userData); delegate = userData.build(); } return delegate; } }; }
Example #3
Source File: DefaultReferenceFinder.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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; } }; }
Example #4
Source File: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
private 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; } // create a copy of the known associated roots to avoid concurrent modification // and conflicts with other readers Map<String, IPackageFragmentRoot> copy = newLinkedHashMap(data.associatedRoots); Iterator<IPackageFragmentRoot> i = copy.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 (copy.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 data.associatedRoots = copy; final IPackageFragmentRoot rootToProcess = someRoot; data.uri2Storage = new ForwardingMap<URI, IStorage>() { Map<URI, IStorage> delegate; @Override protected Map<URI, IStorage> delegate() { if (delegate == null) { PackageFragmentRootData newlyCollected = initializeData(rootToProcess); return delegate = newlyCollected.uri2Storage; } return delegate; } }; } } if(!toBeRemoved.isEmpty()) { synchronized (cachedPackageFragmentRootData) { cachedPackageFragmentRootData.values().removeAll(toBeRemoved); } } }