use of org.eclipse.xtext.util.IResourceScopeCache in project n4js by eclipse.
the class N4JSResource method updateInternalState.
/**
* Overridden to make sure that we add the root AST element sneakily to the resource list to make sure that no
* accidental proxy resolution happens and that we do not increment the modification counter of the contents list.
*/
@Override
protected void updateInternalState(IParseResult newParseResult) {
setParseResult(newParseResult);
EObject newRootAstElement = newParseResult.getRootASTElement();
if (newRootAstElement != null && !getContents().contains(newRootAstElement)) {
// do not increment the modification counter here
sneakyAddToContent(newRootAstElement);
}
reattachModificationTracker(newRootAstElement);
clearErrorsAndWarnings();
addSyntaxErrors();
doLinking();
// make sure that the cache adapter is installed on this resource
IResourceScopeCache cache = getCache();
if (cache instanceof OnChangeEvictingCache) {
((OnChangeEvictingCache) cache).getOrCreate(this);
}
}
use of org.eclipse.xtext.util.IResourceScopeCache in project dsl-devkit by dsldevkit.
the class NodeModelHandler method insertProxyModel.
/**
* {@inheritDoc}
*/
@Override
public void insertProxyModel() {
// Node model can be accessed by:
// 1. checking the adapters of an EObject
ICompositeNode rootNode = null;
TreeIterator<EObject> iterator = EcoreUtil.getAllProperContents(resource, false);
while (iterator.hasNext()) {
EObject eObject = iterator.next();
LazyLoadingCompositeNode node = new LazyLoadingCompositeNode();
eObject.eAdapters().add(node);
if (rootNode == null) {
rootNode = node;
}
}
// 2. fetching the ParseResult instance of the Resource
EObject emfRootObject = resource.getContents().isEmpty() ? null : resource.getContents().get(0);
resource.setParseResult(new ParseResult(emfRootObject, rootNode, false));
// Add cache now, otherwise it will trigger model inference later.
IResourceScopeCache cache = resource.getCache();
if (cache instanceof OnChangeEvictingCache) {
((OnChangeEvictingCache) cache).getOrCreate(resource);
}
}
use of org.eclipse.xtext.util.IResourceScopeCache in project xtext-core by eclipse.
the class DerivedStateAwareResource method updateInternalState.
/**
* Overridden to make sure that the cache is initialized during {@link #isLoading() loading}.
*/
@Override
protected void updateInternalState(IParseResult newParseResult) {
super.updateInternalState(newParseResult);
// make sure that the cache adapter is installed on this resource
IResourceScopeCache cache = getCache();
if (cache instanceof OnChangeEvictingCache) {
((OnChangeEvictingCache) cache).getOrCreate(this);
}
}
use of org.eclipse.xtext.util.IResourceScopeCache in project dsl-devkit by dsldevkit.
the class BugAig1084 method recursiveLookUp.
/**
* Test that recursive calls to {@link ResourceDescription2#getLookUp()} by {@link ResourceDescription2#computeExportedObjects()} do not cause
* stack-overflow.
*/
@Test
public void recursiveLookUp() {
Resource resource = org.mockito.Mockito.mock(Resource.class);
BasicEList<Adapter> emptyEList = new BasicEList<Adapter>();
org.mockito.Mockito.when(resource.eAdapters()).thenReturn(emptyEList);
IResourceScopeCache cache = new OnChangeEvictingCache();
new ResourceDescription2(resource, null, cache) {
@Override
protected List<IEObjectDescription> computeExportedObjects() {
return Lists.newArrayList(getLookUp().getExportedObjects());
}
}.getExportedObjects();
}
Aggregations