|
From: <ls...@us...> - 2007-01-07 08:29:33
|
Revision: 3009
http://jnode.svn.sourceforge.net/jnode/?rev=3009&view=rev
Author: lsantha
Date: 2007-01-07 00:29:31 -0800 (Sun, 07 Jan 2007)
Log Message:
-----------
Classpath patches.
Modified Paths:
--------------
trunk/core/src/classpath/vm/gnu/classpath/VMStackWalker.java
trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java
trunk/core/src/classpath/vm/java/lang/reflect/Method.java
Modified: trunk/core/src/classpath/vm/gnu/classpath/VMStackWalker.java
===================================================================
--- trunk/core/src/classpath/vm/gnu/classpath/VMStackWalker.java 2007-01-07 08:26:36 UTC (rev 3008)
+++ trunk/core/src/classpath/vm/gnu/classpath/VMStackWalker.java 2007-01-07 08:29:31 UTC (rev 3009)
@@ -1,35 +1,51 @@
-/*
- * $Id$
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
+/* VMStackWalker.java -- Reference implementation of VM hooks for stack access
+ Copyright (C) 2005, 2006 Free Software Foundation
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
package gnu.classpath;
import org.jnode.vm.VmSystem;
/**
- * This class provides access to the classes on the Java stack for reflection
- * and security purposes.
+ * This class provides access to the classes on the Java stack
+ * for reflection and security purposes.
*
* <p>
- * This class is only available to priviledged code (i.e., code loaded by the
- * bootstrap loader).
+ * This class is only available to privileged code (i.e., code loaded
+ * by the bootstrap loader).
*
* @author John Keiser
* @author Eric Blake <eb...@em...>
@@ -37,12 +53,12 @@
*/
public final class VMStackWalker {
/**
- * Get a list of all the classes currently executing methods on the Java
- * stack. <code>getClassContext()[0]</code> is the class associated with
- * the currently executing method, i.e., the method that called
+ * Get a list of all the classes currently executing methods on the
+ * Java stack. <code>getClassContext()[0]</code> is the class associated
+ * with the currently executing method, i.e., the method that called
* <code>VMStackWalker.getClassContext()</code> (possibly through
- * reflection). So you may need to pop off these stack frames from the top
- * of the stack:
+ * reflection). So you may need to pop off these stack frames from
+ * the top of the stack:
* <ul>
* <li><code>VMStackWalker.getClassContext()</code>
* <li><code>Method.invoke()</code>
@@ -55,15 +71,15 @@
}
/**
- * Get the class associated with the method invoking the method invoking
- * this method, or <code>null</code> if the stack is not that deep (e.g.,
- * invoked via JNI invocation API). This method is an optimization for the
- * expression <code>getClassContext()[1]</code> and should return the same
- * result.
+ * Get the class associated with the method invoking the method
+ * invoking this method, or <code>null</code> if the stack is not
+ * that deep (e.g., invoked via JNI invocation API). This method
+ * is an optimization for the expression <code>getClassContext()[1]</code>
+ * and should return the same result.
*
* <p>
- * VM implementers are encouraged to provide a more efficient version of
- * this method.
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
*/
public static Class getCallingClass() {
Class[] ctx = getClassContext();
@@ -74,14 +90,14 @@
/**
* Get the class loader associated with the Class returned by
- * <code>getCallingClass()</code>, or <code>null</code> if no such
- * class exists or it is the boot loader. This method is an optimization for
- * the expression <code>getClassContext()[1].getClassLoader()</code> and
- * should return the same result.
+ * <code>getCallingClass()</code>, or <code>null</code> if no such class
+ * exists or it is the boot loader. This method is an optimization for the
+ * expression <code>VMStackWalker.getClassLoader(getClassContext()[1])</code>
+ * and should return the same result.
*
* <p>
- * VM implementers are encouraged to provide a more efficient version of
- * this method.
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
*/
public static ClassLoader getCallingClassLoader() {
Class[] ctx = getClassContext();
@@ -89,4 +105,31 @@
return null;
return ctx[4].getClassLoader();
}
+
+ /**
+ * Retrieve the class's ClassLoader, or <code>null</code> if loaded
+ * by the bootstrap loader. I.e., this should return the same thing
+ * as {@link java.lang.VMClass#getClassLoader}. This duplicate version
+ * is here to work around access permissions.
+ */
+ public static ClassLoader getClassLoader(Class cl){
+ //TODO FIX it according to the javadoc above
+ return cl.getClassLoader();
+ };
+
+ /**
+ * Walk up the stack and return the first non-null class loader.
+ * If there aren't any non-null class loaders on the stack, return null.
+ */
+ public static ClassLoader firstNonNullClassLoader()
+ {
+ Class[] stack = getClassContext();
+ for (int i = 0; i < stack.length; i++)
+ {
+ ClassLoader loader = getClassLoader(stack[i]);
+ if (loader != null)
+ return loader;
}
+ return null;
+ }
+}
Modified: trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java 2007-01-07 08:26:36 UTC (rev 3008)
+++ trunk/core/src/classpath/vm/java/lang/reflect/Constructor.java 2007-01-07 08:29:31 UTC (rev 3009)
@@ -1,24 +1,41 @@
-/*
- * $Id$
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
+/* java.lang.reflect.Constructor - reflection of Java constructors
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
package java.lang.reflect;
import java.lang.annotation.Annotation;
@@ -55,6 +72,8 @@
* @author Eric Blake <eb...@em...>
* @see Member
* @see Class
+ * @see java.lang.Class#getConstructor(Class[])
+ * @see java.lang.Class#getDeclaredConstructor(Class[])
* @see java.lang.Class#getConstructors()
* @see java.lang.Class#getDeclaredConstructors()
* @since 1.1
@@ -299,8 +318,49 @@
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getTypeParameters();
}
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this constructor, in declaration order.
+ * An array of size zero is returned if this constructor declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this constructor.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this constructor, in declaration order.
+ * An array of size zero is returned if this constructor takes no
+ * parameters.
+ *
+ * @return a list of the types of the constructor's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
+
/**
* @see java.lang.reflect.AnnotatedElement#getAnnotation(java.lang.Class)
*/
@@ -322,6 +382,7 @@
return vmMethod.getDeclaredAnnotations();
}
+
/**
* @see java.lang.reflect.AnnotatedElement#isAnnotationPresent(java.lang.Class)
*/
Modified: trunk/core/src/classpath/vm/java/lang/reflect/Method.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/reflect/Method.java 2007-01-07 08:26:36 UTC (rev 3008)
+++ trunk/core/src/classpath/vm/java/lang/reflect/Method.java 2007-01-07 08:29:31 UTC (rev 3009)
@@ -1,24 +1,41 @@
-/*
- * $Id$
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
+/* java.lang.reflect.Method - reflection of Java methods
+ Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
package java.lang.reflect;
import java.lang.annotation.Annotation;
@@ -29,6 +46,8 @@
import org.jnode.vm.classmgr.VmMethod;
import gnu.java.lang.reflect.MethodSignatureParser;
+import java.util.Arrays;
+
/**
* The Method class represents a member method of a class. It also allows
* dynamic invocation, via reflection. This works for both static and
@@ -55,6 +74,8 @@
* @author Eric Blake <eb...@em...>
* @see Member
* @see Class
+ * @see java.lang.Class#getMethod(String,Class[])
+ * @see java.lang.Class#getDeclaredMethod(String,Class[])
* @see java.lang.Class#getMethods()
* @see java.lang.Class#getDeclaredMethods()
* @since 1.1
@@ -319,8 +340,7 @@
* specification, version 3.
* @since 1.5
*/
- /* FIXME[GENERICS]: Should be TypeVariable<Method>[] */
- public TypeVariable[] getTypeParameters()
+ public TypeVariable<Method>[] getTypeParameters()
{
String sig = getSignature();
if (sig == null)
@@ -338,13 +358,73 @@
return null;
}
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this method, in declaration order.
+ * An array of size zero is returned if this method declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this method.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+
/**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this method, in declaration order.
+ * An array of size zero is returned if this method takes no
+ * parameters.
+ *
+ * @return a list of the types of the method's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
+
+ /**
+ * Returns the return type of this method.
+ *
+ * @return the return type of this method
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type getGenericReturnType()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getReturnType();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericReturnType();
+ }
+ /**
* @see java.lang.reflect.AnnotatedElement#getAnnotation(java.lang.Class)
*/
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return vmMethod.getAnnotation(annotationClass);
}
+
/**
* @see java.lang.reflect.AnnotatedElement#getAnnotations()
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|