On 29 mai, 02:18, Vitali Lovich <[email protected]> wrote:
> It would be nice if there was a way to wrap Java methods with an opaque
> Javascript function object so that you could pass them around in the native
> code (obviously there are issues with compiler optimizations in this case).
> Ideally, you would be also able to execute any Javascript function object
> from within Java code, although that does present some problems.
>
> Thoughts?
You should be able to code something like this with a generator,
resulting in code such as the following; but I'm not sure it really is
worth it, compared to coding the same JSNI by hand...
interface MyMethods extends Methods
{
@Method("foo(I)")
JavaScriptObject foo(MyClass instance);
@StaticMethod(MyClass.class, "bar(Ljava/lang/String;)")
JavaScriptObject bar();
}
...
MyMethods methods = GWT.create(MyMethods.class);
callSomeJSNI(methods.foo(myClassInstance));
callSomeJSNI(methods.bar());
Where the generator would build such an implementation:
class MyMethodsImpl implements MyMethods
{
public native JavaScriptObject foo(MyClass instance) /*-{
return function(arg0) { [email protected]::foo(I)
(arg0); }
}-*/;
public native JavaScriptObject bar() /*-{
return @net.example.MyClass::bar(Ljava/lang/String;);
}-*/;
}
(where the bar() impl might require a wrapper function too)
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---