Jump to content


User Tool : Checkstyle


  • Please log in to reply
24 replies to this topic

#1 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 16 March 2005 - 04:52 PM

Step 1:
  Create home directory for checkstyle, for example: "C:\Checkstyle"
  Download and place into it "checkstyle-all-3.4.jar" (or latest version) and "sun_checks.xml"
see google

Step 2:
  -Create New User Tool named "checkstyle"
  - Select 'DOS Command'
  - Enter "java -jar checkstyle-all-3.4.jar -c sun_checks.xml -r $[FilePath]"
  - Set home directory of checkstyle as "Initial Directory"
  - "Capture Output" and "Save all documents first" are good options.

Ready!
Current selected file will be checked on click.
If "Capture Output" is selected, output of checkstyle will be
shown in "General Output" view and lines are linked with Editor (great!)
At last, create customized icon for this user tool (if you work with mouse)

#2 MajinZ

MajinZ

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 16 March 2005 - 09:21 PM

I've heard of Checkstyle before, but I've never used it... Is it a handy tool?

#3 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 17 March 2005 - 07:20 AM

QUOTE(MajinZ @ Mar 16 2005, 09:21 PM)
I've heard of Checkstyle before, but I've never used it... Is it a handy tool?

View Post




"Overview

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. As well, other sample configuration files are supplied for other well known conventions. "

Source:
http://checkstyle.sourceforge.net/



google is your friend :)

#4 MajinZ

MajinZ

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 17 March 2005 - 08:39 AM

The first thing I did was to check Google... So I have already read that text :-)

I'd rather hear your opinion about Checksyle... That means a lot more than just some text describing what it does :-)

#5 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 17 March 2005 - 01:53 PM

I think, checkstyle is easy for teamwork, for example I can't read code like this:

CODE
if (blabla)
{
   doThis();
}
else
{
   doThat();
}


I think, if everyboby in team generates code in some format, the project works better.  


#6 MajinZ

MajinZ

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 17 March 2005 - 02:01 PM

Aaah ok, I see :-)

So it's not really a thing for me, untill now I have always worked alone :-)

#7 Sahisoft

Sahisoft

    Advanced Member

  • Members
  • PipPipPip
  • 74 posts
  • Gender:Male
  • Location:New Jersey, United States
  • Interests:Computer science. What else? :-)

Posted 19 March 2005 - 02:37 AM

QUOTE(flanker @ Mar 17 2005, 09:53 AM)
I think, checkstyle is easy for teamwork, for example I can't read code like this:

CODE
if (blabla)
{
   doThis();
}
else
{
   doThat();
}


I think, if everyboby in team generates code in some format, the project works better.

View Post


This sounds potentially useful. Would you recommend it for a single programmer (not on a development team) as well?

#8 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 19 March 2005 - 08:18 AM

QUOTE(Sahisoft @ Mar 19 2005, 02:37 AM)
This sounds potentially useful. Would you recommend it for a single programmer (not on a development team) as well?

View Post



Yes, I think also for a single programmers may be that tool useful.
For example, it warns, if you write like this:

CODE
public class Foo {

   public int id;

   public int getId() {
       return this.id;
   }
}


#9 MajinZ

MajinZ

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 19 March 2005 - 12:30 PM

Well, off course it can be very usefull for someone who is really interested in it... But I would never use it if I'm the only one working on the project :-)

#10 Nano

Nano

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 March 2005 - 04:28 PM

I am going to try that :P

#11 Naomi

Naomi

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 19 March 2005 - 10:33 PM

Very good if you have a tight lecturer who takes marks off for poor code presentation and layout.

#12 MajinZ

MajinZ

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 20 March 2005 - 06:36 PM

QUOTE(Naomi @ Mar 19 2005, 10:33 PM)
Very good if you have a tight lecturer who takes marks off for poor code presentation and layout.

Yeah well, it's not very hard to learn how to code in a proper way... In the beginning you just have to get used to it :-)

#13 Maephisto

Maephisto

    Member

  • Members
  • PipPip
  • 10 posts

Posted 21 March 2005 - 10:47 AM

QUOTE(MajinZ @ Mar 20 2005, 08:36 PM)
Yeah well, it's not very hard to learn how to code in a proper way... In the beginning you just have to get used to it :-)

View Post




i completely agree...

it could be an interesting tool to write code... i'll try it!

#14 juan

juan

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 22 March 2005 - 11:35 AM

After playing around a little with Checkstyle I found it very useful, once you take out the rules you donīt want to follow. For instance I believe most of us use tabs for indenting. I use 4-column tabs in JCreator. To switch this checking off, comment out the line <module name="TabCharacter"/> in the file sun_checks.xml.
The problem now is that it reports many lines as having more than 80 chars, for it counts each tab as 8 columns instead of 4. Anyone knows how to have Checkstyle count each tab as 4 columns?

#15 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 22 March 2005 - 05:12 PM

QUOTE(juan @ Mar 22 2005, 11:35 AM)
After playing around a little with Checkstyle I found it very useful, once you take out the rules you donīt want to follow. For instance I believe most of us use tabs for indenting. I use 4-column tabs in JCreator. To switch this checking off, comment out the line <module name="TabCharacter"/> in the file sun_checks.xml.
The problem now is that it reports many lines as having more than 80 chars, for it counts each tab as 8 columns instead of 4. Anyone knows how to have Checkstyle count each tab as 4 columns?

View Post




module "TreeWalker" have a property named "tabWidth"
You can set value of that property to  "4":

CODE
<module name="TreeWalker">
 <property name="tabWidth" value="4"/>
</module>


I use spaces for indenting.
And I'v heard Jakarta team also :)


#16 klb

klb

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 25 March 2005 - 01:44 PM

Thanks for the tip. I too think this is useful. I wish it would actually apply the formatting rules to the source code.

#17 diox

diox

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 31 March 2005 - 10:18 AM

Hi, guys!

I've tried to find out the "sun_checks.xml" file but...I'm getting troubles to find..

Somebody could put a link to this file to download it?...

I've been looking through Sun official site but...nothing...

I proud any link...

Thanks!
QUOTE(flanker @ Mar 16 2005, 05:52 PM)
Step 1:
  Create home directory for checkstyle, for example: "C:\Checkstyle"
  Download and place into it "checkstyle-all-3.4.jar" (or latest version) and "sun_checks.xml"
see google

Step 2:
  -Create New User Tool named "checkstyle"
  - Select 'DOS Command'
  - Enter "java -jar checkstyle-all-3.4.jar -c sun_checks.xml -r $[FilePath]"
  - Set home directory of checkstyle as "Initial Directory"
  - "Capture Output" and "Save all documents first" are good options.

Ready!
Current selected file will be checked on click.
If "Capture Output" is selected, output of checkstyle will be
shown in "General Output" view and lines are linked with Editor (great!)
At last, create customized icon for this user tool (if you work with mouse)

View Post




#18 flanker

flanker

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • Location:Germany

Posted 31 March 2005 - 02:22 PM


http://cvs.sourceforge.net/viewcvs.py/*che.../sun_checks.xml




#19 diox

diox

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 31 March 2005 - 03:45 PM

Thanks a lot of!
=:-)
QUOTE(flanker @ Mar 31 2005, 03:22 PM)



#20 shadi

shadi

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 31 March 2005 - 06:17 PM

I have tried check style and i don't think it is that helpfull.
I think if i manage my style while wrting the code, that would be easier than looking at all those messages i got from the style checker.

Anyways this was my idea, others might find it much helpfull.