Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TypecastParenPadCheck |
|
| 2.3333333333333335;2.333 |
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
3 | // Copyright (C) 2001-2014 Oliver Burn | |
4 | // | |
5 | // This library is free software; you can redistribute it and/or | |
6 | // modify it under the terms of the GNU Lesser General Public | |
7 | // License as published by the Free Software Foundation; either | |
8 | // version 2.1 of the License, or (at your option) any later version. | |
9 | // | |
10 | // This library is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | // Lesser General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU Lesser General Public | |
16 | // License along with this library; if not, write to the Free Software | |
17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | //////////////////////////////////////////////////////////////////////////////// | |
19 | package com.puppycrawl.tools.checkstyle.checks.whitespace; | |
20 | ||
21 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
22 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
23 | ||
24 | /** | |
25 | * <p>Checks the padding of parentheses for typecasts. That is whether a space | |
26 | * is required after a left parenthesis and before a right parenthesis, or such | |
27 | * spaces are forbidden. | |
28 | * <p> | |
29 | * </p> | |
30 | * The policy to verify is specified using the {@link PadOption} class and | |
31 | * defaults to {@link PadOption#NOSPACE}. | |
32 | * </p> | |
33 | * <p> | |
34 | * An example of how to configure the check is: | |
35 | * </p> | |
36 | * <pre> | |
37 | * <module name="TypecastParenPad"/> | |
38 | * </pre> | |
39 | * <p> | |
40 | * An example of how to configure the check to require spaces for the | |
41 | * parentheses of constructor, method, and super constructor invocations is: | |
42 | * </p> | |
43 | * <pre> | |
44 | * <module name="TypecastParenPad"> | |
45 | * <property name="option" value="space"/> | |
46 | * </module> | |
47 | * </pre> | |
48 | * @author Oliver Burn | |
49 | * @version 1.0 | |
50 | */ | |
51 | 3 | public class TypecastParenPadCheck extends AbstractParenPadCheck |
52 | { | |
53 | @Override | |
54 | public int[] getRequiredTokens() | |
55 | { | |
56 | 3 | return new int[] {TokenTypes.RPAREN, TokenTypes.TYPECAST}; |
57 | } | |
58 | ||
59 | @Override | |
60 | public int[] getDefaultTokens() | |
61 | { | |
62 | 3 | return getRequiredTokens(); |
63 | } | |
64 | ||
65 | @Override | |
66 | public void visitToken(DetailAST aAST) | |
67 | { | |
68 | // Strange logic in this method to guard against checking RPAREN tokens | |
69 | // that are not associated with a TYPECAST token. | |
70 | 122 | if (aAST.getType() == TokenTypes.TYPECAST) { |
71 | 10 | processLeft(aAST); |
72 | } | |
73 | 112 | else if ((aAST.getParent() != null) |
74 | && (aAST.getParent().getType() == TokenTypes.TYPECAST) | |
75 | && (aAST.getParent().findFirstToken(TokenTypes.RPAREN) | |
76 | == aAST)) | |
77 | { | |
78 | 10 | processRight(aAST); |
79 | } | |
80 | 122 | } |
81 | } |