001///////////////////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
003// Copyright (C) 2001-2024 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.DetailAST;
023import com.puppycrawl.tools.checkstyle.api.TokenTypes;
024
025/**
026 * <div>
027 * Checks that interface type parameter names conform to a specified pattern.
028 * </div>
029 *
030 * <ul>
031 * <li>
032 * Property {@code format} - Sets the pattern to match valid identifiers.
033 * Type is {@code java.util.regex.Pattern}.
034 * Default value is {@code "^[A-Z]$"}.
035 * </li>
036 * </ul>
037 *
038 * <p>
039 * Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
040 * </p>
041 *
042 * <p>
043 * Violation Message Keys:
044 * </p>
045 * <ul>
046 * <li>
047 * {@code name.invalidPattern}
048 * </li>
049 * </ul>
050 *
051 * @since 5.8
052 */
053public class InterfaceTypeParameterNameCheck
054    extends AbstractNameCheck {
055
056    /** Creates a new {@code InterfaceTypeParameterNameCheck} instance. */
057    public InterfaceTypeParameterNameCheck() {
058        super("^[A-Z]$");
059    }
060
061    @Override
062    public int[] getDefaultTokens() {
063        return getRequiredTokens();
064    }
065
066    @Override
067    public int[] getAcceptableTokens() {
068        return getRequiredTokens();
069    }
070
071    @Override
072    public int[] getRequiredTokens() {
073        return new int[] {
074            TokenTypes.TYPE_PARAMETER,
075        };
076    }
077
078    @Override
079    protected final boolean mustCheckName(DetailAST ast) {
080        final DetailAST location =
081            ast.getParent().getParent();
082        return location.getType() == TokenTypes.INTERFACE_DEF;
083    }
084
085}