Unable to add custom check for non-java files to Checker module

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Unable to add custom check for non-java files to Checker module

shrgh
Hi, I am trying to create a custom check for non-java files. This is my check: package com.mycompany.checks; import com.puppycrawl.tools.checkstyle.api.Check; public class EmptyLineCheck extends Check { private int maxLines = 0; public void setMaxLines(int maxLines) { this.maxLines = maxLines; } public int[] getDefaultTokens() { return new int[0]; } public void beginTree(DetailAST detailAst) { String[] lines = getLines(); int count = 0; for (int i=0; i<lines.length; i++) { boolean blank = lines[i].trim().equals(""); if(blank){ count++; } else{ if(count >= maxLines){ int l = i-count; log(l, "Too many empty lines: Line "+l); } } } } } and my config file: When this check is added as a submodule of TreeWalker module in the config file, it works fine (for java files of course). In order to apply it to non-java files, when I try to define it as a submodule of Checker module (i.e outside the Treewalker), I am getting the following exception: Unable to create Checker: cannot initialize module com.mycompany.checks.EmptyLineC heck - com.mycompany.checks.EmptyLineCheck is not allowed as a child in Checker com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize modul e com.mycompany.checks.EmptyLineCheck - com.mycompany.checks.EmptyLineCheck is not a llowed as a child in Checker at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:177) at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic Bean.java:207) at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:138) at com.puppycrawl.tools.checkstyle.Main.main(Main.java:115) Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: com.mycompany. checks.EmptyLineCheck is not allowed as a child in Checker at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:171) Is it not allowed to add custom modules directly to Checker module? If not, how to add this module so that it can be used for any file?