Eclipse plugin checkstyle Result Analysis

Source: Internet
Author: User
Tags checkstyle

Install and configure the checkstyle plugin

Install: directly update and add the update source address:Http://eclipse-cs.sf.net/update/,You can also download the latest plug-in package locally from your http://sourceforge.net/projects/eclipse-cs/files/ for installation.

Configuration: two check configuration files are installed by default. For example, if type is set to build-in, the default configuration files can be modified after the built-in copy files are installed, or check the xml configuration file that already exists in import.

 

There is also a codestyle used in combination, for example, there are several options such as clean up, template, and formatter. The default clean up provided by eclopse does not seem to do anything, therefore, it is best to create one or import one by yourself.

.

Common notes

1Type is missing a javadoc commentclassType description missing

2"{" Shocould be on the previous line "{"It should be in the previous line. Solution: Put "{" in the previous line.

3Methos is missing a javadoc commentJavadoc comments are missing before the method. Solution: add the javadoc annotation as follows:

/**

* Set Default mock parameter. (method description)

* @ Param additionalparameters parameter additional (parameter name)

* @ Return data manager (return value description)

* @ Throws exception if has error (exception description)

*/

4Expected @ throws tag for "exception"The @ throws description is required in the annotation.

Solution: add the following line in the comment before the method: * @ throws exception if has error (exception description)

5"." Is preceeded with whitespace "."No leading space is allowed. Solution: remove the space before "("

6"." Is followed by whitespace "."There cannot be spaces at the end. Solution: remove the space after ")".

7"=" Is not preceeded with whitespace "="Spaces are missing. Solution: Add a space before "= ".

8"=" Is not followed with whitespace "="Space is missing. Solution: Add a space after "="

9"}" Shoshould be on the same line "}"It should be in the same line as the next statement. Solution: Put "}" in front of the next row

10Unused @ Param tag for "unused"No parameter "unused", no need to comment

Solution: "* @ Param Unused parameter additional (parameter name)" Remove the comment of the unused parameter in this line"

11Variable "CA" missing javadocThe variable "ca" lacks javadoc comments

Solution: add the javadoc note before the "ca" variable:/** ca. */(Note: Remember to add ".")

12Line longer than 80characters row length exceeds 80. Solution: divide it into multiple lines for writing. If necessary, you can press Ctrl + Shift + F

13Line contains a Tab characterThe row contains the "tab" character. Quick Solution: You can use the format function in editplus to convert the Tab character to a space, and then save the editplus English version installation file on our host. You can copy the required information. Register editplus and click the file registered in the installation file.

14Redundant "public" ModifierRedundant "public" modifier. Solution: redundant "public"

15Final modifier out of order with the jsl suggestionThe final modifier sequence is incorrect.

16Avoid using the ". *" form of importimportFormat to avoid ". *"

17Redundant import from the same packageImport content from the same package

18Unused import-java.util.listImportThe Java. util. List is not used. Solution: Remove unnecessary imported classes.

19Duplicate import to line 13Repeated import of the same content solution: Remove unnecessary imported classes

20Import from illegal packageImport content from an invalid package

21"While" construct must use "{}"The "while" statement lacks "{}"

22Variable "stest1" must be private and have accessor methodThe variable "stest1" should be private and has a method to call it.

23Variable "ABC" must match pattern "^ [A-Z] [a-zA-Z0-9] * $"Variable" ABC "does not comply with naming rules" ^ [A-Z] [a-zA-Z0-9] * $ "solution: change this name to the rule-compliant name" ABC"

24"(" Is followed by whitespace"(" Cannot be followed by spaces 25 ")" is proceeded by whitespace ")" cannot be preceded by Spaces

Solution: remove the leading or trailing spaces.

25First sentence shocould end with a period.Solution: Add "." to the end of the first line of text in your comment ".".

26Redundant throws: 'namenotfoundexception 'is subclass of 'namingexception '.'Namenotfoundexception 'is a subclass of 'namingexception' that repeatedly throws an exception.

Solution: If two exceptions are thrown, and one exception class is another subclass, you only need to write the parent class.

