use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class ConvertJavaCode method createResource.
private Resource createResource(IFile file, String content) throws ExecutionException {
ResourceSet set = resourceSetProvider.get(file.getProject());
Resource resource = set.createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), false));
try {
resource.load(new LazyStringInputStream(content, file.getCharset()), null);
} catch (CoreException e) {
handleException("Failed to read file content", e, file);
} catch (IOException e) {
handleException("Failed to load resource.", e, file);
}
return resource;
}
use of org.eclipse.emf.ecore.resource.Resource 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.Resource in project xtext-xtend by eclipse.
the class AbstractCodeBuilder method findByFragment.
protected <T extends EObject> T findByFragment(final XtextResource resource, final T object) {
final Resource myResource = object.eResource();
boolean _equals = Objects.equal(myResource, resource);
if (_equals) {
return object;
}
final String fragment = myResource.getURIFragment(object);
EObject _eObject = resource.getEObject(fragment);
final T result = ((T) _eObject);
return result;
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class DocumentRewriterTest method createDocument.
protected XtextDocument createDocument(final String content) throws Exception {
XtextDocument _xblockexpression = null;
{
final IFile file = this._workbenchTestHelper.createFile("Foo", content);
final Resource resource = this._workbenchTestHelper.getResourceSet().getResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true), true);
XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
};
AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
it.setTokenDefProvider(_doubleArrow);
final Provider<Lexer> _function_2 = () -> {
InternalXtendLexer _internalXtendLexer = new InternalXtendLexer();
return ((Lexer) _internalXtendLexer);
};
it.setLexer(_function_2);
it.setFlexerFactory(this.flexerFactory);
};
final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
document.set(content);
document.setInput(((XtextResource) resource));
_xblockexpression = document;
}
return _xblockexpression;
}
use of org.eclipse.emf.ecore.resource.Resource 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);
}
}
Aggregations