Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Iterating over extensions
Iterating over extensions [message #541996] Wed, 23 June 2010 13:38 Go to next message
Nadya is currently offline NadyaFriend
Messages: 1
Registered: June 2010
Junior Member
Hello,

I want to use my extension file as a library where I storage different functions. In order to implement a matching method which picks a function from the library for me, I want to iterate over the extensions (i.e. these functions) from a Java class. XtendFacade has not an access to the extensions. Has anyone here an idea how can I do that? Thanks for your comments!

Regards, Nadya
Re: Iterating over extensions [message #545575 is a reply to message #541996] Thu, 08 July 2010 10:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi, it is right that the extension facade hides this but a look into its code shows that something like this can done:

import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Resource;
import org.eclipse.xtend.expression.TypeSystemImpl;
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;


public class Main {
	
	public static void main(String[] args) {
		ExecutionContext executionContext = createExecutionContext("template::test");
		((ExecutionContextImpl)executionContext).registerMetaModel(new JavaBeansMetaModel());
		
		for (Extension e : executionContext.getAllExtensions()) {
			System.out.println(e);
		}
	}
	
	private static ExecutionContext createExecutionContext(final String... extensions) {
		ExecutionContext executionContext = new ExecutionContextImpl(new TypeSystemImpl());
		executionContext = executionContext.cloneWithResource(new Resource() {

			public String getFullyQualifiedName() {
				return null;
			}

			public void setFullyQualifiedName(final String fqn) {

			}

			public String[] getImportedNamespaces() {
				return null;
			}

			public String[] getImportedExtensions() {
				return extensions;
			}
		});
		return executionContext;
	}

}



This prints all extensions in the given extension file.
This might solve your problem although i do not understand your usecase.

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 08 July 2010 10:21]

Report message to a moderator

Previous Topic:[XPAND] WorkflowInterruptedException: EvaluationException : Nullevaluation
Next Topic:[xpand] fixed indentation
Goto Forum:
  


Current Time: Fri Apr 26 21:29:34 GMT 2024

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

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

Back to the top