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 |
|
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 |
Sebastian Zarnekow 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 |
|
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
|
|
| | |
Goto Forum:
Current Time: Fri Apr 19 09:02:19 GMT 2024
Powered by FUDForum. Page generated in 0.01955 seconds
|