Search in sources :

Example 1 with IContainerState

use of org.eclipse.xtext.resource.containers.IContainerState in project dsl-devkit by dsldevkit.

the class CachingStateBasedContainerManager method createContainer.

@Override
protected synchronized IContainer createContainer(final String handle, final IResourceDescriptions resourceDescriptions) {
    final IResourceDescriptions descriptionsKey = resourceDescriptions instanceof CurrentDescriptions2.ResourceSetAware ? ((CurrentDescriptions2.ResourceSetAware) resourceDescriptions).getDelegate() : resourceDescriptions;
    Map<String, WeakReference<IContainer>> containersMap = descriptionsContainersCache.get(descriptionsKey);
    if (containersMap == null) {
        containersMap = new HashMap<String, WeakReference<IContainer>>();
        descriptionsContainersCache.put(descriptionsKey, containersMap);
    }
    WeakReference<IContainer> containerRef = containersMap.get(handle);
    IContainer container = containerRef != null ? containerRef.get() : null;
    if (container == null) {
        final IContainerState containerState = new ContainerState(handle, getStateProvider().get(descriptionsKey));
        container = new StateBasedContainerWithHandle(descriptionsKey, containerState, handle);
        new CacheInvalidator(descriptionsKey, handle, containerState);
        containerRef = new WeakReference<IContainer>(container);
        containersMap.put(handle, containerRef);
    }
    return container;
}
Also used : IContainerState(org.eclipse.xtext.resource.containers.IContainerState) IContainerState(org.eclipse.xtext.resource.containers.IContainerState) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) WeakReference(java.lang.ref.WeakReference) IContainer(org.eclipse.xtext.resource.IContainer)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 IContainer (org.eclipse.xtext.resource.IContainer)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 IContainerState (org.eclipse.xtext.resource.containers.IContainerState)1