DSL validation across multiple files [message #1728367] |
Sun, 03 April 2016 15:42  |
Eclipse User |
|
|
|
Hi,
MyModel:
(imports+=Import)*
(entities+=Entity)*;
Import:
'import' importURI=STRING;
Entity:
'entity' name=ID ('extends' extends=[Entity|ID])?;
For example I want to validate uniqueness of names of entities across multiple dsl files
I've written the following code
private val names = new HashMap<String, Set<String>>
@Check
def checkUniquenessAcrossFiles(MyModel model) {
names.remove(model.eResource.URI.toString)
val modelNames = new HashSet<String>
model.entities.forEach[e|modelNames.add(e.name)]
names.put(model.eResource.URI.toString, modelNames)
val allNames = new HashSet<String>
names.forEach [ k, v |
v.forEach [ name |
if (allNames.contains(name)) {
error("Entity name should be unique", model, MyDSLPackage.Literals.MY_MODEL__ENTITIES)
} else {
allNames.add(name)
}
]
]
}
but the problem here is that this code is executing when I open dsl file, for instance:
I have two files first.dsl & second.dsl with the same content:
If I open first.dsl only there is no error messages and they appear only after I open second.dsl
So my question what is the right way to validate multiple dsl files?
Thanks in advance
|
|
|
|
|
Re: DSL validation across multiple files [message #1728599 is a reply to message #1728368] |
Tue, 05 April 2016 14:16  |
Eclipse User |
|
|
|
Also never hold any state in fields within validators (and most other components in Xtext).
Karsten Thoms wrote on Sun, 03 April 2016 21:47
Note that this should not be a fast check, thus you should use @Check(CheckType.NORMAL). Default is FAST.
Why is that? I think FAST is good.
|
|
|
Powered by
FUDForum. Page generated in 0.35722 seconds