Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using Xtext to generate Java Code Snippet / Templates Editor?
Using Xtext to generate Java Code Snippet / Templates Editor? [message #641390] Thu, 25 November 2010 10:18 Go to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Hi all.

I'm thinking about a code snippets recommender in Eclipse that allows (among other things) developers to specify and share their own code templates with others. Therefore, I'm currently evaluating whether Xtext can be used to generate a full-featured editor for building such code snippets á la SWT templates.

Here are two examples of what I want to express with Xtext:

if (${name} instanceof ${type}) {
    ${type} ${new_name} = (${type})${name};
    ${cursor}
}


and
${compositeType:newType(org.eclipse.swt.widgets.Composite)} ${composite:newName(org.eclipse.swt.widgets.Composite)}= new ${compositeType}(${parent:var(org.eclipse.swt.widgets.Composite)}, ${style:link(SWT.NONE, SWT.BORDER)});
${composite}.setLayoutData(new ${gridDataType:newType(org.eclipse.swt.layout.GridData)}(SWT.${horizontal:link(FILL, BEGINNING, CENTER, END)}, SWT.${vertical:link(FILL, TOP, CENTER, BOTTOM)}, ${hex:link(true, false)}, ${vex:link(true, false)}));
${composite}.setLayout(new ${layoutType:newType(org.eclipse.swt.layout.GridLayout)}(${numberColumns:link(1, 2, 3, 4, 5)}, ${equalColumns:link(false, true)}));
${imp:import(org.eclipse.swt.SWT)}${cursor}


These examples are taken from the "java statement" snippet defined under Eclipse->Preferences->Java->Editor->Templates. They use the JFace Template Language.

In general don't have to use the JFace template language. Something similar could work. But at the end the language has to express some kind of java code...

What do you think? Is Xtext an appropriate choice for this kind of task?

best,
Marcel

[Updated on: Thu, 25 November 2010 11:22]

Report message to a moderator

Re: Using Xtext to generate Java Code Snippet / Templates Editor? [message #641403 is a reply to message #641390] Thu, 25 November 2010 10:48 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marcel,

in fact we have something similar in the pipeline for the preference
page editor for Xtext based languages (currently available from source
build only). This may serve as a starting point for your solution:
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plug ins/org.eclipse.xtext.ui.codetemplates

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

Am 25.11.10 11:18, schrieb Marcel Bruch:
> Hi all.
>
> I'm thinking about a code snippets recommender in Eclipse that allows
> (among other things) developers to specify and share their own code
> templates with others. Therefore, I'm currently evaluating whether Xtext
> can be used to generate a full-featured editor for building such code
> snippets á la SWT templates.
>
> Here are two examples of what I want to express with Xtext:
>
>
> if (${name} instanceof ${type}) {
> ${type} ${new_name} = (${type})${name};
> ${cursor}
> }
>
>
> and
> ${compositeType:newType(org.eclipse.swt.widgets.Composite)}
> ${composite:newName(org.eclipse.swt.widgets.Composite)}= new
> ${compositeType}(${parent:var(org.eclipse.swt.widgets.Compos ite)},
> ${style:link(SWT.NONE, SWT.BORDER)});
> ${composite}.setLayoutData(new
> ${gridDataType:newType(org.eclipse.swt.layout.GridData)}(SWT .${horizontal:link(FILL,
> BEGINNING, CENTER, END)}, SWT.${vertical:link(FILL, TOP, CENTER,
> BOTTOM)}, ${hex:link(true, false)}, ${vex:link(true, false)}));
> ${composite}.setLayout(new
> ${layoutType:newType(org.eclipse.swt.layout.GridLayout)}(${n umberColumns:link(1,
> 2, 3, 4, 5)}, ${equalColumns:link(false, true)}));
> ${imp:import(org.eclipse.swt.SWT)}${cursor}
>
>
> These exampels are taken from the "java statement" snippet defined under
> Eclipse->Preferences->Java->Editor->Templates. They use the JFace
> Template Language.
>
> In general I'm don't have to use the JFace template language. Something
> similar could work. But at the end the language has to express some kind
> of java code...
>
> What do you think. Is Xtext an appropriate choice for this kind of task?
>
> best,
> Marcel
Re: Using Xtext to generate Java Code Snippet / Templates Editor? [message #642875 is a reply to message #641403] Fri, 03 December 2010 07:20 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Hi Sebastian.

Last time the browser killed my post because of a login timeout. Thus, this post gets much shorter Smile

Your code templates example actually looks like a good starting point. Thanks! Last week I found a student who will work on this topic during a hands-on training now. I'm curious how far she gets with Xtext and JFace template language in the next weeks.

best,
Marcel
Re: Using Xtext to generate Java Code Snippet / Templates Editor? [message #642879 is a reply to message #642875] Fri, 03 December 2010 07:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marcel,

thanks for coming back to this one. Please keep me posted about her
progress.

Btw: I'm using a dedicated news reader (thunderbird) which doesn't
suffer from timeouts. However, my posts are often even shorter :-)

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

Am 03.12.10 08:20, schrieb Marcel Bruch:
> Hi Sebastian.
>
> Last time the browser killed my post because of a login timeout. Thus,
> this post gets much shorter :)
>
> Your code templates example actually looks like a good starting point.
> Thanks! Last week I found a student who will work on this topic during a
> hands-on training now. I'm curious how far she gets with Xtext and JFace
> template language in the next weeks.
>
> best,
> Marcel
Re: Using Xtext to generate Java Code Snippet / Templates Editor? [message #651165 is a reply to message #642879] Fri, 28 January 2011 06:16 Go to previous message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Hi Sebastian,

brief update on this:
The hands-on was canceled by the student. However, a master thesis starts in March which - among other things - will include building the template store. I'm confident that this will work Smile

Best,
Marcel
Previous Topic:severe performance problem / infinite loop? in AbstractInternalAntlrParser
Next Topic:issues when importing grammar
Goto Forum:
  


Current Time: Fri Apr 19 09:02:19 GMT 2024

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

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

Back to the top