1 package com.mycompany.checks; 2 3 import com.puppycrawl.tools.checkstyle.api.*; 4 5 public class MethodLimitCheck extends Check 6 { 7 8 private int max = 30; 9 10 14 public void setMax(int aMax) 15 { 16 max = aMax; 17 } 18 19 23 public int[] getDefaultTokens() 24 { 25 return new int[]{TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF}; 26 } 27 28 31 public void visitToken(DetailAST ast) 32 { 33 35 49 51 DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK); 53 54 int methodDefs = objBlock.getChildCount(TokenTypes.METHOD_DEF); 57 58 if (methodDefs > max) { 60 log(ast.getLineNo(), "too.many.methods", new Integer (max)); 61 } 62 } 63 } 64 | Popular Tags |