KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > coding > AbstractIllegalCheck


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.coding;
20
21 import com.puppycrawl.tools.checkstyle.api.Check;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 /**
26  * Support for checks that look for usage of illegal types.
27  * @author Oliver Burn
28  */

29 public abstract class AbstractIllegalCheck extends Check
30 {
31     /** Illegal class names */
32     private final Set JavaDoc mIllegalClassNames = new HashSet JavaDoc();
33
34     /**
35      * Constructs an object.
36      * @param aInitialNames the initial class names to treat as illegal
37      */

38     protected AbstractIllegalCheck(final String JavaDoc[] aInitialNames)
39     {
40         assert aInitialNames != null;
41         setIllegalClassNames(aInitialNames);
42     }
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 JavaDoc aIdent)
52     {
53         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 JavaDoc[] aClassNames)
63     {
64         assert aClassNames != null;
65         mIllegalClassNames.clear();
66         for (int i = 0; i < aClassNames.length; i++) {
67             final String JavaDoc name = aClassNames[i];
68             mIllegalClassNames.add(name);
69             final int lastDot = name.lastIndexOf(".");
70             if ((lastDot > 0) && (lastDot < (name.length() - 1))) {
71                 final String JavaDoc shortName = name
72                         .substring(name.lastIndexOf(".") + 1);
73                 mIllegalClassNames.add(shortName);
74             }
75         }
76     }
77 }
78
Popular Tags