Reputation: 477
i have the fallowing DSL in Xtext: I want to validate, that if ObjectB has Element, that the containing objects (ObjectA) do not have Element. I get the Warning to ObjectB but not to Object A.
Domainmodel:
ObjectA | ObjectB
;
ObjectB:
'ObjectB'
'{'
(element = Element)?
(objects += ObjectA)*
'}'
;
ObjectA:
'ObjectA'
'{'
(element = Element)?
'}'
;
Element:
'Element' name=ID
;
I would like a warning like the fallowing also in ObjectA:
@check
def ObjectinObject(ObjectB object)
{
if(object.element != null)
{
for (ObjectA e : object.objects)
{
if(e.element != null)
{//The fallowing Code will make Warning at the element and the subelement
warning('warning', DomainmodelPackage$Literals::DOMAINMODEL__ELEMENT)
warning('warning2',e.element ,DomainmodelPackage$Literals::ELEMENT__NAME)
}
}
}
}
Upvotes: 1
Views: 356
Reputation: 66273
There are several "groups" for warning
, error
and info
. One group does have EObject
in the parameter list, the other groups not not.
You already use the one which does not. In that case the message is attached to the EObject
which is the parameter of the check method.
So in order to attach a message to any random EObject
you have to use a method with an EObject
parameter. In your case:
protected void warning(String message, EObject source, EStructuralFeature feature);
and in action:
warning('warning', e, DomainmodelPackage$Literals::OBJECT_A__OBJECTS)
This second group of message methods is only available since Xtext 2.4. If you happen to use an older version, you can try this stanza (in Java, please adopt to Xtend syntax on your own):
getMessageAcceptor().acceptWarning('warning', e,
DomainmodelPackage$Literals::OBJECT_A__OBJECTS, -1,
null);
Upvotes: 3