File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Bext free style checker ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Bext free style checker ?" Watch "NX: Bext free style checker ?" New topic
Author

NX: Bext free style checker ?

Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
For the price sensitive has anyone got a tip for the best style checker?
JIndent seems to be pricey ?
Sathya Sankar
Ranch Hand

Joined: Sep 16, 2000
Posts: 67
Hi Tony,
Try Jacobe from http://www.tiobe.com/jacobe.htm . It is free for windows and linux.
Regards,
GSS


SCJP, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
Cheers jacobe seems alot less hassle than checkstyle
Tony
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

Hi Tony,
I was about to recommend checkstyle - I didn't find it any hassle to set up.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tony Collins
Ranch Hand

Joined: Jul 03, 2003
Posts: 435
I set up the classpath but received errors processing the XML config file.
Tony
Jack Conway
Ranch Hand

Joined: Aug 10, 2003
Posts: 30
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


Co-author, <a href="http://www.ariadnetraining.co.uk/books.htm" target="_blank" rel="nofollow">Java Programming and Enterprise Java</a> (free download)
Jack Conway
Ranch Hand

Joined: Aug 10, 2003
Posts: 30
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

Joined: Aug 10, 2003
Posts: 30
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

Joined: Mar 28, 2003
Posts: 11490
    
  95

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

Joined: Aug 10, 2003
Posts: 30
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.
 
Don't get me started about those stupid light bulbs.
 
subject: NX: Bext free style checker ?