Skip to main content



      Home
Home » Modeling » TMF (Xtext) » DSL validation across multiple files
DSL validation across multiple files [message #1728367] Sun, 03 April 2016 15:42 Go to next message
Eclipse UserFriend
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 15:47 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: DSL validation across multiple files [message #1728597 is a reply to message #1728368] Tue, 05 April 2016 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Karsten,

thanks for your reply
Re: DSL validation across multiple files [message #1728599 is a reply to message #1728368] Tue, 05 April 2016 14:16 Go to previous message
Eclipse UserFriend
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: Tue Jul 08 06:57:04 EDT 2025

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

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

Back to the top