use of org.eclipse.xtext.resource.persistence.ResourceStorageWritable in project xtext-core by eclipse.
the class PortableURIsTest method testPortableReferenceDescriptions.
@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);
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable loadable = resourceA.getResourceStorageFacade().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);
}
}
use of org.eclipse.xtext.resource.persistence.ResourceStorageWritable in project xtext-core by eclipse.
the class ResourceStorageFacade method saveResource.
@Override
public void saveResource(final StorageAwareResource resource, final IFileSystemAccessExtension3 fsa) {
final String path = this.computeOutputPath(resource);
final ResourceStorageFacade.MyByteArrayOutputStream bout = new ResourceStorageFacade.MyByteArrayOutputStream();
final ResourceStorageWritable outStream = this.createResourceStorageWritable(bout);
try {
outStream.writeResource(resource);
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException e = (IOException) _t;
URI _uRI = resource.getURI();
String _plus = ("Cannot write storage for " + _uRI);
ResourceStorageFacade.LOG.warn(_plus, e);
return;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
byte[] _byteArray = bout.toByteArray();
int _length = bout.length();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray, 0, _length);
fsa.generateFile(path, _byteArrayInputStream);
}
Aggregations