org.eclipse.xtext.util.OnChangeEvictingCache Java Examples

The following examples show how to use org.eclipse.xtext.util.OnChangeEvictingCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N4JSResource.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example #2
Source File: DefaultGlobalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: GamlResource.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);

}
 
Example #4
Source File: Xtext2EcoreTransformerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public XtextResource doGetResource(InputStream in, URI uri) throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	Map<URI, URI> uriMap = rs.getURIConverter().getURIMap();
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false),
			URI.createURI("classpath:/"));
	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 Xtext2EcoreTransformerTest.MyErrorAcceptor(result.getErrorAcceptor(),
					Xtext2EcoreTransformerTest.this.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;
}
 
Example #5
Source File: DerivedStateAwareResource.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #6
Source File: KeywordInspectorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void validateRule(AbstractRule rule) {
	assertNotNull("rule", rule);
	warnings.clear();
	KeywordInspector inspector = new KeywordInspector(this, new OnChangeEvictingCache());
	Iterator<Keyword> keywords = Iterators.filter(EcoreUtil.getAllContents(rule, true), Keyword.class);
	while(keywords.hasNext())
		inspector.inspectKeywordHidesTerminalRule(keywords.next());
}
 
Example #7
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #8
Source File: BugAig1084.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #9
Source File: ResourceCache.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
ResourceCache(final Resource resource, final boolean addAsListener) {
  this.resource = resource;
  backend = new OnChangeEvictingCache().getOrCreate(resource);
  if (addAsListener) {
    backend.addCacheListener(this);
  }
}
 
Example #10
Source File: N4JSRuntimeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Binds to special N4JS version of xtext's {@link OnChangeEvictingCache}.
 */
public Class<? extends OnChangeEvictingCache> bindCache() {
	return N4JSCache.class;
}
 
Example #11
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void setCache(OnChangeEvictingCache cache) {
	this.cache = cache;
}
 
Example #12
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public OnChangeEvictingCache getCache() {
	return cache;
}
 
Example #13
Source File: LazyLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.4
 */
protected OnChangeEvictingCache getCache() {
	return cache;
}
 
Example #14
Source File: GamlResource.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public OnChangeEvictingCache getCache() {
	return (OnChangeEvictingCache) super.getCache();
}