Home » Modeling » TMF (Xtext) » Sharing imported dsl files witch custom URI
Sharing imported dsl files witch custom URI [message #61741] |
Tue, 21 July 2009 03:46  |
Eclipse User |
|
|
|
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 #481743 is a reply to message #481705] |
Mon, 24 August 2009 03:47   |
Eclipse User |
|
|
|
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 #487209 is a reply to message #487100] |
Tue, 22 September 2009 09:08   |
Eclipse User |
|
|
|
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 #493369 is a reply to message #61741] |
Sun, 25 October 2009 07:42   |
Eclipse User |
|
|
|
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 08:11   |
Eclipse User |
|
|
|
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 #500473 is a reply to message #500400] |
Thu, 26 November 2009 04:50  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Fri May 02 07:45:25 EDT 2025
Powered by FUDForum. Page generated in 0.05274 seconds
|