Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend generation called but not working in Runtime
Xtend generation called but not working in Runtime [message #1719606] Sat, 09 January 2016 20:16 Go to next message
André Ribeiro is currently offline André RibeiroFriend
Messages: 55
Registered: January 2013
Member
Hello,
I've followed this Christian Dietrich's tutorial to call the Xtend generator for a Xtext-based DSL from a context menu. My problem is that nothing is generated in the "src-gen" folder, despite the handler associated to the command is being called and executed. I've tested running this in debug mode and the handler is executed without throwing any exceptions.
The only difference to the tutorial is that I've replaced the deprecated EclipseResourceFileSystemAccess by EclipseResourceFileSystemAccess2. I don't know if the problem is related with the EclipseResourceFileSystemAccess2 that could be not properly set.
The code of my handler is the following:
public class GenerationHandler extends AbstractHandler implements IHandler {
    
    @Inject
    private IGenerator generator;
 
    @Inject
    private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;
     
    @Inject
    IResourceDescriptions resourceDescriptions;
     
    @Inject
    IResourceSetProvider resourceSetProvider;
     
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object firstElement = structuredSelection.getFirstElement();
            
            if (firstElement instanceof IFile) {
                IFile file = (IFile) firstElement;
                IProject project = file.getProject();
                IFolder srcGenFolder = project.getFolder("src-gen");
                
                if (!srcGenFolder.exists()) {
                    try {
                        srcGenFolder.create(true, true,
                                new NullProgressMonitor());
                    } catch (CoreException e) {
                        return null;
                    }
                }
 
                final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
                fsa.setOutputPath(srcGenFolder.getFullPath().toString());
                fsa.setMonitor(new NullProgressMonitor());
                fsa.setProject(project);
                 
                URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
                ResourceSet rs = resourceSetProvider.get(project);
                Resource r = rs.getResource(uri, true);
                generator.doGenerate(r, fsa);
            }
        }
        return null;
    }
 
    @Override
    public boolean isEnabled() {
        return true;
    }
}


When I activate the IBuilderParticipant in the plugin.xml the code is properly generated.
Can someone help me with this?

Thank you very much!


André Ribeiro
IST Lisbon
Portugal
Re: Xtend generation called but not working in Runtime [message #1719618 is a reply to message #1719606] Sun, 10 January 2016 07:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what is the error message you get?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend generation called but not working in Runtime [message #1719619 is a reply to message #1719618] Sun, 10 January 2016 07:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
p.s.

debugging shows that the output directory handling is different

final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
fsa.setOutputPath("src-gen");


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[SOLVED] Re: Xtend generation called but not working in Runtime [message #1719631 is a reply to message #1719619] Sun, 10 January 2016 14:46 Go to previous message
André Ribeiro is currently offline André RibeiroFriend
Messages: 55
Registered: January 2013
Member
Hi Christian,
You're the best! This worked:
Christian Dietrich wrote on Sun, 10 January 2016 07:28

fsa.setOutputPath("src-gen");

The solution was so simple that I feel a bit ashamed, but to be honest I didn't know how the output directory handling works for EclipseResourceFileSystemAccess2.

Thank you very much!


André Ribeiro
IST Lisbon
Portugal
Previous Topic:Strange error message
Next Topic:Call Xtend Generator in Xtext 2.9 - Web
Goto Forum:
  


Current Time: Fri Apr 19 09:53:21 GMT 2024

Powered by FUDForum. Page generated in 0.01812 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top