Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Check unique names only in the provided scope
icon5.gif  Check unique names only in the provided scope [message #1703675] Tue, 04 August 2015 03:48 Go to next message
Eclipse UserFriend
Hello Smile
I have my customized scope provider that is working fine. I added the check :"composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"" in my validation fragment to check if the names are unique.
I noticed that it checks that the names are unique in all my file and not in the provided scope!

Any help how can I start looking into this or if there is anything I need to customize ?

Thanks in advance.
Re: Check unique names only in the provided scope [message #1710564 is a reply to message #1703675] Wed, 07 October 2015 10:42 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Nod I have come across the same issue. I want to enforce uniqueness of the IDs/Names only in the current Scope, not the whole file.

Did you find an apropriate solution to it? Does anyone else have a good idea about that?

Thanks

Phil
Re: Check unique names only in the provided scope [message #1859061 is a reply to message #1710564] Tue, 09 May 2023 12:37 Go to previous message
Eclipse UserFriend
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,
				""); 
	}
}


Previous Topic:Adding a standard library to a DSL
Next Topic:Include classpath of plugin dependencies in xtext-maven-plugin
Goto Forum:
  


Current Time: Thu May 15 12:27:24 EDT 2025

Powered by FUDForum. Page generated in 0.26013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top