Search in sources :

Example 6 with StorageAwareResource

use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-xtend by eclipse.

the class ResourceStorageTest method testUpstreamResourcesAreLoadedFromStorage.

@Test
public void testUpstreamResourcesAreLoadedFromStorage() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class MyClass {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.helper.createFile("mypack/MyClass.xtend", _builder.toString());
        final IProject downStreamProject = WorkbenchTestHelper.createPluginProject("downstream", this.helper.getProject().getName());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package downstream");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class SomeClass {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void foo(mypack.MyClass myClass) {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile downstreamFile = this.helper.createFileImpl("/downstream/src/downstream/SomeClass.xtend", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI downstreamUri = this.uriMapper.getUri(downstreamFile);
        final ResourceSet resourceSet = this.resourceSetProvider.get(downStreamProject);
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(downstreamUri)));
        Resource _resource = resourceSet.getResource(downstreamUri, true);
        final StorageAwareResource downstreamResource = ((StorageAwareResource) _resource);
        EObject _get = downstreamResource.getContents().get(1);
        final JvmGenericType type = ((JvmGenericType) _get);
        final JvmType parameterType = IterableExtensions.<JvmFormalParameter>head(IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(type.getMembers(), JvmOperation.class)).getParameters()).getParameterType().getType();
        Assert.assertNotNull(parameterType);
        Resource _eResource = parameterType.eResource();
        Assert.assertTrue(((StorageAwareResource) _eResource).isLoadedFromStorage());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IProject(org.eclipse.core.resources.IProject) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 7 with StorageAwareResource

use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-xtend by eclipse.

the class ResourceStorageTest method testLoadFromStorage.

@Test
public void testLoadFromStorage() {
    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("src/mypack/MyClass.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypack");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class OtherClass extends MyClass {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("override foo() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile file2 = this.helper.createFile("src/mypack/OtherClass.xtend", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI uri = this.uriMapper.getUri(file);
        final URI uri2 = this.uriMapper.getUri(file2);
        final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject());
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        Resource _resource = resourceSet.getResource(uri2, true);
        final StorageAwareResource resource2 = ((StorageAwareResource) _resource);
        Assert.assertTrue(resource2.isLoadedFromStorage());
        EcoreUtil.resolveAll(resource2);
        final Function1<IEObjectDescription, String> _function = (IEObjectDescription it) -> {
            return it.getName().toString();
        };
        Assert.assertEquals("mypack.OtherClass", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(resource2.getResourceDescription().getExportedObjects(), _function), ","));
        Resource _resource_1 = resourceSet.getResource(uri, false);
        final StorageAwareResource resource = ((StorageAwareResource) _resource_1);
        Assert.assertTrue(resource.isLoadedFromStorage());
        final Function1<IEObjectDescription, String> _function_1 = (IEObjectDescription it) -> {
            return it.getName().toString();
        };
        Assert.assertEquals("mypack.MyClass", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(resource.getResourceDescription().getExportedObjects(), _function_1), ","));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) 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) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 8 with StorageAwareResource

use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-core by eclipse.

the class PortableURIsTest method testPortableUris.

@Test
public void testPortableUris() {
    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 Type extended = IterableExtensions.<Type>head(IterableExtensions.<Main>head(Iterables.<Main>filter(resourceA.getContents(), Main.class)).getTypes()).getExtends();
        final URI uri = EcoreUtil.getURI(extended);
        final URI portableURI = resourceA.getPortableURIs().toPortableURI(resourceA, uri);
        Assert.assertEquals(resourceA.getURI(), portableURI.trimFragment());
        Assert.assertTrue(resourceA.getPortableURIs().isPortableURIFragment(portableURI.fragment()));
        Assert.assertSame(extended, resourceA.getEObject(portableURI.fragment()));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 9 with StorageAwareResource

use of org.eclipse.xtext.resource.persistence.StorageAwareResource 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);
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceStorageWritable(org.eclipse.xtext.resource.persistence.ResourceStorageWritable) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Main(org.eclipse.xtext.linking.langATestLanguage.Main) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 10 with StorageAwareResource

use of org.eclipse.xtext.resource.persistence.StorageAwareResource in project xtext-core by eclipse.

the class StorageAwareResourceDescriptionManager method getResourceDescription.

@Override
public IResourceDescription getResourceDescription(final Resource resource) {
    IResourceDescription _switchResult = null;
    boolean _matched = false;
    if (resource instanceof StorageAwareResource) {
        IResourceDescription _resourceDescription = ((StorageAwareResource) resource).getResourceDescription();
        boolean _tripleNotEquals = (_resourceDescription != null);
        if (_tripleNotEquals) {
            _matched = true;
            _switchResult = ((StorageAwareResource) resource).getResourceDescription();
        }
    }
    if (!_matched) {
        _switchResult = super.getResourceDescription(resource);
    }
    return _switchResult;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource)

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