| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SeverityMatchFilter |
|
| 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 | package com.puppycrawl.tools.checkstyle.filters; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.AuditEvent; | |
| 22 | import com.puppycrawl.tools.checkstyle.api.AutomaticBean; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.Filter; | |
| 24 | import com.puppycrawl.tools.checkstyle.api.SeverityLevel; | |
| 25 | ||
| 26 | /** | |
| 27 | * This is a very simple filter based on severity matching. | |
| 28 | * The filter admits option severity and accepts an AuditEvent | |
| 29 | * if its severity equals the filter's severity. | |
| 30 | * @author Rick Giles | |
| 31 | */ | |
| 32 | 3 | public class SeverityMatchFilter |
| 33 | extends AutomaticBean | |
| 34 | implements Filter | |
| 35 | { | |
| 36 | /** the severity level to accept */ | |
| 37 | 3 | private SeverityLevel mSeverityLevel = SeverityLevel.ERROR; |
| 38 | ||
| 39 | /** whether to accept or reject on severity matches */ | |
| 40 | 3 | private boolean mAcceptOnMatch = true; |
| 41 | ||
| 42 | /** | |
| 43 | * Sets the severity level. The string should be one of the names | |
| 44 | * defined in the <code>SeverityLevel</code> class. | |
| 45 | * | |
| 46 | * @param aSeverity The new severity level | |
| 47 | * @see SeverityLevel | |
| 48 | */ | |
| 49 | public final void setSeverity(String aSeverity) | |
| 50 | { | |
| 51 | 2 | mSeverityLevel = SeverityLevel.getInstance(aSeverity); |
| 52 | 2 | } |
| 53 | ||
| 54 | /** | |
| 55 | * Sets whether to accept or reject on matching severity level. | |
| 56 | * @param aAcceptOnMatch if true, accept on matches; if | |
| 57 | * false, reject on matches. | |
| 58 | */ | |
| 59 | public final void setAcceptOnMatch(boolean aAcceptOnMatch) | |
| 60 | { | |
| 61 | 1 | mAcceptOnMatch = aAcceptOnMatch; |
| 62 | 1 | } |
| 63 | ||
| 64 | /** {@inheritDoc} */ | |
| 65 | public boolean accept(AuditEvent aEvent) | |
| 66 | { | |
| 67 | 9 | final boolean result = mSeverityLevel.equals(aEvent.getSeverityLevel()); |
| 68 | 9 | if (mAcceptOnMatch) { |
| 69 | 6 | return result; |
| 70 | } | |
| 71 | 3 | return !result; |
| 72 | } | |
| 73 | } |