Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractTypeParameterNameCheck |
|
| 1.4;1.4 |
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.naming; | |
20 | ||
21 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
22 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
23 | ||
24 | /** | |
25 | * <p> | |
26 | * Abstract class for checking if a class/method type parameter's name | |
27 | * conforms to a format specified by the format property. | |
28 | * </p> | |
29 | * | |
30 | * <p>This class extends {@link AbstractNameCheck}</p> | |
31 | * | |
32 | * @author Travis Schneeberger | |
33 | * @version 1.0 | |
34 | */ | |
35 | 1 | public abstract class AbstractTypeParameterNameCheck |
36 | extends AbstractNameCheck | |
37 | { | |
38 | /** the location of the type parameter **/ | |
39 | private int mLocation; | |
40 | ||
41 | /** | |
42 | * Creates a new <code>AbstractTypeParameterNameCheck</code> instance. | |
43 | * @param aFormat format to check with | |
44 | */ | |
45 | public AbstractTypeParameterNameCheck(String aFormat) | |
46 | { | |
47 | 4 | super(aFormat); |
48 | 4 | } |
49 | ||
50 | @Override | |
51 | public final int[] getDefaultTokens() | |
52 | { | |
53 | 4 | return new int[] { |
54 | TokenTypes.TYPE_PARAMETER, | |
55 | }; | |
56 | } | |
57 | ||
58 | @Override | |
59 | public final void init() | |
60 | { | |
61 | 4 | this.mLocation = getLocation(); |
62 | ||
63 | 4 | assert (this.mLocation == TokenTypes.CLASS_DEF) |
64 | || (this.mLocation == TokenTypes.METHOD_DEF); | |
65 | 4 | } |
66 | ||
67 | @Override | |
68 | protected final boolean mustCheckName(DetailAST aAST) | |
69 | { | |
70 | 44 | DetailAST location = |
71 | aAST.getParent().getParent(); | |
72 | ||
73 | 44 | if (location.getType() == TokenTypes.MODIFIERS) { |
74 | 0 | location = location.getParent(); |
75 | } | |
76 | ||
77 | 44 | return location.getType() == this.mLocation; |
78 | } | |
79 | ||
80 | /** | |
81 | * This method must be overriden to specify the | |
82 | * location of the type parameter to check. | |
83 | * | |
84 | * @return <code> TokenTypes.CLASS_DEF </code> | |
85 | * or <code> TokenTypes.METHOD_DEF </code> | |
86 | */ | |
87 | protected abstract int getLocation(); | |
88 | } |