| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractNestedDepthCheck |
|
| 1.1428571428571428;1.143 |
| 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 | package com.puppycrawl.tools.checkstyle.checks.coding; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.Check; | |
| 22 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 23 | ||
| 24 | /** | |
| 25 | * Abstract class which provides helpers functionality for nestedchecks. | |
| 26 | * | |
| 27 | * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a> | |
| 28 | */ | |
| 29 | public abstract class AbstractNestedDepthCheck extends Check | |
| 30 | { | |
| 31 | /** maximum allowed nesting depth */ | |
| 32 | private int mMax; | |
| 33 | /** curren nesting depth */ | |
| 34 | private int mDepth; | |
| 35 | ||
| 36 | /** | |
| 37 | * Creates new instance of checks. | |
| 38 | * @param aMax default allowed nesting depth. | |
| 39 | */ | |
| 40 | public AbstractNestedDepthCheck(int aMax) | |
| 41 | 6 | { |
| 42 | 6 | setMax(aMax); |
| 43 | 6 | } |
| 44 | ||
| 45 | @Override | |
| 46 | public final int[] getRequiredTokens() | |
| 47 | { | |
| 48 | 0 | return getDefaultTokens(); |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | public void beginTree(DetailAST aRootAST) | |
| 53 | { | |
| 54 | 6 | mDepth = 0; |
| 55 | 6 | } |
| 56 | ||
| 57 | /** | |
| 58 | * Getter for maximum allowed nesting depth. | |
| 59 | * @return maximum allowed nesting depth. | |
| 60 | */ | |
| 61 | public final int getMax() | |
| 62 | { | |
| 63 | 0 | return mMax; |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Setter for maximum allowed nesting depth. | |
| 68 | * @param aMax maximum allowed nesting depth. | |
| 69 | */ | |
| 70 | public final void setMax(int aMax) | |
| 71 | { | |
| 72 | 10 | mMax = aMax; |
| 73 | 10 | } |
| 74 | ||
| 75 | /** | |
| 76 | * Increasing current nesting depth. | |
| 77 | * @param aAST note which increases nesting. | |
| 78 | * @param aMessageId message id for logging error. | |
| 79 | */ | |
| 80 | protected final void nestIn(DetailAST aAST, String aMessageId) | |
| 81 | { | |
| 82 | 56 | if (mDepth > mMax) { |
| 83 | 8 | log(aAST, aMessageId, mDepth, mMax); |
| 84 | } | |
| 85 | 56 | ++mDepth; |
| 86 | 56 | } |
| 87 | ||
| 88 | /** Decreasing current nesting depth */ | |
| 89 | protected final void nestOut() | |
| 90 | { | |
| 91 | 56 | --mDepth; |
| 92 | 56 | } |
| 93 | } |