Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Bext free style checker ?

 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the price sensitive has anyone got a tip for the best style checker?
JIndent seems to be pricey ?
 
Sathya Sankar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
Try Jacobe from http://www.tiobe.com/jacobe.htm . It is free for windows and linux.
Regards,
GSS
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers jacobe seems alot less hassle than checkstyle
Tony
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11890
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
I was about to recommend checkstyle - I didn't find it any hassle to set up.
Regards, Andrew
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set up the classpath but received errors processing the XML config file.
Tony
 
Jack Conway
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I'm just trying to use checkstyle now - I'm getting an error complaining about basedir in the XML file. I just lurrrve trudging through masses of documentation to sort this sort of thing out
I'll try Jacobe right now
 
Jack Conway
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Tony and anyone else looking for a style checker. I tried Jacobe and found it too light (but much more user friendly than Checkstyle).
For Checkstyle, the property Basedir needs to point to the directory where your configuration file is, I think.
So far, I've just tested checkstyle with a single Java file which I have dropped into the Checkstyle directory. I'll fix this shortly.
The Java source I am testing is called "ServerFactory.java". My command line was as follows:

As you can see, I'm running Windows (XP), and my checkstyle folder is on my desktop. I'll be improving this set up shortly, but at least the tool seems to be running without crashing with a nasty exception.
I got the following output, which looks useful:

C:\Documents and Settings\Richard\Desktop\checkstyle-3.1\package.html:0: Missing
package documentation file.
ServerFactory.java:0: File does not end with a newline.
ServerFactory.java:1: Line does not match expected header line of '/////////////
///////////////////////////////////////////////////////////////////'.
ServerFactory.java:13:1: Utility classes should not have a public or default con
structor.
ServerFactory.java:14:1: '{' should be on the previous line.
ServerFactory.java:15:4: Missing a Javadoc comment.
ServerFactory.java:16:4: '{' should be on the previous line.
ServerFactory.java:20: Line is longer than 80 characters.
ServerFactory.java:20:4: Missing a Javadoc comment.
ServerFactory.java:20:49: Unable to get class information for suncertify.db.Inva
lidDatabaseFileException.
Audit done
[ September 15, 2003: Message edited by: Jack Conway ]
[ September 15, 2003: Message edited by: Jack Conway ]
[ September 15, 2003: Message edited by: Jack Conway ]
 
Jack Conway
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmmm. Not useful. The error messages do not seem to match the Sun standards at all (where does the "////////////////////////////////////") come from?
Can anyone help? I'm getting very tired of checkstyle; I should have done the work by hand given the amount of time I've wasted on this.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11890
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jack,
You might want to do a quick check on the sun_checks.xml file. The first few lines should be a large block similar to:

(Note: it does have "some best practices" so there are some things that it will report that are just best practices - not actually documented in the listing above)
Of the errors you got, I think most of them were correct. It is just the errors for SunFactory line 1 that seemed odd. What is the first line of this file?

I think you have copied your source file to the same directory as checkstyle, therefore it cannot find your package documentation file. That is a reasonable error.

OK - this might cause issues with some compilers (it used to with some old Microsoft Pascal and C compilers). If you did not end the file with a blank line, the compiler ignored the last line, which often caused the compilation to fail. You will see a lot of people still putting things like "//// end" at the end of their file - it makes printouts easier to read, and gives bad compilers something to swallow.
Not really a problem, but it is nice to add a line just to ensure you dont get caught if you use a non standard java compiler.



I am guessing that you only have static methods in this class? And you dont have an explicit constructor? In which case, this is correct: you should have a private constructor.

Yes, that is in the Sun code conventions

And are you missing a javadoc comment there

Yes, that is in the Sun code conventions

You should not have lines longer than 80 characters. I think this is a "best coding practice". The Sun code conventions do explain how to wrap lines, but I don't think they give an explicit maximum size of lines. I would have to check. But this is definately something you want to look at.

And are you missing a javadoc comment there

Again, this is probably because you have copied one source file to the checkstyle directory, and checkstyle cannot find the other class to ensure you are using it correctly.
For what its worth, here is my run line:


Of course, typing huge command lines like that are not very nice, so I created a script (batch file for people on Microsoft OSes) to give me that command line: all I have to do is provide the name(s) of the file(s) to be verified and it does the rest.
Can anyone help? I'm getting very tired of checkstyle; I should have done the work by hand given the amount of time I've wasted on this.

I can understand your frustration. The nice thing is that once you have this set up the way you like it, it will just work for all your other files.
Regards, Andrew
 
Jack Conway
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Thanks for that. You're right that most of the errors were fine - I deliberately threw my least well documented and maintained file to see if it caught everything. It was the error with the "/////////////////" in that threw me - as this isn't part of the sun standards, I assumed that it wasn't working properly. As I'd had so many other problems with it, I had a fit of pique and lost my temper!
Your command line made me realise I'd overlooked the java.header file in the docs directory - it contains the following:

So, presumably, this file must contain your own version of a template header, and this is why I'm getting that odd error? So I simply need to edit this file and drop in my own header template?
I think I have it working now -thanks for all the help! All I need to do now is to get it working on my entire codebase in one go, and I think I'll investigate the XSL style sheets to see if I can get a "prettified" HTML output.
Many thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic