Checkstyle Custom rule fails to instantiate
tymieniecki <[email protected]> Sun, 29 Jan 2012 08:42:49 -0800 (PST)
| Newsgroups | gmane.comp.java.audit.checkstyle.user |
|---|---|
| Message-ID | <[email protected]> |
package softquatrachecks;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
/**
*
*
* This package provides the custom checks that were required outside
* of the standard checks provided
*
*/
public class LoggerAttrCheck extends Check
{
/**
*
* Indicator 7: Logging Mechanisms
*
* The Logger must be declared as a static final class attribute
*
*/
@Override
public int[] getDefaultTokens()
{
return new int[] {
TokenTypes.VARIABLE_DEF
};
}
@Override
public void visitToken(DetailAST aAST)
{
if(aAST.getType()==TokenTypes.VARIABLE_DEF)
visitVariableDef(aAST);
}
/**
* Checks type of given variable.
* @param aAST variable to check.
*/
private void visitVariableDef(DetailAST aAST)
{
checkVariableDefn(aAST);
}
/**
*
* Checks variable to see if its a Logger and static final
* * @param aAST node to check.
*/
private void checkVariableDefn(DetailAST aAST)
{
final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
final FullIdent ident = CheckUtils.createFullType(type);
if ((ident.getText().equals("Logger"))) {
if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenTypes.LITERAL_STATIC)))
{
log(type.getLineNo(), type.getColumnNo(),
"Logger not defined as static final class attribute",
type.getText());
}
}
}
}
When the rule is processed I get the message:
"Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr"
Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="softquatrachecks"/>
</checkstyle-packages>
Any Ideas folks
--
View this message in context: http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-to-instantiate-tp4338632p4338632.html
Sent from the CheckStyle - User mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2