Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 07:48 Go to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
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 14:42 Go to previous messageGo to next message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
Registered: November 2010
Location: Germany
Member
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 16:37 Go to previous message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

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
Previous Topic:Adding a standard library to a DSL
Next Topic:Include classpath of plugin dependencies in xtext-maven-plugin
Goto Forum:
  


Current Time: Wed Dec 11 19:16:29 GMT 2024

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

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

Back to the top