In eclipse, use the Checkstyle,checkstyle plug-in to check your Java code for custom profiles:

Source: Internet
Author: User
Tags array definition modifier modifiers checkstyle log4j

Absrtact: Recently the project team is doing code check, so the leader let the Checkstyle this plugin to understand, now I write our custom checkstyle.xml file record, so that we can use together:

One: To use the Checkstyle plug-in in eclipse to check the Java code, that must first install Eclipse Checkstyle plug-ins, how to install, I believe you know, here is not much to say

Two: The following is the custom Checkstyle.xml file (this is the core)

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE module Public "-//puppy crawl//dtd Check Configuration 1.3//en" "Http://www.puppycrawl.com/dtds/configuration_  
1_3.dtd "> <!--This configuration file is written by the Eclipse-cs plugin configuration Editor--> <!--checkstyle-configuration:check Description:none--> <module name= "Checker" > <prop Erty name= "Severity" value= "error"/> <property name= "charset" value= "UTF-8"/> <message key= " General.exception "Value=" has an exception-{0} "/> <message key=" general.filenotfound "value=" File not found! " /> <!--Chapter 2.2A--> <!--tab indent is not allowed, this rule must be--> <module name= "Filetabcharacter" outside the <TreeWalker> label > <property name= "severity" value= "error"/> <property "name=" Eachline "true" value=/> Sage key= "Containstab" value= "Bank contains tab characters, violates code specification 2.2 chapters"/> </module> <!--chapters 3.1.1--> <!--check each Java p Is there any Java in the AckageThe annotation file, by default, allows a package-info.java, or it can be configured with the Allowlegacy property to allow package.html. This rule must be outside the <TreeWalker> label--> <module name= "javadocpackage"/> <module "name=" > Treewalker Perty name= "Severity" value= "error"/> <property name= "Tabwidth" value= "4"/> <message key= "genera" L.exception "Value=" has an exception-{0} "/> <!--chapter 1.2.2--> <!--modifier order detection--> <module name=" Mo Difierorder ' > <message key= ' mod.order ' value= ' ' {0} ' modifier order error. Code violation 1.2.2 Chapter "/> <message key=" a Nnotation.order "value=" ' {0} ' annotation modifiers cannot precede a non-annotation modifier. " 
		    /> </module> <!--chapter 2.2B--> <!--indent style--> <module name= "Indentation" > <property name= "Severity" value= "error"/> <property name= "Basicoffset" value= "4"/> <mess Age key= "Indentation.error" value= "you indent {1} spaces, correctly indent {2} spaces, violating code specification 2.2 chapters"/> <!--child indent--> <message key= "Indentation.child.error" Value= "You indent {1} spaces, correct should indent {2} spaces, violate code Specification 2.2 chapters"/> </module> <!--chapters 2.3--> <!--page width--> <module name= "LineLength" > <property name= "Max" value= "no"/> <message "key=" Maxlinelen E= "More than 80 lines of characters." 2.3 Chapters "/> </module> <!--chapters 2.4--> <!--operator line-breaking policy check--> <modu Le name= "operatorwrap" > <property name= "severity" value= "Error"/> "<property name=" option "value=" n L "/> <property name=" tokens "value=" assign,band,bor,div,equal,ge,gt,land,le,lor,lt,minus_assign,mod,mod_ Assign,not_equal,plus,plus_assign,question,star,star_assign "/> <message key=" line.after "value=" ' {0} ' Not placed at the top of the new line, violating code specification 2.4 chapters "/> </module> <!--chapters 2.6--> <module name=" Parenpad "> &L T;property name= "Severity" value= "error"/> <property name= "tokens" value= "Lparen,rparen,ctor_call,method_call" , Super_ctor_call "/> <messagE key= "ws.followed" value= "' {0} ' is preceded by a space that violates the Code specification 2.6 chapter"/> <message key= "ws.preceded" value= "" {0} ", which violates the Code Specification 2 .6 Chapters "/> </module> <module name=" Typecastparenpad "> <property name=" severity "value=" Error "/> <property name=" tokens "value=" Rparen,typecast "/> <message key=" ws.followed "value=" ' {0} "The next more space, violating the code specification 2.6 chapters"/> <message key= "ws.preceded" value= "' {0} ', preceded by one more space, violating code specification 2.6 chapters"/> &LT;/MODULE&G    
	    T <module name= "Whitespaceafter" > <property name= "severity" value= "error"/> <property "name=" S "value=" Comma,semi "/> <message key=" ws.notfollowed "value=" ' {0} ' followed by one more space, violating code Specification 2.6 chapter "/> </module > <module name= "whitespacearound" > <property name= "severity" value= "Error"/> Rty name= "tokens" value= "Rcurly,literal_assert,literal_assert,literal_catch,literal_do,literal_else,literal_ Finally,literal_for,literaL_if,literal_return,literal_synchronized,literal_try,literal_while "/> <property name=" Allowemptyconstructors "value=" true "/> <property name=" Allowemptymethods "value=" true "/> key= "ws.notpreceded" value= "' {0} ' keyword less a space before, violating the coding specification 2.6 chapter"/> <message key= "ws.notfollowed" "value=" ' {0} ' after the keyword One less space, violating code specification 2.6 chapters "/> </module> <!--chapters 2.7--> <!--per line statement quantity--> <module name=" Onestateme Ntperline "> <!--module's metadata type settings, tested to find that the label does not--> <metadata name=" net.sf.eclipsecs.core.comment "value=" coding Problems-> only one statement per line allowed "/> <message key=" Multiple.statements.line "value=" to prohibit a row of multiple-sentence generation Code, violating code specification 2.7 chapters "/> </module> <!--chapters 2.8--> <!--per row variable declaration quantity--> <module name=" Multiplevar Iabledeclarations "> <property name=" severity "value=" error "/> <message" key=. Declarations.comma "value=" the definition of each variable must be at its declaration and on the same line, violating the Code specification 2.8 chapters "/> <message key=" multiple.variable.declarations "value=" each row can only define one variable, violating code specification 2.8 chapters "/> &L  T;/module> <!--Chapter 2.9.1--> <!--Checks the placement of right curly braces ('} ') for else, try, and catch tokens.   
	      The policy to verify are specified using Property option. Option: Do the right curly braces appear on a single line tokens: Defines the type of check--> <module name= "rightcurly" > <property name= 
	    
	    "Option" value= "Alone"/> <property name= "severity" value= "Error"/> </module> <!--chapters 2.9.1--> <!--Check the left brace on the left brace must be placed at the line end of the previous line of code--> <module name= "leftcurly" > <proper
	 	Ty name= "severity" value= "error"/> <message key= "line.previous" value= "left curly braces are not placed at the end of the previous line of code, violating the code specification 2.9.1 Chapter"/>  
	    	</module> <!--chapters 2.9.2--> <!--check code blocks for missing braces--> <module name= "Needbraces" > <message key= "needbraces" value= "' {0} ' structure without braces" ' {}"s, violating code specification 2.9.2 Chapters"/> </module> <!--chapters 3.2--> <!--Review file header comments--> <!--chapters 3.3--> <!--Check the Javadoc annotations for classes and interfaces--> <module name= "Javadoctype" > <property 
		    Name= "Severity" value= "error"/> <message key= "Type.missingtag" The Javadoc type annotations are missing the {0} label. Code code violation 3.3 chapter "value= <message key= "javadoc.missing" value= is missing Javadoc annotations. Code Code violation 3.3 chapter "/> <message key=" Javadoc.unusedtagge Neral "value=" Javadoc label not used. Violation of code Specification 3.23 Chapter "/> <message key=" Javadoc.unusedtag "value=" unused {0} label for ' {1} ' . Violation of code Specification 3.3 chapter "/> <message key=" Type.tagformat "value=" Javadoc type label {0} must match pattern ' {1} '. Code code violation 3.3 chapter "/> ;/module> <!--chapters 3.4,3.7--> <!--public protect private variables are checked for comments--> <module name= "JAVADOCV
		    Ariable "> <property name=" severity "value=" error "/> <property" Scope "name=" public "value= <message key= "JavaDoc.missing "value=" variable annotations: lack of Javadoc annotations, violating code Specification 3.4 chapters "/> </module> <module name=" Javadocvariable "> <property name= "Severity" value= "error"/> <property name= "Scope" value= "protected"/> <messa GE key= "javadoc.missing" value= "variable comment: lack of javadoc annotations, violation of code Specification 3.4 chapter"/> </module> <module name= "Javadocvari Able "> <property name=" severity "value=" error "/> <message" key= "javadoc.missing" value= "variable comment: missing Java Doc comments, violation of code specification 3.4 chapters "/> </module> <!--chapters 3.5--> <!--Check all the methods of Javadoc, can not declare runtimeexception-- > <module name= "Javadocmethod" > <property name= "Allowundeclaredrte" value= "true"/> <!--allow get s The ET method has no annotation--> <property name= "Allowmissingpropertyjavadoc" value= "true"/> <message key= "javadoc.missing" "Value=" method comments: Lack of Javadoc annotations, violation of code specification 3.5 chapters "/> </module> <!--naming conventions--> <!--Chapters 4.2--> &L t;! --Package name naming specification--> &LT;module name= "PackageName" > <!--<property name= "format" value= "^[a-z]+ (\.[ a-z][a-z0-9]*) *$ "/>--> <property name=" format "value=" ^org\.neris\. [A-z]+ (\.[  
	    a-z]+) +$ "/> <message key=" Name.invalidpattern "value=" package name ' {0} ' does not conform to Org.neris. Project name. module name, Code violation 4.2 chapter "/>
	    </module> <!--Chapter 4.3,4.4--> <!--class naming, matching rule default: (^[a-z][a-za-z0-9]*$), must start with a capital letter--> <module name= "TypeName" > <property name= "tokens" value= "Class_def"/> "<message key=" Name.inv  Alidpattern "value=" class name ' {0} ' is not named through the Big hump nomenclature, the specific name should use the meaning complete English description, violates the code specification 4.3 chapters "/> </module> <!-- Interface naming, matching rule default: (^[a-z][a-za-z0-9]*$), must start with uppercase letters--> <module name= "TypeName" > <property name= "Tokens" Val Ue= "Interface_def"/> <message key= "Name.invalidpattern" value= "interface name ' {0} ' has not been named by the Big Hump nomenclature, and the specific name should be described in English with a full meaning, violation of code specification 4.3 chapters "/> </module> <!--chapters 4.6--> <!--method name--&Gt <module name= "methodname" > <property name= "severity" value= "error"/> <property "name=" Format "value=" (^[a-z][a-za-z0-9]*$) "/> <message key=" Name.invalidpattern "value=" method name ' {0} ' is not named by the small hump nomenclature , the specific name should use the full meaning of the English description. Violation of code Specification 4.6 chapters "/> </module> <!--chapters 4.7--> <!--local variable naming--> &L T;module name= "LocalVariableName" > <property name= "format" value= "(^[a-z][a-za-z0-9]*$)"/> & Lt;message key= "Name.invalidpattern" value= "variable name ' {0} ' is not named by the small hump nomenclature, the specific name should use the full meaning of the English description." Code violation 4.7 chapter "/> </mod Ule> <!--Partial final variables, including check of parameters in Catch--> <module name= "Localfinalvariablename" > &L T;property name= "Severity" value= "error"/> <message key= "Name.invalidpattern" value= "variable name ' {0} ' is not named by the small hump nomenclature, with  
	    	The name of the body should be described in English with a complete meaning. Violation of code Specification 4.7 chapters "/> </module> <!--variable name--> <module name=" MemberName "> <messaGE key= "Name.invalidpattern" value= "variable name ' {0} ' is not named by the small hump nomenclature, and the specific name should be described in English with a complete meaning." Code violation 4.7 chapter "/> </module> <!--static variable name--> <module name= "Staticvariablename" > <message key= "name.invalidpattern" value= "change The quantity name ' {0} ' is not named by the small hump nomenclature, and the specific name should be described in English with a complete meaning. Code violation 4.7 Chapter "/> </module> <!--array variable named--> <mod Ule name= "Arraytypestyle" > <property name= "severity" value= "error"/> <message "key="
	    E "value=" array definition does not take int[] Index this way, violating code specification 4.7.2 Chapters "/> </module> <!--chapters 4.8--> <!--constant naming--> <module name= "Constantname" > <property name= "severity" "Error" value=/> "<message" name. Invalidpattern "value=" constant ' {0} ' constant name violates code specification 4.8 chapters. " /> </module> <!--chapters 5.1--> <!--import statement does not use wildcard characters--> <module name= "Avoidstarimpo RT "> <property name=" severity "value=" error "/> <message" key=DStar "value=" cannot use the * number when referencing a package. Code violations 5.1 Chapters "/> </module> <!--chapters 5.2--> <!--magic number detection--> <module name= "MagicNumber" > <property name= "severity" value= "error"/> <message "key=" C.number "value=" ' {0} ' is a magic number (that is, a constant). Violation of code Specification 5.2 chapters "/> </module> <!--chapters 5.4--> <!--extra keywords , contains the not applicable as keyword--> <module name= "Redundantmodifier" > <message key= "redundantmodifier" value= "" {0} ' superfluous modifiers. Code violation 5.4 Chapter "/> </module> <!--chapters 5.5--> <!--overloaded Parent class method--> <module name= "Missingoverride" > <message key= "annotation.missing.override" value= "overloaded method lacks @override, violates code specification 5.5 chapters"/> <m
		Essage key= "Tag.not.valid.on" value= comment-> Javadoc {0} label is not valid at this location. "/> </module> <!--Chapter 5.6--> <!--judgment statement uses--> <module name= "simplifybooleanexpression" > <property name= "severity" value= "error "/> <message key= "Simplify.expression" Value= "has Boolean redundancy, Illegal coding specification 5.6 chapters." /> </module> <!--Chapter 5.7--> <!--check whether the switch statement has forgotten the default label--> <module name= "Missing Switchdefault "> <property name=" severity "value=" Error "/>" <message "key=" Missing.switch.default "Val Ue= There is no default statement behind the switch statement. Code of Criminal Code 5.7 chapters "/> </module> <!--Check the order of the default labels in the switch statement--> <mod Ule name= "Defaultcomeslast" > <property name= "severity" value= "error"/> <message "key=" . Last "value=" recommends that default be placed at the end of the switch statement. /> </module> <!--chapters 5.9--> <!--prohibit the use of System.out.println--> <module name= "Regexp" &
		 	Gt <property name= "format" value= "System\.out\.println"/> <property name= "message" value= "Do not use System.out and Sys Tem.out for console printing, you should use the Log tool class (such as: log4j) for uniform recording or printing, illegal code specification 5.9 chapters "/> <property name=" Illegalpattern "value=" true "/ > </module> <!--prohibit the use of System.err. println--> <module name= "Regexp" > <property name= "format" value= "System\.err\.println"/> < Property Name= "value=" do not use System.out and System.err for console printing, you should use the Log tool class (such as: log4j) for uniform recording or printing, illegal coding specifications 5.9 Chapters "/> &L T;property name= "Illegalpattern" value= "true"/> </module> <!--Chapter 5.10--> <!--not allowed to test with Main method > <module name= "Uncommentedmain" > </module> <!--chapter 5.11--> <!--Needbra  
	
Ces check if parentheses should be used where there is no parenthesis tokens: Define the type of check--> <module name= "needbraces"/> </module>
 </module>


Three: After installing Eclipse's Checkstyle plug-in, you can add the Checkstyle.xml file, how to add, there are many documents on the Web

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.