| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractNameCheck |
|
| 1.6666666666666667;1.667 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 Oliver Burn | |
| 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 | import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck; | |
| 25 | ||
| 26 | /** | |
| 27 | * Abstract class for checking that names conform to a specified format. | |
| 28 | * | |
| 29 | * @author Rick Giles | |
| 30 | * @version 1.0 | |
| 31 | */ | |
| 32 | public abstract class AbstractNameCheck | |
| 33 | extends AbstractFormatCheck | |
| 34 | { | |
| 35 | /** | |
| 36 | * Creates a new <code>AbstractNameCheck</code> instance. | |
| 37 | * @param aFormat format to check with | |
| 38 | */ | |
| 39 | public AbstractNameCheck(String aFormat) | |
| 40 | { | |
| 41 | 86 | super(aFormat); |
| 42 | 86 | } |
| 43 | ||
| 44 | /** | |
| 45 | * Decides whether the name of an AST should be checked against | |
| 46 | * the format regexp. | |
| 47 | * @param aAST the AST to check. | |
| 48 | * @return true if the IDENT subnode of aAST should be checked against | |
| 49 | * the format regexp. | |
| 50 | */ | |
| 51 | protected boolean mustCheckName(DetailAST aAST) | |
| 52 | { | |
| 53 | 0 | return true; |
| 54 | } | |
| 55 | ||
| 56 | @Override | |
| 57 | public void visitToken(DetailAST aAST) | |
| 58 | { | |
| 59 | 1209 | if (mustCheckName(aAST)) { |
| 60 | 546 | final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT); |
| 61 | 546 | if (!getRegexp().matcher(nameAST.getText()).find()) { |
| 62 | 362 | log(nameAST.getLineNo(), |
| 63 | nameAST.getColumnNo(), | |
| 64 | "name.invalidPattern", | |
| 65 | nameAST.getText(), | |
| 66 | getFormat()); | |
| 67 | } | |
| 68 | } | |
| 69 | 1209 | } |
| 70 | } |