| Iterating over extensions [message #541996] |
Wed, 23 June 2010 09:38  |
Nadya 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 06:02  |
Christian Dietrich Messages: 4426 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
[Updated on: Thu, 08 July 2010 06:21] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.01461 seconds