001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 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//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks.naming; 020 021import com.puppycrawl.tools.checkstyle.api.DetailAST; 022import com.puppycrawl.tools.checkstyle.api.TokenTypes; 023 024/** 025* <p> 026 * Checks that parameter names conform to a format specified 027 * by the format property. The format is a 028 * {@link java.util.regex.Pattern regular expression} 029 * and defaults to 030 * <strong>^[a-z][a-zA-Z0-9]*$</strong>. 031 * </p> 032 * <p> 033 * An example of how to configure the check is: 034 * </p> 035 * <pre> 036 * <module name="ParameterName"/> 037 * </pre> 038 * <p> 039 * An example of how to configure the check for names that begin with 040 * a lower case letter, followed by letters, digits, and underscores is: 041 * </p> 042 * <pre> 043 * <module name="ParameterName"> 044 * <property name="format" value="^^[a-z](_?[a-zA-Z0-9]+)*$"/> 045 * </module> 046 * </pre> 047 * 048 * @author Oliver Burn 049 */ 050public class ParameterNameCheck 051 extends AbstractNameCheck 052{ 053 /** 054 * Creates a new <code>ParameterNameCheck</code> instance. 055 */ 056 public ParameterNameCheck() 057 { 058 super("^[a-z][a-zA-Z0-9]*$"); 059 } 060 061 @Override 062 public int[] getDefaultTokens() 063 { 064 return new int[] {TokenTypes.PARAMETER_DEF}; 065 } 066 067 @Override 068 protected boolean mustCheckName(DetailAST ast) 069 { 070 return !( 071 (ast.getParent() != null) 072 && (ast.getParent().getType() == TokenTypes.LITERAL_CATCH)); 073 } 074}