use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class XtendFileRenameParticipant method createRenameElementContexts.
@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
if (super.getNewName().endsWith(".xtend")) {
IFile file = (IFile) element;
final IPath filePath = file.getFullPath();
final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
String className = trimFileExtension(file.getName());
if (className != null) {
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(resourceURI, true);
if (resource != null && !resource.getContents().isEmpty()) {
for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
if (equal(className, type.getName())) {
IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
if (renameElementContext instanceof IChangeRedirector.Aware)
((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {
@Override
public IPath getRedirectedPath(IPath source) {
return source.equals(filePath) ? newPath : source;
}
});
return singletonList(renameElementContext);
}
}
}
}
}
return super.createRenameElementContexts(element);
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class MavenProjectResourceSetProvider method get.
public ResourceSet get() {
ResourceSet rs = new XtextResourceSet();
MavenProjectAdapter.install(rs, project);
return rs;
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class ActiveAnnotationsProcessingInIDETest method assertProcessing.
@Override
public void assertProcessing(final Pair<String, String> macroContent, final Pair<String, String> clientContent, final Procedure1<? super CompilationUnitImpl> expectations) {
try {
this.macroFile = this.newSource(ActiveAnnotationsProcessingInIDETest.macroProject, macroContent.getKey(), macroContent.getValue().toString());
final int lidx = macroContent.getKey().lastIndexOf("/");
if ((lidx != (-1))) {
this.exportedPackage = macroContent.getKey().substring(0, lidx).replace("/", ".");
boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(ActiveAnnotationsProcessingInIDETest.macroProject.getProject(), this.exportedPackage);
if (_addExportedPackages) {
IResourcesSetupUtil.reallyWaitForAutoBuild();
}
}
this.clientFile = this.newSource(ActiveAnnotationsProcessingInIDETest.userProject, clientContent.getKey(), clientContent.getValue().toString());
IResourcesSetupUtil.waitForBuild();
final ResourceSet resourceSet = this.resourceSetProvider.get(ActiveAnnotationsProcessingInIDETest.userProject.getProject());
final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(this.clientFile.getFullPath().toString(), true), true);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
this.validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
final CompilationUnitImpl unit = this.compilationUnitProvider.get();
unit.setXtendFile(IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(resource.getContents(), XtendFile.class)));
expectations.apply(unit);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet 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.ResourceSet 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);
}
}
Aggregations