Hi Alexey,
Please share all sources where i can see a problem easily.
For now i could presume that " jar cf mycompanychecks.jar MethodLimitCheck.java " does not create proper jar with correct folder structure for package.
Thanks,
Roman Ivanov
--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package com.mycompany.checks;import com.puppycrawl.tools.checkstyle.api.*;
public class MethodLimitCheck extends Check{ private static final int DEFAULT_MAX = 30; private int max = DEFAULT_MAX;
@Override public int[] getDefaultTokens() { return new int[]{TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF}; }
@Override public void visitToken(DetailAST ast) { // find the OBJBLOCK node below the CLASS_DEF/INTERFACE_DEF DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK); // count the number of direct children of the OBJBLOCK // that are METHOD_DEFS int methodDefs = objBlock.getChildCount(TokenTypes.METHOD_DEF); // report error if limit is reached if (methodDefs > this.max) { log(ast.getLineNo(), "too many methods, only " + this.max + " are allowed"); } }}
<?xml version="1.0"?><!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"<module name="Checker"> <module name="TreeWalker"> <!-- your standard Checks that come with Checkstyle --> <module name="UpperEll"/> <module name="MethodLength"/> <!-- your Check goes here -->
<module name="com.mycompany.checks.MethodLimitCheck"> <property name="max" value="45"/> </module>
</module></module>
java -classpath checkswithfolders.jar:checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c custom_config.xml -r .
java -classpath checkswithoutfolders.jar:checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c custom_config.xml -r .
java -classpath checkswithfolders.jar:checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c custom_config.xml -r .java -classpath checkswithoutfolders.jar:checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c custom_config.xml -r .Unable to create Checker: cannot initialize module TreeWalker - Unable to instantiate com.mychecks.MethodLimitCheckcom.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Unable to instantiate com.mychecks.MethodLimitCheck
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:179) at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:184) at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143) at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate com.mychecks.MethodLimitCheck
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:155) at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161) at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:184) at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:158) ... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate com.mychecks.MethodLimitCheckCheck
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:98) at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:152) ... 6 more
java -classpath checkswithoutfolders.jar:checkstyle-5.7-all.jar com.puppycrawl.tools.checkstyle.Main -c standard_config.xml -r .Starting audit...Audit done.
Typically a JAR file contains the class files and auxiliary resources associated with applets and applications.