| [Xtend] Lists in JAVA extensions [message #536729] |
Sun, 30 May 2010 09:31  |
Hauke Fuhrmann Messages: 319 Registered: July 2009 |
Senior Member |
|
|
Hi there,
for a Java internal calculation, I need to either
* pass a List as parameter to a JAVA extension or
* get a List as return value from a JAVA extension
How do I do those?
The Xtend reference does not say anything about return values of Java
extension methods at all. So how are they handled?
When I try one of these, I always get
"[Callable not found] - getPorts : getPorts"
--- xtend file
Void getPorts(List ports) :
JAVA my.PtolemyHelper.getPorts(java.util.List);
--- java file
public static void getPorts(java.util.List ports){
System.out.println("test");
}
It's the same when I change java.util.List with
org.eclipse.emf.common.util.EList.
So how can I pass an Xtend List to Java? And how could I return a Java
list to Xtend?
Cheers,
Hauke
|
|
|
|
| Re: [Xtend] Lists in JAVA extensions [message #536733 is a reply to message #536729] |
Sun, 30 May 2010 10:52   |
Gerd Kainz Messages: 23 Registered: May 2010 |
Junior Member |
|
|
Hi Hauke,
this might solve your problem.
Xtend:
List[Node] getPassedNodes(List[Node] nodes): JAVA javacode.Routing.getPassedNodes(java.util.List);
Java:
package javacode;
import org.eclipse.emf.common.util.BasicEList;
public class Routing {
public static List<Node> getPassedNodes(List<Node> nodes) {
List<Node> passedNodes;
passedNodes = new BasicEList<Node>();
passedNodes.addAll(nodes);
return passedNodes;
}
}
It's important that you specify the return type of your Xtend function even if you don't need to specify it for your Java method in Xtend.
As Alternative to BasicEList you can use any List implementation such as ArrayList.
Best regards,
Gerd
[Updated on: Sun, 30 May 2010 10:53] Report message to a moderator
|
|
|
| Re: [Xtend] Lists in JAVA extensions [message #536752 is a reply to message #536733] |
Sun, 30 May 2010 13:09   |
Sven Efftinge Messages: 1667 Registered: July 2009 |
Senior Member |
|
|
Hi Gerd,
Gerd Kainz schrieb:
> It's important that you specify the return type of your Xtend function
> even if you don't need to specify it for your Java method in Xtend.
In the case of Java extensions specifying return types is mandatory.
But Hauke used void/Void as the return type which is perfectly ok.
So I don't think that your suggestion solves the issue.
Sven
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
|
|
|
|
|
| Re: [Xtend] Lists in JAVA extensions [message #536780 is a reply to message #536771] |
Sun, 30 May 2010 17:36   |
Sven Efftinge Messages: 1667 Registered: July 2009 |
Senior Member |
|
|
I just tested it in a normal java process using the example the wizard
generates.
I was able to define the following two methods
List[Entity] entities(Model this) :
JAVA metamodel.Helper.getEntities(org.eclipse.emf.ecore.EObject);
Model model(List[Entity] this) :
JAVA metamodel.Helper.getModel(org.eclipse.emf.common.util.EList) ;
which were bound to the following two Java signatures:
public static EList<EObject> getEntities(EObject obj)
public static EObject getModel(EList<EObject> list)
No problem.
It seems that it has something to do with the OSGi context.
Sven
Hauke Fuhrmann schrieb:
> Sven Efftinge schrieb:
>> how and from where do you call the extension?
>
> Hmm... not sure I understand the question. I would say "the normal way"...
>
> I use the extension as a model-to-model transformation from a Workflow
> that I instanciated programmatically in Java code. I execute the
> transformation by an Eclipse UI command handler.
>
> The Xtend file is correctly found and all the rest of the transformation
> is running. The static Java method is in a Java class in the same plugin
> as the Xtend file and the command handler. A simple "test(String)" Java
> extension in the same file works without problems. Hence it must be a
> problem with the parameters somehow.
>
> Cheers,
> Hauke
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
|
|
|
|
| Re: [Xtend] Lists in JAVA extensions [message #536807 is a reply to message #536781] |
Mon, 31 May 2010 02:18   |
Sven Efftinge Messages: 1667 Registered: July 2009 |
Senior Member |
|
|
Hauke Fuhrmann schrieb:
> It looks like it's at all no problem with passing lists, but with
> another parameter (first I tried to reduce the example to a smaller
> case, which seems to actually not show the problem):
>
> --- xtend
> Void test(EntityType entity) :
> JAVA my.Test.test(my.metamodel.EntityType)
> ;
> --- java
> public static void test(EntityType test) {
> System.out.println(test.getName());
> }
>
> Then I get the [Callable not found] error.
> The generated my.metamodel code is in the same plugin. Is there a
> problem with passing such custom metamodel objects?
What makes this type 'custom' (i.e. special)?
What kind of meta model do you use? I suspect that you face the problem
when running the generator. If that is the case, please share the
configuration of your workflow, especially the metaModel part.
Sven
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07678 seconds