Java Code Examples for org.eclipse.xtext.resource.IResourceDescription.Manager#getResourceDescription()
The following examples show how to use
org.eclipse.xtext.resource.IResourceDescription.Manager#getResourceDescription() .
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: ResourceSetBasedResourceDescriptions.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public IResourceDescription getResourceDescription(URI uri) { if (data != null) { return data.getResourceDescription(uri); } Resource resource = resourceSet.getResource(uri, false); if (resource == null) return null; IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri); if (resourceServiceProvider == null) return null; Manager manager = resourceServiceProvider.getResourceDescriptionManager(); if (manager == null) return null; return manager.getResourceDescription(resource); }
Example 2
Source File: LoadOnDemandResourceDescriptions.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public IResourceDescription getResourceDescription(URI uri) { IResourceDescription result = delegate.getResourceDescription(uri); if (result == null) { Resource resource = EcoreUtil2.getResource(context, uri.toString()); if (resource != null) { IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri); if (serviceProvider==null) throw new IllegalStateException("No "+IResourceServiceProvider.class.getSimpleName()+" found in registry for uri "+uri); final Manager resourceDescriptionManager = serviceProvider.getResourceDescriptionManager(); if (resourceDescriptionManager == null) throw new IllegalStateException("No "+IResourceDescription.Manager.class.getName()+" provided by service provider for URI "+uri); result = resourceDescriptionManager.getResourceDescription(resource); } } return result; }
Example 3
Source File: EagerResourceSetBasedResourceDescriptions.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private IResourceDescription computeResourceDescription(URI uri) { Resource resource = resourceSet.getResource(uri, false); if (resource == null) return null; IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri); if (resourceServiceProvider == null) return null; Manager manager = resourceServiceProvider.getResourceDescriptionManager(); if (manager == null) return null; return manager.getResourceDescription(resource); }
Example 4
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testComputeEObjectDescriptionsForEmptyFile() throws Exception { Resource res = getResourceAndExpect(new StringInputStream(""),URI.createURI("foo.xtext"),1); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).isEmpty()); }
Example 5
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testComputeEObjectDescriptionsForUnnamedGrammar() throws Exception { Resource res = getResourceAndExpect(new StringInputStream("grammar "),URI.createURI("foo.xtext"),1); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).isEmpty()); }
Example 6
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetExportedEObjectsErroneousResource() throws Exception { Resource res = getResourceAndExpect(new StringInputStream("grammar foo Start : 'main';"),URI.createURI("foo.xtext"),1); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).size()==2); }
Example 7
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetExportedEObjects() throws Exception { Resource res = getResource(new StringInputStream("grammar foo generate x \"someURI\" Start : 'main';"),URI.createURI("foo.xtext")); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); Iterable<IEObjectDescription> iterable = description.getExportedObjects(); assertTrue(Lists.newArrayList(iterable).size()==3); }
Example 8
Source File: XtextResourceDescriptionTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug350695() throws Exception { Resource res = getResource(new StringInputStream("grammar org.foo.Zonk generate x \"someURI\" Start : 'main';"), URI.createURI("foo.xtext")); Manager manager = get(IResourceDescription.Manager.class); IResourceDescription description = manager.getResourceDescription(res); assertTrue(Iterables.isEmpty(description.getExportedObjects(XtextPackage.Literals.GRAMMAR, QualifiedName.create("org.foo.Zonk"), false))); IEObjectDescription element = Iterables.getOnlyElement( description.getExportedObjects(XtextPackage.Literals.GRAMMAR, QualifiedName.create("org","foo","Zonk"), false)); assertNotNull(element); }
Example 9
Source File: ProfilingTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testSimple() throws Exception { with(new IndexTestLanguageStandaloneSetup(){ @Override public Injector createInjector() { return Guice.createInjector(new org.eclipse.xtext.index.IndexTestLanguageRuntimeModule(){ @Override public java.lang.Class<? extends org.eclipse.xtext.scoping.IScopeProvider> bindIScopeProvider() { return OptimizedScopeProvider.class; } } ); } }); XtextResourceSet rs = get(XtextResourceSet.class); Resource outer = rs.createResource(URI.createURI("outer."+getCurrentFileExtension())); outer.load(new StringInputStream(outerFile(ELEMENTS)), null); Resource inner = rs.createResource(URI.createURI("inner."+getCurrentFileExtension())); StopWatch watch = new StopWatch(); inner.load(new StringInputStream(generateFile(ELEMENTS)), null); // resource.load(new StringInputStream(generateFile(1000)), null); watch.resetAndLog("loading"); EcoreUtil.resolveAll(inner); watch.resetAndLog("linking"); assertTrue(inner.getErrors().size()+" errors ", inner.getErrors().isEmpty()); Manager manager = get(IResourceDescription.Manager.class); // Yourkit.startTracing(); IResourceDescription iResourceDescription = manager.getResourceDescription(inner); Sets.newHashSet(iResourceDescription.getReferenceDescriptions()); // Yourkit.stopCpuProfiling(); watch.resetAndLog("resourcedescriptions"); // System.out.println(Sets.newHashSet(inner.getAllContents()).size()); }
Example 10
Source File: DirtyStateEditorSupport.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.7 */ public void announceDirtyState(XtextResource resource) { if (resource == null || !dirtyResource.isInitialized()) return; ClientAwareDirtyResource clientAwareResource = delegatingClientAwareResource; if (state != State.CLEAN || ((!resource.isTrackingModification() || resource.isModified()) && clientAwareResource.isDirty() && dirtyStateManager.manageDirtyState(clientAwareResource))) { synchronized (dirtyStateManager) { Manager resourceDescriptionManager = getResourceDescriptionManagerIfOwnLanguage(resource); if (resourceDescriptionManager != null) { final IResourceDescription newDescription = resourceDescriptionManager.getResourceDescription(resource); if (state == State.SHOULD_UPDATE || haveEObjectDescriptionsChanged(newDescription, resourceDescriptionManager)) { if(state == State.SHOULD_UPDATE) { if(clientAwareResource.isDirty()) state = State.DIRTY; else state = State.CLEAN; } IResourceDescription oldDescription = dirtyResource.getDescription(); dirtyResource.copyState(newDescription); if (resoureStorageFacade != null && (resource instanceof StorageAwareResource)) { try { StorageAwareResource storageAwareResource = (StorageAwareResource) resource; class MyByteArrayOutputStream extends ByteArrayOutputStream { @Override public synchronized byte[] toByteArray() { return buf; } public int length() { return count; } } final MyByteArrayOutputStream bout = new MyByteArrayOutputStream(); ResourceStorageWritable resourceOutputStream = resoureStorageFacade.createResourceStorageWritable(bout); resourceOutputStream.writeResource(storageAwareResource); dirtyResource.setResourceStorageLoadableProvider(new Provider<ResourceStorageLoadable>() { @Override public ResourceStorageLoadable get() { return resoureStorageFacade.createResourceStorageLoadable(new ByteArrayInputStream(bout.toByteArray(), 0 , bout.length())); } }); } catch(IOException e) { // something went wrong when writing the resource - stream's content is bogus and not attached to the dirty resource info LOG.warn("Cannot persist storage for " + resource.getURI(), e); } } if (dirtyStateManager instanceof DirtyStateManager) { ((DirtyStateManager)dirtyStateManager).announceDirtyStateChanged(oldDescription, clientAwareResource); } else { dirtyStateManager.announceDirtyStateChanged(clientAwareResource); } } } } } }