Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Calling acceleo from a java method (IField) instead of a java class (IFile)
Calling acceleo from a java method (IField) instead of a java class (IFile) [message #705359] Fri, 29 July 2011 19:29 Go to next message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
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 (what are they?), 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
Re: Calling acceleo from a java method (IField) instead of a java class (IFile) [message #707114 is a reply to message #705359] Mon, 01 August 2011 08:57 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi Kenji,

The generated UI project is there to help people get a generic example of how to integrate an Acceleo generation with Eclipse. For this, proposing generation on IFiles is the most usual use case, while generating on IFields seem counter-intuitive : with an "IFile", we can load an "EMF model", which in turn will serve as the input of the generation. However, with "IField"... I don't see the link to a model except if you use a Java metamodel and a "bridge" from a Java Compilation Unit to that metamodel.

This is something that is possible to know, it will just require some customization work on your part to make the generated UI module work on a Java file. I believe someone had made the necessary steps to launch an Acceleo generation on a Java file using MoDisco... maybe related to this?

Laurent Goubet
Obeo
Re: Calling acceleo from a java method (IField) instead of a java class (IFile) [message #708171 is a reply to message #707114] Tue, 02 August 2011 14:32 Go to previous message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
Hi Laurent

I understand and agree with your point.

What I had in mind is some way to let the user select a java class attribute and let him/her right click on it and call the code generator, passing the selected method as a parameter. But, yes, it is also expected to have a model somewhere because it is M2T transformation after all Wink

Thanks

Kenji
Previous Topic:how to generate an acceleo plugin
Next Topic:[Acceleo 3.1] Problem launching transformation
Goto Forum:
  


Current Time: Fri Apr 19 08:33:30 GMT 2024

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

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

Back to the top