Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER
icon9.gif  NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #650740] Wed, 26 January 2011 10:54 Go to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hello,

I am trying to redefine a QualifiedNameResolver.

So for one of the element of my model, I don't have any name attribute in it.
In my personal QualifiedNameResolver I define qualifiedName for my element using one of its attribute name.

Now my problem is the following:
When doing validation, NamesAreUniqueValidator is seeing there is two elements with the same name, by calling NamesAreUniqueValidationHelper.checkUniqueNames() but when this one try to create an error, it calls (in createDuplicateNameError()) getNameFeature() on the object, which ask for the name of the object using SimpleAttributeResolver.NAME_RESOLVER which is using the name attribute, instead of using... I don't know what!

The second problem is that it makes fail the whole validation process, and then other duplicates are not showed either.

Is there a solution to that or is it a bug??

Thank you

There you can find the complete example:
http://www.eclipse.org/forums/index.php?t=msg&th=203250
Re: NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #650782 is a reply to message #650740] Wed, 26 January 2011 14:13 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Hi Victor,

your are free to bind your own subclass of
NamesAreUniqueValidationHelper and overwrite #getFeatureName.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 26.01.11 11:54, schrieb Victor v:
> Hello,
>
> I am trying to redefine a QualifiedNameResolver.
>
> So for one of the element of my model, I don't have any name attribute
> in it.
> In my personal QualifiedNameResolver I define qualifiedName for my
> element using one of its attribute name.
>
> Now my problem is the following:
> When doing validation, NamesAreUniqueValidator is seeing there is two
> elements with the same name, by calling
> NamesAreUniqueValidationHelper.checkUniqueNames() but when this one try
> to create an error, it calls (in createDuplicateNameError())
> getNameFeature() on the object, which ask for the name of the object
> using SimpleAttributeResolver.NAME_RESOLVER which is using the name
> attribute, instead of using... I don't know what!
>
> The second problem is that it makes fail the whole validation process,
> and then other duplicates are not showed either.
>
> Is there a solution to that or is it a bug??
>
> Thank you
>
> There you can find the complete example:
> http://www.eclipse.org/forums/index.php?t=msg&th=203250
Re: NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #650785 is a reply to message #650782] Wed, 26 January 2011 14:26 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Sebastian Zarnekow wrote on Wed, 26 January 2011 09:13
Hi Victor,

your are free to bind your own subclass of
NamesAreUniqueValidationHelper and overwrite #getFeatureName.

Regards,
Sebastian


Ok, I tried to do that, this is what I wrote:
protected EStructuralFeature getNameFeature(EObject object) {
		if (EcoreUtil2.isAssignableFrom(SpeadlPackage.Literals.COMPONENT, object.eClass())) {
			EStructuralFeature a = SimpleAttributeResolver.newResolver(String.class, "fullyQualifiedName").getAttribute(((Component)object).getType());
			return a;
		} else return super.getNameFeature(object);
	}


But it doesn't seem to work either...
Re: NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #650986 is a reply to message #650785] Thu, 27 January 2011 11:13 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 658
Registered: July 2009
Senior Member
Could you give a bit more context how it is doesn't work? Have you bound
your NamesAreUniqueValidationHelper in the right module? Is your code
being called?

Am 26.01.11 15:26, schrieb Victor v:
> Sebastian Zarnekow wrote on Wed, 26 January 2011 09:13
>> Hi Victor,
>>
>> your are free to bind your own subclass of
>> NamesAreUniqueValidationHelper and overwrite #getFeatureName.
>>
>> Regards,
>> Sebastian
>
>
> Ok, I tried to do that, this is what I wrote:
>
> protected EStructuralFeature getNameFeature(EObject object) {
> if (EcoreUtil2.isAssignableFrom(SpeadlPackage.Literals.COMPONEN T,
> object.eClass())) {
> EStructuralFeature a = SimpleAttributeResolver.newResolver(String.class,
> "fullyQualifiedName").getAttribute(((Component)object).getType());
> return a;
> } else return super.getNameFeature(object);
> }
>
>
> But it doesn't seem to work either...


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #651006 is a reply to message #650986] Thu, 27 January 2011 12:39 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Jan Koehnlein wrote on Thu, 27 January 2011 06:13
Could you give a bit more context how it is doesn't work? Have you bound
your NamesAreUniqueValidationHelper in the right module? Is your code
being called?



Yes, thank you for your answer.

