Access file create during auto code geneation of xtext

78 views Asked by At

I translate one dsl (A) to another dsl (B) create in xtext.

The code generation of A looks like

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
    fsa.generateFile('transformed.wp', resource.allContents.filter(typeof(ActionSystem)).map [
        compile
    ].join(', '))

    val rs = new ResourceSetImpl();
    val r = rs.getResource(URI.createPlatformResourceURI('transformed.wp'), true);
    val List<EObject> contentOfYourFile = r.getContents();
    }

the error is then I call URI.createPlatformResourceURI('transformed.wp') the file cannot be found.

How do I access the file 'transformed.wp'.

The idea will be to copy part of the emf model of A to the model of B after the code was generated.

1

There are 1 answers

0
Johan On

The solution was in IFileSystemAccess2

//create the file name
var fileuri = fsa.getURI('transformed.wp');
//get the name of the resource
var resource_name = fileuri.toString();
//get eh name of the resource
var file = fileuri.lastSegment;