1.CheckStyle is a project under SourceForge that provides a tool to help Java developers comply with certain coding specifications.
Checkstyle provides most of the functionality that is checked for code specifications
Main contents of Checkstyle test
· Javadoc Gaze
• Naming conventions
• Title
· Import statement
• Volume size
• Blank
• modifiers
• block
• Code issues
• Class Design
• Hybrid inspection (pack some practical examples of non-essential system.out and Printstacktrace)
First, CheckStyle installation method
When installed, it is possible to pass
Help "Eclipse Marketplace Search Method installation
or
Help "Install New software
Name:Eclipse-cs
Location :http://eclipse-cs.sourceforge.net/update
A description of some Checkstyle
1 Type is missing a Javadoc commentclass
Missing type description
2 "{" Should is on the previous line
' {' should be on the previous line. Workaround: Put "{" On the previous line
3 Methos is missing a Javadoc comment
Method in front of the missing Javadoc gaze. Workaround: Join Javadoc gaze, similar to this:
/**
* Set default mock parameter. (method description)
* @param additionalparameters parameter additional (name of the participant)
* @return Data Manager (return value description)
* @throws Exception if has error (exception description)
*/
4 expected @throws tag for "Exception"
In the gaze I hope to have a @throws explanation
Workaround: Add such a line to the gaze before the method: * @throws Exception if has error (exception description)
5 "." is preceeded with whitespace "."
There must be no spaces in front.
Workaround: Put the "." The preceding space is removed
6 "." is followed by whitespace "."
There must be no spaces behind.
Workaround: Put the "." The space behind is removed
7 "=" is not preceeded with whitespace
The space is missing in front of "=". Workaround: Add a space before "="
8 "=" is not followed with whitespace "="
There is a missing space behind. Workaround: Add a space after "="
9 "}" should be on the same line "}"
Should be on the same line as the next statement.
Workaround: Put "}" in front of the next line
Ten Unused @param tag for "Unused"
No number of "unused". No need to stare
Solution: "* @param unused parameter additional (reference name)" Take this line of unused the gaze out of the number "
Variable "CA" Missing Javadoc
Variable "CA" missing Javadoc gaze
Workaround: Add Javadoc gaze before the "CA" variable:/** ca. */(Note: Be sure to add ".") )
Line longer than 80characters
The line length exceeds 80. Workaround: Divide it into multiple lines of writing. When necessary, able to ctrl+shift+f
Line contains a tab character
The line contains the "tab" character.
Redundant "public" modifier
The "public" modifier for redundancy. Workaround: Remove the "public" modifier
Final modifier out of order with the JSL suggestion
Final modifier in the wrong order
Avoid using the ". *" Form of import
The import format avoids the use of ". *". Workaround: Can not join the import first, then need to use the direct "CTRL + O" import.
Redundant import from the same package
Import content from the same package. Extra. You can delete it.
Unused import-java.util.list
Import incoming java.util.list is not used. Workaround: Remove unnecessary classes that are imported
Duplicate Import to Line 13
Import the same content over and over again. Workaround: Remove unnecessary classes that are imported
Import from Illegal package
Import content from an illegal package
"While" construct must use "{}"
"While" statement is missing "{}"
Variable "STest1" must be private and has accessor method
The variable "STest1" should be private, and there is a way to call it
Variable "ABC" must match pattern "^[a-z][a-za-z0-9]*$"
The variable "ABC" does not conform to the naming convention "^[a-z][a-za-z0-9]*$", the Workaround: Change the name to a rule-compliant named "ABC"
("is followed by whitespace
"(" Cannot have space after ")" is proceeded by whitespace ")" must not be preceded by a space. " Workaround: Remove the front or back spaces
First sentence should end with a period
Workaround: You should add a "." To the end of your gaze's first line of text.
Redundant throws: ' Namenotfoundexception ' is subclass of ' namingexception '.
' Namenotfoundexception ' is a subclass of ' namingexception ' that repeatedly throws an exception.
Workaround: Suppose you throw two exceptions, and an exception class is a subclass, then just write the parent class
to remove the namenotfoundexception exception. The corresponding Javadoc gaze abnormal gaze description also needs to be removed
Parameter docType should be final.
The parameter docType should be the final type, Workaround: Add a final
DOCTYPE line with trailing spaces.
Extra Blank lines, Workaround: Remove this line of blank lines
must have At least one statement.
at least one declaration
Workaround:} catch (NumberFormatException nfe) {
Log.error ("Auto renews the Agreement failed ", NFE);//abnormal capture cannot be empty. Add a sentence to the exception. such as printing, and so on
> ' is not followed by whitespace. and also ' (' is preceded with whitespace.
When defining collections and enumerations. The last ">" should be preceded by a space, "(" No spaces are allowed in front of it.) Workaround: Remove the generic
Got an exception-java.lang.runtimeexception:unable-get class information for @throws tag ' Sy Stemexception '.
Reason: unreasonable throws.
Workaround: To ensure that certain types are used. such as some classes, interfaces are not throws. Remove the exception to the declaration.
Throwing Exceptions in the implementation class
Web-based solutions:
1, this is the Checkstyle report of the fault. Refreh is usually required to clean/build this project. Suppose not. Be able to try clean all projects, restart Eclipse.
2, because the compiled class is not in the Checkstyle classpath. So, just to configure the compiled class to the classpath in <checkstyle/> there is no problem. In addition, Also found Checkstyle line length seems to have a problem, obviously not more than 120 characters, but still error. Helpless, I put eclipse in Java > code style > Formatter in the maximum line wit H changed to 100, then format, basically no problem.
The File does not end with a newline.
Workaround: Remove the error class and create a new class with the same name. Copy all the code to the past.
Utility classes should not has a public or default constructor.
There should be no public or default construction method in the inner class of the interface
WORKAROUND: In the inner class, define a private construction method, and then the inner class is declared as the final type.
Assuming that there is static in front, final must also be placed after static
Variable ' Functioncode ' must be private and has accessor methods.
Change the variable to private and provide an access method
Workaround: Change the modifiers for these variables to private, and then provide the set. Get method, and add the corresponding method Javadoc gaze, Count gaze. And the final is added before the return value and the type of the parameters.
and change the place where this variable was called to access by means of a method
' X ' hides a field.
public class Foo
{
private int bar;
public Foo (int bar)
{
This.bar = bar;
}
Public final int Getbar ()
{
return bar;
}
}
The global private int bar; and the bar variable name of the local public Foo (int bar) repeats.
Workaround: Change the name of the reference in the method to the public Foo (int newBar)
{
This.bar = NewBar;
}。
Got an exception-unexpected character 0xfffd in identifier
This is because Checkstyle does not recognize the coding format that was developed.
Web-based solutions:
1. Can be configured in eclipse, can be specified in Other-->checker
2, can change the Checkstyle configuration file:
<module name= "Checker" >
<property name= "severity" value= "Warning"/>
<property name= "CharSet" value= "UTF-8"/>
<module name= "TreeWalker" >
If it is UTF-8, then add bold italic to the statement, you can.
PNS Got an exception-java.lang.runtimeexception:unable-get class information for @throws tag *whatever*.
Online reference solution: Check Checksytle JavaDoc---JavaDoc---and logloaderrors.
Suppose it is checkstyle oneself load in error, hit a log to be able to, not the whole errors scary.
The same error may also be wrapped in another place.
Coding problems--and redundant Throws--logloaderrors Select to
Expected @param tag for ' DataManager '.
Gaze resolution with missing DataManager parameters: Add @param dataManager dataManager in gaze
Parameter X should be final.
public class Foo
{
private int bar;
public Foo (int bar)
{
This.bar = bar;
}
Public final int Getbar ()
{
return bar;
}
}
Explanation: The local variable of public foo (int bar) is considered immutable, and the check needs to add Finalkeyword to define public foo (final int bar) for this error. can be ignored without checking.
Redundant ' X ' modifier.
Public interface Cachehrtreeservice extends Manager {
/**
* Organization Tree
* @param orgdto
* @return
* @throws Exception
*/
public void Setorganization (Organizationdto orgdto) throws Exception;
/**
* Organization Tree
* @return
* @throws Exception
*/
Public Organizationdto getorganization () throws Exception;
......
}
Explanation: Extra fields. Public Organizationdto getorganization () throws Exception; At this time public is the extra field, because it is public when defined by interface.
Need to be checked.
The should Class X is declared as final.
Explanation: For a singleton design pattern, a unique class object is required to be returned. However, Hrfactory and Contextfactory are optimized for two classes. No need to check.
Other singleton classes still need to be checked.
The Method ' Addchildrenid ' isn't designed for extension-needs to be abstract, final or empty.
Explanation: Inherited by the parent class, this class is a bit special to ignore.
Variable ' ID ' must be private and has accessor methods.
Explanation: The Basehrdto class, which is the parent class. Attributes are inherited to subclasses and are more specific. But other classes, the fame need to add the scope ' private ' keyword. Need to be checked.
The Array brackets at illegal position.
Explanation: Code writing, habits are not the same.
Need to be checked. Only prompt
Eclipse improves development speed-plug-in Checkstyle use