Refactored Filters to the way Checkstyle uses them;

i.e. a Filter accepts or rejects an Object,
and a FilterSet, not a FilterChain, aggregates Filters.
This commit is contained in:
Rick Giles 2003-07-15 20:18:02 +00:00
parent a9bfdceec2
commit 1e7d8eef06
18 changed files with 205 additions and 223 deletions

View File

@ -31,7 +31,7 @@ import com.puppycrawl.tools.checkstyle.api.Configuration;
import com.puppycrawl.tools.checkstyle.api.Context;
import com.puppycrawl.tools.checkstyle.api.FileSetCheck;
import com.puppycrawl.tools.checkstyle.api.Filter;
import com.puppycrawl.tools.checkstyle.api.FilterChain;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
@ -125,7 +125,7 @@ public class Checker extends AutomaticBean
private Context mChildContext;
/** The audit event filter chain */
private final FilterChain mFilterChain = new FilterChain();
private final FilterSet mFilterChain = new FilterSet();
/**
* The severity level of any violations found by submodules.
@ -298,7 +298,7 @@ public class Checker extends AutomaticBean
protected void fireAuditStarted()
{
final AuditEvent evt = new AuditEvent(this);
if (mFilterChain.decide(evt) != Filter.DENY) {
if (mFilterChain.accept(evt)) {
final Iterator it = mListeners.iterator();
while (it.hasNext()) {
final AuditListener listener = (AuditListener) it.next();
@ -311,7 +311,7 @@ public class Checker extends AutomaticBean
protected void fireAuditFinished()
{
final AuditEvent evt = new AuditEvent(this);
if (mFilterChain.decide(evt) != Filter.DENY) {
if (mFilterChain.accept(evt)) {
final Iterator it = mListeners.iterator();
while (it.hasNext()) {
final AuditListener listener = (AuditListener) it.next();
@ -328,7 +328,7 @@ public class Checker extends AutomaticBean
{
final String stripped = getStrippedFileName(aFileName);
final AuditEvent evt = new AuditEvent(this, stripped);
if (mFilterChain.decide(evt) != Filter.DENY) {
if (mFilterChain.accept(evt)) {
final Iterator it = mListeners.iterator();
while (it.hasNext()) {
final AuditListener listener = (AuditListener) it.next();
@ -345,7 +345,7 @@ public class Checker extends AutomaticBean
{
final String stripped = getStrippedFileName(aFileName);
final AuditEvent evt = new AuditEvent(this, stripped);
if (mFilterChain.decide(evt) != Filter.DENY) {
if (mFilterChain.accept(evt)) {
final Iterator it = mListeners.iterator();
while (it.hasNext()) {
final AuditListener listener = (AuditListener) it.next();
@ -364,7 +364,7 @@ public class Checker extends AutomaticBean
final String stripped = getStrippedFileName(aFileName);
for (int i = 0; i < aErrors.length; i++) {
final AuditEvent evt = new AuditEvent(this, stripped, aErrors[i]);
if (mFilterChain.decide(evt) != Filter.DENY) {
if (mFilterChain.accept(evt)) {
final Iterator it = mListeners.iterator();
while (it.hasNext()) {
final AuditListener listener = (AuditListener) it.next();

View File

@ -30,7 +30,7 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.FilterChain;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
import com.puppycrawl.tools.checkstyle.filters.SuppressElement;
/**
@ -52,7 +52,7 @@ public final class SuppressionsLoader
* the filter chain to return in getAFilterChain(),
* configured during parsing
*/
private final FilterChain mFilterChain = new FilterChain();
private final FilterSet mFilterChain = new FilterSet();
/**
* Creates a new <code>SuppressionsLoader</code> instance.
@ -69,7 +69,7 @@ public final class SuppressionsLoader
* Returns the loaded filter chain.
* @return the loaded filter chain.
*/
public FilterChain getFilterChain()
public FilterSet getFilterChain()
{
return mFilterChain;
}
@ -116,7 +116,7 @@ public final class SuppressionsLoader
* @return the filter chain of suppression elements specified in the file.
* @throws CheckstyleException if an error occurs.
*/
public static FilterChain loadSuppressions(String aFilename)
public static FilterSet loadSuppressions(String aFilename)
throws CheckstyleException
{
FileReader reader = null;
@ -138,7 +138,7 @@ public final class SuppressionsLoader
* @return the filter chain of suppression elements in aSource.
* @throws CheckstyleException if an error occurs.
*/
private static FilterChain loadSuppressions(
private static FilterSet loadSuppressions(
InputSource aSource, String aSourceName)
throws CheckstyleException
{

View File

@ -19,30 +19,16 @@
package com.puppycrawl.tools.checkstyle.api;
/**
* Users should extend this class to implement customized
* Object filtering.
* An interface for filtering objects.
* @author Rick Giles
*/
public interface Filter
{
/** The object is acceptable to this filter. */
int ACCEPT = -1;
/** The object is rejected by this filter. */
int DENY = 0;
/** This filter is neutral with respect to the object. */
int NEUTRAL = 1;
/**
* Determines the filtering of an Object.
* If the decision is <code>DENY</code>, then the Object is rejected.
* If the decision is <code>NEUTRAL</code>, then the filter is neutral
* with respect to the Object.
* If the decision is <code>ACCEPT</code> then the object will be accepted.
* @param aObject the object to decide on.
* @return the decision of the filter.
* Determines whether or not a filtered Object is accepted.
* @param aObject the Object to filter.
* @return true if the aObject is accepted.
*/
int decide(Object aObject);
boolean accept(Object aObject);
}

View File

@ -18,72 +18,74 @@
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.api;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* A filter chain applies filters to Objects in chain order.
* If the decision of a filter in the chain is ACCEPT, then
* the chain accepts the Object immediately, without consulting
* the remaining filters.
* If the decision of a filter in the chain is DENY, then
* the chain rejects the Object immediately, without consulting
* the remaining filters.
* If the decision of a filter in the chain is NEUTRAL, then
* the mext filter in the chain, if any, is consulted.
* A filter set applies filters to Objects.
* If a filter in the set rejects an Object, then the
* Object is rejected. Otherwise, the Object is accepted.
* @author Rick Giles
*/
public class FilterChain
public class FilterSet
implements Filter
{
/** filter chain */
private List mFilterChain = new ArrayList();
/** filter set */
private Set mFilters = new HashSet();
/**
* Adds a Filter as the last filter in the chain.
* Adds a Filter to the set.
* @param aFilter the Filter to add.
*/
public void addFilter(Filter aFilter)
{
mFilterChain.add(aFilter);
mFilters.add(aFilter);
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter#decide */
public int decide(Object aObject)
/**
* Returns the Filters of the filter set.
* @return the Filters of the filter set.
*/
protected Set getFilters()
{
final Iterator it = mFilterChain.iterator();
while (it.hasNext()) {
final Filter filter = (Filter) it.next();
final int decision = filter.decide(aObject);
if (decision != Filter.NEUTRAL) {
return decision;
}
}
return Filter.NEUTRAL;
return mFilters;
}
/** @see java.lang.Object#toString() */
public String toString()
{
return mFilterChain.toString();
return mFilters.toString();
}
/** @see java.lang.Object#hashCode() */
public int hashCode()
{
return mFilterChain.hashCode();
return mFilters.hashCode();
}
/** @see java.lang.Object#equals(java.lang.Object) */
public boolean equals (Object aObject)
{
if (aObject instanceof FilterChain) {
final FilterChain other = (FilterChain) aObject;
return this.mFilterChain.equals(other.mFilterChain);
if (aObject instanceof FilterSet) {
final FilterSet other = (FilterSet) aObject;
return this.mFilters.equals(other.mFilters);
}
else {
return false;
}
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter */
public boolean accept(Object aObject)
{
final Iterator it = mFilters.iterator();
while (it.hasNext()) {
final Filter filter = (Filter) it.next();
if (!filter.accept(aObject)) {
return false;
}
}
return true;
}
}

View File

@ -18,22 +18,24 @@
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.filters;
import java.util.Iterator;
import java.util.StringTokenizer;
import com.puppycrawl.tools.checkstyle.api.FilterChain;
import com.puppycrawl.tools.checkstyle.api.Filter;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
/**
* <p>
* This filter accepts an integer that matches a CSV value, or
* is in a CSV range. It is neutral on other Objects.
* This filter accepts an integer that matches a CSV value, where
* each value is an integer or a range of integers.
* </p>
* @author Rick Giles
*/
public class CSVFilter
extends FilterChain
extends FilterSet
{
/**
* Contructs a <code>CSVFilter</code> from a CSV, Comma-Separated Values,
* Constructs a <code>CSVFilter</code> from a CSV, Comma-Separated Values,
* string. Each value is an integer, or a range of integers. A range of
* integers is of the form integer-integer, such as 1-10.
* @param aPattern the CSV string.
@ -60,4 +62,24 @@ public class CSVFilter
}
}
}
/**
* Determines whether an Object matches a CSV integer value.
* @param aObject the Object to check.
* @return true if aObject is an Integer that matches a CSV value.
*/
public boolean accept(Object aObject)
{
if (!(aObject instanceof Integer)) {
return false;
}
final Iterator it = getFilters().iterator();
while (it.hasNext()) {
final Filter filter = (Filter) it.next();
if (filter.accept(aObject)) {
return true;
}
}
return false;
}
}

View File

@ -40,9 +40,9 @@ public class DenyAllFilter
{
/** @see com.puppycrawl.tools.checkstyle.filter.Filter */
public int decide(Object aObject)
public boolean accept(Object aObject)
{
return Filter.DENY;
return false;
}
}

View File

@ -41,14 +41,9 @@ public class IntMatchFilter
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter */
public int decide(Object aObject)
public boolean accept(Object aObject)
{
if ((mMatchValue.equals(aObject))) {
return Filter.ACCEPT;
}
else {
return Filter.NEUTRAL;
}
return mMatchValue.equals(aObject);
}
/** @see java.lang.Object#toString() */

View File

@ -49,17 +49,14 @@ public class IntRangeFilter
mUpperBound = new Integer(aUpperBound);
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter#decide */
public int decide(Object aObject)
/** @see com.puppycrawl.tools.checkstyle.api.Filter */
public boolean accept(Object aObject)
{
if ((mLowerBound.compareTo(aObject) <= 0)
&& (mUpperBound.compareTo(aObject) >= 0))
{
return Filter.ACCEPT;
}
else {
return Filter.NEUTRAL;
if (!(aObject instanceof Integer)) {
return false;
}
return ((mLowerBound.compareTo(aObject) <= 0)
&& (mUpperBound.compareTo(aObject) >= 0));
}
/** @see java.lang.Object#hashCode() */

View File

@ -25,14 +25,8 @@ import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
/**
* This is a very simple filter based on severity matching.
* The filter admits two options severity and acceptOnMatch.
* If there is an exact match between the value of the
* severity option and the severity of the AuditEvent,
* then the decide(AuditEvent) method
* returns Filter.ACCEPT in case the acceptOnMatch option value is
* set to true, if it is false then Filter.DENY is returned.
* If there is no match, or the filtered Object is not
* an AuditEvent, Filter.NEUTRAL is returned.
* The filter admits option severity and accepts an AuditEvent
* if its severity equals the filter's severity.
* @author Rick Giles
*/
public class SeverityMatchFilter
@ -42,12 +36,6 @@ public class SeverityMatchFilter
/** the severity level to accept */
private SeverityLevel mSeverityLevel = SeverityLevel.ERROR;
/**
* Do we return ACCEPT when a match occurs?
* Default is <code>true</code>.
*/
private boolean mAcceptOnMatch = true;
/**
* Sets the severity level. The string should be one of the names
* defined in the <code>SeverityLevel</code> class.
@ -60,64 +48,16 @@ public class SeverityMatchFilter
mSeverityLevel = SeverityLevel.getInstance(aSeverity);
}
/**
* Get the severity level's name.
*
* @return the check's severity level name.
*/
public final String getSeverity()
{
return mSeverityLevel.getName();
}
/**
* Sets whether we return ACCEPT or DENY when a match occurs.
* @param aAcceptOnMatch if true return ACCEPT when a match
* occurs; if false, return DENY.
*/
public final void setAcceptOnMatch(boolean aAcceptOnMatch)
{
mAcceptOnMatch = aAcceptOnMatch;
}
/**
* Returns whether we return ACCEPT or DENY when a match occurs.
* @return true if return ACCEPT when a match occurs;
* return false if DENY.
*/
public boolean getAcceptOnMatch()
{
return mAcceptOnMatch;
}
/** @see com.puppycrawl.tools.checkstyle.filter.Filter */
public int decide(Object aObject)
public boolean accept(Object aObject)
{
if (!(aObject instanceof AuditEvent)) {
return Filter.NEUTRAL;
return false;
}
final AuditEvent event = (AuditEvent) aObject;
if (mSeverityLevel == null) {
return Filter.NEUTRAL;
}
boolean matchOccurred = false;
if (mSeverityLevel.equals(event.getSeverityLevel())) {
matchOccurred = true;
}
if (matchOccurred) {
if (mAcceptOnMatch) {
return Filter.ACCEPT;
}
else {
return Filter.DENY;
}
}
else {
return Filter.NEUTRAL;
}
return mSeverityLevel.equals(event.getSeverityLevel());
}
}

View File

@ -111,10 +111,10 @@ public class SuppressElement
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter */
public int decide(Object aObject)
public boolean accept(Object aObject)
{
if (!(aObject instanceof AuditEvent)) {
return Filter.NEUTRAL;
return true;
}
final AuditEvent event = (AuditEvent) aObject;
@ -125,30 +125,30 @@ public class SuppressElement
|| (event.getLocalizedMessage() == null)
|| !mCheckRegexp.match(event.getSourceName()))
{
return Filter.NEUTRAL;
return true;
}
// deny if no line/column matching
// reject if no line/column matching
if ((mLineFilter == null) && (mColumnFilter == null)) {
return Filter.DENY;
return false;
}
// deny line if it is accepted by the line CSV filter
// reject line if it is accepted by the line CSV filter
if (mLineFilter != null) {
final Integer line = new Integer(event.getLine());
if (mLineFilter.decide(line) == Filter.ACCEPT) {
return Filter.DENY;
if (mLineFilter.accept(line)) {
return false;
}
}
// deny if column accepted by the column CSV filter
// reject if column accepted by the column CSV filter
if (mColumnFilter != null) {
final Integer column = new Integer(event.getColumn());
if (mColumnFilter.decide(column) == Filter.ACCEPT) {
return Filter.DENY;
if (mColumnFilter.accept(column)) {
return false;
}
}
return Filter.NEUTRAL;
return true;
}
/** @see java.lang.Object#toString() */

View File

@ -22,7 +22,7 @@ import com.puppycrawl.tools.checkstyle.SuppressionsLoader;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Filter;
import com.puppycrawl.tools.checkstyle.api.FilterChain;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
/**
* <p>
@ -37,7 +37,7 @@ public class SuppressionFilter
implements Filter
{
/** chain of individual suppresses */
private FilterChain mFilterChain = new FilterChain();
private FilterSet mFilterChain = new FilterSet();
/**
* Loads the suppressions for a file.
@ -51,9 +51,9 @@ public class SuppressionFilter
}
/** @see com.puppycrawl.tools.checkstyle.api.Filter */
public int decide(Object aObject)
public boolean accept(Object aObject)
{
return mFilterChain.decide(aObject);
return mFilterChain.accept(aObject);
}
/** @see java.lang.Object#toString() */

View File

@ -5,7 +5,7 @@ import org.apache.regexp.RESyntaxException;
import junit.framework.TestCase;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.FilterChain;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
import com.puppycrawl.tools.checkstyle.filters.SuppressElement;
/**
@ -17,20 +17,20 @@ public class SuppressionsLoaderTest extends TestCase
public void testNoSuppressions()
throws CheckstyleException
{
final FilterChain fc =
final FilterSet fc =
SuppressionsLoader.loadSuppressions(
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_none.xml");
final FilterChain fc2 = new FilterChain();
final FilterSet fc2 = new FilterSet();
assertEquals(fc, fc2);
}
public void testMultipleSuppression()
throws CheckstyleException, RESyntaxException
{
final FilterChain fc =
final FilterSet fc =
SuppressionsLoader.loadSuppressions(
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_multiple.xml");
final FilterChain fc2 = new FilterChain();
final FilterSet fc2 = new FilterSet();
SuppressElement se0 = new SuppressElement("file0", "check0");
fc2.addFilter(se0);
SuppressElement se1 = new SuppressElement("file1", "check1");

View File

@ -14,10 +14,11 @@ public class AllTests
TestSuite suite =
new TestSuite("Test for com.puppycrawl.tools.checkstyle.filter");
//$JUnit-BEGIN$
suite.addTest(new TestSuite(FilterSetTest.class));
suite.addTest(new TestSuite(IntMatchFilterTest.class));
suite.addTest(new TestSuite(IntRangeFilterTest.class));
suite.addTest(new TestSuite(CSVFilterTest.class));
suite.addTest(new TestSuite(SupressElementTest.class));
suite.addTest(new TestSuite(SuppressElementTest.class));
//$JUnit-END$
return suite;
}

View File

@ -4,54 +4,54 @@ import com.puppycrawl.tools.checkstyle.api.Filter;
import junit.framework.TestCase;
/** Tests IntMatchFilter */
/** Tests CSVFilter */
public class CSVFilterTest extends TestCase
{
public void testDecideSingle()
{
final Filter filter = new CSVFilter("0");
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(1)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("equal", filter.accept(new Integer(0)));
assertFalse("greater than", filter.accept(new Integer(1)));
}
public void testDecidePair()
{
final Filter filter = new CSVFilter("0, 2");
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal 0", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(1)));
assertEquals("equal 2", Filter.ACCEPT, filter.decide(new Integer(2)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("equal 0", filter.accept(new Integer(0)));
assertFalse("greater than", filter.accept(new Integer(1)));
assertTrue("equal 2", filter.accept(new Integer(2)));
}
public void testDecideRange()
{
final Filter filter = new CSVFilter("0-2");
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal 0", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("equal 1", Filter.ACCEPT, filter.decide(new Integer(1)));
assertEquals("equal 2", Filter.ACCEPT, filter.decide(new Integer(2)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(3)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("equal 0", filter.accept(new Integer(0)));
assertTrue("equal 1", filter.accept(new Integer(1)));
assertTrue("equal 2", filter.accept(new Integer(2)));
assertFalse("greater than", filter.accept(new Integer(3)));
}
public void testDecideEmptyRange()
{
final Filter filter = new CSVFilter("2-0");
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal 0", Filter.NEUTRAL, filter.decide(new Integer(0)));
assertEquals("equal 1", Filter.NEUTRAL, filter.decide(new Integer(1)));
assertEquals("equal 2", Filter.NEUTRAL, filter.decide(new Integer(2)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(3)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertFalse("equal 0", filter.accept(new Integer(0)));
assertFalse("equal 1", filter.accept(new Integer(1)));
assertFalse("equal 2", filter.accept(new Integer(2)));
assertFalse("greater than", filter.accept(new Integer(3)));
}
public void testDecideRangePlusValue()
{
final Filter filter = new CSVFilter("0-2, 10");
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal 0", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("equal 1", Filter.ACCEPT, filter.decide(new Integer(1)));
assertEquals("equal 2", Filter.ACCEPT, filter.decide(new Integer(2)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(3)));
assertEquals("equal 10", Filter.ACCEPT, filter.decide(new Integer(10)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("equal 0", filter.accept(new Integer(0)));
assertTrue("equal 1", filter.accept(new Integer(1)));
assertTrue("equal 2", filter.accept(new Integer(2)));
assertFalse("greater than", filter.accept(new Integer(3)));
assertTrue("equal 10", filter.accept(new Integer(10)));
}
}

View File

@ -0,0 +1,40 @@
package com.puppycrawl.tools.checkstyle.filters;
import junit.framework.TestCase;
import com.puppycrawl.tools.checkstyle.api.FilterSet;
/** Tests SuppressElementFilter */
public class FilterSetTest extends TestCase
{
private FilterSet filter;
public void setUp()
{
filter = new FilterSet();
}
public void testEmptyChain()
{
assertTrue("0", filter.accept(new Integer(0)));
}
public void testOneFilter()
{
filter.addFilter(new IntMatchFilter(0));
assertTrue("0", filter.accept(new Integer(0)));
assertFalse("1", filter.accept(new Integer(1)));
assertFalse("\"0\"", filter.accept("0"));
}
public void testMultipleFilter()
{
filter.addFilter(new IntMatchFilter(0));
filter.addFilter(new IntRangeFilter(0, 2));
assertTrue("0", filter.accept(new Integer(0)));
assertFalse("1", filter.accept(new Integer(1)));
assertFalse("\"0\"", filter.accept("0"));
filter.addFilter(new IntRangeFilter(3, 4));
assertFalse("0 not in [3,4]", filter.accept(new Integer(0)));
}
}

View File

@ -10,9 +10,9 @@ public class IntMatchFilterTest extends TestCase
public void testDecide()
{
final Filter filter = new IntMatchFilter(0);
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("equal", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(1)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("equal", filter.accept(new Integer(0)));
assertFalse("greater than", filter.accept(new Integer(1)));
}
public void testEquals()

View File

@ -4,35 +4,35 @@ import com.puppycrawl.tools.checkstyle.api.Filter;
import junit.framework.TestCase;
/** Tests IntMatchFilter */
/** Tests IntRangeFilter */
public class IntRangeFilterTest extends TestCase
{
public void testDecide()
{
final Filter filter = new IntRangeFilter(0, 10);
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("in range", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("in range", Filter.ACCEPT, filter.decide(new Integer(5)));
assertEquals("in range", Filter.ACCEPT, filter.decide(new Integer(10)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(11)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("in range", filter.accept(new Integer(0)));
assertTrue("in range", filter.accept(new Integer(5)));
assertTrue("in range", filter.accept(new Integer(10)));
assertFalse("greater than", filter.accept(new Integer(11)));
}
public void testDecideSingle()
{
final Filter filter = new IntRangeFilter(0, 0);
assertEquals("less than", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("in range", Filter.ACCEPT, filter.decide(new Integer(0)));
assertEquals("greater than", Filter.NEUTRAL, filter.decide(new Integer(1)));
assertFalse("less than", filter.accept(new Integer(-1)));
assertTrue("in range", filter.accept(new Integer(0)));
assertFalse("greater than", filter.accept(new Integer(1)));
}
public void testDecideEmpty()
{
final Filter filter = new IntRangeFilter(10, 0);
assertEquals("out", Filter.NEUTRAL, filter.decide(new Integer(-1)));
assertEquals("out", Filter.NEUTRAL, filter.decide(new Integer(0)));
assertEquals("out", Filter.NEUTRAL, filter.decide(new Integer(5)));
assertEquals("out", Filter.NEUTRAL, filter.decide(new Integer(10)));
assertEquals("out", Filter.NEUTRAL, filter.decide(new Integer(11)));
assertFalse("out", filter.accept(new Integer(-1)));
assertFalse("out", filter.accept(new Integer(0)));
assertFalse("out", filter.accept(new Integer(5)));
assertFalse("out", filter.accept(new Integer(10)));
assertFalse("out", filter.accept(new Integer(11)));
}
public void testEquals()

View File

@ -3,13 +3,12 @@ package com.puppycrawl.tools.checkstyle.filters;
import org.apache.regexp.RESyntaxException;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.Filter;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import junit.framework.TestCase;
/** Tests IntMatchFilter */
public class SupressElementTest extends TestCase
/** Tests SuppressElementFilter */
public class SuppressElementTest extends TestCase
{
private SuppressElement filter;
@ -22,7 +21,7 @@ public class SupressElementTest extends TestCase
public void testDecideDefault()
{
final AuditEvent ev = new AuditEvent(this, "Test.java");
assertEquals(ev.getFileName(), Filter.NEUTRAL, filter.decide(ev));
assertTrue(ev.getFileName(), filter.accept(ev));
}
public void testDecideLocalizedMessage()
@ -31,7 +30,7 @@ public class SupressElementTest extends TestCase
new LocalizedMessage(0, 0, "", "", null, this.getClass());
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
//deny because there are matches on file and check names
assertEquals("Names match", Filter.DENY, filter.decide(ev));
assertFalse("Names match", filter.accept(ev));
}
public void testDecideByLine()
@ -41,9 +40,9 @@ public class SupressElementTest extends TestCase
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
//deny because there are matches on file name, check name, and line
filter.setLines("1-10");
assertEquals("In range 1-10)", Filter.DENY, filter.decide(ev));
assertFalse("In range 1-10", filter.accept(ev));
filter.setLines("1-9, 11");
assertEquals("Not in 1-9, 11)", Filter.NEUTRAL, filter.decide(ev));
assertTrue("Not in 1-9, 11", filter.accept(ev));
}
public void testDecideByColumn()
@ -53,9 +52,9 @@ public class SupressElementTest extends TestCase
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
//deny because there are matches on file name, check name, and column
filter.setColumns("1-10");
assertEquals("In range 1-10)", Filter.DENY, filter.decide(ev));
assertFalse("In range 1-10", filter.accept(ev));
filter.setColumns("1-9, 11");
assertEquals("Not in 1-9, 11)", Filter.NEUTRAL, filter.decide(ev));
assertTrue("Not in 1-9, 1)", filter.accept(ev));
}
public void testEquals() throws RESyntaxException