triggering acceleo from a java method instead of file [message #704598] |
Thu, 28 July 2011 20:45 |
Eclipse User |
|
|
|
Hi
generating an acceleo UI project is great, but it allows me to bind a command to an eclipse file
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.presto"
id="br.com.spread.acceleo.presto.ui.popupMenus.contribution.IFile">
it would be great if I could, instead, bind the generation action to a java method. In order to do that, the generated UI project should include JDT, so I could associate the action to org.eclipse.jdt.core.IField
so I could get the field just like this
private IField[] getSelectedFields(IStructuredSelection selection) {
List elements= selection.toList();
if (elements.size() > 0) {
IField[] result= new IField[elements.size()];
ICompilationUnit unit= null;
for (int index= 0; index < elements.size(); index++) {
if (elements.get(index) instanceof IField) {
IField field= (IField) elements.get(index);
if (index == 0) {
// remember the CU of the first element
unit= field.getCompilationUnit();
if (unit == null) {
return null;
}
} else if (!unit.equals(field.getCompilationUnit())) {
// all fields must be in the same CU
return null;
}
try {
final IType type= field.getDeclaringType();
if (type.isInterface() || type.isAnonymous()) {
return null;
}
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
return null;
}
result[index]= field;
} else {
return null;
}
}
return result;
}
return null;
}
of course, the generated acceleo ui project should include all the JDT plugins dependencies, and it would be less generic, but much better for java code generation.
do you guys this could be a good approach? Or is there a better way?
Thanks in advance
Kenji
|
|
|
Powered by
FUDForum. Page generated in 0.02741 seconds