1 20 package com.puppycrawl.tools.checkstyle.checks.sizes; 21 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 import com.puppycrawl.tools.checkstyle.api.Check; 24 import com.puppycrawl.tools.checkstyle.api.DetailAST; 25 26 50 public class ParameterNumberCheck 51 extends Check 52 { 53 54 private static final int DEFAULT_MAX_PARAMETERS = 7; 55 56 57 private int mMax = DEFAULT_MAX_PARAMETERS; 58 59 63 public void setMax(int aMax) 64 { 65 mMax = aMax; 66 } 67 68 69 public int[] getDefaultTokens() 70 { 71 return new int[] {TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF}; 72 } 73 74 75 public void visitToken(DetailAST aAST) 76 { 77 final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS); 78 final int count = params.getChildCount(TokenTypes.PARAMETER_DEF); 79 if (count > mMax) { 80 final DetailAST name = aAST.findFirstToken(TokenTypes.IDENT); 81 log(name.getLineNo(), name.getColumnNo(), 82 "maxParam", new Integer (mMax)); 83 } 84 } 85 } 86 | Popular Tags |