1

I would like to use the Google code style guidelines as an Eclipse code formatter. So, I imported this formatter XML definition file.

However, it disrupts GWT comments, which in my code start at the end of the line with /* -{ and continue on to multiple lines. The formatter pushes all these lines to the right margin.

GWT comments pushed to right

I set -{ }- as "on-off tags."

GWT in-comment tags

I also edited the formatter to not format any comments.

No comment-formatting

However, this misformatting still occurs.

How can I use the Google code-style but still keep GWT comments as-is?

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • I also would like to know. As a workround, I usually end up manually selecting the Java bits and using the formatter to format them. If you consolidate all your Javascript native methods (e.g. by moving them to the end of the class), it's not too much hassle. – ᴇʟᴇvᴀтᴇ Mar 03 '16 at 10:45
  • Did you try eclipse Checkstyle Plug-in ? You can install it from the eclipse market place. It works well for me, I haven't tried it with GWT though.. – Sashidhar Thallam Mar 03 '16 at 10:58
  • for me the formatting works, even without setting the formatter on/off. can you paste a complete example of the native method code that gets formatted?? – Tobika Mar 03 '16 at 12:39
  • @Shashidhar thank you, I will try that. – Joshua Fox Mar 04 '16 at 13:28
  • @tobika I'll try that, though it may take a few days. – Joshua Fox Mar 04 '16 at 13:29
  • just post seomthing like "public static native void yourMethod() /*-{ //Javascript here }-*/;" So i can see the formatting – Tobika Mar 04 '16 at 13:32

1 Answers1

1

You need to install the GWT Plugin for Eclipse (or the Google Plugin for Eclipse) and open Java source files with the GWT-aware editor. That way, JSNI is no longer seen as a simple comment and is formatted as JavaScript (using the JS formatter settings)

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks, I actually do have that. But apparently the Google formatter (the XML definition) which I found (separately from the plugin for Eclipse) is not JNSI-aware. Manually setting on/off tags does not work.I am using another formatter which does deal with it. – Joshua Fox Mar 07 '16 at 10:17
  • Hmm, are you sure this is related to the formatting definitions and not the editor? (right click, Open With…, GWT editor) If you see JSNI as comments, without syntactic coloration, then AFAICT you're not using the right editor. Now, formatting the whole project might behave differently. – Thomas Broyer Mar 07 '16 at 20:15
  • My goal is to autoformat the Java code. For this I am using a 'formatter'. – Joshua Fox Mar 08 '16 at 06:19