Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Is it possible to write the dsl validations in xtend2?
Is it possible to write the dsl validations in xtend2? [message #710786] Fri, 05 August 2011 12:02 Go to next message
Nikolai Busse is currently offline Nikolai BusseFriend
Messages: 15
Registered: August 2011
Junior Member
Is it possible to write the DSL validations in Xtend2?
It would be nice to use the Xtend features in this place.

I've tried to create a module MyDslValidator.xtend in the example project:
package org.xtext.example.mydsl.validation

import org.eclipse.xtext.validation.Check
import org.xtext.example.mydsl.myDsl.*
import org.xtext.example.mydsl.myDsl.MyDslPackage

class MyDslValidator extends AbstractMyDslJavaValidator {

//	@Check
//	public void checkUniqueAttrNameIgC (Attribute a)
//	{
//		Entity e = (Entity)(a.eContainer());
//		for ( Attribute a1 : e.getAttributes() ) {
//			if ( a1 == a ) continue;
//			if ( a.getName().toUpperCase().equals(a1.getName().toUpperCase()) )	{
//				warning("Names should be unique ignoring case", 
//						MyDslPackage.Literals.ATTRIBUTE__NAME);
//			}
//		}
//	}
	
	@Check
	def void checkUniqueAttrNameIgC (Attribute a)
	{
		if ( (a.eContainer as Entity).attributes
				.filter( a1 | a.name.toUpperCase == a1.name.toUpperCase)
				.size == 1 )
			return
		error("Names should be unique ignoring case",
			MyDslPackage.Literals.ATTRIBUTE__NAME)
	}
}


but the MyDslPackage.Literals.ATTRIBUTE__NAME causes problems

- Couldn't resolve reference to JvmIdentifiableElement 'ATTRIBUTE__NAME'.
- Couldn't resolve reference to JvmIdentifiableElement 'Literals'.
- Couldn't resolve reference to JvmIdentifiableElement 'MyDslPackage'.

Re: Is it possible to write the dsl validations in xtend2? [message #710789 is a reply to message #710786] Fri, 05 August 2011 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the Syntax is MyDslPackage$Literals::GREETING__NAME. of couse you have to import MydslPackage Wink

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Is it possible to write the dsl validations in xtend2? [message #710813 is a reply to message #710789] Fri, 05 August 2011 12:38 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Hi Nikolai!

You should subclass the original validator, since the workflow would recreate the Java stub again which conflicts with the generated Xtend class.

~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Is it possible to write the dsl validations in xtend2? [message #710872 is a reply to message #710813] Fri, 05 August 2011 14:17 Go to previous message
Nikolai Busse is currently offline Nikolai BusseFriend
Messages: 15
Registered: August 2011
Junior Member
Hi Christian and Karsten,

thanks a lot for the quick help. This way it works fine:

.../org.xtext.example.mydsl/src/org/xtext/example/mydsl/validation/MyDslXtendValidator.xtend
package org.xtext.example.mydsl.validation

import org.eclipse.xtext.validation.Check
import org.xtext.example.mydsl.myDsl.*

class MyDslXtendValidator extends MyDslJavaValidator {
	@Check
	def checkUniqueAttrNameIgC (Attribute a)
	{
		if ( (a.eContainer as Entity).attributes
				.filter( a1 | a.name.toUpperCase == a1.name.toUpperCase)
				.size == 1 )
			return;
		error("Names should be unique ignoring case",
			  MyDslPackage$Literals::ATTRIBUTE__NAME
		)
	}
}

and add in

.../org.xtext.example.mydsl/src/org/xtext/example/mydsl/MyDslRuntimeModule.java
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	// contributed by org.eclipse.xtext.generator.validation.JavaValidatorFragment
	@org.eclipse.xtext.service.SingletonBinding(eager=true)	
	public Class<? extends org.xtext.example.mydsl.validation.MyDslJavaValidator> bindMyDslJavaValidator() {
		return org.xtext.example.mydsl.validation.MyDslXtendValidator].class;
	}
}

Previous Topic:Xtend2 for Ecore M2M transformation
Next Topic:How can I determine when Resource loading is complete?
Goto Forum:
  


Current Time: Fri Apr 19 07:30:32 GMT 2024

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

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

Back to the top