1 package com.puppycrawl.tools.checkstyle.filters; 20 21 import java.util.regex.Pattern ; 22 import java.util.regex.PatternSyntaxException ; 23 24 import com.puppycrawl.tools.checkstyle.api.AuditEvent; 25 import com.puppycrawl.tools.checkstyle.api.Filter; 26 import com.puppycrawl.tools.checkstyle.api.Utils; 27 28 41 public class SuppressElement 42 implements Filter 43 { 44 45 private static final int HASH_MULT = 29; 46 47 48 private final Pattern mFileRegexp; 49 50 51 private final String mFilePattern; 52 53 54 private Pattern mCheckRegexp; 55 56 57 private String mCheckPattern; 58 59 60 private String mModuleId; 61 62 63 private CSVFilter mLineFilter; 64 65 66 private String mLinesCSV; 67 68 69 private CSVFilter mColumnFilter; 70 71 72 private String mColumnsCSV; 73 74 81 public SuppressElement(String aFiles) 82 throws PatternSyntaxException 83 { 84 mFilePattern = aFiles; 85 mFileRegexp = Utils.getPattern(aFiles); 86 } 87 88 92 public void setChecks(final String aChecks) 93 { 94 mCheckPattern = aChecks; 95 mCheckRegexp = Utils.getPattern(aChecks); 96 } 97 98 102 public void setModuleId(final String aModuleId) 103 { 104 mModuleId = aModuleId; 105 } 106 111 public void setLines(String aLines) 112 { 113 mLinesCSV = aLines; 114 if (aLines != null) { 115 mLineFilter = new CSVFilter(aLines); 116 } 117 else { 118 mLineFilter = null; 119 } 120 } 121 122 127 public void setColumns(String aColumns) 128 { 129 mColumnsCSV = aColumns; 130 if (aColumns != null) { 131 mColumnFilter = new CSVFilter(aColumns); 132 } 133 else { 134 mColumnFilter = null; 135 } 136 } 137 138 139 public boolean accept(AuditEvent aEvent) 140 { 141 if ((aEvent.getFileName() == null) 143 || !mFileRegexp.matcher(aEvent.getFileName()).find() 144 || (aEvent.getLocalizedMessage() == null) 145 || ((mModuleId != null) && !mModuleId.equals(aEvent 146 .getModuleId())) 147 || ((mCheckRegexp != null) && !mCheckRegexp.matcher( 148 aEvent.getSourceName()).find())) 149 { 150 return true; 151 } 152 153 if ((mLineFilter == null) && (mColumnFilter == null)) { 155 return false; 156 } 157 158 if (mLineFilter != null) { 160 final Integer line = new Integer (aEvent.getLine()); 161 if (mLineFilter.accept(line)) { 162 return false; 163 } 164 } 165 166 if (mColumnFilter != null) { 168 final Integer column = new Integer (aEvent.getColumn()); 169 if (mColumnFilter.accept(column)) { 170 return false; 171 } 172 } 173 return true; 174 } 175 176 177 public String toString() 178 { 179 return "SupressElement[files=" + mFilePattern + ",checks=" 180 + mCheckPattern + ",lines=" + mLinesCSV + ",columns=" 181 + mColumnsCSV + "]"; 182 } 183 184 185 public int hashCode() 186 { 187 int result = HASH_MULT * mFilePattern.hashCode(); 188 if (mCheckPattern != null) { 189 result = HASH_MULT * result + mCheckPattern.hashCode(); 190 } 191 if (mModuleId != null) { 192 result = HASH_MULT * result + mModuleId.hashCode(); 193 } 194 if (mLinesCSV != null) { 195 result = HASH_MULT * result + mLinesCSV.hashCode(); 196 } 197 if (mColumnsCSV != null) { 198 result = HASH_MULT * result + mColumnsCSV.hashCode(); 199 } 200 return result; 201 } 202 203 204 public boolean equals(Object aObject) 205 { 206 if (aObject instanceof SuppressElement) { 207 final SuppressElement other = (SuppressElement) aObject; 208 209 if (!this.mFilePattern.equals(other.mFilePattern)) { 211 return false; 212 } 213 214 if (mCheckPattern != null) { 216 if (!mCheckPattern.equals(other.mCheckPattern)) { 217 return false; 218 } 219 } 220 else if (other.mCheckPattern != null) { 221 return false; 222 } 223 224 if (mModuleId != null) { 226 if (!mModuleId.equals(other.mModuleId)) { 227 return false; 228 } 229 } 230 else if (other.mModuleId != null) { 231 return false; 232 } 233 234 if (mLineFilter != null) { 236 if (!mLineFilter.equals(other.mLineFilter)) { 237 return false; 238 } 239 } 240 else if (other.mLineFilter != null) { 241 return false; 242 } 243 244 if (mColumnFilter != null) { 246 if (!mColumnFilter.equals(other.mColumnFilter)) { 247 return false; 248 } 249 } 250 else if (other.mColumnFilter != null) { 251 return false; 252 } 253 254 return true; 256 } 257 return false; 258 } 259 } 260 | Popular Tags |