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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations