📄 method.java
字号:
/* libaegisvm - The Aegis Virtual Machine for executing Java bytecode Copyright (C) 2001-2002 Philip W. L. Fong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/package java.lang.reflect;public final class Method extends AccessibleObject implements Member { private Class declaringClass; // The VM depends on the object private int id; // layout of the class. private Method(Class declaringClass, int id) { this.declaringClass = declaringClass; this.id = id; } public Class getDeclaringClass() { return declaringClass; } public native String getName(); private native String getDescriptor(); public native int getModifiers(); public Class getReturnType() { return aegis.Reflect.getReturnType(declaringClass, getDescriptor()); } public Class[] getParameterTypes() { return aegis.Reflect.getParameterTypes(declaringClass,getDescriptor()); } private native int getExceptionsCount(); private native String getException(int id); public Class[] getExceptionTypes() { int count = getExceptionsCount(); Class[] exceptions = new Class[count]; for (int i = 0; i < count; i++) { try { String exception = getException(i); exceptions[i] = Class.forName(exception.replace('/', '.'), false, declaringClass.getClassLoader()); } catch (ClassNotFoundException ex) { throw new NoClassDefFoundError(); } } return exceptions; } public boolean equals(Object obj) { if (! (obj instanceof Method)) return false; Method M = (Method) obj; return declaringClass == M.declaringClass && id == M.id; } public int hashCode() { return declaringClass.hashCode() ^ getName().hashCode(); } public String toString() { String S = Modifier.toString(getModifiers()) + getReturnType().getName() + ' ' + declaringClass.getName() + '.' + getName() + '('; Class[] params = getParameterTypes(); if (params.length > 0) { S += params[0].getName(); for (int i = 1; i < params.length; i++) S += ',' + params[i].getName(); } S += ')'; Class[] exceptions = getExceptionTypes(); if (exceptions.length > 0) { S += " throws " + exceptions[0].getName(); for (int i = 1; i < exceptions.length; i++) S += ',' + exceptions[i].getName(); } return S; } /** * \todo Accessibility check. */ public Object invoke(Object obj, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (!Modifier.isStatic(getModifiers())) { if (obj == null) throw new NullPointerException(); if (! declaringClass.isInstance(obj)) throw new IllegalArgumentException(); } // fix me: accessibility check goes here args = aegis.Reflect.widen(args, getParameterTypes()); return invoke(declaringClass, id, obj, args); } private static native Object invoke(Class clazz, int i, Object obj, Object[] args) throws InvocationTargetException;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -