Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Sharing imported dsl files witch custom URI
Sharing imported dsl files witch custom URI [message #61741] Tue, 21 July 2009 07:46 Go to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi,
I'm writing code for a dsl where the import instead of import
"platform:/resource/myproject/model/refModel.model" has the form File :
\..\..\some\file\to\include.dat without quotes.
I managed to make it with the help from guys at the oAW forum. Here is the
link
to the post
http://www.openarchitectureware.org/forum/viewtopic.php?show topic=14040

Testing some cases I came with another question (I don't know if others
already asked): I have one "dsl main file" which include for example 10
other dsl files in the same subfolder, let say .\ModelSubfolder ... is
there a way (such as wildcard .\ModelSubfolder\*) to import all the files
in that folder?

Again, is there a way in which the imported model file, when opened in the
editor via crossreference could be aware of the whole model (from the
caller for example) without import . Maybe defining the scope?

Thank you very much for your help
Ste
Re: Sharing imported dsl files witch custom URI [message #61834 is a reply to message #61741] Tue, 21 July 2009 10:11 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Stefano,

I'm afraid there is out of the box wildcard support for imported models.
You'll have to implement the resolution strategy on your own. A custom
ScopeProvider will be your way to go. Your very own implementation of a
Scope Provider can pretty much do anything that you want. It may even
merge other model elements into the scope of a model file. However, we
not provide a first class service for model enhancement that will make
other model elements available for native emf functions as
EcoreUtil.getAllContents. Please feel free to file a bugzilla and
describe your usecase. Maybe we can come up with a solution for the 0.8
release.
Meanwhile you may try to use the call to ILinker.linkModel as it allows
kind of tricky implementations and may be used to define default values
or magically include other model elements. But it is not first class and
you may have to implement an ITransientValueService. Otherwise the
serializer will get confused by automatically added elements.

Regards,
Sebastian

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

Am 21.07.2009 9:46 Uhr, schrieb Stefano Cottafavi:
> Hi,
> I'm writing code for a dsl where the import instead of import
> "platform:/resource/myproject/model/refModel.model" has the form File :
> \..\..\some\file\to\include.dat without quotes.
> I managed to make it with the help from guys at the oAW forum. Here is
> the link
> to the post
> http://www.openarchitectureware.org/forum/viewtopic.php?show topic=14040
>
> Testing some cases I came with another question (I don't know if others
> already asked): I have one "dsl main file" which include for example 10
> other dsl files in the same subfolder, let say .\ModelSubfolder ... is
> there a way (such as wildcard .\ModelSubfolder\*) to import all the
> files in that folder?
>
> Again, is there a way in which the imported model file, when opened in
> the editor via crossreference could be aware of the whole model (from
> the caller for example) without import . Maybe defining the scope?
>
> Thank you very much for your help
> Ste
>
Re: Sharing imported dsl files witch custom URI [message #481705 is a reply to message #61741] Sun, 23 August 2009 20:00 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sebastian,
I'm not used to do tricky things with Xtext, till now I focused only on the appearence of editor and outline view for my dsl.

About the wildcard I really don't know how to code your suggestions. Please, is there some snippet of code you can suggest me. Everything will be appreciated laso useful links or docs.

Btw thank you very much for the effort you and your colleagues put into helping people via this forum.

Cheers
Stefano
Re: Sharing imported dsl files witch custom URI [message #481706 is a reply to message #61741] Sun, 23 August 2009 20:06 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sebastian,
I'm not used to do tricky things with Xtext, till now I focused only on the appearence of editor and outline view for my dsl.

About the wildcard I really don't know how to code your suggestions. Please, is there some snippet of code you can suggest me. Everything will be appreciated laso useful links or docs.

Btw thank you very much for the effort you and your colleagues put into helping people via this forum.

Cheers
Stefano
Re: Sharing imported dsl files witch custom URI [message #481743 is a reply to message #481705] Mon, 24 August 2009 07:47 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Stefano,

the linking and content assist use an implementation of the
IScopeProvider interface to calculate all available instances. If you
plug you own implementation, you can pretty much return a scope that
contains anything you want - even the elements from other model files in
the very same directory. It is possible to traverse the current input
model, collect all import statements and resolve them in the way you
like (with wildcards or without...). Xtext ships with some reasonable
defaults that are a good match for many use cases but in your scenario,
you'll have to implement a custom scope provider.
The reference documentation (http://www.xtext.org) and the source code
of Xtext will be a good starting point to learn about scoping.
If you have any further questions, please don't hesitate to ask.

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

Am 23.08.09 22:04, schrieb Stefano Cottafavi:
> Hi Sebastian,
> I'm not used to do tricky things with Xtext, till now I focused only on
> the appearence of editor and outline view for my dsl.
>
> About the wildcard I really don't know how to code your suggestions.
> Please, is there some snippet of code you can suggest me. Everything
> will be appreciated laso useful links or docs.
>
> Btw thank you very much for the effort you and your colleagues put into
> helping people via this forum.
>
> Cheers
> Stefano
Re: Sharing imported dsl files witch custom URI [message #487100 is a reply to message #481743] Mon, 21 September 2009 21:13 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sebastian,
after a while I'm here with little code for the getScope method

public IScope getScope(EObject context, EReference reference) {
		URI 	uri = context.eResource().getURI();
		String 	ext = uri.fileExtension();
		if(ext.matches("dat")) {
			List<IScopedElement> allElems = new ArrayList<IScopedElement>();

			IWorkspaceRoot 	wsr 	= ResourcesPlugin.getWorkspace().getRoot();
			IPath 			path 	= wsr.getFile(new Path(uri.toPlatformString(false))).getLocation();
			File[] 			flist 	= path.toFile().getParentFile().listFiles();
			
			for(File f:flist) {	
				//Resource r = context.eResource().getResourceSet().createResource(URI.createFileURI(f.getAbsolutePath()));
				Resource r = ImportUriUtil.getResource(context.eResource(),f.toURI().toString());
				context.eResource().getResourceSet().getResources().add(r);
				Model m = (Model)r.getContents().get(0);
				List<SectionKeyword> sk = m.getOptional();
				for(SectionKeyword nk:sk){ 				// loop section keywords
					for(EObject d:nk.eContents()){ 		// loop name keywords
						String name = d.eContents().get(0).toString();
						allElems.add(ScopedElement.create(name, d));
					}
				}
			}

			Scope scope = new Scope();
			scope.setElements(allElems);
			return scope;
		}
		return super.getScope(context, reference);
}


The idea is to get all files (.dat) in a folder and add their content to the returned scope, with no import statement but retrieving the path from eResource.
I'm not able to add File (all the File in the for loop) to the resourceset. how can this be done? talking about hte overall method to build the scope, is this good? any suggestion?

Cheers,
Stefano
Re: Sharing imported dsl files witch custom URI [message #487209 is a reply to message #487100] Tue, 22 September 2009 13:08 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Stefano,

what do you mean by "I'm not able to add resources to the resource set".
Do you get any exceptions?

context.eResource().getResourceSet().getResource(uri, true) should work.

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

Stefano Cottafavi schrieb:
> Hi Sebastian,
> after a while I'm here with little code for the getScope method
>
> public IScope getScope(EObject context, EReference reference) {
> URI uri = context.eResource().getURI();
> String ext = uri.fileExtension();
> if(ext.matches("dat")) {
> List<IScopedElement> allElems = new
> ArrayList<IScopedElement>();
>
> IWorkspaceRoot wsr =
> ResourcesPlugin.getWorkspace().getRoot();
> IPath path = wsr.getFile(new
> Path(uri.toPlatformString(false))).getLocation();
> File[] flist =
> path.toFile().getParentFile().listFiles();
>
> for(File f:flist) {
> //Resource r =
> context.eResource().getResourceSet().createResource(URI.crea teFileURI(f.getAbsolutePath()));
>
> Resource r =
> ImportUriUtil.getResource(context.eResource(),f.toURI().toSt ring());
> context.eResource().getResourceSet().getResources().add(r);
> Model m = (Model)r.getContents().get(0);
> List<SectionKeyword> sk = m.getOptional();
> for(SectionKeyword nk:sk){ // loop
> section keywords
> for(EObject d:nk.eContents()){ // loop name
> keywords
> String name = d.eContents().get(0).toString();
> allElems.add(ScopedElement.create(name, d));
> }
> }
> }
>
> Scope scope = new Scope();
> scope.setElements(allElems);
> return scope;
> }
> return super.getScope(context, reference);
> }
>
> The idea is to get all files (.dat) in a folder and add their content to
> the returned scope, with no import statement but retrieving the path
> from eResource.
> I'm not able to add File (all the File in the for loop) to the
> resourceset. how can this be done? talking about hte overall method to
> build the scope, is this good? any suggestion?
>
> Cheers,
> Stefano
Re: Sharing imported dsl files witch custom URI [message #488066 is a reply to message #487209] Fri, 25 September 2009 13:41 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Dear Sebastian,
your suggestion was very helpful.
context.eResource().getResourceSet().getResource(uri, true) do works perfectly.

Now I can traverse all files in the same folder, collect all model's elements and add those to the scope.... but in the editor have no support for the Ctrl+MouseOver, I mean I cannot navigate to the referenced element (also I have no more error "red underlining" for missing references). Is this normal?

Any suggestion/hint is appreciated.

Best regards and thank you for all the help you give.

Stefano
Re: Sharing imported dsl files witch custom URI [message #493369 is a reply to message #61741] Sun, 25 October 2009 11:42 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sebastian,
after a while I found a solution that do what I want. Here's the code

private Scope internalGetScope(EObject context, EReference reference) {
		if(internalScope==null) {
			URI 			uri = context.eResource().getURI();
			
			List<IScopedElement> allElems = new ArrayList<IScopedElement>();
			IWorkspaceRoot 	wsr 	= ResourcesPlugin.getWorkspace().getRoot();
			IPath 			path 	= wsr.getFile(new Path(uri.toPlatformString(false))).getLocation();
			File[] 			flist 	= path.toFile().getParentFile().listFiles(fileFilter);

			for(File f:flist) {	
				Resource r = ImportUriUtil.getResource(context.eResource(),f.toURI().toString());

				Model m = (Model)r.getContents().get(0);
				List<SectionKeyword> skl = m.getOptional();
				for(SectionKeyword sk:skl){ 				// loop section keywords
					List<NameKeyword> nkl = sk.getSection();
					for(NameKeyword nk:nkl){ 				// loop name keywords
						allElems.add(ScopedElement.create(nk.getName(), nk));
					}
				}

			}
			
			internalScope = new Scope();
			internalScope.setOuterScope(super.getScope(context, reference).getOuterScope());
			internalScope.setElements(allElems);
			
		}
		return internalScope;
	}

In my intention check if internalscope is already defined, should prevent for contexts in the same file to re-loop/re-build every time the same scope.
Now another question rise: scenario is that I have this folder with a large number of files (every one with large number of model's objects inside). Every file in this folder would share the same scope. Now, when I open a file in the editor from that folder the scope is built (this take some seconds and for the moment I can leave with that); when another file from the same folder is opened too, the scope is rebuilt, and that's something I would avoid.
How can I share the scope between files/resources?

Thanks,
Stefano
Re: Sharing imported dsl files witch custom URI [message #494364 is a reply to message #493369] Fri, 30 October 2009 12:11 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Stefano,

I'm not sure about your approach. Have you evaluated the EMF Index
project and the index based scope provider?

However: You could extract that internalGetScope implementation into
another class, annotate it with @Singleton and inject this
implementation into your scope provider.
This would ensure, that any scope provider uses the same internalScope.

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

Stefano Cottafavi schrieb:
> Hi Sebastian,
> after a while I found a solution that do what I want. Here's the code
>
>
> private Scope internalGetScope(EObject context, EReference reference) {
> if(internalScope==null) {
> URI uri = context.eResource().getURI();
>
> List<IScopedElement> allElems = new
> ArrayList<IScopedElement>();
> IWorkspaceRoot wsr =
> ResourcesPlugin.getWorkspace().getRoot();
> IPath path = wsr.getFile(new
> Path(uri.toPlatformString(false))).getLocation();
> File[] flist =
> path.toFile().getParentFile().listFiles(fileFilter);
>
> for(File f:flist) {
> Resource r =
> ImportUriUtil.getResource(context.eResource(),f.toURI().toSt ring());
>
> Model m = (Model)r.getContents().get(0);
> List<SectionKeyword> skl = m.getOptional();
> for(SectionKeyword sk:skl){ // loop
> section keywords
> List<NameKeyword> nkl = sk.getSection();
> for(NameKeyword nk:nkl){ // loop
> name keywords
> allElems.add(ScopedElement.create(nk.getName(),
> nk));
> }
> }
>
> }
>
> internalScope = new Scope();
> internalScope.setOuterScope(super.getScope(context,
> reference).getOuterScope());
> internalScope.setElements(allElems);
>
> }
> return internalScope;
> }
> In my intention check if internalscope is already defined, should
> prevent for contexts in the same file to re-loop/re-build every time the
> same scope.
> Now another question rise: scenario is that I have this folder with a
> large number of files (every one with large number of model's objects
> inside). Every file in this folder would share the same scope. Now, when
> I open a file in the editor from that folder the scope is built (this
> take some seconds and for the moment I can leave with that); when
> another file from the same folder is opened too, the scope is rebuilt,
> and that's something I would avoid.
> How can I share the scope between files/resources?
>
> Thanks,
> Stefano
Re: Sharing imported dsl files witch custom URI [message #500094 is a reply to message #494364] Tue, 24 November 2009 23:05 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sebastian,
thank you for your reply and sorry for my late late response.

I'm not sure about my approach too.. I think I'm going the hard way when maybe there is something easy and clean...
I took some time to have a look at the Index project, read Sven's posts and also downloaded sample projects (I try to create a model but doesn't seem to behave in the way I'm looking for )
I can understand the whole concept of index but maybe I'm missing some crucial point.

As you could have noticed from this and other threads of mine I have a couple of behaviors I would aim at, and that I resume here:
- a main dsl file specifies the imported files (specified in the form of path\filename) and that's ok
- all files in the same folder "see" each others model's elements without any "explicit " import statement inside those files
- the whole "pool" of elements, that I image to be the Index (entirely shared between files) will be updated/rebuild in a clever way (due to the large number of model elements I'm dealing with) only when necessary

Could you suggest an approach.. in particular your thinking about the usability of index in this case.

Thank you very much for your patience.
Cheers
Ste
Re: Sharing imported dsl files witch custom URI [message #500131 is a reply to message #500094] Wed, 25 November 2009 07:21 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Stefano,

> I can understand the whole concept of index but maybe I'm missing some
> crucial point.
> As you could have noticed from this and other threads of mine I have a
> couple of behaviors I would aim at, and that I resume here:
> - a main dsl file specifies the imported files (specified in the form of
> path\filename) and that's ok

Ok, so you use the importUri stuff for that, right?

> - all files in the same folder "see" each others model's elements
> without any "explicit " import statement inside those files

For that, you'll need some definition of what I call "the outer world".
In the UI this can be done by the builder, which remembers the exported
elements for each resource and remembers the "container" the resource
lives in.

> - the whole "pool" of elements, that I image to be the Index (entirely
> shared between files) will be updated/rebuild in a clever way (due to
> the large number of model elements I'm dealing with) only when necessary
> Could you suggest an approach.. in particular your thinking about the
> usability of index in this case.

That is what the new Xtext builder will do for you.

But I guess you'll have to wait at least for the next milestone. And
have to expect breaking changes between the following milestones (until M6).

Cheers,
Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: Sharing imported dsl files witch custom URI [message #500400 is a reply to message #500131] Wed, 25 November 2009 22:20 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi Sven,

yes I use importURI stuff in the first case and it works just fine.

About what you call "the outer world" do I have to bind a custom builder? What class should I extend?

And of course the development of Xtext (and tools) seems really promising.. I will stay tuned about next releases.
Now I'm on galileo but I see that most of the breaking through stuff is coming on the latest builds of 0.8.0 ...should you suggest to move to helios 3.6 now? I suppose latest xtext builds are not intended for galileo, am I right?

Thank you for your support
Ste
Re: Sharing imported dsl files witch custom URI [message #500473 is a reply to message #500400] Thu, 26 November 2009 09:50 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Stefano Cottafavi schrieb:
> Hi Sven,
>
> yes I use importURI stuff in the first case and it works just fine.
>
> About what you call "the outer world" do I have to bind a custom
> builder? What class should I extend?

In 0.7.2 we only support importURI out of the box.
If you want to implement what you desire, you'll have to write quite a
bit of code.

>
> And of course the development of Xtext (and tools) seems really
> promising.. I will stay tuned about next releases.
> Now I'm on galileo but I see that most of the breaking through stuff is
> coming on the latest builds of 0.8.0 ...should you suggest to move to
> helios 3.6 now? I suppose latest xtext builds are not intended for
> galileo, am I right?

If it works, it works with Galileo ;-)
I do not recommend to use the milestones. If you like adventures, you're
of course welcome and any feedback is appreciated. But be warned we
often throw new things away completely, because we didn't get it right
in the first place.

That is at least the case until M6.

Cheers,
Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Previous Topic:Serialization & formatting
Next Topic:Organize imports on generated code
Goto Forum:
  


Current Time: Wed Jul 17 03:29:29 GMT 2024

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

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

Back to the top