Precisely, I have the following, on top of the files mentioned in the other topic:
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyQNP.class;
	}
	public Class<? extends INamesAreUniqueValidationHelper> bindINamesAreUniqueValidationHelper() {
		return MyNAUVH.class;
	}
}


public class MyNAUVH extends NamesAreUniqueValidationHelper {
	@Override
	protected EStructuralFeature getNameFeature(EObject object) {
		if (EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.COMPONENT, object.eClass())) {
			EStructuralFeature a = SimpleAttributeResolver.newResolver(String.class, "fullyQualifiedName").getAttribute(((Component)object).getType());
			return a;
		} else return super.getNameFeature(object);
	}
}


So, on my toy problem, it seems to work more or less.
I have only one problem:
The whole Component is highlighted instead of only the fullyQualifiedName attribute of its type attribute, I guess this is because the error creator only knows about the component and not about an attribute of its attributes.

With my real problem, not the simple one here, it does not work, and I am not sure to understand why.

I can reproduce the not working situation with the following in my toy problem:
	@Override
	protected EStructuralFeature getNameFeature(EObject object) {
		if (EcoreUtil2.isAssignableFrom(MyDslPackage.Literals.COMPONENT, object.eClass())) {
			EStructuralFeature a = SimpleAttributeResolver.newResolver(JvmGenericType.class, "type").getAttribute((Component)object);
			return a;
		} else return super.getNameFeature(object);
	}


I traced it one with debug mode and an exception happen at one point, because "a" is null, but it should not, I checked that the type attribute of object is not null.
Also, I am surprised that in the Ecore, the type of Component.type is JvmGenericType and not ComponentTypeWithParam (see the definition of the grammar in: http://www.eclipse.org/forums/index.php?t=msg&th=203250).

So I think there is 2 problems:

1) there is something strange with SimpleAttributeResolver in this situation (maybe because of this JvmGenericType vs ComponentTypeWithParam thing)
2) the default implementation of NamesAreUniqueValidationHelper doesn't take into account the fact that maybe the feature returned by getNameFeature is not in the object but is in a subobject... But maybe this is my fault for checking the name of Component instead of ComponentTypeWithParam... But then I would need to change my implementation of QualifiedNameProvider which will impact other things...
3) the default implementation of NamesAreUniqueValidationHelper should maybe allows also to redifine how shortName is computed in getDuplicateNameErrorMessage :)

Thank you

Re: NamesAreUniqueValidationHelper ALWAYS using SimpleAttributeResolver.NAME_RESOLVER [message #651140 is a reply to message #650785] Thu, 27 January 2011 22:27 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2961
Registered: July 2009
Senior Member
Hi Victor,

will your method #getNameFeature be called? Did you try to debug it?
To me it looks like an implementation that is far to complicated. I'd
expected something along the lines:

protected EStructuralFeature getNameFeature(EObject object) {
if (EcoreUtil2.isAssignableFrom(SpreadlPackage.Literals.COMPONE NT,
object.eClass()) {
return object.eClass().getEStructuralFeature("fullyQualifiedName");
// or even
return SpreadlPackage.Literals.COMPONENT__FULLY_QUALIFIED_NAME;
}
return super..
}

Assuming there is something wrong in the framework so your
implementation will not be used but the default:

Please try to remove the NamesAreUniqueValidator from the list of
composed checks in your mwe2 file and register your own implementation
directly similar to the registration of your XyzJavaValidator in your
runtime module.
You'll have to override getEPackages in your subclass and return your
EPackage. This will at least ensure that your own implementation is
grabbed and used.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 26.01.11 15:26, schrieb Victor v:
> Sebastian Zarnekow wrote on Wed, 26 January 2011 09:13
>> Hi Victor,
>>
>> your are free to bind your own subclass of
>> NamesAreUniqueValidationHelper and overwrite #getFeatureName.
>>
>> Regards,
>> Sebastian
>
>
> Ok, I tried to do that, this is what I wrote:
>
> protected EStructuralFeature getNameFeature(EObject object) {
> if (EcoreUtil2.isAssignableFrom(SpeadlPackage.Literals.COMPONEN T,
> object.eClass())) {
> EStructuralFeature a = SimpleAttributeResolver.newResolver(String.class,
> "fullyQualifiedName").getAttribute(((Component)object).getType());
> return a;
> } else return super.getNameFeature(object);
> }
>
>
> But it doesn't seem to work either...
Previous Topic:AbstractXtextTests in 2.0
Next Topic:severe performance problem / infinite loop? in AbstractInternalAntlrParser
Goto Forum:
  


Current Time: Thu Dec 18 23:18:44 GMT 2014

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

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