Search in sources :

Example 1 with AbstractFileSystemAccess2

use of org.eclipse.xtext.generator.AbstractFileSystemAccess2 in project xtext-core by eclipse.

the class ResourceStorageFacade method getOrCreateResourceStorageLoadable.

/**
 * Finds or creates a ResourceStorageLoadable for the given resource.
 * Clients should first call shouldLoadFromStorage to check whether there exists a storage version
 * of the given resource.
 *
 * @return an IResourceStorageLoadable
 */
@Override
public ResourceStorageLoadable getOrCreateResourceStorageLoadable(final StorageAwareResource resource) {
    try {
        final ResourceStorageProviderAdapter stateProvider = IterableExtensions.<ResourceStorageProviderAdapter>head(Iterables.<ResourceStorageProviderAdapter>filter(resource.getResourceSet().eAdapters(), ResourceStorageProviderAdapter.class));
        if ((stateProvider != null)) {
            final ResourceStorageLoadable inputStream = stateProvider.getResourceStorageLoadable(resource);
            if ((inputStream != null)) {
                return inputStream;
            }
        }
        InputStream _xifexpression = null;
        boolean _exists = resource.getResourceSet().getURIConverter().exists(this.getBinaryStorageURI(resource.getURI()), CollectionLiterals.<Object, Object>emptyMap());
        if (_exists) {
            _xifexpression = resource.getResourceSet().getURIConverter().createInputStream(this.getBinaryStorageURI(resource.getURI()));
        } else {
            InputStream _xblockexpression = null;
            {
                final AbstractFileSystemAccess2 fsa = this.getFileSystemAccess(resource);
                final String outputRelativePath = this.computeOutputPath(resource);
                _xblockexpression = fsa.readBinaryFile(outputRelativePath);
            }
            _xifexpression = _xblockexpression;
        }
        final InputStream inputStream_1 = _xifexpression;
        return this.createResourceStorageLoadable(inputStream_1);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ResourceStorageProviderAdapter(org.eclipse.xtext.resource.persistence.ResourceStorageProviderAdapter) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractFileSystemAccess2(org.eclipse.xtext.generator.AbstractFileSystemAccess2)

Example 2 with AbstractFileSystemAccess2

use of org.eclipse.xtext.generator.AbstractFileSystemAccess2 in project xtext-core by eclipse.

the class ResourceStorageFacade method doesStorageExist.

/**
 * @return whether a stored resource state exists for the given resource
 */
protected boolean doesStorageExist(final StorageAwareResource resource) {
    final ResourceStorageProviderAdapter stateProvider = IterableExtensions.<ResourceStorageProviderAdapter>head(Iterables.<ResourceStorageProviderAdapter>filter(resource.getResourceSet().eAdapters(), ResourceStorageProviderAdapter.class));
    if (((stateProvider != null) && (stateProvider.getResourceStorageLoadable(resource) != null))) {
        return true;
    }
    boolean _exists = resource.getResourceSet().getURIConverter().exists(this.getBinaryStorageURI(resource.getURI()), CollectionLiterals.<Object, Object>emptyMap());
    if (_exists) {
        return true;
    }
    boolean _isArchive = resource.getURI().isArchive();
    if (_isArchive) {
        return false;
    }
    final AbstractFileSystemAccess2 fsa = this.getFileSystemAccess(resource);
    final String outputRelativePath = this.computeOutputPath(resource);
    final URI uri = fsa.getURI(outputRelativePath);
    return ((uri != null) && resource.getResourceSet().getURIConverter().exists(uri, null));
}
Also used : ResourceStorageProviderAdapter(org.eclipse.xtext.resource.persistence.ResourceStorageProviderAdapter) URI(org.eclipse.emf.common.util.URI) AbstractFileSystemAccess2(org.eclipse.xtext.generator.AbstractFileSystemAccess2)

Example 3 with AbstractFileSystemAccess2

use of org.eclipse.xtext.generator.AbstractFileSystemAccess2 in project xtext-core by eclipse.

the class ResourceStorageFacade method getFileSystemAccess.

protected AbstractFileSystemAccess2 getFileSystemAccess(final StorageAwareResource resource) {
    final AbstractFileSystemAccess2 fsa = this.fileSystemAccessProvider.get();
    fsa.setContext(resource);
    final Function1<OutputConfiguration, String> _function = (OutputConfiguration it) -> {
        return it.getName();
    };
    fsa.setOutputConfigurations(IterableExtensions.<String, OutputConfiguration>toMap(this.outputConfigurationProvider.getOutputConfigurations(resource), _function));
    return fsa;
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) AbstractFileSystemAccess2(org.eclipse.xtext.generator.AbstractFileSystemAccess2)

Aggregations

AbstractFileSystemAccess2 (org.eclipse.xtext.generator.AbstractFileSystemAccess2)3 ResourceStorageProviderAdapter (org.eclipse.xtext.resource.persistence.ResourceStorageProviderAdapter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URI (org.eclipse.emf.common.util.URI)1 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)1 ResourceStorageLoadable (org.eclipse.xtext.resource.persistence.ResourceStorageLoadable)1