[EMFTVM] Calling static methods [message #1402904] |
Fri, 18 July 2014 05:48  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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()
|
|
|
Powered by
FUDForum. Page generated in 0.06064 seconds