Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » triggering acceleo from a java method instead of file
triggering acceleo from a java method instead of file [message #704598] Thu, 28 July 2011 20:45
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, 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
Previous Topic:Error when trying to make a New XML file
Next Topic:?? Could not publish to server (Glassfish) Helios
Goto Forum:
  


Current Time: Thu Dec 18 02:40:39 GMT 2014

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

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