1 20 package com.puppycrawl.tools.checkstyle.checks.whitespace; 21 22 import com.puppycrawl.tools.checkstyle.api.DetailAST; 23 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 24 25 65 public class ParenPadCheck extends AbstractParenPadCheck 66 { 67 68 public int[] getDefaultTokens() 69 { 70 return new int[] {TokenTypes.RPAREN, 71 TokenTypes.LPAREN, 72 TokenTypes.CTOR_CALL, 73 TokenTypes.SUPER_CTOR_CALL, 74 TokenTypes.METHOD_CALL, 75 }; 76 } 77 78 79 public void visitToken(DetailAST aAST) 80 { 81 if (aAST.getType() != TokenTypes.RPAREN) { 84 if ((aAST.getType() == TokenTypes.CTOR_CALL) 85 || (aAST.getType() == TokenTypes.SUPER_CTOR_CALL)) 86 { 87 aAST = (DetailAST) aAST.getFirstChild(); 88 } 89 if (!isPreceedsEmptyForInit(aAST)) { 90 processLeft(aAST); 91 } 92 } 93 else if ((aAST.getParent() == null) 94 || (aAST.getParent().getType() != TokenTypes.TYPECAST) 95 || (aAST.getParent().findFirstToken(TokenTypes.RPAREN) 96 != aAST)) 97 { 98 if (!isFollowsEmptyForIterator(aAST)) { 99 processRight(aAST); 100 } 101 } 102 } 103 104 108 private boolean isFollowsEmptyForIterator(DetailAST aAST) 109 { 110 boolean followsEmptyForIterator = false; 111 final DetailAST parent = aAST.getParent(); 112 if ((parent != null) 114 && (parent.getType() == TokenTypes.LITERAL_FOR) 115 && (parent.findFirstToken(TokenTypes.FOR_EACH_CLAUSE) == null)) 116 { 117 final DetailAST forIterator = 118 parent.findFirstToken(TokenTypes.FOR_ITERATOR); 119 followsEmptyForIterator = (forIterator.getChildCount() == 0) 120 && (aAST == forIterator.getNextSibling()); 121 } 122 return followsEmptyForIterator; 123 } 124 125 129 private boolean isPreceedsEmptyForInit(DetailAST aAST) 130 { 131 boolean preceedsEmptyForInintializer = false; 132 final DetailAST parent = aAST.getParent(); 133 if ((parent != null) 135 && (parent.getType() == TokenTypes.LITERAL_FOR) 136 && (parent.findFirstToken(TokenTypes.FOR_EACH_CLAUSE) == null)) 137 { 138 final DetailAST forIterator = 139 parent.findFirstToken(TokenTypes.FOR_INIT); 140 preceedsEmptyForInintializer = (forIterator.getChildCount() == 0) 141 && (aAST == forIterator.getPreviousSibling()); 142 } 143 return preceedsEmptyForInintializer; 144 } 145 } 146 | Popular Tags |