How to query the root element from importURI?

128 Views Asked by At

I'm developing a DSL, and I'm using Xtext's importURI attibute to deal with imports. It is working fine in the editor, but I don't know how to query the root element of the resource from the importURIs - which are just strings (later, in Acceleo). What would be the best way to do that?

P.S. My DSL allows only explicit imports. Also I have 2 meta-models : First one's root element is Alg, and the second one imports Alg(s) (root element - Root).

Right now, I have a Service that "goes" through all elements and return the root element of the imported resources. I think there is no need to go through the whole tree just to find something that could be deduced from import statements.

So, what would be the List<Alg> getAlgs(Root root) java method to retrieve all Alg roots?

Grammar:

Root returns Root:
    {Root} (name = QualifiedName ":")?
    (importStatement += ImportStatement)*
    [...];

ImportStatement:
    'import' importURI=STRING;

[...]

Acceleo:

[query public getAlgRoot(arg0 : Root) : Sequence(Alg)
    = invoke('org.example.tojava.services.AlgpRootService', 'getAlgs(org.example.mydsl.model.Root)', Sequence{arg0}) 
/]
1

There are 1 best solutions below

3
Banoffee On

Usually the STRING in importURI should be a URI that points to the resource you wish to import, which makes its elements accessible for cross-references in your original grammar. So I would say you are simply missing the cross-reference to Alg objects.