View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 the original author or authors.
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  
20  package com.puppycrawl.tools.checkstyle.checks.naming;
21  
22  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
23  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
24  
25  /**
26   * <div>
27   * Checks that type names conform to a specified pattern.
28   * </div>
29   *
30   * @since 3.0
31   */
32  public class TypeNameCheck
33      extends AbstractAccessControlNameCheck {
34  
35      /**
36       * Default pattern for type name.
37       */
38      public static final String DEFAULT_PATTERN = "^[A-Z][a-zA-Z0-9]*$";
39  
40      /**
41       * Creates a new {@code TypeNameCheck} instance.
42       */
43      public TypeNameCheck() {
44          super(DEFAULT_PATTERN);
45      }
46  
47      @Override
48      public int[] getDefaultTokens() {
49          return getAcceptableTokens();
50      }
51  
52      @Override
53      public int[] getAcceptableTokens() {
54          return new int[] {
55              TokenTypes.CLASS_DEF,
56              TokenTypes.INTERFACE_DEF,
57              TokenTypes.ENUM_DEF,
58              TokenTypes.ANNOTATION_DEF,
59              TokenTypes.RECORD_DEF,
60          };
61      }
62  
63      @Override
64      public int[] getRequiredTokens() {
65          return CommonUtil.EMPTY_INT_ARRAY;
66      }
67  
68      /**
69       * Setter to control if check should apply to package-private members.
70       *
71       * @param applyTo new value of the property.
72       * @propertySince 5.0
73       */
74      @Override
75      public final void setApplyToPackage(boolean applyTo) {
76          super.setApplyToPackage(applyTo);
77      }
78  
79      /**
80       * Setter to control if check should apply to private members.
81       *
82       * @param applyTo new value of the property.
83       * @propertySince 5.0
84       */
85      @Override
86      public final void setApplyToPrivate(boolean applyTo) {
87          super.setApplyToPrivate(applyTo);
88      }
89  
90      /**
91       * Setter to control if check should apply to protected members.
92       *
93       * @param applyTo new value of the property.
94       * @propertySince 5.0
95       */
96      @Override
97      public final void setApplyToProtected(boolean applyTo) {
98          super.setApplyToProtected(applyTo);
99      }
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 }