GWT/JavaScript code generation tool

179 views
Skip to first unread message

dhoffer

unread,
Dec 11, 2013, 12:19:12 PM12/11/13
to google-we...@googlegroups.com
Are there any tools out there that can auto generate the GWT wrapper code for native JavaScript code?  I'm looking for a way to automate using JavaScript in GWT applications, sometimes it's best to start with an existing JavaScript client library and wrap for use in GWT.  I have in mind the CometD JS client library for instance.  Ideally I'd like to integrate this with the maven build.  What I'm looking for is exactly like SWIG for generating wrapper code from existing C/C++ code.

-Dave

Juan Pablo Gardella

unread,
Dec 11, 2013, 1:20:54 PM12/11/13
to google-we...@googlegroups.com
I like a tool for that. If some tool exists, GWT will be very attractive because currently a big problem is that is not very easy reuse javascript libs.


2013/12/11 dhoffer <dhof...@gmail.com>
Are there any tools out there that can auto generate the GWT wrapper code for native JavaScript code?  I'm looking for a way to automate using JavaScript in GWT applications, sometimes it's best to start with an existing JavaScript client library and wrap for use in GWT.  I have in mind the CometD JS client library for instance.  Ideally I'd like to integrate this with the maven build.  What I'm looking for is exactly like SWIG for generating wrapper code from existing C/C++ code.

-Dave

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

David Hoffer

unread,
Dec 11, 2013, 1:27:11 PM12/11/13
to Google Web Toolkit
Right, seems it would have a wide range of uses and could jump-start the usage of GWT.  I wonder if the SWIG folks have looked at this, it seems perfect and an easy use case for them...except that the source is JS instead of C/C++.

-Dave


--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/GkvZUIs2knY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

Alain Ekambi

unread,
Dec 11, 2013, 1:28:00 PM12/11/13
to google-we...@googlegroups.com
What about writing a wrapper ? 
I m not sure it s even possible to "auto wrap"  everything exisiting  js library.
I m writing a wrapper for Ext JS and  there are some "places"   that I m not sure they can be auto generated.


2013/12/11 Juan Pablo Gardella <gardella...@gmail.com>

Juan Pablo Gardella

unread,
Dec 11, 2013, 1:33:24 PM12/11/13
to google-we...@googlegroups.com
It is more easy if we have a tool that writes the wrapper for us, but for now I suppose this tool does not exist, but will be very useful.


2013/12/11 Alain Ekambi <jazzma...@gmail.com>

Alain Ekambi

unread,
Dec 11, 2013, 1:40:51 PM12/11/13
to google-we...@googlegroups.com
Would be nice. I m just not sure if that can work for every JS library out there.
I heard that GWT 3 will have a better interop with JS libraries.
Just not sure how that will work.

David Hoffer

unread,
Dec 11, 2013, 1:42:20 PM12/11/13
to Google Web Toolkit
Alain,

Your in the process of writing a wrapper so you might know if there are technical hurdles that would prevent this...but I think it would be possible.  The folks at SWIG manage to auto generate wrapper code starting with incredibly complex C++ code and manage to generate perfectly fine Java wrapper code (as well as about a dozen other languages)...so it seems that it would be possible.

-Dave


You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/GkvZUIs2knY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.

David Hoffer

unread,
Dec 11, 2013, 1:48:37 PM12/11/13
to Google Web Toolkit
Alain,

This is off topic...but you said your writing a GWT wrapper for Ext JS?  Why not just use GXT (Sencha's pure GWT library)?

-Dave

Alain Ekambi

unread,
Dec 11, 2013, 1:48:48 PM12/11/13
to google-we...@googlegroups.com
Unlike C++ JavaScript is a dynamic language.
I m just not sure it s possible  for such a tool to generate descent wrapper for JS code.

For example take the following JS code

function doSomething(o){

}

How would a tool what the type of o is. Object ? Number ? String ? 

Commenting the code could be a solution (Like Closure does).
But  not all JS libraries have descent comment informations.

That s why I m saying I m not sure  how such a tool  would work for every given JS library.
But I might be wrong though.


2013/12/11 David Hoffer <dhof...@gmail.com>

Alain Ekambi

unread,
Dec 11, 2013, 2:02:03 PM12/11/13
to google-we...@googlegroups.com
@David

Good question. I actually get this question all the time.

Ext4j is for people that want to (or are already using) use Ext JS in their project.
Below are a coupe of reasons why I decided to write a wrapper instead of using GXT.
Which by the way  is a great tool but dont quit meet the requirements of my customers.


1) Licensing.
Most of my customers already have an Ext JS license and are not willing to pay for another product.
Since Ext4j wil be Apache nothing will change for existing Ext JS c users.

