eol standalone failed to run native types [message #1771536] |
Sun, 27 August 2017 06:44 |
Banafsheh Azizi Messages: 328 Registered: July 2016 |
Senior Member |
|
|
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
Member of MDSE Research Group
http://mdse.ui.ac.ir
[Updated on: Sun, 27 August 2017 07:10] Report message to a moderator
|
|
|
|
|
Re: eol standalone failed to run native types [message #1771709 is a reply to message #1771541] |
Tue, 29 August 2017 18:18 |
Banafsheh Azizi Messages: 328 Registered: July 2016 |
Senior Member |
|
|
When I run your code, it doesn't have an error. However, e.g., with running the main function of EolStandaloneExample class of the attached minimal example, it has an error although the Native type is shown on Tools. I also attached the jar file of plugin.
Moreover, I read at the end of https://www.eclipse.org/epsilon/doc/articles/call-java-from-epsilon/ about adding the line of code "context.getNativeTypeDelegates().add(new ExtensionPointToolNativeTypeDelegate());". I don't really know where I should insert the line of code. By the way, when I insert "module.getContext().getNativeTypeDelegates().add(new ExtensionPointToolNativeTypeDelegate());" in the EpsilonStandaloneExample class. It doesn't effect (I still have an error because of the Native type).
Member of MDSE Research Group
http://mdse.ui.ac.ir
[Updated on: Tue, 29 August 2017 18:39] Report message to a moderator
|
|
|
|
Re: eol standalone failed to run native types [message #1771778 is a reply to message #1771709] |
Wed, 30 August 2017 10:26 |
|
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,
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
Re: eol standalone failed to run native types [message #1771829 is a reply to message #1771778] |
Thu, 31 August 2017 07:53 |
Banafsheh Azizi Messages: 328 Registered: July 2016 |
Senior Member |
|
|
Thanks all.
Thanos Zolotas wrote on Wed, 30 August 2017 09:31
I then tried to figure out if the project you provided is working or not. In my new Eclipse instance (this is important because I don't have haetae installed so in order to load all the plugins from the source code I checked-out I need to run a new Eclipse instance) I imported the project and run the main.
Do you import the pure project I send in new eclipse? Or you add some dependencies to it?
would you please share your project to I run it and check whether I have an error?
Member of MDSE Research Group
http://mdse.ui.ac.ir
[Updated on: Thu, 31 August 2017 08:53] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09458 seconds