Skip to main content



      Home
Home » Modeling » TMF (Xtext) » @Check Validator with 2 or more parameters(Only works with 1 parameter)
@Check Validator with 2 or more parameters [message #1732734] Thu, 19 May 2016 07:22 Go to next message
Eclipse UserFriend
Hi everyone,

I'm a totally newbie at XText and grammar definition.

I have a very simple grammar where I can define 'Element', 'Diagram', and 'Model'.

It need to be generic as a metamodel, but I want to do some validations (warnings and errors) to make more friendly. For example, I could define that a "Class belongs to SequenceDiagram from BPMN". It's totally wrong, but my grammar allows this crazyness.

I already use @Check to validate if an Element name begins with capital or not, but I failed to create a @Check that receive two or more parameters. It only works with one.

What I want is a @Check method that receive Element and Diagram (for example) so I could that if Element is a Class so Diagram need to be ClassDiagram. If not, then a error message is displayed. How can I use @Check with 2 or more parameters?

Best regards
Re: @Check Validator with 2 or more parameters [message #1732737 is a reply to message #1732734] Thu, 19 May 2016 14:38 Go to previous messageGo to next message
Eclipse UserFriend
Hi that is not possible

But you can define the check on one of the elements or the parent element and then navigate the as up and down
Inside the check method
Re: @Check Validator with 2 or more parameters [message #1732743 is a reply to message #1732737] Thu, 19 May 2016 15:21 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, but how could I navigate up and down?
Re: @Check Validator with 2 or more parameters [message #1732744 is a reply to message #1732743] Thu, 19 May 2016 15:30 Go to previous messageGo to next message
Eclipse UserFriend
this depends on the grammar.

maybe your model has a list of (child) elements and diagrams or vice versa. there will be a getter for that Smile
using eContainer() you can move up to the parent.
the utility EcoreUtil2 have helpful methods for that as well
Re: @Check Validator with 2 or more parameters [message #1732749 is a reply to message #1732744] Thu, 19 May 2016 16:47 Go to previous message
Eclipse UserFriend
Thanks!!!!

I don't know if I wrote the best code but works!!!


@Check
def checkIfDiagramContainsRightElements(Diagram diagram) {
	if (diagram.kind.equals(DiagramKind.CLASSDIAGRAM)) {
		if (diagram.eContainer().eGet(ModelPackage.Literals.ELEMENT__KIND) == ElementKind.CLASS) {
			println("YES!!!")
		}
	}
}
Previous Topic:How to integrate xtext plugin inside custom project
Next Topic:what is syntactic predicates ?
Goto Forum:
  


Current Time: Sat Nov 08 09:28:26 EST 2025

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

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

Back to the top