use of org.eclipse.emf.ecore.resource.Resource 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.emf.ecore.resource.Resource 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.emf.ecore.resource.Resource in project xtext-core by eclipse.
the class FileAwareTestLanguageResourceRelocationStrategy method applyChange.
@Override
public void applyChange(final ResourceRelocationContext context) {
final Function1<ResourceRelocationChange, Boolean> _function = (ResourceRelocationChange it) -> {
return Boolean.valueOf(this.canHandle(it));
};
final Consumer<ResourceRelocationChange> _function_1 = (ResourceRelocationChange change) -> {
final IChangeSerializer.IModification<Resource> _function_2 = (Resource resource) -> {
final EObject rootElement = IterableExtensions.<EObject>head(resource.getContents());
if ((rootElement instanceof PackageDeclaration)) {
final String newPackage = IterableExtensions.join(IterableExtensions.<String>drop(change.getToURI().trimSegments(1).segmentsList(), 2), ".");
((PackageDeclaration) rootElement).setName(newPackage);
}
};
context.addModification(change, _function_2);
};
IterableExtensions.<ResourceRelocationChange>filter(context.getChanges(), _function).forEach(_function_1);
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.
the class ResourceRelocationContext method loadAndWatchResource.
/**
* Loads and watches the respective resource and applies the relocation change.
* Clients may usually rather call {@link #addModification} to register their
* side-effects.
*
* @param change the change to execute
*/
protected Resource loadAndWatchResource(final ResourceRelocationChange change) {
try {
Resource _switchResult = null;
final ResourceRelocationContext.ChangeType changeType = this.changeType;
if (changeType != null) {
switch(changeType) {
case MOVE:
case RENAME:
Resource _xblockexpression = null;
{
final Resource original = this.resourceSet.getResource(change.getFromURI(), true);
final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
original.setURI(change.getToURI());
};
this.changeSerializer.<Resource>addModification(original, _function);
_xblockexpression = original;
}
_switchResult = _xblockexpression;
break;
case COPY:
Resource _xblockexpression_1 = null;
{
final Resource copy = this.resourceSet.createResource(change.getFromURI());
copy.load(this.resourceSet.getURIConverter().createInputStream(change.getFromURI()), null);
copy.setURI(change.getToURI());
_xblockexpression_1 = copy;
}
_switchResult = _xblockexpression_1;
break;
default:
break;
}
}
final Resource resource = _switchResult;
return resource;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.
the class DocumentExtensions method newLocation.
public Location newLocation(final EObject owner, final EStructuralFeature feature, final int indexInList) {
final Resource resource = owner.eResource();
final ITextRegion textRegion = this.locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList);
return this.newLocation(resource, textRegion);
}
Aggregations