|
|
Re: Check unique names only in the provided scope [message #1859061 is a reply to message #1710564] |
Tue, 09 May 2023 16:37 |
|
Hello,
The org.eclipse.xtext.validation.NamesAreUniqueValidator validator implementation only works for elements that are at the root of your model. That is, it will only check the top level elements in your grammar.
For a "scope" contained validation, you should add your own check methods to the language Validator (generated by Xtext). For example, for the 15 min tutorial, we could check that DataTypes don't have duplicate names:
@Check
public void checkDataTypeUniqueName(DataType entry) {
Domainmodel domain = (Blog) Domainmodel.eContainer();
if (domain.getElements().stream()
.filter(e -> (e instanceof DataType) && e != entry)
.anyMatch(d -> d.getName().equals(entry.getName()))
) {
error(
"Duplicate names detected: " + entry,
DomainmodelPackage.Literals.DATATYPE__NAME,
IssueCodes.DUPLICATE_DATATYPE_NAME,
"");
}
}
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
Powered by
FUDForum. Page generated in 0.03306 seconds