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.filters; 020 021import com.puppycrawl.tools.checkstyle.api.AuditEvent; 022import com.puppycrawl.tools.checkstyle.api.AutomaticBean; 023import com.puppycrawl.tools.checkstyle.api.CheckstyleException; 024import com.puppycrawl.tools.checkstyle.api.Filter; 025import com.puppycrawl.tools.checkstyle.api.FilterSet; 026 027/** 028 * <p> 029 * This filter accepts AuditEvents according to file, check, line, and 030 * column, as specified in a suppression file. 031 * </p> 032 * @author Rick Giles 033 */ 034public class SuppressionFilter 035 extends AutomaticBean 036 implements Filter 037{ 038 /** set of individual suppresses */ 039 private FilterSet filters = new FilterSet(); 040 041 /** 042 * Loads the suppressions for a file. 043 * @param fileName name of the suppressions file. 044 * @throws CheckstyleException if there is an error. 045 */ 046 public void setFile(String fileName) 047 throws CheckstyleException 048 { 049 filters = SuppressionsLoader.loadSuppressions(fileName); 050 } 051 052 /** {@inheritDoc} */ 053 @Override 054 public boolean accept(AuditEvent event) 055 { 056 return filters.accept(event); 057 } 058 059 @Override 060 public String toString() 061 { 062 return filters.toString(); 063 } 064 065 @Override 066 public int hashCode() 067 { 068 return filters.hashCode(); 069 } 070 071 @Override 072 public boolean equals(Object object) 073 { 074 if (object instanceof SuppressionFilter) { 075 final SuppressionFilter other = (SuppressionFilter) object; 076 return this.filters.equals(other.filters); 077 } 078 return false; 079 } 080}