Editing
Cs-doclet
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Integrating with eclipse-cs == When you integrate your checks with eclipse-cs, then you learn that you have to write two more metadata files: '''File "checkstyle-metadata.xml":''' <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE checkstyle-metadata PUBLIC "-//eclipse-cs//DTD Check Metadata 1.1//EN" "http://eclipse-cs.sourceforge.net/dtds/checkstyle-metadata_1_1.dtd"> <checkstyle-metadata> <rule-group-metadata name="%Whitespace.group" priority="999"> <rule-metadata internal-name="com.pany.cs.checks.ColorCheck" parent="TreeWalker" name="%ColorCheck.name" > <alternative-name internal-name="com.pany.cs.checks.ColorCheck" /> <description>%ColorCheck.desc</description> <property-metadata name="color" datatype="String" default-value="Yellow" > <description>%ColorCheck.color</description> </property-metadata> <message-key key="theColorIs" /> </rule-metadata> </rule-group-metadata> </checkstyle-metadata> '''File "checkstyle-metadata.properties":''' Whitespace.group = Whitespace ColorCheck.name = com.pany: ColorCheck ColorCheck.desc =\ A completely useless check which merely prints a (localizable) message each \ time it encounters an annotation. ColorCheck.color = A completely useless check parameter. Tedious, isn't it? Well, you can tell cs-doclet to also generate ''these'' files from annotations (and doc comments): '''File "src/com/pany/cs/checks/MyCheck.java":''' // File "src/com/pany/cs/ColorCheck.java". package com.pany.cs.checks; import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.TokenTypes; import de.unkrig.csdoclet.StringRuleProperty; import de.unkrig.csdoclet.Rule; /** * <span style="color:red">A completely useless check which merely prints a</span> * <span style="color:red">(localizable) message each time it encounters an annotation.</span> */ <span style="color:red">@Rule( group = "%Whitespace.group", groupName = "Whitespace", name = "com.pany: ColorCheck", parent = "TreeWalker" )</span> public class ColorCheck extends Check { @Message("The color is ''{0}''") private static final String MESSAGE_KEY_THE_COLOR_IS = "theColorIs"; /** * <span style="color:red">A completely useless check parameter</span>. */ <span style="color:red">@StringRuleProperty(defaultValue = DEFAULT_COLOR)</span> public void setColor(String value) { this.color = value; } private String color = <span style="color:red">DEFAULT_COLOR</span>; <span style="color:red">private static final String DEFAULT_COLOR = "Yellow";</span> @Override public int[] getDefaultTokens() { return new int[] { TokenTypes.ANNOTATION }; } @Override public void visitToken(DetailAST ast) { this.log(ast, MESSAGE_KEY_THE_COLOR_IS, this.color); } } $ javadoc \ > -doclet de.unkrig.doclet.cs.CsDoclet \ > -docletpath "path/to/cs-doclet.jar;bin;path/to/checkstyle-6.1-all.jar;path/to/net.sf.eclipsecs.core-6.1.jar" \ > <span style="color:red">-checkstyle-metadata.properties-dir src</span> \ > <span style="color:red">-checkstyle-metadata.xml-dir src</span> \ > -messages.properties-dir src \ > -sourcepath src \ > -classpath ../net.sf.checkstyle-6.1/checkstyle-6.1/checkstyle-6.1-all.jar \ > com.pany.cs.checks Loading source files for package com.pany.cs.checks... Constructing Javadoc information... $ And you'll get: '''File "src/com/pany/cs/checks/checkstyle-metadata.properties":''' # This file was generated by the CS doclet; see http://cs-doclet.unkrig.de/ # Rule groups: <span style="color:red">Whitespace.group</span> = <span style="color:red">Whitespace</span> # Custom checks, in alphabetical order. # --------------- <span style="color:red">com.pany: ColorCheck</span> --------------- <span style="color:red">ColorCheck.name</span> = <span style="color:red">com.pany: ColorCheck</span> <span style="color:red">ColorCheck.desc</span> =\ <span style="color:red">A completely useless check which merely prints a (localizable) message each time it encounters an annotation.</span> <span style="color:red">ColorCheck.color</span> = <span style="color:red">A completely useless check parameter.</span> '''File "src/com/pany/cs/checks/checkstyle-metadata.xml":''' <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE checkstyle-metadata PUBLIC "-//eclipse-cs//DTD Check Metadata 1.1//EN" "http://eclipse-cs.sourceforge.net/dtds/checkstyle-metadata_1_1.dtd"> <checkstyle-metadata> <!-- This file was generated by the CS doclet; see http://cs-doclet.unkrig.de/ --> <!-- ColorCheck --> <rule-group-metadata name="<span style="color:red">%Whitespace.group</span>" priority="999"> <rule-metadata internal-name="<span style="color:red">com.pany.cs.checks.ColorCheck</span>" parent="<span style="color:red">TreeWalker</span>" name="<span style="color:red">%ColorCheck.name</span>" > <alternative-name internal-name="<span style="color:red">com.pany.cs.checks.ColorCheck</span>" /> <description><span style="color:red">%ColorCheck.desc</span></description> <property-metadata name="<span style="color:red">color</span>" datatype="<span style="color:red">String</span>" default-value="<span style="color:red">Yellow</span>" > <description><span style="color:red">%ColorCheck.color</span></description> </property-metadata> <message-key key="theColorIs" /> </rule-metadata> </rule-group-metadata> </checkstyle-metadata>
Summary:
Please note that all contributions to unkrig.de may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Unkrig.de:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help
Tools
What links here
Related changes
Special pages
Page information