Search in sources :

Example 1 with OnChangeEvictingCache

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);
    }
}
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 OnChangeEvictingCache

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);
    }
}
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 OnChangeEvictingCache

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

Example 4 with OnChangeEvictingCache

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();
}
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)

Example 5 with OnChangeEvictingCache

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;
}
Also used : XtextLinker(org.eclipse.xtext.xtext.XtextLinker) IDiagnosticConsumer(org.eclipse.xtext.diagnostics.IDiagnosticConsumer) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar)

Aggregations

OnChangeEvictingCache (org.eclipse.xtext.util.OnChangeEvictingCache)7 IResourceScopeCache (org.eclipse.xtext.util.IResourceScopeCache)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 Grammar (org.eclipse.xtext.Grammar)1 Keyword (org.eclipse.xtext.Keyword)1 IDiagnosticConsumer (org.eclipse.xtext.diagnostics.IDiagnosticConsumer)1 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ParseResult (org.eclipse.xtext.parser.ParseResult)1 IContainer (org.eclipse.xtext.resource.IContainer)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 Source (org.eclipse.xtext.resource.IResourceDescription.Event.Source)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1