Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Check if a feature matches one among more terminals
Check if a feature matches one among more terminals [message #988498] Fri, 30 November 2012 09:28 Go to next message
Marco Naddeo is currently offline Marco NaddeoFriend
Messages: 62
Registered: November 2012
Member
Hi Smile

in a declarative validator for a type of my own language, how can I check if a feature of this grammar element matches one among more terminals?

Suppose that the rule defining this type is:

ANonTerminal:
  myFeature=TERMINAL1 anotherFeature=AnotherNonTerminal |
  myFeature=TERMINAL2 anotherFeature=AnotherNonTerminal |
  myFeature=TERMINAL3 anotherFeature=AnotherNonTerminal
;


and I want to write something like this:

public class AbstractMyLanguageJavaValidator extends AbstractDomainmodelJavaValidator {

  ...

  @Check
  public void myOwnCheck(ANonTerminal elem) {
    if (elem.getMyFeature == TERMINAL2) {
      warning(...);
    }
  }

}


Could you help me please? Thanks in advance! Smile
Re: Check if a feature matches one among more terminals [message #988645 is a reply to message #988498] Fri, 30 November 2012 20:32 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Hi Marco,

please try to use NodeModelUtils.findNodeForFeature, ask the node for
the grammar element and check that against the grammar access of your
language.

Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.11.12 14:35, schrieb Marco Naddeo:
> Hi :)
>
> in a declarative validator for a type of my own language, how can I
> check if a feature of this grammar element matches one among more
> terminals?
>
> Suppose that the rule defining this type is:
>
> ANonTerminal:
> myFeature=TERMINAL1 anotherFeature=AnotherNonTerminal |
> myFeature=TERMINAL2 anotherFeature=AnotherNonTerminal |
> myFeature=TERMINAL3 anotherFeature=AnotherNonTerminal
> ;
>
> and I want to write something like this:
>
>
> public class AbstractMyLanguageJavaValidator extends
> AbstractDomainmodelJavaValidator {
>
> ...
>
> @Check
> public void myOwnCheck(ANonTerminal elem) {
> if (elem.getMyFeature == TERMINAL2) {
> warning(...);
> }
> }
>
> }
>
> Could you help me please? Thanks in advance! :)
Previous Topic:Combine tests and validation
Next Topic:Need hover for keyword or block of elements
Goto Forum:
  


Current Time: Thu Dec 18 05:40:17 GMT 2014

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

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