Scoping with Xtext / TMF

The new Xtext version in Galileo changed a few things. To do scoping, a little bit of Java development is necessary. Documentation is very brief, but with a little research it is quite easy. Consider the following grammar, that allows us to define components, instances of those components and – the interesting part here – connect ports of instances:

The default code completion will traverse all defined Ports for the references p and p2 in the Connection rule. A better behaviour would be:

  • Show only the ports in the instances (in, in2)
  • For p, show only “OUT”-Ports, for p2, show only “IN”-ports.

To do this, we need to define methods in a class derived from AbstractDeclarativeScopeProvider. The method names follow the signature scope_<rule>_<element>, so the code fragment for p2 is:

With some additional code the full Provider for p and p2 looks like this:

4 thoughts on “Scoping with Xtext / TMF

  1. Hello, Please, can you post the whole Xtext-grammar? It is not possible to write a "Instance" or "Connection"-rule in the created editor. And what do you mean with the rule "Interface"? Thanks! Thomas V.
  2. The grammar is only an excerpt to show the scoping. I might publish more of it when I have time.
  3. Scoping is not very well documented. Could you please provide an example for the new Xtext 1.0
  4. Hmm, according to the documentation, the Declarative Scoping is still the same. The documentation about scoping is at http://www.eclipse.org/Xtext/documentation/1_0_0/xtext.html#scoping Is there a specific problem that you encounter?

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">