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.gui2;
21:
22: import edu.umd.cs.findbugs.BugInstance;
23: import edu.umd.cs.findbugs.gui2.BugAspects.SortableValue;
24:
25: /**
26: * These are the leaves of the tree, note that coloring is not done here, it is done in BugRenderer
27: * This class is basically just a wrapper for BugInstance
28: */
29:
30: // only thing of note is the equals method, which purposefully uses == since JTree's only show one of multiple equal objects.
31: public class BugLeafNode {
32:
33: private BugInstance bug;
34:
35: BugLeafNode(BugInstance b) {
36: bug = b;
37: }
38:
39: public BugInstance getBug() {
40: return bug;
41: }
42:
43: @Override
44: public String toString() {
45:
46: return bug.getMessageWithoutPrefix();
47: }
48:
49: public boolean matches(SortableValue keyValuePair) {
50: /*
51: try
52: {
53: Method m = BugInstance.class.getMethod("get" + keyValuePair.key,new Class[0]);
54: return (keyValuePair.value.equals(m.invoke(this,new Object[0])));
55: }
56: catch(SecurityException e)
57: {
58: System.err.println("NoOoOOOooOoOo000!!!1!!!1one!");
59: } catch (NoSuchMethodException e) {
60: throw new IllegalArgumentException("get" + keyValuePair.key + " does not exist");
61: } catch (IllegalArgumentException e) {
62: e.printStackTrace();
63: } catch (IllegalAccessException e) {
64: System.err.println("Make the method get" + keyValuePair.key + " public or package or ... something. .. Now.");
65: e.printStackTrace();
66: } catch (InvocationTargetException e) {
67: e.printStackTrace();
68: }
69: */
70: return keyValuePair.key.getFrom(bug).equals(keyValuePair.value);
71: }
72:
73: @Override
74: public boolean equals(Object o) {
75: if (!(o instanceof BugLeafNode))
76: return false;
77: else
78: return bug == (((BugLeafNode) o).getBug());
79: }
80:
81: @Override
82: public int hashCode() {
83: return bug.hashCode();
84: }
85:
86: public boolean matches(BugAspects aspects) {
87: if (aspects.size() == 0)
88: return true;
89: for (BugAspects.SortableValue strPair : aspects) {
90: if (!matches(strPair))
91: return false;
92: }
93:
94: return true;
95: }
96: }
|