Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to implement specific "Dublicate Check" in XText
How to implement specific "Dublicate Check" in XText [message #638537] Thu, 11 November 2010 15:24 Go to next message
Florian Gessner is currently offline Florian GessnerFriend
Messages: 20
Registered: November 2010
Junior Member
Hello!

When I check my grammar via xtext I sometimes get a dublicate error which is not correct in the given scenario.
E.g:

EntityDefinition:
	'entity' name=ID toParentCardinality=Cardinality? extendsDefinition=EntityExtends?
	'{' elements+=EntityElement* '}';

EntityExtends:
	'extends' superEntity=Navigation 'in context' context=ContextPath;


within the same document there can be multiple entities with the same name but different contexts defined in entity extends.

How can I change this check or disable the built-in functionality?
Based on which information xtext generates the dublicate check? Is this releated to the ID terminal?

Thanks and Best Regards
Florian
Re: How to implement specific "Dublicate Check" in XText [message #638544 is a reply to message #638537] Thu, 11 November 2010 15:34 Go to previous messageGo to next message
Fernando Gonz is currently offline Fernando GonzFriend
Messages: 13
Registered: October 2010
Junior Member
Hi,

I removed the NamesAreUniqueValidator from the workflow and implemented custom java validations that take the scope into account.

// java-based API for validation
fragment = validation.JavaValidatorFragment {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}

It works but I'm learning so you should take care of my pieces of advice.


Re: How to implement specific "Dublicate Check" in XText [message #638552 is a reply to message #638544] Thu, 11 November 2010 15:50 Go to previous messageGo to next message
Florian Gessner is currently offline Florian GessnerFriend
Messages: 20
Registered: November 2010
Junior Member
Thanks for the fast reply.

For sure I can completly deactivate the validation for all EObject but my hope was that it is possible to skip/delimit the check depending on the type of the EObject.

Thanks and Best Regards
Florian
Re: How to implement specific "Dublicate Check" in XText [message #638560 is a reply to message #638552] Thu, 11 November 2010 16:02 Go to previous messageGo to next message
Fernando Gonz is currently offline Fernando GonzFriend
Messages: 13
Registered: October 2010
Junior Member
I debuged inside NamesAreUniqueValidator. It finally delegates to this interface[1]
and there is nothing in the parameters regarding scope or context.

I think it may be possible to override NamesAreuniqueValidator to make it pass the delegate just the IEobjectDescription objects in the scope you are interested in.

Best regards,
Fernando.


[1] public interface INamesAreUniqueValidationHelper {

/**
* Create errors for objects that have the same name. Objects, that do not belong to
* the same cluster will not get any errors.
* @see INamesAreUniqueValidationHelper#checkUniqueNames(Iterable, CancelIndicator, ValidationMessageAcceptor)
*/
void checkUniqueNames(Iterable<IEObjectDescription> descriptions, ValidationMessageAcceptor acceptor);

/**
* Create errors for objects that have the same name. Objects, that do not belong to
* the same cluster will not get any errors. The cancel indicator may be used to interrupt
* the validation.
*/
void checkUniqueNames(Iterable<IEObjectDescription> descriptions, CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor);

}
Re: How to implement specific "Dublicate Check" in XText [message #638755 is a reply to message #638560] Fri, 12 November 2010 13:39 Go to previous messageGo to next message
Florian Gessner is currently offline Florian GessnerFriend
Messages: 20
Registered: November 2010
Junior Member
Hi Fernando,

thanks for your help. I was now able to solve the issue:

1) I implemented an own INamesAreUniqueValidationHelper (which extends the default) which now skips the check for some EObjects
2) I implemented an own IQualifiedNameProvider which changes the qualified names. this again fixes the dublicate errors on a higher level.

Best Regards
Florian

[Updated on: Fri, 12 November 2010 13:40]

Report message to a moderator

Re: How to implement specific "Dublicate Check" in XText [message #638781 is a reply to message #638560] Fri, 12 November 2010 15:03 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

this looks related to my thread "Scoping and the name attribute"; by
reading the documentation I didn't find this
INamesAreUniqueValidationHelper mentioned... it might be worth saying
something about this.

By the way, what does "cluster" mean? From what I see as the default
behavior in my DSL I guess that cluster means container? Can it be?

thanks
cheers
Lorenzo

On 11/11/2010 05:02 PM, Fernando Gonzalez wrote:
> I debuged inside NamesAreUniqueValidator. It finally delegates to this
> interface[1] and there is nothing in the parameters regarding scope or
> context.
> I think it may be possible to override NamesAreuniqueValidator to make
> it pass the delegate just the IEobjectDescription objects in the scope
> you are interested in.
>
> Best regards,
> Fernando.
>
>
> [1] public interface INamesAreUniqueValidationHelper {
>
> /**
> * Create errors for objects that have the same name. Objects, that do
> not belong to
> * the same cluster will not get any errors.
> * @see INamesAreUniqueValidationHelper#checkUniqueNames(Iterable,
> CancelIndicator, ValidationMessageAcceptor)
> */
> void checkUniqueNames(Iterable<IEObjectDescription> descriptions,
> ValidationMessageAcceptor acceptor);
>
> /**
> * Create errors for objects that have the same name. Objects, that do
> not belong to
> * the same cluster will not get any errors. The cancel indicator may be
> used to interrupt * the validation.
> */
> void checkUniqueNames(Iterable<IEObjectDescription> descriptions,
> CancelIndicator cancelIndicator, ValidationMessageAcceptor acceptor);
>
> }


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: How to implement specific "Dublicate Check" in XText [message #639052 is a reply to message #638781] Mon, 15 November 2010 06:45 Go to previous message
Florian Gessner is currently offline Florian GessnerFriend
Messages: 20
Registered: November 2010
Junior Member
Hi Lorenzo,

With an implementation of INamesAreUniqueValidationHelper you can influence the uniquenss check of names. In many cases the implementation of xtext works fine but in my case I had to implement an own check.

I also did not know this interface before starting this thread. The documentation is a good starting point but does not treat all aspects of xtext in details. Therefore you should check the sources.

There you can also find the description of a cluster ( NamesAreUniqueValidationHandler.getAssociatedClusterType() ):
Quote:

... set of instances that should have unique names



Best Regards
Florian
Previous Topic:Is it possible to export the Xtext parser?
Next Topic:To export errors...
Goto Forum:
  


Current Time: Fri Apr 26 23:36:21 GMT 2024

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

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

Back to the top