Skip to main content



      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 08:02 Go to next message
Eclipse UserFriend
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 08:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian
Re: Is it possible to write the dsl validations in xtend2? [message #710813 is a reply to message #710789] Fri, 05 August 2011 08:38 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Is it possible to write the dsl validations in xtend2? [message #710872 is a reply to message #710813] Fri, 05 August 2011 10:17 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 06:57:30 EDT 2025

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

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

Back to the top