001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2026 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.naming; 021 022import com.puppycrawl.tools.checkstyle.api.TokenTypes; 023import com.puppycrawl.tools.checkstyle.utils.CommonUtil; 024 025/** 026 * <div> 027 * Checks that type names conform to a specified pattern. 028 * </div> 029 * 030 * @since 3.0 031 */ 032public class TypeNameCheck 033 extends AbstractAccessControlNameCheck { 034 035 /** 036 * Default pattern for type name. 037 */ 038 public static final String DEFAULT_PATTERN = "^[A-Z][a-zA-Z0-9]*$"; 039 040 /** 041 * Creates a new {@code TypeNameCheck} instance. 042 */ 043 public TypeNameCheck() { 044 super(DEFAULT_PATTERN); 045 } 046 047 @Override 048 public int[] getDefaultTokens() { 049 return getAcceptableTokens(); 050 } 051 052 @Override 053 public int[] getAcceptableTokens() { 054 return new int[] { 055 TokenTypes.CLASS_DEF, 056 TokenTypes.INTERFACE_DEF, 057 TokenTypes.ENUM_DEF, 058 TokenTypes.ANNOTATION_DEF, 059 TokenTypes.RECORD_DEF, 060 }; 061 } 062 063 @Override 064 public int[] getRequiredTokens() { 065 return CommonUtil.EMPTY_INT_ARRAY; 066 } 067 068 /** 069 * Setter to control if check should apply to package-private members. 070 * 071 * @param applyTo new value of the property. 072 * @propertySince 5.0 073 */ 074 @Override 075 public final void setApplyToPackage(boolean applyTo) { 076 super.setApplyToPackage(applyTo); 077 } 078 079 /** 080 * Setter to control if check should apply to private members. 081 * 082 * @param applyTo new value of the property. 083 * @propertySince 5.0 084 */ 085 @Override 086 public final void setApplyToPrivate(boolean applyTo) { 087 super.setApplyToPrivate(applyTo); 088 } 089 090 /** 091 * Setter to control if check should apply to protected members. 092 * 093 * @param applyTo new value of the property. 094 * @propertySince 5.0 095 */ 096 @Override 097 public final void setApplyToProtected(boolean applyTo) { 098 super.setApplyToProtected(applyTo); 099 } 100 101 /** 102 * Setter to control if check should apply to public members. 103 * 104 * @param applyTo new value of the property. 105 * @propertySince 5.0 106 */ 107 @Override 108 public final void setApplyToPublic(boolean applyTo) { 109 super.setApplyToPublic(applyTo); 110 } 111 112}