I have another StackOverflow question on how to install and run a custom checkstyle. I've learned how to do this, and I will update that answer shortly with detailed instructions. Now I am having trouble customizing my check. Below is my code. The problem is I would like to see the fully qualified package as a string (e.g com.amir.foo) - but instead when I run getText() or just toString(), I get some obscure result ([checkstyle] package set to : ANNOTATIONS). Does anyone know how to work with this to achieve the desired results?
import com.puppycrawl.tools.checkstyle.api.*;
public class MyCheck extends Check
{
FullIdent packageDeclaration;
public int[] getDefaultTokens() {
return new int[]{TokenTypes.PACKAGE_DEF};
}
public void visitToken(DetailAST ast)
{
switch(ast.getType()) {
case TokenTypes.PACKAGE_DEF:
System.out.println("got package!");
visitPackage(ast);
break;
default:
System.out.println("naughty!");
}
}
private void visitPackage(DetailAST pack) {
packageDeclaration = FullIdent.createFullIdentBelow(pack);
System.out.println("package set to : " +packageDeclaration);
}
}