7

I wrote code generator that creates Java and C++ source code from custom IDL using Antlr. It works perfectly except for the Java code formatting. Currently I use Gnu Indent, but the format that it spits out is hardly readable and makes debugging a pain. I would love to use the same code formatter as NetBeans does (like when you press Alt+Shift+F) to format the generated files. What I do not want is to go through each of these files and manually pressing Alt+Shift+F. I tried using the NetBeans API, but either I am not looking in the right places or Google is being an idiot, I cannot find a proper working example to do this on files not loaded in the editor...

Can someone at least guide me towards the right direction for this?

NeoAcheron
  • 111
  • 6
  • 1
    In Eclipse you can execute the "format code" shortcut while the project (or a folder/package) is select and every Java source inside of it will be formatted. Maybe this works in Netbeans as well. – Joachim Sauer Mar 08 '11 at 10:13
  • I want to do this from my code generator, it can be run from the command line as well, which should spit out nicely formatted Java. – NeoAcheron Mar 08 '11 at 10:17
  • possible duplicate of http://stackoverflow.com/questions/996646/stand-alone-java-code-formatter-beautifier-pretty-printer – Martin Klinke Mar 08 '11 at 22:58
  • Not interested in a stand alone application to invoke after my source has been generated. I am already using GNU Indent to do this, and it feels slow! It takes about 5 minutes on a fast machine to go through all the generated source! – NeoAcheron Mar 10 '11 at 06:55

2 Answers2

3

You could use the following plugin http://plugins.netbeans.org/plugin/18365/format-files

Ben
  • 2,155
  • 16
  • 16
  • 1
    Or use NB 7.2, when it is out. "The Source/Format action should work on packages, folders, source groups and projects" Details https://www.netbeans.org/bugzilla/show_bug.cgi?id=67397#c3 – Ben May 06 '12 at 16:38
1

Jalopy

Harsha Hulageri
  • 2,760
  • 1
  • 20
  • 23
  • 1
    Have you ever tried using Jalopy in your code? The open source version hasn't been active for the past 6 years... I am not willing to pay for commercial version, the NetBeans API can do it already and its free. – NeoAcheron Mar 10 '11 at 06:48