01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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:
20: package edu.umd.cs.findbugs.filter;
21:
22: import java.io.IOException;
23:
24: import edu.umd.cs.findbugs.BugInstance;
25: import edu.umd.cs.findbugs.xml.XMLOutput;
26:
27: /**
28: * Match bug instances having one of given codes or patterns.
29: *
30: * @author rafal@caltha.pl
31: */
32: public class DesignationMatcher implements Matcher {
33: private StringSetMatch designations;
34:
35: /**
36: * Constructor.
37: *
38: * @param designations
39: * comma-separated list of designations
40: * @param patterns
41: * coma-separated list of bug patterns.
42: * @param categories
43: * coma-separated list of bug categories.
44: */
45: public DesignationMatcher(String designations) {
46: this .designations = new StringSetMatch(designations);
47: }
48:
49: public boolean match(BugInstance bugInstance) {
50: return designations.match(bugInstance.getUserDesignationKey());
51: }
52:
53: @Override
54: public String toString() {
55: return "Designations(designations=" + designations + ")";
56: }
57:
58: @Override
59: public int hashCode() {
60: return designations.hashCode();
61: }
62:
63: @Override
64: public boolean equals(Object o) {
65: if (!(o instanceof DesignationMatcher))
66: return false;
67: DesignationMatcher other = (DesignationMatcher) o;
68: return designations.equals(other.designations);
69: }
70:
71: public void writeXML(XMLOutput xmlOutput, boolean disabled)
72: throws IOException {
73: xmlOutput.startTag("Designation");
74: if (disabled)
75: xmlOutput.addAttribute("disabled", "true");
76: addAttribute(xmlOutput, "designation", designations);
77: xmlOutput.stopTag(true);
78: }
79:
80: public void addAttribute(XMLOutput xmlOutput, String name,
81: StringSetMatch matches) throws IOException {
82: String value = matches.toString();
83: if (value.length() != 0)
84: xmlOutput.addAttribute(name, value);
85: }
86:
87: }
|