Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] Lists in JAVA extensions
[Xtend] Lists in JAVA extensions [message #536729] Sun, 30 May 2010 13:31 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 328
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 #536732 is a reply to message #536729] Sun, 30 May 2010 14:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hello Hauke,

the extension / java class you defined looks ok and work in my hello world example.

The exception you get hints to some configuration / metamodel / classpath problem so please veryfy that the configuration is correct and that everything can be found on the classpath.

Regards, Christian

Re: [Xtend] Lists in JAVA extensions [message #536733 is a reply to message #536729] Sun, 30 May 2010 14:52 Go to previous messageGo to next message
Gerd Kainz is currently offline Gerd KainzFriend
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 14:53]

Report message to a moderator

Re: [Xtend] Lists in JAVA extensions [message #536752 is a reply to message #536733] Sun, 30 May 2010 17:09 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
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 on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Xtend] Lists in JAVA extensions [message #536753 is a reply to message #536729] Sun, 30 May 2010 17:10 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
Hauke,

how and from where do you call the extension?

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Xtend] Lists in JAVA extensions [message #536771 is a reply to message #536753] Sun, 30 May 2010 19:15 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 328
Registered: July 2009
Senior Member
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
Re: [Xtend] Lists in JAVA extensions [message #536780 is a reply to message #536771] Sun, 30 May 2010 21:36 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
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 on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Xtend] Lists in JAVA extensions [message #536781 is a reply to message #536771] Sun, 30 May 2010 21:47 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 328
Registered: July 2009
Senior Member
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?

A strange workaround is to wrap the EntityType parameter in a List. That
works.

Hauke
Re: [Xtend] Lists in JAVA extensions [message #536807 is a reply to message #536781] Mon, 31 May 2010 06:18 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
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 on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Xtend] Lists in JAVA extensions [message #536931 is a reply to message #536807] Mon, 31 May 2010 14:30 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 328
Registered: July 2009
Senior Member
Sven Efftinge schrieb:
> What makes this type 'custom' (i.e. special)?

Well, its some instance object of my metamodel. So it's not really
special. But it's not a primitive.

> 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.

I call it from a Java plugin in a command handler. If you want to see it:

http://rtsys.informatik.uni-kiel.de/trac/kieler/browser/trun k/plugins/de.cau.cs.kieler.core.model/src/de/cau/cs/kieler/c ore/model/util/XtendTransformationUtil.java?rev=5980

Cheers,
Hauke
Re: [Xtend] Lists in JAVA extensions [message #536983 is a reply to message #536931] Mon, 31 May 2010 19:08 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
Mmhh.. could it be that the model consists of instances of a different
EPackage? I mean a different instance, maybe a dynamic?

Hauke Fuhrmann schrieb:
> Sven Efftinge schrieb:
>> What makes this type 'custom' (i.e. special)?
>
> Well, its some instance object of my metamodel. So it's not really
> special. But it's not a primitive.
>
>> 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.
>
> I call it from a Java plugin in a command handler. If you want to see it:
>
> http://rtsys.informatik.uni-kiel.de/trac/kieler/browser/trun k/plugins/de.cau.cs.kieler.core.model/src/de/cau/cs/kieler/c ore/model/util/XtendTransformationUtil.java?rev=5980
>
>
> Cheers,
> Hauke


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:[Acceleo] How to generate code from Actions in Activity diagram in control flow order?
Next Topic:XPAND 1.0.0
Goto Forum:
  


Current Time: Thu Nov 27 23:43:46 GMT 2014

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

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