Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:22 Go to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
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 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13220
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: @Check Validator with 2 or more parameters [message #1732743 is a reply to message #1732737] Thu, 19 May 2016 19:21 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
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 19:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13220
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: @Check Validator with 2 or more parameters [message #1732749 is a reply to message #1732744] Thu, 19 May 2016 20:47 Go to previous message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
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:Retrieve index without having to load resources in standalone context?
Next Topic:what is syntactic predicates ?
Goto Forum:
  


Current Time: Fri Nov 22 07:26:21 GMT 2019

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

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

Back to the top