aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to format code (Eclipse) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to format code (Eclipse)" Watch "How to format code (Eclipse)" New topic
Author

How to format code (Eclipse)

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
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

Joined: Oct 13, 2005
Posts: 40036
    
  28
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

    Joined: Mar 05, 2007
    Posts: 107
    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


    Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
    Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 16303
        
      21

    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.


    Customer surveys are for companies who didn't pay proper attention to begin with.
    Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 16303
        
      21

    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
     
    subject: How to format code (Eclipse)