Validator - Error/Warning Message Syntax [message #983055] |
Tue, 13 November 2012 16:35 |
Katja N Messages: 3 Registered: November 2012 |
Junior Member |
|
|
Hello everyone,
I am a master student working on a DSL for the creation of dynamic web-based surveys in the context of my master thesis. While I haven't had a lot of trouble implementing the actual DSL and an accompanying HTML generator, I am now struggling a little bit with the JavaValidator. I am new to this and one of my major problems is that I have difficulties getting the error/warning messages to display where I would like them to in the editor.
A very simplified example. In my DSL, I have defined (survey) items:
Item:
"item" name=ID (requests+=Text)+
"{"
(instructions=Instructions)?
answers=AnswerCategories
"}"
;
Text:
PlainText | PipedText
;
PlainText:
text=STRING
;
PipedText:
"insertAnswer" answerFrom=[Item]
;
Basically, an item consists of a question, further instructions, and answer categories. The question (or "requests" as I called them in my DSL) consist of plain text strings and references to other items (this is used to pipe the selected answer from the referenced item into the question text of the new item).
I was now trying to make sure that plain text strings are not empty (as a first step), using the following code in the JavaValidator:
@Check
public void checkRequestTextNotEmpty(Item item){
for(Text t : item.getRequests()){
if ((t instanceof PlainText) && ((PlainText) t).getText().isEmpty()){
warning("[WARNING] Request empty", SurveMePackage.Literals.ITEM__REQUESTS);
}
}
}
When I type into the editor something like "item MyFirstItem 'How old are you...' '' '...and when were you born?'", the error message is triggered, however, the first plain text string is underlined as the error source, rather than the whole list of requests, let alone the part that is actually causing the error. This may not be a huge problem, however, I would generally like to gain a better understanding of the error() and warning() methods, i.e. their syntax.
Could someone please explain to me if it is possible to mark the actual part of the list that is causing the issue and if so, how? And could you maybe give me a general explanation of how to use the error() and warning() messages reasonably, i.e. give an example of how to use it with different parameters etc.? I had a look in the API, but the methods were not explained in more detail in there, and I find it hard to fully comprehend how to make the best use of them.
Thank you very much in advance!
|
|
|
Re: Validator - Error/Warning Message Syntax [message #983097 is a reply to message #983055] |
Tue, 13 November 2012 17:17 |
|
Hi,
it should be right staight forward
error(<message>, <object to mark>, <feature to mark>, <index to mark or -1 if you dont care>, <error-code>,<data1>, ...<datan>);
=> in your case
error("[WARNING] Request empty",item, SurveMePackage.Literals.ITEM__REQUESTS,item.getRequests().indexof(t), "CODE");
but you may actually want to check Texts or mark them so
error("[WARNING] Request empty",t, SurveMePackage.Literals.PLAIN_TEXT__TEXT,-1"CODE");
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.54766 seconds