Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Name validation for imported files
Name validation for imported files [message #984611] Wed, 14 November 2012 21:09 Go to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
I have a language where names imported from another file cannot be overwritten by newly defined variables. So if I have

file1.mydsl
  a : int
  b : int

file2.mydsl
  import "file1.mydsl"
  a : int
  c : int


I want it to flag an error on the 'a' declared in file2.mydsl. I've tried following the solution presented in this post, but it is overinclusive. In particular, if I have an unrelated file3.mydsl which declares 'c' it will still give an error in file1.mydsl, even though file3.mydsl is never imported into that context. I am using the ImportUriGlobalScopeProvider, but IContainer.Manager.getVisibleContainers seems to have a different notion of visibility from the scope provider. Any ideas?
Re: Name validation for imported files [message #984629 is a reply to message #984611] Wed, 14 November 2012 21:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you can simply check if the uri of the duplications found somehow match your import scheme. (the IEObjectDescription contains the uri as well)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Name validation for imported files [message #985580 is a reply to message #984629] Thu, 15 November 2012 14:07 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
Thanks for the response Christian. Are you suggesting that I navigate my model to find the import statements and then compare them against the URI of the "visible" object? This seems like a lot more work than I would expect for such a task, and I don't think it would cover transitive imports (a imports b and b imports c, etc). I was hoping there was a way to just leverage all the work already done in the scopeprovider to simply detect if a name is already present in the scope and flag that as an error.

-Andrew
Re: Name validation for imported files [message #985605 is a reply to message #985580] Thu, 15 November 2012 14:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi alternatively you could ask your global scope provider for an
scope for a reference of your type and traverse the scopes elements.

--
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: Name validation for imported files [message #985621 is a reply to message #985605] Thu, 15 November 2012 14:45 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
Here is the code I am trying now, but it isn't working.

@Check
public void checkNamesUnique(Name name) {
	IScope scope = globalScopeProvider.getScope(name.eResource(), MydslPackage.Literals.NAME__EXPR, null);
	System.out.println(scope.getAllElements());
}


In this language 'Name' is the element being referenced and it can appear inside an 'Expr'. When the code above is run, the set of all elements is always empty. Am I calling the global scope provider incorrectly?

-Andrew
Re: Name validation for imported files [message #985636 is a reply to message #985621] Thu, 15 November 2012 15:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi am not sure if null is a valid filter you could try
predicates.always true. And I don't know if there reference is
correct. You could try

Ereference ref = ecorefactory.created reference.
ref.setetype(xxx.ltersls.name)

--
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: Name validation for imported files [message #985640 is a reply to message #985621] Thu, 15 November 2012 15:10 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
I switched to calling the global scope provider with the following EReference:

MydslPackage.Literals.INTERFACE_DEF__VARDEFS


Where VarDefs is the place where Names are declared. This seems to return the proper scope so I can do the validation easily.

Next I'll look at how to detect duplicate names from two different imports (e.g. both file1.mydsl and file2.mydsl declare 'a' and are both imported into file3.mydsl).

Thanks,
Andrew
Re: Name validation for imported files [message #985650 is a reply to message #985640] Thu, 15 November 2012 15:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi it is pretty the same. Check the global scope for duplicates

--
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: Name validation for imported files [message #985679 is a reply to message #985650] Thu, 15 November 2012 16:44 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
My plan was to check the global scope for duplicates, but I don't see how to navigate the global scope. If I call scope.getAllElements() it only returns non-shadowed elements. Thus my plan was to walk up the scope manually and look at each part of the scope by hand, but there doesn't seem to be a way to look at just the local elements of a scope (such methods are protected rather than public). Is there a known way to do this?

-Andrew
Re: Name validation for imported files [message #985690 is a reply to message #985679] Thu, 15 November 2012 17:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi what so you mean with "only non shadowed"

--
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: Name validation for imported files [message #985697 is a reply to message #985690] Thu, 15 November 2012 17:39 Go to previous messageGo to next message
Andrew Gacek is currently offline Andrew GacekFriend
Messages: 32
Registered: October 2011
Member
Suppose I have

file1.mydsl
  a : int
  b : int

file2.mydsl
  a : int
  c : int

file3.mydsl
  import "file1.mydsl"
  import "file2.mydsl"


Then if I get the global scope of file3 and ask for all elements, I get back [a, b, c] where the 'a' refers only the 'a' from file1. The the 'a' from file2 is shadowed so I can't detect the name conflict from the scope directly.
Re: Name validation for imported files [message #985705 is a reply to message #985697] Thu, 15 November 2012 18:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi is the a conflict at all if the default implementation of the
importuriglobalscope provider has this first come first serve rule
built in

Maybe you have to query the index for this use case anyway

--
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: Name validation for imported files [message #985706 is a reply to message #985705] Thu, 15 November 2012 18:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
PS maybe iterating the parents works too

--
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
Previous Topic:Creating Proxies from JvmType
Next Topic:Display Exception while generating Model-Output to User
Goto Forum:
  


Current Time: Fri Apr 19 05:15:47 GMT 2024

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

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

Back to the top