Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customization of NamesAreUniqueValidator
Customization of NamesAreUniqueValidator [message #1219389] Tue, 03 December 2013 15:59 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello everyone,

I would like to know if it possible to customize the "org.eclipse.xtext.validation.NamesAreUniqueValidator"?
I would like to keep this standard validator which I enabled in my workflow. But in some special cases, I need non unique names in my dsl-model. (example: several constructors of a class with different parameters).

Is this maybe possible?

Best regards,
Alex
Re: Customization of NamesAreUniqueValidator [message #1219595 is a reply to message #1219389] Wed, 04 December 2013 19:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

you could try todo something like

package org.xtext.example.mydsl.validation;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper;
import org.xtext.example.mydsl.myDsl.MyDslPackage;

public class MyDslNamesAreUniqueValidationHelper extends
		NamesAreUniqueValidationHelper {

	@Override
	protected EClass getAssociatedClusterType(EClass eClass) {
		if (MyDslPackage.Literals.GREETING == eClass) return null;
		return super.getAssociatedClusterType(eClass);
	}
	
}


or change the nameprovider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customization of NamesAreUniqueValidator [message #1219670 is a reply to message #1219595] Thu, 05 December 2013 10:45 Go to previous messageGo to next message
Girish Kumar is currently offline Girish KumarFriend
Messages: 48
Registered: May 2011
Member
Hi Christian ,

By overriding NamesAreUniqueValidationHelper's getAssociatedClusterType will not solve probelm...

Also should make this helper to be injected to the validator.

Regards
Girish
Re: Customization of NamesAreUniqueValidator [message #1219675 is a reply to message #1219670] Thu, 05 December 2013 11:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Of course you have to add a binding

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customization of NamesAreUniqueValidator [message #1219685 is a reply to message #1219675] Thu, 05 December 2013 12:18 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello Christian,

it works perfectly for me. I can now delimit the subset of elements, which I dont want to get checked.

Binding should be done in the runtimeModule like:

public class MyDslRuntimeModule extends  AbstractMyDslRuntimeModule {
	
	public Class<? extends INamesAreUniqueValidationHelper> bindNamesAreUniqueValidationHelper() {
		return MyDslNamesAreUniqueValidationHelper.class;
	}

}


Thx,
Alex
Re: Customization of NamesAreUniqueValidator [message #1383948 is a reply to message #1219685] Tue, 27 May 2014 11:02 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

after rechecking my models and my validators I recognized, that this is not working! I also tried to manipulate my if-clause so it may really catch only special instances of my model.

public class CdalfNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper {

	@Override
	protected EClass getAssociatedClusterType(EClass eClass) {

		if (eClass.getInstanceClass() == de.mydsl.Operation.class || eClass.getInstanceTypeName().equals("de.mydsl.Operation") )
		{
			return null;
		}

		return super.getAssociatedClusterType(eClass);
	}
}


When I debug my code, all operation-instances are found, but the NavesAreUniqueValidation is disabled for EVERY ELEMENT!

Does anyone have a clue?

~Alex
Re: Customization of NamesAreUniqueValidator [message #1383996 is a reply to message #1383948] Tue, 27 May 2014 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

make sure that u you the validator at all
your impl looks very strange for me the following works fine for me

Model:
	elements+=Element*;
	
Element:
	AElement | BElement;
	
AElement: 
	"a" name=ID
;	

BElement:
	"b" name=ID
;


public class MyDslNamesAreUniqueValidationHelper extends
		NamesAreUniqueValidationHelper {
	@Override
	protected EClass getAssociatedClusterType(EClass eClass) {
		if (MyDslPackage.Literals.AELEMENT == eClass) {
			return null;
		}
		return super.getAssociatedClusterType(eClass);
	}
}
public class MyDslRuntimeModule extends org.xtext.example.mydsl1.AbstractMyDslRuntimeModule {

	public Class<? extends NamesAreUniqueValidationHelper> bindNamesAreUniqueValidationHelper() {
		return MyDslNamesAreUniqueValidationHelper.class;
	}
	
}
 @ComposedChecks(validators=NamesAreUniqueValidator)
class MyDslValidator extends AbstractMyDslValidator {

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customization of NamesAreUniqueValidator [message #1384130 is a reply to message #1383996] Wed, 28 May 2014 07:53 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

I had enabled the composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" in the workflow-file! After disabling it, your example works fine.

But what about nested elements?
Example: I disable the checking for operations ---> is the namechecking for nested elements of an operatin (parameters, local variables etc..) also disabled?

Thanks

[Updated on: Wed, 28 May 2014 08:10]

Report message to a moderator

Previous Topic:XText cross-reference to rule containing a cross-reference
Next Topic:Getting root project absolute path
Goto Forum:
  


Current Time: Thu Apr 25 09:49:42 GMT 2024

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

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

Back to the top