001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.bytecode;
031:
032: import com.caucho.util.CharBuffer;
033:
034: /**
035: * Represents an introspected java method.
036: */
037: abstract public class JMethod extends JAccessibleObject {
038: /**
039: * Returns the method name.
040: */
041: abstract public String getName();
042:
043: /**
044: * Returns true for a static method.
045: */
046: abstract public boolean isStatic();
047:
048: /**
049: * Returns true for a private method.
050: */
051: abstract public boolean isPrivate();
052:
053: /**
054: * Returns true for a public method.
055: */
056: abstract public boolean isPublic();
057:
058: /**
059: * Returns true for a protected method.
060: */
061: abstract public boolean isProtected();
062:
063: /**
064: * Returns true for an abstract method.
065: */
066: abstract public boolean isAbstract();
067:
068: /**
069: * Returns true for a final method.
070: */
071: abstract public boolean isFinal();
072:
073: /**
074: * Returns the declaring class
075: */
076: abstract public JClass getDeclaringClass();
077:
078: /**
079: * Returns the return type.
080: */
081: abstract public JClass getReturnType();
082:
083: /**
084: * Returns the parameterized return type of the field.
085: */
086: abstract public JType getGenericReturnType();
087:
088: /**
089: * Returns the parameter types.
090: */
091: abstract public JClass[] getParameterTypes();
092:
093: /**
094: * Returns the exception types.
095: */
096: abstract public JClass[] getExceptionTypes();
097:
098: /**
099: * Returns the declared annotaions.
100: */
101: abstract public JAnnotation[] getDeclaredAnnotations();
102:
103: /**
104: * Returns a full method name with arguments.
105: */
106: public String getFullName() {
107: CharBuffer name = new CharBuffer();
108:
109: name.append(getName());
110: name.append("(");
111:
112: JClass[] params = getParameterTypes();
113: for (int i = 0; i < params.length; i++) {
114: if (i != 0)
115: name.append(", ");
116:
117: name.append(params[i].getShortName());
118: }
119:
120: name.append(')');
121:
122: return name.toString();
123: }
124:
125: /**
126: * Returns true if equals.
127: */
128: public boolean equals(Object o) {
129: if (o == this )
130: return true;
131: else if (o == null || getClass() != o.getClass())
132: return false;
133:
134: JMethod jMethod = (JMethod) o;
135:
136: // note that the equality test doesn't include the class loader
137: if (!getName().equals(jMethod.getName()))
138: return false;
139:
140: JClass[] aParam = getParameterTypes();
141: JClass[] bParam = jMethod.getParameterTypes();
142:
143: if (aParam.length != bParam.length)
144: return false;
145:
146: for (int i = 0; i < aParam.length; i++) {
147: if (aParam[i] == bParam[i])
148: continue;
149: else if (aParam[i] == null || bParam[i] == null)
150: return false;
151: else if (!aParam[i].equals(bParam[i]))
152: return false;
153: }
154:
155: return true;
156: }
157:
158: public String toString() {
159: return "JMethod[" + getName() + "]";
160: }
161: }
|