1 package com.puppycrawl.tools.checkstyle.checks.sizes; 20 21 import com.puppycrawl.tools.checkstyle.api.Check; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 import com.puppycrawl.tools.checkstyle.api.DetailAST; 24 25 58 public class AnonInnerLengthCheck extends Check 59 { 60 61 private static final int DEFAULT_MAX = 20; 62 63 64 private int mMax = DEFAULT_MAX; 65 66 67 public int[] getDefaultTokens() 68 { 69 return new int[] {TokenTypes.LITERAL_NEW}; 70 } 71 72 73 public void visitToken(DetailAST aAST) 74 { 75 final DetailAST openingBrace = aAST.findFirstToken(TokenTypes.OBJBLOCK); 76 if (openingBrace != null) { 77 final DetailAST closingBrace = 78 openingBrace.findFirstToken(TokenTypes.RCURLY); 79 final int length = 80 closingBrace.getLineNo() - openingBrace.getLineNo() + 1; 81 if (length > mMax) { 82 log(aAST.getLineNo(), 83 aAST.getColumnNo(), 84 "maxLen.anonInner", 85 new Integer (length), 86 new Integer (mMax)); 87 } 88 } 89 } 90 91 92 95 public void setMax(int aLength) 96 { 97 mMax = aLength; 98 } 99 } 100 | Popular Tags |