/** * 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); } }
protected List<IContainer> getVisibleContainers(Resource resource) { IResourceDescription description = descriptionManager.getResourceDescription(resource); IResourceDescriptions resourceDescriptions = getResourceDescriptions(resource); String cacheKey = getCacheKey("VisibleContainers", resource.getResourceSet()); OnChangeEvictingCache.CacheAdapter cache = new OnChangeEvictingCache().getOrCreate(resource); List<IContainer> result = null; result = cache.get(cacheKey); if (result == null) { result = containerManager.getVisibleContainers(description, resourceDescriptions); // SZ: I'ld like this dependency to be moved to the implementation of the // container manager, but it is not aware of a CacheAdapter if (resourceDescriptions instanceof IResourceDescription.Event.Source) { IResourceDescription.Event.Source eventSource = (Source) resourceDescriptions; DelegatingEventSource delegatingEventSource = new DelegatingEventSource(eventSource); delegatingEventSource.addListeners(Lists.newArrayList(Iterables.filter(result, IResourceDescription.Event.Listener.class))); delegatingEventSource.initialize(); cache.addCacheListener(delegatingEventSource); } cache.set(cacheKey, result); } return result; }
/** {@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); } }
/** * In the case of synthetic resources, pass the URI they depend on * * @throws IOException */ public void loadSynthetic(final InputStream is, final IExecutionContext additionalLinkingContext) throws IOException { final OnChangeEvictingCache r = getCache(); r.getOrCreate(this).set("linking", additionalLinkingContext); getCache().execWithoutCacheClear(this, new IUnitOfWork.Void<GamlResource>() { @Override public void process(final GamlResource state) throws Exception { state.load(is, null); EcoreUtil.resolveAll(GamlResource.this); } }); r.getOrCreate(this).set("linking", null); }
@Override public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception { XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); rs.setClasspathURIContext(this.getClass()); Resource _createResource = this.getResourceFactory().createResource(uri); final XtextResource resource = ((XtextResource) _createResource); rs.getResources().add(resource); XtextLinker linker = new XtextLinker() { @Override protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) { Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer); ErrorAcceptor _errorAcceptor = result.getErrorAcceptor(); Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock); result.setErrorAcceptor(_myErrorAcceptor); return result; } }; ILinker _linker = resource.getLinker(); linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider()); ILinker _linker_1 = resource.getLinker(); linker.setLinkingService(((Linker) _linker_1).getLinkingService()); ILinker _linker_2 = resource.getLinker(); linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper()); XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover(); linker.setPackageRemover(_packageRemover); LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider(); linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider); OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache(); linker.setCache(_onChangeEvictingCache); resource.setLinker(linker); resource.load(in, null); return resource; }
/** * 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); } }
@Override public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception { XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class); rs.setClasspathURIContext(this.getClass()); Resource _createResource = this.getResourceFactory().createResource(uri); final XtextResource resource = ((XtextResource) _createResource); rs.getResources().add(resource); XtextLinker linker = new XtextLinker() { @Override protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) { Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer); ErrorAcceptor _errorAcceptor = result.getErrorAcceptor(); Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock); result.setErrorAcceptor(_myErrorAcceptor); return result; } }; ILinker _linker = resource.getLinker(); linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider()); ILinker _linker_1 = resource.getLinker(); linker.setLinkingService(((Linker) _linker_1).getLinkingService()); ILinker _linker_2 = resource.getLinker(); linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper()); XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover(); linker.setPackageRemover(_packageRemover); LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider(); linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider); OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache(); linker.setCache(_onChangeEvictingCache); resource.setLinker(linker); resource.load(in, null); return resource; }
/** * 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(); }
ResourceCache(final Resource resource, final boolean addAsListener) { this.resource = resource; backend = new OnChangeEvictingCache().getOrCreate(resource); if (addAsListener) { backend.addCacheListener(this); } }
/** * Binds to special N4JS version of xtext's {@link OnChangeEvictingCache}. */ public Class<? extends OnChangeEvictingCache> bindCache() { return N4JSCache.class; }
public void setCache(OnChangeEvictingCache cache) { this.cache = cache; }
public OnChangeEvictingCache getCache() { return cache; }
/** * @since 2.4 */ protected OnChangeEvictingCache getCache() { return cache; }
@Override public OnChangeEvictingCache getCache() { return (OnChangeEvictingCache) super.getCache(); }