use of org.eclipse.xtext.resource.IContainer in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method testGetContainer_01.
@Test
public void testGetContainer_01() {
IResourceDescription description = new URIBasedTestResourceDescription(uri1);
IContainer container = containerManager.getContainer(description, this);
assertEquals(2, Iterables.size(container.getResourceDescriptions()));
assertNotNull(container.getResourceDescription(uri1));
assertNotNull(container.getResourceDescription(uri2));
assertNull(container.getResourceDescription(uri3));
}
use of org.eclipse.xtext.resource.IContainer in project xtext-eclipse by eclipse.
the class StateBasedContainerManagerTest method testGetContainer_02.
@Test
public void testGetContainer_02() {
IFile file = getFile(project1, "doesNotExist");
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
IResourceDescription description = new URIBasedTestResourceDescription(uri);
IContainer container = containerManager.getContainer(description, this);
assertEquals(3, Iterables.size(container.getResourceDescriptions()));
assertNotNull(container.getResourceDescription(uri));
assertNotNull(container.getResourceDescription(uri1));
assertNotNull(container.getResourceDescription(uri2));
assertNull(container.getResourceDescription(uri3));
}
use of org.eclipse.xtext.resource.IContainer 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;
}
use of org.eclipse.xtext.resource.IContainer in project dsl-devkit by dsldevkit.
the class FixedDirtyStateEditorSupport method isReparseRequired.
/**
* {@inheritDoc}
*/
@Override
protected boolean isReparseRequired(final XtextResource resource, final Event event) {
// NOPMD (NPath complexity)
IResourceDescription.Manager resourceDescriptionManager = resource.getResourceServiceProvider().getResourceDescriptionManager();
final IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
// The DefaultResourceDescriptionManager honors container visibility only for platform and archive URIs... oh well; let's do it explicitly here.
final IContainer.Manager containerManager = resource.getResourceServiceProvider().getContainerManager();
// Unfortunately, we need a Collection in the call to isAffected() below...
List<Delta> visibleChanges = Lists.newArrayList(Iterables.filter(event.getDeltas(), new Predicate<Delta>() {
private List<IContainer> containers;
private Iterable<IContainer> getContainers() {
// Getting the containers is a relatively expensive operation. We delay doing this until we really need it.
if (containers == null) {
containers = containerManager.getVisibleContainers(description, resourceDescriptions);
}
return containers;
}
@Override
public boolean apply(final Delta delta) {
if (delta.haveEObjectDescriptionsChanged()) {
if (delta.getNew() == null) {
// If it was deleted, we don't know whether it was visible. Hmphhh.
return true;
}
if (delta.getUri().isFile()) {
// Apparently these are java-resources, which are always visible?! (c.f. Xtext bug 383919.)
return true;
}
for (IContainer container : getContainers()) {
if (container.hasResourceDescription(delta.getUri())) {
return true;
}
}
}
return false;
}
}));
// Fix Xtext bug 383919: delegate the whole checking to the description manager, which may have optimized processing in place anyway.
if (resourceDescriptionManager.isAffected(visibleChanges, description, resourceDescriptions)) {
return true;
}
if (!isDirty() && !getDirtyStateManager().hasContent(resource.getURI())) {
IResourceDescription originalDescription = resourceDescriptions.getResourceDescription(resource.getURI());
if (originalDescription != null && descriptionUtils != null) {
Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(originalDescription);
for (Delta delta : visibleChanges) {
if (outgoingReferences.contains(delta.getUri())) {
return true;
}
}
}
}
return false;
}
use of org.eclipse.xtext.resource.IContainer in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method getVisibleContainers.
/**
* Return the visible containers given a context object.
*
* @param context
* The context object
* @param originalResource
* the original resource
* @return The list of visible containers.
*/
protected List<IContainer> getVisibleContainers(final EObject context, final Resource originalResource) {
// NOPMD by WTH on 26.01.11 09:26 (NPath
// complexity...)
final Resource ctxRsc = originalResource == null ? context.eResource() : originalResource;
if (!(ctxRsc instanceof XtextResource)) {
// $NON-NLS-1$ //$NON-NLS-2$
LOGGER.error(MessageFormat.format("Context {0} is not in an Xtext resource: {1}", context, ctxRsc != null ? ctxRsc.getURI() : "null"));
throw new IllegalStateException();
}
final XtextResource rsc = (XtextResource) ctxRsc;
// Cache these container lists, they're expensive to create
// $NON-NLS-1$
final String key = "CONTAINERCACHE&" + rsc.getURI().toString();
List<IContainer> result = null;
// $NON-NLS-1$
final ResourceCache<String, List<IContainer>> cache = CacheManager.getInstance().getOrCreateResourceCache("AbstractPolymorphicScopeProvider#cache", rsc);
if (cache != null) {
result = cache.get(key);
if (result != null) {
return result;
}
}
final EObject ctx = ctxRsc != context.eResource() ? ctxRsc.getContents().get(0) : context;
// We need to get the container manager dynamically, otherwise we may end up using the wrong ResourceDescriptions if
// the context object in actually from another resource.
final IResourceServiceProvider resourceServiceProvider = rsc.getResourceServiceProvider();
final IResourceDescription.Manager descriptionManager = resourceServiceProvider.getResourceDescriptionManager();
final IContainer.Manager containerManager = resourceServiceProvider.getContainerManager();
final IResourceDescription description = descriptionManager.getResourceDescription(ctx.eResource());
final IResourceDescriptions resourceDescriptions = getResourceDescriptions(ctx.eResource());
result = containerManager.getVisibleContainers(description, resourceDescriptions);
if (cache != null) {
cache.set(key, result);
}
return result;
}
Aggregations