Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Determines complexity of methods, classes and files bycounting the Non Commenting Source Statements (NCSS). Thischeck adheres to the specification for theJavaNCSS-Toolwritten by Chr. Clemens Lee.
Roughly said the NCSS metric is calculated bycounting the source lines which are not comments, (nearly)equivalent to counting the semicolons and opening curly braces.
The NCSS for a class is summarized from the NCSSof all its methods, the NCSS of its nested classes and thenumber of member variable declarations.
The NCSS for a file is summarized from the ncss of all its top level classes,the number of imports and the package declaration.
Rationale: Too large methods and classes are hard to read andcostly to maintain. A large NCSS number often means that amethod or class has too many responsibilities and/orfunctionalities which should be decomposed into smaller units.
Checks for missing Javadoc comments for a method or constructor.The scope to verify is specified using the Scope class anddefaults to Scope.PUBLIC. To verify anotherscope, set property scope to a differentscope.
Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.
For getters and setters for the property allowMissingPropertyJavadoc,the methods must match exactly the structures below.
public void setNumber(final int number){mNumber = number;}public int getNumber(){return mNumber;}public boolean isSomething(){return false;}
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks visibility of class members. Only static final, immutable or annotatedby specified annotation members may be public; other class members must be privateunless the property protectedAllowed or packageAllowed is set.
Public members are not flagged if the name matches the publicmember regular expression (contains "^serialVersionUID$" by default).
Note thatCheckstyle 2 used to include "^f[A-Z][a-zA-Z0-9]*$" in the defaultpattern to allow names used in container-managed persistence for Enterprise JavaBeans(EJB) 1.1 with the default settings. With EJB 2.0 it is no longer necessary to havepublic access for persistent fields, so the default has been changed.
Rationale: Enforce encapsulation.
Check also has options making it less strict:
ignoreAnnotationCanonicalNames - the list of annotations which ignore variablesin consideration. If user will provide short annotation name that type will match to anynamed the same type without consideration of package.
allowPublicFinalFields - which allows public final fields.
allowPublicImmutableFields - which allows immutable fields to be declared aspublic if defined in final class.
Field is known to be immutable if:
It's declared as final
Has either a primitive type or instance of class user defined to be immutable(such as String, ImmutableCollection from Guava and etc)
Classes known to be immutable are listed in immutableClassCanonicalNames by theircanonical names.
Property Rationale: Forcing all fields of class to have private modifier by default isgood in most cases, but in some cases it drawbacks in too much boilerplate get/set code.One of such cases are immutable classes.
Restriction: Check doesn't check if class is immutable, there's nochecking if accessory methods are missing and all fields are immutable, we only checkif current field is immutable or final. Under the flagallowPublicImmutableFields, the enclosing class must also be final, to encourageimmutability. Under the flag allowPublicFinalFields, the final modifier onthe enclosing class is optional.
Star imports are out of scope of this Check. So if one of type imported viastar import collides with user specified one by its short name -there won't be Check's violation.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks for missing Javadoc comments for a method or constructor.The scope to verify is specified using the Scope class anddefaults to Scope.PUBLIC. To verify anotherscope, set property scope to a differentscope.
Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.
For getters and setters for the property allowMissingPropertyJavadoc,the methods must match exactly the structures below.
public void setNumber(final int number){mNumber = number;}public int getNumber(){return mNumber;}public boolean isSomething(){return false;}
Checks for missing Javadoc comments for a method or constructor.The scope to verify is specified using the Scope class anddefaults to Scope.PUBLIC. To verify anotherscope, set property scope to a differentscope.
Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.
For getters and setters for the property allowMissingPropertyJavadoc,the methods must match exactly the structures below.
public void setNumber(final int number){mNumber = number;}public int getNumber(){return mNumber;}public boolean isSomething(){return false;}
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.
Determines complexity of methods, classes and files bycounting the Non Commenting Source Statements (NCSS). Thischeck adheres to the specification for theJavaNCSS-Toolwritten by Chr. Clemens Lee.
Roughly said the NCSS metric is calculated bycounting the source lines which are not comments, (nearly)equivalent to counting the semicolons and opening curly braces.
The NCSS for a class is summarized from the NCSSof all its methods, the NCSS of its nested classes and thenumber of member variable declarations.
The NCSS for a file is summarized from the ncss of all its top level classes,the number of imports and the package declaration.
Rationale: Too large methods and classes are hard to read andcostly to maintain. A large NCSS number often means that amethod or class has too many responsibilities and/orfunctionalities which should be decomposed into smaller units.
Checks visibility of class members. Only static final, immutable or annotatedby specified annotation members may be public; other class members must be privateunless the property protectedAllowed or packageAllowed is set.
Public members are not flagged if the name matches the publicmember regular expression (contains "^serialVersionUID$" by default).
Note thatCheckstyle 2 used to include "^f[A-Z][a-zA-Z0-9]*$" in the defaultpattern to allow names used in container-managed persistence for Enterprise JavaBeans(EJB) 1.1 with the default settings. With EJB 2.0 it is no longer necessary to havepublic access for persistent fields, so the default has been changed.
Rationale: Enforce encapsulation.
Check also has options making it less strict:
ignoreAnnotationCanonicalNames - the list of annotations which ignore variablesin consideration. If user will provide short annotation name that type will match to anynamed the same type without consideration of package.
allowPublicFinalFields - which allows public final fields.
allowPublicImmutableFields - which allows immutable fields to be declared aspublic if defined in final class.
Field is known to be immutable if:
It's declared as final
Has either a primitive type or instance of class user defined to be immutable(such as String, ImmutableCollection from Guava and etc)
Classes known to be immutable are listed in immutableClassCanonicalNames by theircanonical names.
Property Rationale: Forcing all fields of class to have private modifier by default isgood in most cases, but in some cases it drawbacks in too much boilerplate get/set code.One of such cases are immutable classes.
Restriction: Check doesn't check if class is immutable, there's nochecking if accessory methods are missing and all fields are immutable, we only checkif current field is immutable or final. Under the flagallowPublicImmutableFields, the enclosing class must also be final, to encourageimmutability. Under the flag allowPublicFinalFields, the final modifier onthe enclosing class is optional.
Star imports are out of scope of this Check. So if one of type imported viastar import collides with user specified one by its short name -there won't be Check's violation.
Checks for missing Javadoc comments for a method or constructor.The scope to verify is specified using the Scope class anddefaults to Scope.PUBLIC. To verify anotherscope, set property scope to a differentscope.
Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.
For getters and setters for the property allowMissingPropertyJavadoc,the methods must match exactly the structures below.
public void setNumber(final int number){mNumber = number;}public int getNumber(){return mNumber;}public boolean isSomething(){return false;}
Checks for missing Javadoc comments for a method or constructor.The scope to verify is specified using the Scope class anddefaults to Scope.PUBLIC. To verify anotherscope, set property scope to a differentscope.
Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.
For getters and setters for the property allowMissingPropertyJavadoc,the methods must match exactly the structures below.
public void setNumber(final int number){mNumber = number;}public int getNumber(){return mNumber;}public boolean isSomething(){return false;}
Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.
Checks cyclomatic complexity against a specified limit.It is a measure of the minimum number ofpossible paths through the source and therefore the number ofrequired tests, it is not a about quality of code!It is only applied to methods, c-tors,static initializers and instance initializers.
The complexity is equal to the number of decision points + 1.Decision points: if, while, do, for, ?:, catch, switch, casestatements and operators && and ||in the body of target.
By pure theory level 1-4 is considered easy to test, 5-7 OK, 8-10consider re-factoring to ease testing, and 11+ re-factor now as testing will be painful.
When it comes to code quality measurement by this metriclevel 10 is very good level as a ultimate target (that is hard to archive).Do not be ashamed to have complexity level 15 or even higher,but keep it below 20 to catch really bad designed code automatically.
Please use Suppression to avoid violations on cases that could not be split in fewmethods without damaging readability of code or encapsulation.
Checks for TODO: comments. Actuallyit is a genericregularexpression matcher on Java comments. To check for otherpatterns in Java comments, set the format property.