KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JMethod


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import com.caucho.util.CharBuffer;
33
34 /**
35  * Represents an introspected java method.
36  */

37 abstract public class JMethod extends JAccessibleObject {
38   /**
39    * Returns the method name.
40    */

41   abstract public String JavaDoc getName();
42
43   /**
44    * Returns true for a static method.
45    */

46   abstract public boolean isStatic();
47
48   /**
49    * Returns true for a private method.
50    */

51   abstract public boolean isPrivate();
52
53   /**
54    * Returns true for a public method.
55    */

56   abstract public boolean isPublic();
57
58   /**
59    * Returns true for an abstract method.
60    */

61   abstract public boolean isAbstract();
62
63   /**
64    * Returns true for a final method.
65    */

66   abstract public boolean isFinal();
67
68   /**
69    * Returns the declaring class
70    */

71   abstract public JClass getDeclaringClass();
72
73   /**
74    * Returns the return type.
75    */

76   abstract public JClass getReturnType();
77
78   /**
79    * Returns the parameterized return type of the field.
80    */

81   abstract public JType getGenericReturnType();
82
83   /**
84    * Returns the parameter types.
85    */

86   abstract public JClass []getParameterTypes();
87
88   /**
89    * Returns the exception types.
90    */

91   abstract public JClass []getExceptionTypes();
92
93   /**
94    * Returns the declared annotaions.
95    */

96   abstract public JAnnotation []getDeclaredAnnotations();
97
98   /**
99    * Returns a full method name with arguments.
100    */

101   public String JavaDoc getFullName()
102   {
103     CharBuffer name = new CharBuffer();
104
105     name.append(getName());
106     name.append("(");
107
108     JClass []params = getParameterTypes();
109     for (int i = 0; i < params.length; i++) {
110       if (i != 0)
111         name.append(", ");
112
113       name.append(params[i].getShortName());
114     }
115
116     name.append(')');
117
118     return name.toString();
119   }
120
121   /**
122    * Returns true if equals.
123    */

124   public boolean equals(Object JavaDoc o)
125   {
126     if (o == this)
127       return true;
128     else if (o == null || getClass() != o.getClass())
129       return false;
130
131     JMethod jMethod = (JMethod) o;
132
133     // note that the equality test doesn't include the class loader
134
if (! getName().equals(jMethod.getName()))
135       return false;
136
137     JClass []aParam = getParameterTypes();
138     JClass []bParam = jMethod.getParameterTypes();
139
140     if (aParam.length != bParam.length)
141       return false;
142
143     for (int i = 0; i < aParam.length; i++) {
144       if (aParam[i] == bParam[i])
145     continue;
146       else if (aParam[i] == null || bParam[i] == null)
147     return false;
148       else if (! aParam[i].equals(bParam[i]))
149     return false;
150     }
151
152     return true;
153   }
154
155   public String JavaDoc toString()
156   {
157     return "JMethod[" + getName() + "]";
158   }
159 }
160
Popular Tags