2) Develeopement Pace
Ext JS is always a step ahead of GXT when it comes to features, components, themes etc..

3) Community.
The Ext JS  community seems a bit more active than the GXT one. There for example way more extensions for Ext JS than GXT. One could argue that it s easy to create those in GXT but no one does.

4) Look and feel
This is a bit subjective but I found that Ext looks a bit better than GXT

5) Code Reuse.
People I work  for most of the time also want a mobile client next to their  desktop client. Ext4j will play more nicely with some  mobile wrappers I wrote. I could nt get GXT to work with  my existing tools.


So if you want to build on Top of Ext JS and add structure programming and the powerful Java ecosystem Ext4j could help.

Otherwise simply go with GXT.


2013/12/11 Alain Ekambi <jazzma...@gmail.com>

Jens

unread,
Dec 11, 2013, 2:19:26 PM12/11/13
to google-we...@googlegroups.com
For example take the following JS code

function doSomething(o){

}

How would a tool what the type of o is. Object ? Number ? String ? 


That's what I thought too and I think thats the reason why such a tool does not exist. JavaScript is too dynamic to make such code generation work reliably.

-- J.

David Hoffer

unread,
Dec 11, 2013, 2:24:34 PM12/11/13
to Google Web Toolkit
Okay sounds like you've thought about the GXT option/issues.

Alain Ekambi

unread,
Dec 11, 2013, 2:28:27 PM12/11/13
to google-we...@googlegroups.com
@David.
Yes. I did.
I ve been using GXT for a couple of years now. Even wrote some extensions.

But for the type of application I m working now Ext JS is the  framework  customers chooses.
So it was either do it in pure JS or write a wrapper. I choosed the second.

Hopefully other people will find this useful.

You can see a preview here by the way : http://eemi2010.github.io/ext4j

The first release should come out soon.


2013/12/11 David Hoffer <dhof...@gmail.com>

David Hoffer

unread,
Dec 11, 2013, 2:33:58 PM12/11/13
to Google Web Toolkit
How do you handle that same case when writing the wrapper manually?  Do you manually inspect the method to see what are allowed types and then define the java wrapper appropriately?  Or do you just go with Object and let the user of the wrapper code figure out what is allowed?  Again, this might be naive as I haven't tried to write a tool but I think I'd be okay with the tool just using Object to start with then it would be great if the tool allowed me to customize/tailor the type mapping once it's known what the allowed types are.  Not sure how that would be accomplished as one probably can't add comments/annotations to existing library code.  I'd love to see what the SWIG folks think about this there the experts on this sort of thing (I did post a message there).

-Dave


--

Alain Ekambi

unread,
Dec 11, 2013, 2:42:16 PM12/11/13
to google-we...@googlegroups.com
All the tools I wrote I looked at the docs and wrote each methods by hand.
Sometimes I even ran the code to see what type the method expects since some methods are not documented at all. Digging inside JS frameworks is an interesting adventure.
I ve seen some nasty things :)

Hard work I agree. But This gives me a better understanding of the libraries I m wrapping.
This  also gives me the chance to make the API more javaish.

If you are going to taylor the tool afterward you will have to go through the entire library anyway to make sure all methods are corrects.




2013/12/11 David Hoffer <dhof...@gmail.com>

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

Thomas Lefort

unread,
Dec 12, 2013, 4:07:39 PM12/12/13
to google-we...@googlegroups.com
What if there were some level of interaction? for instance "tick the types supported" whenever it's ambiguous, and then it generates accordingly.

Rogelio Flores

unread,
Dec 19, 2013, 9:46:43 PM12/19/13
to google-we...@googlegroups.com
You guys should look at the keynote Ray Cromwell gave at the GWT.create conference where he talked about JS Interop planned for GWT 3.0, which will use annotations to wrap more easily JS libraries within GWT code. One goal is to do something similar on the JS side (some type of JS annotations) to allow automatic generation of a GWT Wrapper from a given JS library:


There was also a presentation that covered more details:
Reply all
Reply to author
Forward
0 new messages