• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

code convention tools

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JIndent is easy to use, but I think it uses 4 spaces where suppose to be 8 spaces. Am I right or wrong?
Jalopy??? Please, if someone use it before, tell me (us) how to work with it...
CheckStyle??? Please, if someone use it before, tell me (us) how to work with it...
Any other tools???
Why don't put those tools in FAQ for mark???
Regards...
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


JIndent is easy to use, but I think it uses 4 spaces where suppose to be 8 spaces.


According to Java Coding Conventions, "four spaces should be used as the unit of indentation".
Eugene.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Qusay Jaafar:
CheckStyle??? Please, if someone use it before, tell me (us) how to work with it...
Regards...


CheckStyle is fairly simple to use. To run it against all the files in a directory (recursively)
java com.puppycrawl.tools.checkstyle.Main -r <dirname>
This will use the default config file which follows Sun's standards.
Read the documentation for more info.
-BJ
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About check style, I used the following command:
C:\checkstyle>java com.puppycrawl.tools.checkstyle.Main -r C:\temp MySourceCode.java
but I got the following message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/puppycrawl/tools/checkstyle/Main
then I supposed that is a class path problem. I wrote the following command:
C:\checkstyle>java -classpath .;C:\checkstyle com.puppycrawl.tools.checkstyle.Main -r C:\temp MySourceCode.java
but still same problem.
Any Idea?
Regards
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, any other comments please?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to cover the bases, did you add
checkstyle-all-3.0.jar to your classpath?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to Qusay Jaafar ,
For Check Style, I create a batch file named checkstyle.bat under the %JAVA_HOME%\bin directory.

@echo off
rem checkStyle.bat
rem artu 2002-9-24
java -classpath F:\document\Java\checkstyle-src-2.4\lib\antlr.jar;F:\document\Java\checkstyle-src-2.4\lib\antlr-tools.jar;F:\document\Java\checkstyle-src-2.4\lib\jakarta-regexp-1.2.jar;F:\document\Java\checkstyle-src-2.4\lib\junit.jar;F:\document\Java\checkstyle-src-2.4\target\checkstyle com.puppycrawl.tools.checkstyle.Main %1 %2 %3 %4 %5
@echo on

Then, I can use the following DOS command to check a single file:
D:\>checkstyle F:\temp\Test.java
Or the following DOS command to check a directory:
D:\>checkstyle -r F:\temp

Hope this helps.
 
Qusay Jaafar
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the final result:
using checkstyle:
-----------------
1. set the classpath for checkstyle-all-3.0.jar
2. type:
java com.puppy.tools.checkstyle.Main
-c docs/sun_checks.xml
-r c:\myJavaClasses\MySourceCode.java
This will work, but if you set the class path as:
java -classpath .;c:\(your directory) com.puppy.(the other stuff like above), this will not work.
You need to set the classpath into Environmental variables of your system. Why? (I don't know)...
using JIndent
--------------
1. type:
java -jar Jindent.jar MySourceCode.java
This will re-arrange the source code according to sun code convention.
Again, but, if you test the re-arranged source code with checkstyle, there are some differences.
INTERSTING THING, isn't it?
Regards
reply
    Bookmark Topic Watch Topic
  • New Topic