custom check

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

custom check

androuser
Hi,
We have been using CheckStyle in our project to create custom checks. We have a requirement, which I
am unable to implement through checkStyle. The
requirement is all classes having names ending with *VO.java must
have a method named "toString".

this is my visittoken method

i am getting class in aAst.

public void visitToken(DetailAST aAst) {
    final DetailAST className = aAst.findFirstToken(TokenTypes.IDENT);
    if (className.getText().endsWith("VO") || className.getText().endsWith("DTO")) {
         DetailAST objBlock = aAst.findFirstToken(TokenTypes.OBJBLOCK);
         DetailAST temp = aAst;
         for(int i=1;i<=objBlock.getChildCount();i++) {
        if(i == 1) {
            temp = objBlock.getFirstChild();
            System.out.println(i + "******" +temp.getText());
        }
                                               
        else {
            if(temp.getNextSibling().getText() == "METHOD_DEF") {
                     temp = temp.getNextSibling().findFirstToken(TokenTypes.IDENT);
                System.out.println(i + "/////////" + temp.getText());
                 }
        }
         }
     }
}

all am able to get is the tokentype... that is METHOD_DEF.. but i need the actual method names in the class.

Please help me with this.

Thanks,
AndroUser