Coverage Report - com.puppycrawl.tools.checkstyle.checks.naming.InterfaceTypeParameterNameCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
InterfaceTypeParameterNameCheck
100%
8/8
100%
2/2
1
 
 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  
  * Checks that interface type parameter names conform to a format specified
 28  
  * by the format property.  The format is a
 29  
  * {@link java.util.regex.Pattern regular expression} and defaults to
 30  
  * <strong>^[A-Z]$</strong>.
 31  
  * </p>
 32  
  * <p>
 33  
  * An example of how to configure the check is:
 34  
  * </p>
 35  
  * <pre>
 36  
  * &lt;module name="InterfaceTypeParameterName"/&gt;
 37  
  * </pre>
 38  
  * <p>
 39  
  * An example of how to configure the check for names that are only a single
 40  
  * letter is
 41  
  * </p>
 42  
  * <pre>
 43  
  * &lt;module name="InterfaceTypeParameterName"&gt;
 44  
  *    &lt;property name="format" value="^[a-zA-Z]$"/&gt;
 45  
  * &lt;/module&gt;
 46  
  * </pre>
 47  
  *
 48  
  * @author maxvetrenko
 49  
  */
 50  
 public class InterfaceTypeParameterNameCheck
 51  
     extends AbstractNameCheck {
 52  
     /** Creates a new {@code InterfaceTypeParameterNameCheck} instance. */
 53  
     public InterfaceTypeParameterNameCheck() {
 54  12
         super("^[A-Z]$");
 55  12
     }
 56  
 
 57  
     @Override
 58  
     public int[] getDefaultTokens() {
 59  15
         return getAcceptableTokens();
 60  
     }
 61  
 
 62  
     @Override
 63  
     public int[] getAcceptableTokens() {
 64  36
         return new int[] {
 65  
             TokenTypes.TYPE_PARAMETER,
 66  
         };
 67  
     }
 68  
 
 69  
     @Override
 70  
     public int[] getRequiredTokens() {
 71  16
         return getAcceptableTokens();
 72  
     }
 73  
 
 74  
     @Override
 75  
     protected final boolean mustCheckName(DetailAST ast) {
 76  26
         final DetailAST location =
 77  26
             ast.getParent().getParent();
 78  26
         return location.getType() == TokenTypes.INTERFACE_DEF;
 79  
     }
 80  
 }