问题
I've written a custom check MethodLimitCheck.java
. I also have a custom configuration file myconfigurationfile.xml
which contains the following:
module name="Checker">
<!-- interfaces are limited to 10 methods -->
<module name="com.mycompany.checks.MethodLimitCheck">
<property name="tokens" value="INTERFACE_DEF"/>
<property name="max" value="10"/>
</module>
<!-- normal classes are limited to 25 methods -->
<module name="com.mycompany.checks.MethodLimitCheck">
<property name="tokens" value="CLASS_DEF"/>
<property name="max" value="15"/>
</module>
</module>
</module>
How do I get the checkstyle eclipse plugin to use this custom check? If I reference the myconfigurationfile.xml
in Eclipse -> window -> preferences -> Checkstyle it displays the error:
cannot initialize module TreeWalker - Unable to instantiate
com.mycompany.checks.MethodLimitCheck
cannot initialize module TreeWalker - Unable to instantiate
com.mycompany.checks.MethodLimitCheck
So the plugin is not able to run my custom check using the configuration file that I give it. I don't know where to place the configuration file or the java check that I wrote. There are three different checkstyle folders inside program files -> Eclipse -> plugins.
回答1:
This is quite difficult, I'm afraid. You need to write a small Eclipse plugin which is used to make the check available to Eclipse as explained here. The packaged plugin JAR can then be placed into the dropins folder. If you did everything right, you will be able to select your new check in the Checkstyle options.
Be prepared to spend a few days on this though, or find someone who already has experience writing Eclipse plugins.
来源:https://stackoverflow.com/questions/23917915/getting-the-checkstyle-plug-in-in-eclipse-to-use-your-custom-check