Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Working with JSNI

The Google Plugin for Eclipse adds special treatment for one particular feature of GWT: JavaScript Native Interface (JSNI) .

JSNI Methods

With GWT, you can embed raw JavaScript directly into your web applications with JSNI methods. JSNI methods are declared as native Java methods and contain inline JavaScript code within a specially-formatted multi-line comment to hide it from the Java compiler. However, this means that by default, Eclipse treats JSNI method bodies as regular Java comments.

The Google plugin, however, understands JSNI methods and makes working with embedded JavaScript nearly as easy as editing your regular Java code. It provides syntax coloring and auto-indent functionality.

JSNI code

Java References from JSNI

JSNI methods often refer to fields or classes defined in your application's Java source. The plugin provides several features to make referencing Java from JSNI easier.

Auto-completion

JSNI Java ref completion

Validation

The plugin validates Java references and alerts you when one is broken.

Note: You can change the default severity of any type of problem with Preferences > Google > Errors/Warnings .

JSNI validation

Search Integration

Java references inside JSNI are also included when you perform a Java Search.

JSNI search

Refactoring Integration

When you refactor a referenced Java class or member, the JSNI references will be updated as well.

JSNI refactoring

JSNI Method Body Auto-completion

GWT 1.5 introduced JavaScript Overlay Types , which are Java classes that act as thin wrappers around actual JavaScript objects. The plugin makes it a snap to implement overlay types, by providing code-completions for generating the most common JSNI method bodies. Just hit Ctrl-Space at the end of a JSNI instance method signature.

JSNI body completions

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.