I'm committing the attached patch to add the new isXXX tests to java.lang.Class (and corresponding methods in VMClass). This also fixes the typing of methods in Class and java.lang.reflect.Constructor.
Changelog:
2005-04-04 Andrew John Hughes <[EMAIL PROTECTED]>
* java/lang/Class.java:
(newInstance): Returns an instance of T instead of Object.
(isEnum()): Now calls VMClass for a proper implementation.
(isSynthetic()): New method implemented.
(isAnnotation()): New method implemented.
* vm/reference/java/lang/VMClass.java:
(isEnum()): New native method.
(isSynthetic()): New native method.
(isAnnotation()): New native method.
* vm/reference/java/lang/reflect/Constructor.java:
(newInstance(Object...)): Changed input parameter to a vararg.
--
Andrew :-)
Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
No software patents in Europe -- http://nosoftwarepatents.com
"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/lang/Class.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Class.java,v
retrieving revision 1.22.2.11
diff -u -3 -p -u -r1.22.2.11 Class.java
--- java/lang/Class.java 21 Mar 2005 12:10:17 -0000 1.22.2.11
+++ java/lang/Class.java 4 Apr 2005 22:11:26 -0000
@@ -1094,11 +1094,11 @@ public final class Class<T>
* @throws ExceptionInInitializerError if class initialization caused by
* this call fails with an exception
*/
- public Object newInstance()
+ public T newInstance()
throws InstantiationException, IllegalAccessException
{
memberAccessCheck(Member.PUBLIC);
- Constructor constructor;
+ Constructor<T> constructor;
synchronized(this)
{
constructor = this.constructor;
@@ -1151,7 +1151,7 @@ public final class Class<T>
}
try
{
- return constructor.newInstance(null);
+ return constructor.newInstance();
}
catch (InvocationTargetException e)
{
@@ -1393,7 +1393,28 @@ public final class Class<T>
*/
public boolean isEnum()
{
- return getSuperclass() == Enum.class;
+ return VMClass.isEnum(this);
+ }
+
+ /**
+ * Returns true if this class is a synthetic class, generated by
+ * the compiler.
+ *
+ * @return true if this is a synthetic class.
+ */
+ public boolean isSynthetic()
+ {
+ return VMClass.isSynthetic(this);
+ }
+
+ /**
+ * Returns true if this class is an <code>Annotation</code>.
+ *
+ * @return true if this is an annotation class.
+ */
+ public boolean isAnnotation()
+ {
+ return VMClass.isAnnotation(this);
}
}
Index: vm/reference/java/lang/VMClass.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMClass.java,v
retrieving revision 1.10.2.2
diff -u -3 -p -u -r1.10.2.2 VMClass.java
--- vm/reference/java/lang/VMClass.java 7 Jan 2005 03:42:30 -0000 1.10.2.2
+++ vm/reference/java/lang/VMClass.java 4 Apr 2005 22:11:27 -0000
@@ -296,4 +296,30 @@ final class VMClass
* Downcast object to the class' type.
*/
static native <K> K cast(Object obj, Class<K> k);
+
+ /**
+ * Returns true if this class is a synthetic class, generated by the
+ * compiler.
+ *
+ * @param klass the Class object that's calling us
+ * @return whether this class is synthetic or not
+ */
+ static native boolean isSynthetic(Class klass);
+
+ /**
+ * Returns true if this class represents an annotation.
+ *
+ * @param klass the Class object that's calling us
+ * @return whether this class is an annotation or not
+ */
+ static native boolean isAnnotation(Class klass);
+
+ /**
+ * Returns true if this class was declared as an enum.
+ *
+ * @param klass the Class object that's calling us
+ * @return whether this class is an enumeration or not
+ */
+ static native boolean isEnum(Class klass);
+
} // class VMClass
Index: vm/reference/java/lang/reflect/Constructor.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/vm/reference/java/lang/reflect/Constructor.java,v
retrieving revision 1.11.2.2
diff -u -3 -p -u -r1.11.2.2 Constructor.java
--- vm/reference/java/lang/reflect/Constructor.java 1 Nov 2004 15:57:08
-0000 1.11.2.2
+++ vm/reference/java/lang/reflect/Constructor.java 4 Apr 2005 22:11:27
-0000
@@ -248,7 +248,7 @@ public final class Constructor<T>
* @throws ExceptionInInitializerError if construction triggered class
* initialization, which then failed
*/
- public T newInstance(Object args[])
+ public T newInstance(Object... args)
throws InstantiationException, IllegalAccessException,
InvocationTargetException
{
signature.asc
Description: Digital signature
_______________________________________________ Classpath-patches mailing list [email protected] http://lists.gnu.org/mailman/listinfo/classpath-patches
