Looking for Java code beautifier (or maybe not beautify, but something to make code more elegant) [closed]
Asked Answered
C

13

11

I don't know how to describe it, but I'm looking for a tool that makes suggestions to my code on how to be... more elegant.

For example to make a nested if() statement a switch statement. something like this. As I don't know how to describe my problem I don't know what to search for. I thing code beautifier do not specifically change statements, right?

Couthie answered 25/8, 2010 at 7:7 Comment(2)
can't really decide whether I should upvote this question or vote to close it. so I'll do neither :-)Riot
Agree above all suggestions. ps: Like manufaturing a Ferrari, handmade is inevitable for piece of art:)Bontebok
C
6

Have a look at IntelliJ IDEA "Intentions":

Chitchat answered 25/8, 2010 at 7:9 Comment(1)
That's pretty impressive. Things like intentions/Control Flow/Replace If with Switch really save a lot of time. Gotta look into idea again some time. +1Riot
C
3

Except for the auto-formatting and style checking your IDE provides, you may be interested in a static code analysis tool like Crap4J, or something from this list of SCA tools for Java. They help you improve the readability of your code, and warn you when you use error-prone constructs. There are IDE plugins for most tools to let you find bad code as you write it.

Cottingham answered 25/8, 2010 at 7:17 Comment(0)
V
3

You might want to have a look into Netbeans. It provides code hints, which point out common practices and mistakes.

Vaso answered 25/8, 2010 at 7:23 Comment(0)
D
1

You could use a tool like emmaecl, which integrates nicely with Eclipse.

You could also use something like Sonar which does quality analysis on your sources and provides metrics and hints on how to improve the code. Sonar is a web service you install. It would integrate nicely with an automated build tool like Hudson, but that's not required.

Dispose answered 25/8, 2010 at 7:17 Comment(0)
T
1

You seem to be looking for a tool that will help you improve not your code's visual appearance and consistency (this is what a beautifier does), but its higher-level structure. FindBugs is your friend. Besides locating real bugs in your code, it will also identify more than 80 bad coding practices and more than 60 dodgy constructs (see this list).

Thomasenathomasin answered 25/8, 2010 at 7:19 Comment(0)
S
1

Have a look at FindBugs and PMD for improving the quality of your Java source codes.

Have a look at this post for beautifying your Java source codes.

Sera answered 25/8, 2010 at 7:21 Comment(0)
H
1

You can use Artistic Style (works for C, C++, C# and Java) which has many options so you can set-up style you like.

You can use it either from command line or if you look hard you might find plugins for the mainstream IDEs (For what I know, it's integrated in KDevelop and there is plugin for Qt Creator).

Halftrack answered 25/8, 2010 at 7:30 Comment(0)
D
0

Most IDEs will have formatting capability. Eclipse, which is a free, OpenSource IDE, will format Java soruce files

Dallman answered 25/8, 2010 at 7:11 Comment(0)
F
0

Eclipse can format your code. You can customize it here: Window/Preferences/Java/Code Style

Maybe static code analysis tools like Findbugs or PMD could interesst you.

Footman answered 25/8, 2010 at 7:20 Comment(0)
D
0

Eclipse has a code "Clean Up" functionality. You can find it under

Window -> Preferences -> Java -> Code Style - Clean Up.

The nice thing about this is that you can check this preferences in with your project in SVN. This way if you have multiple people collaborating on a project you just define your code Clean Up options and maybe your Formatter options. This goes a long way to not having to define everything in coding guidelines (they are still necessary, but there's a lot of stuff you can now define via those options).

Danieledaniell answered 25/8, 2010 at 7:23 Comment(0)
P
0

You might also want to explore Checkstyle.

Poultice answered 25/8, 2010 at 8:14 Comment(0)
S
0

If using the IDE, then at least Netbeans and Eclipse both have functionality to clean up and reformat code.

Netbeans allows you to configure the code formatting to quite detailed level, i.e. including line break before the curly braces or not. Breaking long lines etc. Settings/Preferences->Editor->Formatting.

After configuration you just use ctrl+shift+f (cmd+shift+f) on your open file and all the crap gets automagically cleaned up.

I'm pretty certain the same thing is available for Eclipse also. Haven't dug into the configuration part, but formatting at least was available and was reformatting and cleaning up the code pretty neatly.

From commercial standalone tools jindent does the trick http://www.jindent.com/ for example.

Sleepwalk answered 25/8, 2010 at 14:10 Comment(0)
C
0

I'd look at Sonar if I were you (http://sonarsource.org), it uses many of the aforementioned tools, such as PMD, Checkstyle and Findbugs and gives you an intuitive overview of the quality of your code.

Clancy answered 25/8, 2010 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.