use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-xtend by eclipse.
the class ResourceStorageTest method testShouldLoadFromStorage.
@Test
public void testShouldLoadFromStorage() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package mypack");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("public def void foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IFile file = this.helper.createFile("mypack/MyClass.xtend", _builder.toString());
IResourcesSetupUtil.waitForBuild();
final URI uri = this.uriMapper.getUri(file);
final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject());
SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
Resource _createResource = resourceSet.createResource(uri);
final StorageAwareResource resource = ((StorageAwareResource) _createResource);
final Procedure0 _function = () -> {
Assert.assertTrue(resource.getResourceStorageFacade().shouldLoadFromStorage(resource));
};
this.doWorkInJob(_function);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
file.delete(true, _nullProgressMonitor);
IResourcesSetupUtil.waitForBuild();
final Procedure0 _function_1 = () -> {
Assert.assertFalse(resource.getResourceStorageFacade().shouldLoadFromStorage(resource));
};
this.doWorkInJob(_function_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-xtend by eclipse.
the class XtendBatchCompiler method generateJavaFiles.
protected void generateJavaFiles(ResourceSet resourceSet) {
JavaIoFileSystemAccess javaIoFileSystemAccess = javaIoFileSystemAccessProvider.get();
javaIoFileSystemAccess.setOutputPath(outputPath);
javaIoFileSystemAccess.setWriteTrace(writeTraceFiles);
GeneratorContext context = new GeneratorContext();
context.setCancelIndicator(CancelIndicator.NullImpl);
for (Resource resource : newArrayList(resourceSet.getResources())) {
if (isSourceFile(resource)) {
if (isWriteStorageFiles()) {
StorageAwareResource storageAwareResource = (StorageAwareResource) resource;
storageAwareResource.getResourceStorageFacade().saveResource(storageAwareResource, javaIoFileSystemAccess);
}
generator.generate(resource, javaIoFileSystemAccess, context);
}
}
}
use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-xtend by eclipse.
the class ResourceStorageTest method testConstantValueIsPersisted.
@Test
public void testConstantValueIsPersisted() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val CONSTANT = \'a\' + \'b\' + 0");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String contents = _builder.toString();
final XtendFile file = this.file(contents);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
Resource _eResource = file.eResource();
this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
final StorageAwareResource resource = ((StorageAwareResource) _createResource);
final InMemoryURIConverter converter = new InMemoryURIConverter();
converter.addModel(resource.getURI().toString(), contents);
ResourceSet _resourceSet = resource.getResourceSet();
_resourceSet.setURIConverter(converter);
EList<Resource> _resources = file.eResource().getResourceSet().getResources();
_resources.add(resource);
resource.loadFromStorage(in);
EObject _get = resource.getContents().get(1);
final JvmGenericType jvmClass = ((JvmGenericType) _get);
JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
final JvmField field = ((JvmField) _last);
Assert.assertTrue(field.isConstant());
Assert.assertTrue(field.isSetConstant());
Assert.assertEquals("ab0", field.getConstantValue());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-core by eclipse.
the class ClusteringStorageAwareResourceLoader method executeClustered.
public <T extends Object> Iterable<T> executeClustered(final Iterable<URI> uris, final Function1<? super Resource, ? extends T> operation) {
ArrayList<T> _xblockexpression = null;
{
final ArrayList<URI> loadedURIs = CollectionLiterals.<URI>newArrayList();
final ArrayList<URI> sourceLevelURIs = CollectionLiterals.<URI>newArrayList();
final ArrayList<Resource> resources = CollectionLiterals.<Resource>newArrayList();
final ArrayList<T> result = CollectionLiterals.<T>newArrayList();
final Iterator<URI> iter = uris.iterator();
while (iter.hasNext()) {
{
final URI uri = iter.next();
boolean _continueProcessing = this.context.getClusteringPolicy().continueProcessing(this.context.getResourceSet(), uri, loadedURIs.size());
boolean _not = (!_continueProcessing);
if (_not) {
final Function1<Resource, T> _function = (Resource it) -> {
return operation.apply(it);
};
List<T> _map = ListExtensions.<Resource, T>map(resources, _function);
Iterables.<T>addAll(result, _map);
resources.clear();
this.clearResourceSet();
loadedURIs.clear();
}
loadedURIs.add(uri);
boolean _isSource = this.isSource(uri);
if (_isSource) {
sourceLevelURIs.add(uri);
final Resource existingResource = this.context.getResourceSet().getResource(uri, false);
if ((existingResource instanceof StorageAwareResource)) {
boolean _isLoadedFromStorage = ((StorageAwareResource) existingResource).isLoadedFromStorage();
if (_isLoadedFromStorage) {
((StorageAwareResource) existingResource).unload();
}
}
SourceLevelURIsAdapter.setSourceLevelUris(this.context.getResourceSet(), sourceLevelURIs);
}
Resource _resource = this.context.getResourceSet().getResource(uri, true);
resources.add(_resource);
}
}
final Function1<Resource, T> _function = (Resource it) -> {
return operation.apply(it);
};
List<T> _map = ListExtensions.<Resource, T>map(resources, _function);
Iterables.<T>addAll(result, _map);
_xblockexpression = result;
}
return _xblockexpression;
}
use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-core by eclipse.
the class PortableURIs method toPortableURI.
/**
* Creates and returns a portable URI from the given resource to the targetURI.
* Returns <code>null</code> is no portable URI can be constructed, which is the case if the
* targetObject is not itself exported or is a child of an exported EObject.
*
* @param sourceResource the resource from which the EObject should later be resolved
* @param targetURI the target URI that should be resolvable by the created portable URI
*
* @return a portable URI or <code>null</code>
*/
public URI toPortableURI(final StorageAwareResource sourceResource, final URI targetURI) {
Resource _resource = sourceResource.getResourceSet().getResource(targetURI.trimFragment(), false);
EObject _eObject = null;
if (_resource != null) {
_eObject = _resource.getEObject(targetURI.fragment());
}
final EObject to = _eObject;
boolean _or = false;
if ((to == null)) {
_or = true;
} else {
Resource _eResource = to.eResource();
ResourceSet _resourceSet = null;
if (_eResource != null) {
_resourceSet = _eResource.getResourceSet();
}
boolean _tripleNotEquals = (_resourceSet != null);
_or = _tripleNotEquals;
}
if (_or) {
final URI result = this.toPortableURI(sourceResource, to);
if ((result != null)) {
return result;
}
}
return null;
}
Aggregations