KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > whitespace > TypecastParenPadCheck


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 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  * &lt;module name="TypecastParenPad"/&gt;
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  * &lt;module name="TypecastParenPad"&gt;
45  * &lt;property name="option" value="space"/&gt;
46  * &lt;/module&gt;
47  * </pre>
48  * @author Oliver Burn
49  * @version 1.0
50  */

51 public class TypecastParenPadCheck extends AbstractParenPadCheck
52 {
53     /** {@inheritDoc} */
54     public int[] getRequiredTokens()
55     {
56         return new int[] {TokenTypes.RPAREN, TokenTypes.TYPECAST};
57     }
58
59     /** {@inheritDoc} */
60     public int[] getDefaultTokens()
61     {
62         return getRequiredTokens();
63     }
64
65     /** {@inheritDoc} */
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
if (aAST.getType() == TokenTypes.TYPECAST) {
71             processLeft(aAST);
72         }
73         else if ((aAST.getParent() != null)
74                  && (aAST.getParent().getType() == TokenTypes.TYPECAST)
75                  && (aAST.getParent().findFirstToken(TokenTypes.RPAREN)
76                      == aAST))
77         {
78             processRight(aAST);
79         }
80     }
81 }
82
Popular Tags