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?

4
  • 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. Commented Mar 8, 2011 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. Commented Mar 8, 2011 at 10:17
  • possible duplicate of stackoverflow.com/questions/996646/… Commented Mar 8, 2011 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! Commented Mar 10, 2011 at 6:55

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Or use NB 7.2, when it is out. "The Source/Format action should work on packages, folders, source groups and projects" Details netbeans.org/bugzilla/show_bug.cgi?id=67397#c3
1

Jalopy

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.