1 package com.puppycrawl.tools.checkstyle.checks.design; 20 21 import com.puppycrawl.tools.checkstyle.api.DetailAST; 22 import com.puppycrawl.tools.checkstyle.api.Check; 23 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 24 25 43 public final class ThrowsCountCheck extends Check 44 { 45 46 private static final int DEFAULT_MAX = 1; 47 48 49 private int mMax; 50 51 52 public ThrowsCountCheck() 53 { 54 setMax(DEFAULT_MAX); 55 } 56 57 58 public int[] getDefaultTokens() 59 { 60 return new int[] { 61 TokenTypes.LITERAL_THROWS, 62 }; 63 } 64 65 66 public int[] getRequiredTokens() 67 { 68 return getDefaultTokens(); 69 } 70 71 75 public int getMax() 76 { 77 return mMax; 78 } 79 80 84 public void setMax(int aMax) 85 { 86 mMax = aMax; 87 } 88 89 90 public void visitToken(DetailAST aAST) 91 { 92 switch (aAST.getType()) { 93 case TokenTypes.LITERAL_THROWS: 94 visitLiteralThrows(aAST); 95 break; 96 default: 97 throw new IllegalStateException (aAST.toString()); 98 } 99 } 100 101 105 private void visitLiteralThrows(DetailAST aAST) 106 { 107 final int count = (aAST.getChildCount() + 1) / 2; 109 if (count > getMax()) { 110 log(aAST.getLineNo(), aAST.getColumnNo(), "throws.count", 111 new Integer (count), new Integer (getMax())); 112 } 113 } 114 } 115 | Popular Tags |