Validator [message #1844281] |
Wed, 08 September 2021 01:31 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Muhammad Salman Tayyab![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=salmantayyab454%40gmail.com) Messages: 36 Registered: March 2020 Location: Germany |
Member |
|
|
Hi, I am writing a validator to avoid repetition.
Variable names should be unique.
In the grammar screenshot (attached below), the "videos" variable should always be unique.
In the other screenshot, I tried to write the custom validation rule for it. Please see the validation file screenshot and guide me, what I have to do. I am new to Xtext and confused about how to write the correct code for it. Thank you.
Salman
|
|
|
|
Re: Validator [message #1844297 is a reply to message #1844282] |
Wed, 08 September 2021 11:24 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Muhammad Salman Tayyab![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=salmantayyab454%40gmail.com) Messages: 36 Registered: March 2020 Location: Germany |
Member |
|
|
Do you mean that I have to write this repetition check in the dslgenerator.xtend file?
Below I have modified the validation file. Please have a look and guide me because I am confused in this.
@Check
public void checkDuplicateVarName(Video video) {
///var map = new HashMap <String, Video >
Set<String> existing = new HashSet<>();
for(Videodef v: video.getVideos()) {
if(!existing.add(v.getName())) {
error("Variable Name should be unique",
VideoDslPackage.Literals.VIDEO__VIDEOS,
DUPLICATE_VAR);
}
}
}
Salman
[Updated on: Wed, 08 September 2021 11:37] Report message to a moderator
|
|
|
Re: Validator [message #1844302 is a reply to message #1844297] |
Wed, 08 September 2021 13:28 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Muhammad Salman Tayyab![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=salmantayyab454%40gmail.com) Messages: 36 Registered: March 2020 Location: Germany |
Member |
|
|
@Check
public void checkDuplicateVarName(Video video) {
///var map = new HashMap <String, Video >
Set<String> existing = new HashSet<>();
for(Videodef v: video.getVideos()) {
if(!existing.add(v.getName())) {
error("Variable Name should be unique",
VideoDslPackage.Literals.VIDEO__VIDEOS,
DUPLICATE_VAR);
}
}
}
Hello, From the above code, error always appears on the first line.
How can I add the error message to the line on which we are writing the duplicate variable?
Salman
[Updated on: Wed, 08 September 2021 13:29] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03431 seconds