View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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.DetailAST;
23  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
24  
25  /**
26   * <p>
27   * Abstract class for checking if a class/method type parameter's name
28   * conforms to a format specified by the format property.
29   * </p>
30   *
31   * <p>This class extends {@link AbstractNameCheck}</p>
32   * @deprecated Checkstyle will not support abstract checks anymore. Use
33   *             {@link AbstractNameCheck} instead.
34   * @author Travis Schneeberger
35   * @noinspection AbstractClassNeverImplemented
36   */
37  @Deprecated
38  public abstract class AbstractTypeParameterNameCheck
39      extends AbstractNameCheck {
40  
41      /**
42       * Creates a new {@code AbstractTypeParameterNameCheck} instance.
43       * @param format format to check with
44       */
45      protected AbstractTypeParameterNameCheck(String format) {
46          super(format);
47      }
48  
49      /**
50       * This method must be overridden to specify the
51       * location of the type parameter to check.
52       *
53       * @return {@code TokenTypes.CLASS_DEF }
54       *     or {@code TokenTypes.METHOD_DEF }
55       */
56      protected abstract int getLocation();
57  
58      @Override
59      public final int[] getDefaultTokens() {
60          return new int[] {
61              TokenTypes.TYPE_PARAMETER,
62          };
63      }
64  
65      @Override
66      public final int[] getAcceptableTokens() {
67          return new int[] {
68              TokenTypes.TYPE_PARAMETER,
69          };
70      }
71  
72      @Override
73      protected final boolean mustCheckName(DetailAST ast) {
74          final DetailAST location =
75              ast.getParent().getParent();
76          return location.getType() == getLocation();
77      }
78  }