Search in sources :

Example 1 with IResourceScopeCache

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);
    }
}
Also used : OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IResourceScopeCache(org.eclipse.xtext.util.IResourceScopeCache)

Example 2 with IResourceScopeCache

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);
    }
}
Also used : ParseResult(org.eclipse.xtext.parser.ParseResult) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) IResourceScopeCache(org.eclipse.xtext.util.IResourceScopeCache)

Example 3 with IResourceScopeCache

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);
    }
}
Also used : OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) IResourceScopeCache(org.eclipse.xtext.util.IResourceScopeCache)

Example 4 with IResourceScopeCache

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();
}
Also used : OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) IResourceScopeCache(org.eclipse.xtext.util.IResourceScopeCache) Adapter(org.eclipse.emf.common.notify.Adapter) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ResourceDescription2(com.avaloq.tools.ddk.xtext.resource.ResourceDescription2) Test(org.junit.Test)

Aggregations

IResourceScopeCache (org.eclipse.xtext.util.IResourceScopeCache)4 OnChangeEvictingCache (org.eclipse.xtext.util.OnChangeEvictingCache)4 EObject (org.eclipse.emf.ecore.EObject)2 ResourceDescription2 (com.avaloq.tools.ddk.xtext.resource.ResourceDescription2)1 List (java.util.List)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ParseResult (org.eclipse.xtext.parser.ParseResult)1 Test (org.junit.Test)1