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 import com.puppycrawl.tools.checkstyle.checks.CheckUtils; 24 25 30 public final class NestedIfDepthCheck extends AbstractNestedDepthCheck 31 { 32 33 private static final int DEFAULT_MAX = 1; 34 35 36 public NestedIfDepthCheck() 37 { 38 super(DEFAULT_MAX); 39 } 40 41 42 public int[] getDefaultTokens() 43 { 44 return new int[] {TokenTypes.LITERAL_IF}; 45 } 46 47 48 public void visitToken(DetailAST aAST) 49 { 50 switch (aAST.getType()) { 51 case TokenTypes.LITERAL_IF: 52 visitLiteralIf(aAST); 53 break; 54 default: 55 throw new IllegalStateException (aAST.toString()); 56 } 57 } 58 59 60 public void leaveToken(DetailAST aAST) 61 { 62 switch (aAST.getType()) { 63 case TokenTypes.LITERAL_IF: 64 leaveLiteralIf(aAST); 65 break; 66 default: 67 throw new IllegalStateException (aAST.toString()); 68 } 69 } 70 71 75 private void visitLiteralIf(DetailAST aIf) 76 { 77 if (!CheckUtils.isElseIf(aIf)) { 78 nestIn(aIf, "nested.if.depth"); 79 } 80 } 81 82 86 private void leaveLiteralIf(DetailAST aIf) 87 { 88 if (!CheckUtils.isElseIf(aIf)) { 89 nestOut(); 90 } 91 } 92 } 93 | Popular Tags |