001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2015 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.checks.coding; 021 022import java.util.Set; 023 024import com.google.common.collect.Sets; 025import com.puppycrawl.tools.checkstyle.api.Check; 026 027/** 028 * Support for checks that look for usage of illegal types. 029 * @deprecated Checkstyle will not support abstract checks anymore. Use {@link Check} instead. 030 * @author Oliver Burn 031 * @noinspection AbstractClassNeverImplemented 032 */ 033@Deprecated 034public abstract class AbstractIllegalCheck extends Check { 035 /** Illegal class names. */ 036 private final Set<String> illegalClassNames = Sets.newHashSet(); 037 038 /** 039 * Constructs an object. 040 * @param initialNames the initial class names to treat as illegal 041 */ 042 protected AbstractIllegalCheck(final String... initialNames) { 043 setIllegalClassNames(initialNames); 044 } 045 046 /** 047 * Checks if given class is illegal. 048 * 049 * @param ident 050 * ident to check. 051 * @return true if given ident is illegal. 052 */ 053 protected final boolean isIllegalClassName(final String ident) { 054 return illegalClassNames.contains(ident); 055 } 056 057 /** 058 * Set the list of illegal classes. 059 * 060 * @param classNames 061 * array of illegal exception classes 062 */ 063 public final void setIllegalClassNames(final String... classNames) { 064 illegalClassNames.clear(); 065 for (final String name : classNames) { 066 illegalClassNames.add(name); 067 final int lastDot = name.lastIndexOf('.'); 068 if (lastDot > 0 && lastDot < name.length() - 1) { 069 final String shortName = name 070 .substring(name.lastIndexOf('.') + 1); 071 illegalClassNames.add(shortName); 072 } 073 } 074 } 075}