Remove the namenotfoundexception exception. The corresponding javadoc annotation exception annotation must also be removed.

27Parameter doctype shocould be final.The doctype parameter should be of the final type. Solution: add a final before the doctype parameter.

28Line has trailing spaces.Extra empty rows solution: Remove this empty row

29Must have at least one statement.At least one statement

Solution:} catch (numberformatexception NFE ){

Log. Error ("auto renews the agreement failed", NFE); // The exception capture cannot be empty. add a sentence to the exception. Such as printing

30'>' Is not followed by whitespace.And '(' is preceded with whitespace.

When defining a set and enumeration, there must be spaces behind the last ">" and no spaces before. Solution: remove the generic

31Got an exception-java. Lang. runtimeexception: Unable to get class information for @ throws tag 'systemexception '.Cause: unreasonable throws.

Solution: Make sure that some types, such as some classes and interfaces, are not throws. Remove declared exceptions. Throw an exception in the implementation class.

Online reference solution: 1. This is an error reported by checkstyle. Refreh, clean/build this project. If not, you can try clean all projects and restart eclipse.

2. The compiled class is not in the classpath of checkstyle. therefore, you only need to configure the compiled class to the <checkstyle/> classpath. in addition, it seems that the line length of checkstyle is also a bit problematic. If it is not more than 120 characters, an error is returned. helpless, I changed the maximum line with in Java> code style> formatter in eclipse to 100, and then formatted it. Basically there is no problem.

32File does not end with a newline.Solution: Delete the error class, create a class with the same name, andCodeAll copied

33Utility Classes shocould not have a public or default constructor.Internal classes in the interface should not have public or default constructor Methods

Solution: In the internal class, define a private constructor and declare the internal class as the final type. If there is static above, final must also be placed after static

34Variable 'functioncode' must be private and have accessor methods. Change the variable to private and provide the access method.

Solution: Change the modifier of these variables to private, then provide the set and get methods, and add the corresponding method javadoc comments and parameter comments. Add final before the return value and parameter type. And changed the place where this variable was called to access through methods.

35'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 is the same as the local public Foo (INT bar) bar variable name.
Solution: Change the parameter name in the method to public Foo (INT newbar)
{
This. bar = newbar;
}.

36Got an exception-Unexpected character 0 xfffd in identifier

This is because checkstyle cannot identify the encoding format.

Online reference solution:

1. It can be configured in eclipse, and can be specified in other --> checker

2. You can modify the checkstyle configuration file:

<Module name = "checker">

<Property name = "severity" value = "warning"/>

<Property name = "charset" value = "UTF-8"/>

<Module name = "treewalker">

If it is a UTF-8, then add the bold italic statement, you can.

37Got an exception-java. Lang. runtimeexception: Unable to get class information for @ throws tag * whatever *.
Online reference solution: select the checksytle javadoc --> method javadoc --> logloaderrors. If an error occurs when the checkstyle is loaded by itself, you can create a log. Do not make the errors messy.
The same error may also be returned in another case. Coding problems --> redundant throws --> select logloaderrors

38Expected @ Param tag for 'datamanager '.If the datamanager parameter is missing, add @ Param datamanager to the comment.

Answers to some other online errors:
1.Parameter x shocould 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 unchangeable. The final keyword must be added to the check to define public Foo (final int bar). Ignore the check.

2.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: redundant fields. Public organizationdto getorganization () throws exception; at this time, public is a redundant field, because it is public when the interface is defined.

Check.

3 .-Class X shoshould be declared as final.

Explanation: For the singleton design mode, a unique class object is required to be returned. However, hrfactory and contextfactory are two optimized classes and do not need to be checked.
Check other Singleton classes.

4 .-Method 'addchildrenid' is not designed for extension-needs to be
Abstract, final or empty.

Explanation: It is inherited by the parent class. This class is special and can be ignored.

5.Variable 'id' must be private and have accessor methods. Explanation: basehrdto class, which is a parent class. attributes are inherited from child classes, which are special. However, for other classes, the domain name must contain the 'private' keyword. Check.

6 .-Array brackets at illegal position. Explanation: the code is written in different ways. Check required, only prompt

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.