Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » DSL validation across multiple files
DSL validation across multiple files [message #1728367] Sun, 03 April 2016 19:42 Go to next message
Andrey Petrenko is currently offline Andrey PetrenkoFriend
Messages: 8
Registered: March 2016
Junior Member
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:
entity Base


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 #1728368 is a reply to message #1728367] Sun, 03 April 2016 19:47 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You have to query the scope provider for another element with the same qualified name and same EClass, but from another resource. It should be sufficient to inject the IGlobalScopeProvider.

Note that this should not be a fast check, thus you should use @Check(CheckType.NORMAL). Default is FAST.

HTH,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: DSL validation across multiple files [message #1728597 is a reply to message #1728368] Tue, 05 April 2016 17:31 Go to previous messageGo to next message
Andrey Petrenko is currently offline Andrey PetrenkoFriend
Messages: 8
Registered: March 2016
Junior Member
Hi Karsten,

thanks for your reply
Re: DSL validation across multiple files [message #1728599 is a reply to message #1728368] Tue, 05 April 2016 18:16 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

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.
Previous Topic:Cross references in multiple files
Next Topic:[SOLVED] How to get ride of the scrollbars in EmbeddedEditor
Goto Forum:
  


Current Time: Sat Apr 20 01:36:53 GMT 2024

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

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

Back to the top