Unable to add custom check for non-java files to Checker module
shrgh <[email protected]> Fri, 6 Aug 2010 05:34:33 -0700 (PDT)
| Newsgroups | gmane.comp.java.audit.checkstyle.user |
|---|---|
| Message-ID | <[email protected]> |
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= 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?
--
View this message in context: http://checkstyle.2069334.n4.nabble.com/Unable-to-add-custom-check-for-non-java-files-to-Checker-module-tp2316262p2316262.html
Sent from the CheckStyle - User mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Checkstyle-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user