File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to format code (Eclipse)

 
amit sharma
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get Eclipse project from my friend.The code is not properly indented .It very difficult to read the code.How can i format the code in eclipse.
Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Eclipse, try
  • Highlight the part of the code you wish to indent
  • You can push ctrl-A to highlight all the code if you prefer
  • Push ctrl-I to indent it
  • Voila!
  • CR
     
    Sunil Vasudevan
    Ranch Hand
    Posts: 107
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you need to create a template for code formatting and format any class file you need then follow the steps mentioned below:

    1. Go to the Menu Windows -> Preferences.

    2. in Preferences window, navigate to Java -> Code Style -> Formatter.
    Here you have a built-in formatter provided by Eclipse. If needed, you can create your own formatting configurations.

    3. To format your code, use short cut CTRL + Shift + F
     
    Tim Holloway
    Saloon Keeper
    Pie
    Posts: 17629
    39
    Android Eclipse IDE Linux
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    There's also at least one external plug-in that you can inject into Eclipse. It's named jalopy. It is an extremely flexible java formatter with all sorts of options. Back when the built-in Eclipse code formatter was rather crude and stupid, I used it extensively.

    Jalopy is available for multiple environments. I've used it from IntelliJ and from the command line as well as inside Eclipse.
     
    Tim Holloway
    Saloon Keeper
    Pie
    Posts: 17629
    39
    Android Eclipse IDE Linux
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Campbell Ritchie:
    On Eclipse, try
  • Highlight the part of the code you wish to indent
  • You can push ctrl-A to highlight all the code if you prefer
  • Push ctrl-I to indent it
  • Voila!
  • CR

    OR, if you have a whole project full of ugly code:

    1. Multi-select the files (or directories) of ugly code.

    2. Invoke the Source/Format menu command,
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic