use of org.eclipse.xtext.util.OnChangeEvictingCache 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.OnChangeEvictingCache 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.OnChangeEvictingCache 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.OnChangeEvictingCache 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();
}
use of org.eclipse.xtext.util.OnChangeEvictingCache in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method doGetResource.
@Override
public XtextResource doGetResource(InputStream in, URI uri) throws Exception {
XtextResourceSet rs = get(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());
XtextResource resource = (XtextResource) getResourceFactory().createResource(uri);
rs.getResources().add(resource);
XtextLinker linker = new XtextLinker() {
@Override
protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) {
Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer);
result.setErrorAcceptor(new MyErrorAcceptor(result.getErrorAcceptor(), errorAcceptorMock));
return result;
}
};
linker.setScopeProvider(((XtextLinker) resource.getLinker()).getScopeProvider());
linker.setLinkingService(((Linker) resource.getLinker()).getLinkingService());
linker.setLinkingHelper(((Linker) resource.getLinker()).getLinkingHelper());
linker.setPackageRemover(new XtextLinker.PackageRemover());
linker.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
linker.setCache(new OnChangeEvictingCache());
resource.setLinker(linker);
resource.load(in, null);
return resource;
}
Aggregations