Search in sources :

Example 11 with StorageAwareResource

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) Test(org.junit.Test)

Example 12 with StorageAwareResource

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);
        }
    }
}
Also used : JavaIoFileSystemAccess(org.eclipse.xtext.generator.JavaIoFileSystemAccess) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) GeneratorContext(org.eclipse.xtext.generator.GeneratorContext)

Example 13 with StorageAwareResource

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InMemoryURIConverter(org.eclipse.xtend.core.tests.util.InMemoryURIConverter) ResourceStorageFacade(org.eclipse.xtext.resource.persistence.ResourceStorageFacade) IResourceStorageFacade(org.eclipse.xtext.resource.persistence.IResourceStorageFacade) Resource(org.eclipse.emf.ecore.resource.Resource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 14 with StorageAwareResource

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;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ArrayList(java.util.ArrayList) List(java.util.List) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) URI(org.eclipse.emf.common.util.URI)

Example 15 with StorageAwareResource

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

StorageAwareResource (org.eclipse.xtext.resource.persistence.StorageAwareResource)15 Resource (org.eclipse.emf.ecore.resource.Resource)14 Test (org.junit.Test)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 URI (org.eclipse.emf.common.util.URI)6 EObject (org.eclipse.emf.ecore.EObject)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 BatchLinkableResource (org.eclipse.xtext.xbase.resource.BatchLinkableResource)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)4 ResourceStorageLoadable (org.eclipse.xtext.resource.persistence.ResourceStorageLoadable)4 IFile (org.eclipse.core.resources.IFile)3 InMemoryURIConverter (org.eclipse.xtend.core.tests.util.InMemoryURIConverter)3 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 AbsoluteURI (org.eclipse.xtext.generator.trace.AbsoluteURI)3 SourceRelativeURI (org.eclipse.xtext.generator.trace.SourceRelativeURI)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 IResourceStorageFacade (org.eclipse.xtext.resource.persistence.IResourceStorageFacade)3