1 package com.puppycrawl.tools.checkstyle.checks.coding; 20 21 import com.puppycrawl.tools.checkstyle.api.DetailAST; 22 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 23 24 28 public final class NestedTryDepthCheck extends AbstractNestedDepthCheck 29 { 30 31 private static final int DEFAULT_MAX = 1; 32 33 34 public NestedTryDepthCheck() 35 { 36 super(DEFAULT_MAX); 37 } 38 39 40 public int[] getDefaultTokens() 41 { 42 return new int[] {TokenTypes.LITERAL_TRY}; 43 } 44 45 46 public void visitToken(DetailAST aAST) 47 { 48 switch (aAST.getType()) { 49 case TokenTypes.LITERAL_TRY: 50 visitLiteralTry(aAST); 51 break; 52 default: 53 throw new IllegalStateException (aAST.toString()); 54 } 55 } 56 57 58 public void leaveToken(DetailAST aAST) 59 { 60 switch (aAST.getType()) { 61 case TokenTypes.LITERAL_TRY: 62 leaveLiteralTry(); 63 break; 64 default: 65 throw new IllegalStateException (aAST.toString()); 66 } 67 } 68 69 73 private void visitLiteralTry(DetailAST aTry) 74 { 75 nestIn(aTry, "nested.try.depth"); 76 } 77 78 79 private void leaveLiteralTry() 80 { 81 nestOut(); 82 } 83 } 84 | Popular Tags |