KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > classfile > FieldOrMethodDescriptor


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.classfile;
21
22 /**
23  * Common superclass for FieldDescriptor and MethodDescriptor.
24  *
25  * @author David Hovemeyer
26  */

27 public abstract class FieldOrMethodDescriptor {
28     private String JavaDoc className;
29     private String JavaDoc name;
30     private String JavaDoc signature;
31     private boolean isStatic;
32
33     public FieldOrMethodDescriptor(String JavaDoc className, String JavaDoc name, String JavaDoc signature, boolean isStatic) {
34         this.className = className;
35         this.name = name;
36         this.signature = signature;
37         this.isStatic = isStatic;
38     }
39     
40     /**
41      * @return Returns the class name
42      */

43     public String JavaDoc getClassName() {
44         return className;
45     }
46     
47     /**
48      * @return Returns the method name
49      */

50     public String JavaDoc getName() {
51         return name;
52     }
53     
54     /**
55      * @return Returns the method signature
56      */

57     public String JavaDoc getSignature() {
58         return signature;
59     }
60     
61     /**
62      * @return Returns true if method is static, false if not
63      */

64     public boolean isStatic() {
65         return isStatic;
66     }
67     
68     protected int compareTo(FieldOrMethodDescriptor o) {
69         int cmp;
70         cmp = this.className.compareTo(o.className);
71         if (cmp != 0) {
72             return cmp;
73         }
74         cmp = this.name.compareTo(o.name);
75         if (cmp != 0) {
76             return cmp;
77         }
78         cmp = this.signature.compareTo(o.signature);
79         if (cmp != 0) {
80             return cmp;
81         }
82         return (this.isStatic ? 1 : 0) - (o.isStatic ? 1 : 0);
83     }
84     
85     /* (non-Javadoc)
86      * @see java.lang.Object#equals(java.lang.Object)
87      */

88     @Override JavaDoc
89     public boolean equals(Object JavaDoc obj) {
90         if (obj == null || obj.getClass() != this.getClass()) {
91             return false;
92         }
93         FieldOrMethodDescriptor other = (FieldOrMethodDescriptor) obj;
94         return this.className.equals(other.className)
95             && this.name.equals(other.name)
96             && this.signature.equals(other.signature)
97             && this.isStatic == other.isStatic;
98     }
99     
100     /* (non-Javadoc)
101      * @see java.lang.Object#hashCode()
102      */

103     @Override JavaDoc
104     public int hashCode() {
105         return className.hashCode() * 7919
106             + name.hashCode() * 3119
107             + signature.hashCode() * 131
108             + (isStatic ? 1 : 0);
109     }
110     
111     /* (non-Javadoc)
112      * @see java.lang.Object#toString()
113      */

114     @Override JavaDoc
115     public String JavaDoc toString() {
116         // FIXME: format more nicely
117
return (isStatic ? "static " : "") + className + "." + name + ":" + signature;
118     }
119 }
120
Popular Tags