Search code examples
javaxtextxtend

Identifying identical parts in xtend (based on xtext grammar)


Part of my xText grammar is as follows:

Transition:
   'Transition' from=TransitionTerminal;
TransitionTerminal: StateTerminal|SubStateTerminal;
StateTerminal: 'st' state=[State|ID];
State: 'state' name=ID;

Now, I want to identify Transitions with the same TransitionTerminal as in 'from'. So, in xtend I would write:

var origin = transition.from
//to check 'from' given some other Transition t, I use:
if(origin==t.from) {}

However, the above if statement is never entered. I suppose that additional nesting based on the provided grammar needs to be provided. Any help on how to achieve this is welcome.


Solution

  • You may want to try to use EcoreUtil.equals(EObject, EObject) to compare two instances of EObject structurally as in:

    if(EcoreUtil.equals(origin, t.from) {}