org.eclipse.xtext.resource.persistence.ResourceStorageWritable Java Examples
The following examples show how to use
org.eclipse.xtext.resource.persistence.ResourceStorageWritable.
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: PortableURIsTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testPortableReferenceDescriptions() { try { final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class); Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage")); final StorageAwareResource resourceA = ((StorageAwareResource) _createResource); Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage")); final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1); StringConcatenation _builder = new StringConcatenation(); _builder.append("type B"); _builder.newLine(); resourceB.load(this.getAsStream(_builder.toString()), null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'"); _builder_1.newLine(); _builder_1.newLine(); _builder_1.append("type A extends B"); _builder_1.newLine(); resourceA.load(this.getAsStream(_builder_1.toString()), null); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final ResourceStorageWritable writable = resourceA.getResourceStorageFacade().createResourceStorageWritable(bout); writable.writeResource(resourceA); IResourceStorageFacade _resourceStorageFacade = resourceA.getResourceStorageFacade(); byte[] _byteArray = bout.toByteArray(); ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray); final ResourceStorageLoadable loadable = _resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream); Resource _createResource_2 = resourceSet.createResource(URI.createURI("hubba:/bubba3.langatestlanguage")); final StorageAwareResource resourceC = ((StorageAwareResource) _createResource_2); resourceC.loadFromStorage(loadable); final IReferenceDescription refDesc = IterableExtensions.<IReferenceDescription>head(resourceC.getResourceDescription().getReferenceDescriptions()); EObject _head = IterableExtensions.<EObject>head(resourceB.getContents()); Assert.assertSame(IterableExtensions.<Type>head(((Main) _head).getTypes()), resourceSet.getEObject(refDesc.getTargetEObjectUri(), false)); EObject _head_1 = IterableExtensions.<EObject>head(resourceC.getContents()); Assert.assertSame(IterableExtensions.<Type>head(((Main) _head_1).getTypes()), resourceSet.getEObject(refDesc.getSourceEObjectUri(), false)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: BatchLinkableResourceStorageFacade.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public ResourceStorageWritable createResourceStorageWritable(OutputStream out) { return new BatchLinkableResourceStorageWritable(out, isStoreNodeModel()); }
Example #3
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); } } } } } }
Example #4
Source File: DirectLinkingResourceStorageFacade.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
@Override public ResourceStorageWritable createResourceStorageWritable(final OutputStream out) { return new DirectLinkingResourceStorageWritable(out, isStoreNodeModel()); }