JSInterop handle JavaScript get/set function with the same name

394 views
Skip to first unread message

confile

unread,
Nov 3, 2014, 4:13:52 AM11/3/14
to google-web-tool...@googlegroups.com
Consider the following JavaScript functions:


// get draggable flag
var draggable = node.draggable();

// enable drag and drop
node.draggable(true);


I do not see how I can modle them in JsInterop. The following would not work:

@JsType(prototype = "$wnd.Kinetic.Node")

public interface KNode {

 void draggable(boolean value);

 boolean draggable();

}

The former would not work because overlaying in Java based on return type is forbidden. I also could not use @JsProperty because the getter and setter are JavaScript functions.

Is there another way to deal with this in JsInterop?




Goktug Gokdogan

unread,
Nov 3, 2014, 2:00:29 PM11/3/14
to google-web-toolkit-contributors
There is going to be a JsMethod to provide custom names to the method so that you can name the method as abc() and map it to xyx() in the js.

But before that I didn't understand why it doesn't work out of the box. You are not overloading based on return type; one of the methods has an argument and the other one doesn't have any?

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/862d9a24-3a07-4181-9cc0-17b7a26401ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

confile

unread,
Nov 3, 2014, 4:27:27 PM11/3/14
to google-web-tool...@googlegroups.com
Will the custom names method be part of the GWT 2.7 release? That would be great. I think with this method you can handle nearly everything with JsInterop.

When I tried the above JsType as Interface I get the following error: 

GET /recompile/mobilePhoneGapIOS
   Job test.mobile.MobilePhoneGapIOS_1_6
      starting job: test.mobile.MobilePhoneGapIOS_1_6
      binding: mgwt.density=xhigh
      Compiling module test.mobile.MobilePhoneGapIOS
         Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
         Tracing compile failure path for type 'org.test.kinetic.client.KNode'
            [ERROR] Errors in 'file:/Users/mg/Documents/Grails/GGTS3.5.1Test/test/src/gwt/org/test/kinetic/client/KNode.java'
               [ERROR] Line 22: JsType methods cannot overload another method.
            [ERROR] Errors in 'file:/Users/mg/Documents/Grails/GGTS3.5.1Test/test/src/gwt/org/test/kinetic/client/events/KNodeEventCallbackJSO.java'
               [ERROR] org.test.kinetic.client.events.KNodeEvent cannot be resolved to a type
            [ERROR] Errors in 'file:/Users/mg/Documents/Grails/GGTS3.5.1Test/test/src/gwt/org/test/kinetic/client/events/KNodeEvent.java'
               [ERROR] org.test.kinetic.client.KShape cannot be resolved to a type
            [ERROR] Errors in 'file:/Users/mg/Documents/Grails/GGTS3.5.1Test/test/src/gwt/org/test/kinetic/client/KShape.java'
               [ERROR] org.test.kinetic.client.KNode cannot be resolved to a type
         Computing all possible rebind results for 'test.mobile.client.app.photoEditor.PhotoEditor.Resources'
            Rebinding test.mobile.client.app.photoEditor.PhotoEditor.Resources
               Checking rule <generate-with class='com.googlecode.gwtphonegap.server.log.rebind.PhoneGapLogThresholdGenerator'/>
                  [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
         [ERROR] Errors in 'test/mobile/client/app/photoEditor/PhotoEditor.java'
            [ERROR] Line 67: Failed to resolve 'test.mobile.client.app.photoEditor.PhotoEditor.Resources' via deferred binding
         Unification traversed 510 fields and methods and 343 types. 15 are considered part of the current module and 15 had all of their fields and methods traversed.
         [WARN] Some stale types ([org.test.kinetic.client.KNode]) were not reprocessed as was expected. This is either a compiler bug or a Generator has legitimately stopped creating these types.
      [ERROR] Compiler returned false
      [WARN] recompile failed
      [WARN] continuing to serve previous version



Michael



Am Montag, 3. November 2014 20:00:29 UTC+1 schrieb Goktug Gokdogan:
There is going to be a JsMethod to provide custom names to the method so that you can name the method as abc() and map it to xyx() in the js.

But before that I didn't understand why it doesn't work out of the box. You are not overloading based on return type; one of the methods has an argument and the other one doesn't have any?
On Mon, Nov 3, 2014 at 1:13 AM, confile <michael....@googlemail.com> wrote:
Consider the following JavaScript functions:


// get draggable flag
var draggable = node.draggable();

// enable drag and drop
node.draggable(true);


I do not see how I can modle them in JsInterop. The following would not work:

@JsType(prototype = "$wnd.Kinetic.Node")

public interface KNode {

 void draggable(boolean value);

 boolean draggable();

}

The former would not work because overlaying in Java based on return type is forbidden. I also could not use @JsProperty because the getter and setter are JavaScript functions.

Is there another way to deal with this in JsInterop?




--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

Goktug Gokdogan

unread,
Nov 3, 2014, 6:15:10 PM11/3/14
to google-web-toolkit-contributors
Method overloading is supposed to be ok if there is no prototype is given, however in your case prototype is provided hence even if we fix it, it will not work for your case.

There two ways to cover your use case here. One is making var-args work (if it is not already working) so that you can do something like following to cover both in single method:

  boolean draggable(Object... args)

You can give it a try and see if works (but I doubt it will work right now).

The second way is to support overloading. We already decided to support overloading at least based on number of arguments and this scenario is covered under that.

However we don't have an ETA for this and 2.7 is already at RC1 so you need to wait for the next release.

To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/6dfbc8e7-9997-4918-aeb3-befea70bd9d2%40googlegroups.com.

confile

unread,
Nov 4, 2014, 3:22:52 AM11/4/14
to google-web-tool...@googlegroups.com
Well, this means that the following. You said your first solution does not work and the second one will be in the next release (so I guess you mean GWT 2.8) then there is no solution to this problem yet?

Steffi Müller

unread,
Nov 4, 2014, 4:22:15 AM11/4/14
to google-web-tool...@googlegroups.com
Hi Goktug, 

I have the same problem as described by Michael. In my case I get the same error

"JsType methods cannot overload another method."

It would be great if the JsInterop method overloading will be included in the GWT 2.7 final release. That makes things a lot more easy. 
 


Am Dienstag, 4. November 2014 00:15:10 UTC+1 schrieb Goktug Gokdogan:

Joost Gustavson

unread,
Nov 4, 2014, 6:40:15 AM11/4/14
to google-web-tool...@googlegroups.com
+1 same here. Hope this get solved in GWT 2.7 RC2.

Joost

Cristian Rinaldi

unread,
Nov 4, 2014, 7:56:46 AM11/4/14
to google-web-tool...@googlegroups.com
@Goktug:
   This news is great !!! 
   The issue of the overload was something he had already asked in another thread, it's good to read that will be supported. 

Thank you ...

confile

unread,
Nov 4, 2014, 9:04:03 AM11/4/14
to google-web-tool...@googlegroups.com
@Cristian I did not get what you say. Will this be part of GWT 2.7 release?

Cristian Rinaldi

unread,
Nov 4, 2014, 11:04:07 AM11/4/14
to google-web-tool...@googlegroups.com
@confile

  @goktug said "However we don't have an ETA for this and 2.7 is already at RC1 so you need to wait for the next release."
  This may mean:

  1) wait until the 2.7.0-rc2 or 
  2) wait until the next release of GWT (3.0.0) 

   In my opinion it is more likely to be version 3.0.0, because some things are missing, and many come with Java 8 support. 

   Perhaps @goktug can clarify the picture. 

