Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractIllegalCheck |
|
| 2.0;2 |
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.coding; | |
20 | ||
21 | import com.google.common.collect.Sets; | |
22 | import com.puppycrawl.tools.checkstyle.api.Check; | |
23 | import java.util.Set; | |
24 | ||
25 | /** | |
26 | * Support for checks that look for usage of illegal types. | |
27 | * @author Oliver Burn | |
28 | */ | |
29 | 1 | public abstract class AbstractIllegalCheck extends Check |
30 | { | |
31 | /** Illegal class names */ | |
32 | 25 | private final Set<String> mIllegalClassNames = Sets.newHashSet(); |
33 | ||
34 | /** | |
35 | * Constructs an object. | |
36 | * @param aInitialNames the initial class names to treat as illegal | |
37 | */ | |
38 | protected AbstractIllegalCheck(final String[] aInitialNames) | |
39 | 25 | { |
40 | 25 | assert aInitialNames != null; |
41 | 25 | setIllegalClassNames(aInitialNames); |
42 | 25 | } |
43 | ||
44 | /** | |
45 | * Checks if given class is illegal. | |
46 | * | |
47 | * @param aIdent | |
48 | * ident to check. | |
49 | * @return true if given ident is illegal. | |
50 | */ | |
51 | protected final boolean isIllegalClassName(final String aIdent) | |
52 | { | |
53 | 90 | return mIllegalClassNames.contains(aIdent); |
54 | } | |
55 | ||
56 | /** | |
57 | * Set the list of illegal classes. | |
58 | * | |
59 | * @param aClassNames | |
60 | * array of illegal exception classes | |
61 | */ | |
62 | public final void setIllegalClassNames(final String[] aClassNames) | |
63 | { | |
64 | 28 | assert aClassNames != null; |
65 | 28 | mIllegalClassNames.clear(); |
66 | 230 | for (final String name : aClassNames) { |
67 | 202 | mIllegalClassNames.add(name); |
68 | 202 | final int lastDot = name.lastIndexOf("."); |
69 | 202 | if ((lastDot > 0) && (lastDot < (name.length() - 1))) { |
70 | 103 | final String shortName = name |
71 | .substring(name.lastIndexOf(".") + 1); | |
72 | 103 | mIllegalClassNames.add(shortName); |
73 | } | |
74 | } | |
75 | 28 | } |
76 | } |