Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Organise imports in my DSL
Organise imports in my DSL [message #1062311] Fri, 07 June 2013 03:18 Go to next message
Alfredo Capozucca is currently offline Alfredo Capozucca
Messages: 12
Registered: November 2011
Junior Member
Hi,

I want to implement an import organizer for my DSL in the same manner that exists in Eclipse development environment (i.e. when you hit Shift + Crtl + O). I'm wondering what's the best (i.e. simplest) way to implement such a functionality using Xtext. Any advice is more than welcome.

Regards.
Re: Organise imports in my DSL [message #1062314 is a reply to message #1062311] Fri, 07 June 2013 03:21 Go to previous messageGo to next message
Alfredo Capozucca is currently offline Alfredo Capozucca
Messages: 12
Registered: November 2011
Junior Member
It might be worth adding that in my DSL imports are represented according to the following grammar rule

Import:
'import' importedNamespace=QualifiedName
;

QualifiedName: ID ('.' ID)*;
Re: Organise imports in my DSL [message #1062325 is a reply to message #1062314] Fri, 07 June 2013 04:25 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 655
Registered: July 2009
Senior Member
If you want to refer to Java types, use Xbase and add

importSection=XImportSection

in your grammar. You will get extensive tooling - organize imports,
content assist, validation - for free.

If not, you have to build it your own. Have a look at the classes around
org.eclipse.xtext.xbase.imports.ImportOrganizer
org.eclipse.xtext.xbase.imports.RewritableImportSection
to get the idea. But be warned: It's a lot of work.


Am 07.06.13 09:21, schrieb Alfredo Capozucca:
> It might be worth adding that in my DSL imports are represented
> according to the following grammar rule
>
> Import:
> 'import' importedNamespace=QualifiedName
> ;
>
> QualifiedName: ID ('.' ID)*;


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Organise imports in my DSL [message #1062339 is a reply to message #1062325] Fri, 07 June 2013 05:37 Go to previous messageGo to next message
Alfredo Capozucca is currently offline Alfredo Capozucca
Messages: 12
Registered: November 2011
Junior Member
Dear Jan,

Thanks for the tip. Wouldn't you consider refactoring as a choice to implement this functionality?

Regards.
Re: Organise imports in my DSL [message #1062345 is a reply to message #1062339] Fri, 07 June 2013 06:13 Go to previous message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 655
Registered: July 2009
Senior Member
That's of course your choice. The current implementation relies on the
Xbase/Xtype and the JvmModel, i.e. on Java types (inferred or native).
Depends on your target if it's worthwhile to refactor.

A complete solution involves a lot of services, e.g. content assist
(proposing a type automatically adds an import), validation (find unused
imports), UI (a dialog for choosing from ambiguous candidates),
refactoring, quickfix etc. That's what makes it complicated.

Am 07.06.13 11:37, schrieb Alfredo Capozucca:
> Dear Jan,
>
> Thanks for the tip. Wouldn't you consider refactoring as a choice to
> implement this functionality?
>
> Regards.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:How to set working directory for import URIs
Next Topic:Xtext unordered group
Goto Forum:
  


Current Time: Sun Apr 20 12:34:28 EDT 2014

Powered by FUDForum. Page generated in 0.01822 seconds