eol standalone failed to run native types [message #1771536] |
Sun, 27 August 2017 02:44  |
Eclipse User |
|
|
|
Hi,
I wanna to use eol standalone [1] to run my eol code with java. However, It failed to run native types. e.g., if I have the below code in my eol program:
var interfaceRule : new Native("layout.interfaceRule");
var mode : String = interfaceRule.callMode();
I have the below error:
Exception in thread "main" Type 'layout.interfaceRule' not found
at (/Users/apple/Desktop/w5/standalone1/src/org/eclipse/epsilon/examples/standalone/eol/Demo.eol@5:24-5:54)
at (/Users/apple/Desktop/w5/standalone1/src/org/eclipse/epsilon/examples/standalone/eol/Demo.eol@5:0-5:55)
at org.eclipse.epsilon.eol.types.EolNativeType.<init>(EolNativeType.java:37)
at org.eclipse.epsilon.eol.dom.TypeExpression.execute(TypeExpression.java:51)
at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
at org.eclipse.epsilon.eol.dom.VariableDeclaration.execute(VariableDeclaration.java:58)
at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
at org.eclipse.epsilon.eol.dom.ExpressionStatement.execute(ExpressionStatement.java:19)
at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
at org.eclipse.epsilon.eol.dom.StatementBlock.execute(StatementBlock.java:43)
at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST(ExecutorFactory.java:109)
at org.eclipse.epsilon.eol.EolModule.execute(EolModule.java:55)
at org.eclipse.epsilon.examples.standalone.EpsilonStandaloneExample.execute(EpsilonStandaloneExample.java:81)
at org.eclipse.epsilon.examples.standalone.EpsilonStandaloneExample.execute(EpsilonStandaloneExample.java:69)
at org.eclipse.epsilon.examples.standalone.eol.EolStandaloneExample.main(EolStandaloneExample.java:30)
I have an eol program which calls several native types. Is there any way to eol standalone can handle these statements?
[1]. https://eclipse.org/epsilon/examples/index.php?example=org.eclipse.epsilon.examples.standalone
[Updated on: Sun, 27 August 2017 03:10] by Moderator
|
|
|
|
|
|
|
Re: eol standalone failed to run native types [message #1771778 is a reply to message #1771709] |
Wed, 30 August 2017 06:26   |
Eclipse User |
|
|
|
Hi Banafsheh,
The native java support is implemented to work within Eclipse, so you will need a bit of extra work to make it work. In the current implementation, when you want to use your own Java native types you use an extension point to register your java class so that the EOL engine can find it when you do
var interfaceRule : new Native("layout.interfaceRule");
The ExtensionPointToolNativeTypeDelegate() you mention in your comment is the class responsible for find the native types. It does so by asking Eclipse about all plugins that have used the extension point to register native classes.
For a standalone scenario I think you need to provide your own type delegate, in the lines of:
public class MyNativeTypeDelegate extends AbstractToolNativeTypeDelegate{
public MyNativeTypeDelegate() {
}
public Object createInstance(String clazz, List<Object> parameters) throws EolRuntimeException {
return new InterfaceRule();
}
public boolean knowsAbout(String clazz) {
if (clazz == "layout.interfaceRule")
return true;
return false
}
}
The knowsAbout method is first called to test if the TypeDelegate knows how to create instances of that class, and the createInstance method instantiates the class. Note that this implementation is very fragile. Basically think of it as a factory for your Native types. You could improve it by supporting more types and passing the parameters to the constructor.
With your NativeTypeDelegate in place, then you can use it in your EOL standalone implementation:
...
public void execute() throws Exception {
module = createModule();
module.parse(getFileURI(getSource()));
if (module.getParseProblems().size() > 0) {
System.err.println("Parse errors occured...");
for (ParseProblem problem : module.getParseProblems()) {
System.err.println(problem.toString());
}
return;
}
module.getContext().getNativeTypeDelegates().
add(new MyNativeTypeDelegate());
for (IModel model : getModels()) {
module.getContext().getModelRepository().addModel(model);
}
for (Variable parameter : parameters) {
module.getContext().getFrameStack().put(parameter);
}
preProcess();
result = execute(module);
postProcess();
module.getContext().getModelRepository().dispose();
}
...
Note that you could have many TypeDelegates.
Another option, which might work, is using the EolClasspathNativeTypeDelegate, which adds the class path to the available native types. Which should in turn make all the classes in your standalone jar path available.
Cheers,
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04004 seconds