Skip to main content



      Home
Home » Modeling » ATL » [EMFTVM] Calling static methods
[EMFTVM] Calling static methods [message #1402904] Fri, 18 July 2014 05:48 Go to next message
Eclipse UserFriend
How do I call static methods of a class, which does not have constructor (if it is possible at all)? Let say I have a java class
package example.com;

class TheClass {
    public static int one() {return 1};
    public static int two() {return 2};
}


I need to call its methods inside atl/emftvm code, how do I do it?

This code
rule somerule {
    from s : MM!SomeClass
    to t : MM2!AnotheClass()
    do {
        "#native"!"example::com::TheClass".one();
    }
}

does not work.
Re: [EMFTVM] Calling static methods [message #1403453 is a reply to message #1402904] Wed, 23 July 2014 15:27 Go to previous message
Eclipse UserFriend
op 18-07-14 11:48, Maxim Gromov schreef:
> How do I call static methods of a class, which does not have constructor (if
> it is possible at all)? Let say I have a java class
>
> package example.com;
>
> class TheClass {
> public static int one() {return 1};
> public static int two() {return 2};
> }
>
>
> I need to call its methods inside atl/emftvm code, how do I do it?
>
> This code
>
> rule somerule {
> from s : MM!SomeClass
> to t : MM2!AnotheClass()
> do {
> "#native"!"example::com::TheClass".one();
> }
> }
>
> does not work.

ATL does not have static method invocation, but you can use reflection:

OclType::refInvokeStaticOperation(opname : String, arguments : Sequence(OclAny))

See also https://wiki.eclipse.org/ATL/EMFTVM#OclType_operations

SimpleOCL (https://code.google.com/a/eclipselabs.org/p/simpleocl/) does
implement static method invocation directly, but it's a bit overkill to use
for just a single static method call. In SimpleOCL, your call looks like this:

"#native"!"example::com::TheClass"::one()
Previous Topic:[ATL] Tool support for generating the xmi source model
Next Topic:Generate the XML file of an ATL Transformation
Goto Forum:
  


Current Time: Thu Sep 25 20:24:13 EDT 2025

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

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

Back to the top