KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > BugLeafNode


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 java.lang.reflect.InvocationTargetException JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24
25 import edu.umd.cs.findbugs.BugInstance;
26 import edu.umd.cs.findbugs.gui2.BugAspects.StringPair;
27
28
29 /**
30  * These are the leaves of the tree, note that coloring is not done here, it is done in BugRenderer
31  * This class is basically just a wrapper for BugInstance
32  */

33
34 // only thing of note is the equals method, which purposefully uses == since JTree's only show one of multiple equal objects.
35

36 public class BugLeafNode {
37     
38     private BugInstance bug;
39     
40     BugLeafNode(BugInstance b)
41     {
42         bug=b;
43     }
44     
45     public BugInstance getBug()
46     {
47         return bug;
48     }
49     
50     public String JavaDoc toString()
51     {
52         
53         
54         return bug.getMessageWithoutPrefix();
55     }
56
57     public boolean matches(StringPair keyValuePair) {
58 /*
59         try
60         {
61             Method m = BugInstance.class.getMethod("get" + keyValuePair.key,new Class[0]);
62             return (keyValuePair.value.equals(m.invoke(this,new Object[0])));
63         }
64         catch(SecurityException e)
65         {
66             System.err.println("NoOoOOOooOoOo000!!!1!!!1one!");
67         } catch (NoSuchMethodException e) {
68             throw new IllegalArgumentException("get" + keyValuePair.key + " does not exist");
69         } catch (IllegalArgumentException e) {
70             e.printStackTrace();
71         } catch (IllegalAccessException e) {
72             System.err.println("Make the method get" + keyValuePair.key + " public or package or ... something. .. Now.");
73             e.printStackTrace();
74         } catch (InvocationTargetException e) {
75             e.printStackTrace();
76         }
77 */

78         return keyValuePair.key.getFrom(bug).equals(keyValuePair.value);
79     }
80
81     public boolean equals(Object JavaDoc o)
82     {
83         if (!(o instanceof BugLeafNode))
84             return false;
85         else
86             return bug==(((BugLeafNode)o).getBug());
87     }
88
89     
90     public int hashCode()
91     {
92         return bug.hashCode();
93     }
94     
95     public boolean matches(BugAspects aspects) {
96         if(aspects.size() == 0)
97             return true;
98         for(BugAspects.StringPair strPair : aspects){
99             if(!matches(strPair))
100                 return false;
101         }
102         
103         return true;
104     }
105 }
106
107
108
Popular Tags