I am trying to write custom check and use it from Eclipse.
I have wrote one MethodLimitCheck.java and one myChecker.xml file for that.
java file : MethodLimitCheck.java
package myCheck;
import com.puppycrawl.tools.checkstyle.api.*;
public class MethodLimitCheck extends Check
{
private static final int DEFAULT_MAX = 10;
private int max = DEFAULT_MAX;
public void setMax(int limit)
{
max = limit;
}
@Override
public int[] getDefaultTokens()
{
return new int[]{TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF};
}
@Override
public void visitToken(DetailAST ast)
{
DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK);
int methodDefs = objBlock.getChildCount(TokenTypes.METHOD_DEF);
if (methodDefs > this.max)
{
log(ast.getLineNo(),
"too many methods, only " + this.max + " are allowed");
}
}
}
and xml file : myChecker.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="myCheckStyle.MethodLimitCheck">
<property name="max" value="5" />
</module>
</module>
</module>
how can I use this check in eclipse?
I have taken this example from CheckStyle site. But how to use that in Eclipse?
I need to get the warnings in eclipse like when I use the available checks and form a custom configuration, That can be used from project->property->checkStyle.
I am new with this tool, so if I'm missing something basic, please correct me.