Greetings.

Goktug Gokdogan

unread,
Nov 4, 2014, 3:04:29 PM11/4/14
to google-web-toolkit-contributors
Sorry guys. When I said next release, I meant next major release (2.8 or 3.0).

To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/e1e7513e-dbb0-4326-934c-8cbd2e720aba%40googlegroups.com.

Cristian Rinaldi

unread,
Nov 4, 2014, 4:54:34 PM11/4/14
to google-web-tool...@googlegroups.com
@goktug I saw in the repositories, there GWT 2.8.0-SNAPSHOT, what does it mean? 
It is there where we find changes support java 8 and other changes that have to do with jsInterop?

Jens

unread,
Nov 4, 2014, 5:17:58 PM11/4/14
to google-web-tool...@googlegroups.com
@goktug I saw in the repositories, there GWT 2.8.0-SNAPSHOT, what does it mean? 
It is there where we find changes support java 8 and other changes that have to do with jsInterop?

2.8.0-SNAPSHOT is the daily snapshot build of the git master branch. So if you want the latest version of GWT then you should use 2.8.0-SNAPSHOT. 

-- J.

Cristian Rinaldi

unread,
Nov 4, 2014, 5:24:23 PM11/4/14
to google-web-tool...@googlegroups.com
Thanks @Jens!!

confile

unread,
Nov 5, 2014, 4:24:06 AM11/5/14
to google-web-tool...@googlegroups.com
I also tried method overlaying based on Parameter types.

@JsType(prototype = "$wnd.Kinetic.Node")
public interface KNode {
void fire(String eventType, JavaScriptObject evt, KNodeEventCallbackJSO option);
void fire(String eventType);
}

This does not work. I get the following error:

[ERROR] Line 100: JsType methods cannot overload another method.

   [ERROR] Aborting compile due to errors in some input files

Ray Cromwell

unread,
Nov 5, 2014, 5:27:28 AM11/5/14
to google-web-toolkit-contributors
Overloads are currently not allowed except for @JsProperty setters and
getters in C-style initializer pattern, e.g

interface Foo {
@JsProperty
void x(int a); // this is a setter
@JsProperty
int x(); // this is a getter
}

We plan to relax this restriction in the future. @JsMethod will be the
short term workaround coming soon.
>>>>>>>>>> google-web-toolkit-co...@googlegroups.com.
>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/862d9a24-3a07-4181-9cc0-17b7a26401ee%40googlegroups.com.
>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "GWT Contributors" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to
>>>>>>>> google-web-toolkit-co...@googlegroups.com.
>>>>>>>> To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/6dfbc8e7-9997-4918-aeb3-befea70bd9d2%40googlegroups.com.
>>>>>>>>
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "GWT Contributors" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to google-web-toolkit-co...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-co...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/936ecb2f-4c1d-483a-ab8e-7d958b951777%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages