[kaffe] CVS kaffe (robilad): Merged in java.lang.reflect.Field from GNU Classpath

Kaffe CVS cvs-commits at kaffe.org
Tue Apr 18 11:44:01 PDT 2006


PatchSet 7241 
Date: 2006/04/18 18:31:48
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Merged in java.lang.reflect.Field from GNU Classpath

2006-04-18 Dalibor Topic  <robilad at kaffe.org>

        * kaffe/kaffevm/reflect.c (KaffeVM_makeReflectField),
        kaffe/kaffevm/jni/jni-helpers.c (KaffeJNI_FromReflectedField):
        Updated for new Field implementation.

        * libraries/clib/native/Field.c: Include local native.h.
        (getFieldAddress) Updated for new Field implementation.
        (java_lang_reflect_Field_getModifiers) Renamed to ...
        (java_lang_reflect_Field_getModifiersInternal) ... and updated
        for new Field implementation.
        (java_lang_reflect_Field_getSignature) New function.

        * libraries/javalib/vmspecific/java/lang/reflect/Field.java:
        Merged in from GNU Classpath. Implemented get* and set* methods
        partially in Java, by merging in Kaffe's own implementation.

Members: 
	ChangeLog:1.4746->1.4747 
	kaffe/kaffevm/reflect.c:1.4->1.5 
	kaffe/kaffevm/jni/jni-helpers.c:1.13->1.14 
	libraries/clib/native/Field.c:1.22->1.23 
	libraries/javalib/vmspecific/java/lang/reflect/Field.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4746 kaffe/ChangeLog:1.4747
--- kaffe/ChangeLog:1.4746	Tue Apr 18 15:57:47 2006
+++ kaffe/ChangeLog	Tue Apr 18 18:31:48 2006
@@ -1,5 +1,22 @@
 2006-04-18 Dalibor Topic  <robilad at kaffe.org>
 
+	* kaffe/kaffevm/reflect.c (KaffeVM_makeReflectField),
+	kaffe/kaffevm/jni/jni-helpers.c (KaffeJNI_FromReflectedField):
+	Updated for new Field implementation.
+
+	* libraries/clib/native/Field.c: Include local native.h.
+	(getFieldAddress) Updated for new Field implementation.
+	(java_lang_reflect_Field_getModifiers) Renamed to ...
+	(java_lang_reflect_Field_getModifiersInternal) ... and updated
+	for new Field implementation.
+	(java_lang_reflect_Field_getSignature) New function.
+
+	* libraries/javalib/vmspecific/java/lang/reflect/Field.java:
+	Merged in from GNU Classpath. Implemented get* and set* methods
+	partially in Java, by merging in Kaffe's own implementation.
+
+2006-04-18 Dalibor Topic  <robilad at kaffe.org>
+
 	* include/native.h: Use local java_lang_String.h.
 
 2006-04-18  Guilhem Lavaux  <guilhem at kaffe.org>
Index: kaffe/kaffe/kaffevm/reflect.c
diff -u kaffe/kaffe/kaffevm/reflect.c:1.4 kaffe/kaffe/kaffevm/reflect.c:1.5
--- kaffe/kaffe/kaffevm/reflect.c:1.4	Mon Apr 17 17:57:08 2006
+++ kaffe/kaffe/kaffevm/reflect.c	Tue Apr 18 18:31:52 2006
@@ -153,7 +153,7 @@
 	fld = CLASS_FIELDS(clazz) + slot;
 	field = (Hjava_lang_reflect_Field*)
 	    AllocObject("java/lang/reflect/Field", NULL);
-	unhand(field)->clazz = clazz;
+	unhand(field)->declaringClass = clazz;
 	unhand(field)->slot = slot;
 	unhand(field)->type = resolveFieldType(fld, clazz, &info);
 	if (unhand(field)->type == NULL) {
Index: kaffe/kaffe/kaffevm/jni/jni-helpers.c
diff -u kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.13 kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.14
--- kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.13	Mon Apr 17 17:57:08 2006
+++ kaffe/kaffe/kaffevm/jni/jni-helpers.c	Tue Apr 18 18:31:52 2006
@@ -135,7 +135,7 @@
 
   realField = (Hjava_lang_reflect_Field *)field_local;
 
-  id = (jfieldID) &(unhand(realField)->clazz->fields[unhand(realField)->slot]);
+  id = (jfieldID) &(unhand(realField)->declaringClass->fields[unhand(realField)->slot]);
   END_EXCEPTION_HANDLING();
   
   return id;
Index: kaffe/libraries/clib/native/Field.c
diff -u kaffe/libraries/clib/native/Field.c:1.22 kaffe/libraries/clib/native/Field.c:1.23
--- kaffe/libraries/clib/native/Field.c:1.22	Fri Dec 23 21:13:54 2005
+++ kaffe/libraries/clib/native/Field.c	Tue Apr 18 18:31:52 2006
@@ -3,6 +3,9 @@
  *
  * Copyright (c) 1996,97 T. J. Wilkinson & Associates, London, UK.
  *
+ * Copyright (c) 2006
+ *   Kaffe.org contributors. See ChangeLog for details.
+ *
  * See the file "license.terms" for information on usage and redistribution
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  *
@@ -23,8 +26,9 @@
 #include "baseClasses.h"
 #include "exception.h"
 #include "java_lang_reflect_Field.h"
-#include <native.h>
+#include "native.h"
 #include "defs.h"
+#include "stringSupport.h"
 
 static
 void*
@@ -33,7 +37,7 @@
         Hjava_lang_Class* clas;
         Field* fld;
 
-        clas = (Hjava_lang_Class*)unhand(this)->clazz;
+        clas = (Hjava_lang_Class*)unhand(this)->declaringClass;
         fld = CLASS_FIELDS(clas) + unhand(this)->slot;
 
         if (unhand(this)->slot < CLASS_NSFIELDS(clas)) {
@@ -58,12 +62,12 @@
 
 
 jint 
-java_lang_reflect_Field_getModifiers(struct Hjava_lang_reflect_Field * this)
+java_lang_reflect_Field_getModifiersInternal(struct Hjava_lang_reflect_Field * this)
 {
         Hjava_lang_Class* clas;
         Field* fld;
 
-        clas = (Hjava_lang_Class*) unhand(this)->clazz;
+        clas = (Hjava_lang_Class*) unhand(this)->declaringClass;
         fld = CLASS_FIELDS(clas) + unhand(this)->slot;
 
         return ((jint)(fld->accflags & ACC_MASK));
@@ -177,4 +181,18 @@
 java_lang_reflect_Field_setObject0(struct Hjava_lang_reflect_Field * this, struct Hjava_lang_Object* obj, struct Hjava_lang_Object* val)
 {
 	*(jobject*)getFieldAddress(this, obj) = val;
+}
+
+Hjava_lang_String *
+java_lang_reflect_Field_getSignature(struct Hjava_lang_reflect_Field* this)
+{
+	Hjava_lang_Class* clazz;
+	jint slot;
+
+	clazz = unhand(this)->declaringClass;
+	slot = unhand(this)->slot;
+
+	assert(slot < CLASS_NFIELDS(clazz));
+
+	return utf8Const2Java(CLASS_FIELDS(clazz)[slot].extSignature);
 }
Index: kaffe/libraries/javalib/vmspecific/java/lang/reflect/Field.java
diff -u kaffe/libraries/javalib/vmspecific/java/lang/reflect/Field.java:1.4 kaffe/libraries/javalib/vmspecific/java/lang/reflect/Field.java:1.5
--- kaffe/libraries/javalib/vmspecific/java/lang/reflect/Field.java:1.4	Mon Apr 17 17:58:14 2006
+++ kaffe/libraries/javalib/vmspecific/java/lang/reflect/Field.java	Tue Apr 18 18:31:53 2006
@@ -1,522 +1,149 @@
-/*
- * Java core library component.
- *
- * Copyright (c) 1997, 1998, 2001
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- *
- * Checked Spec: JDK 1.3
- */
+/* java.lang.reflect.Field - reflection of Java fields
+   Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
 
-package java.lang.reflect;
+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. */
 
-public final class Field
-  extends AccessibleObject
-  implements Member
-{
-	private Class clazz;
-	private int slot;
-	private String name;
-	private Class type;
-
-private Field() {
-}
-
-private void checkFinal() throws IllegalAccessException {    
-	if (Modifier.isFinal(getModifiers()) && !flag) {
-		throw new IllegalAccessException("trying to set final field " + toString());
-	}
-}
-
-public boolean equals(Object obj)
-	{
-	// Quick test for identity
-	if (this == obj) {
-		return (true);
-	}
-
-	if (!(obj instanceof Field)) {
-		return (false);
-	}
-
-	Field fobj = (Field)obj;
-	if (clazz == fobj.clazz && type == fobj.type && name.equals(fobj.name)) {
-		return (true);
-	}
-	return (false);
-}
-
-public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Double.TYPE) {
-		return (new Double(getDouble0(obj)));
-	}
-	else if (type == Float.TYPE) {
-		return (new Float(getFloat0(obj)));
-	}
-	else if (type == Long.TYPE) {
-		return (new Long(getLong0(obj)));
-	}
-	else if (type == Integer.TYPE) {
-		return (new Integer(getInt0(obj)));
-	}
-	else if (type == Short.TYPE) {
-		return (new Short(getShort0(obj)));
-	}
-	else if (type == Byte.TYPE) {
-		return (new Byte(getByte0(obj)));
-	}
-	else if (type == Character.TYPE) {
-		return (new Character(getChar0(obj)));
-	}
-	else if (type == Boolean.TYPE) {
-	    return (new Boolean(getBoolean0(obj)));
-	}
-	else {
-		return (getObject0(obj));
-	}
-}
-
-public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Boolean.TYPE) {
-		return (getBoolean0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Byte.TYPE) {
-		return (getByte0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public char getChar(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Character.TYPE) {
-		return (getChar0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public double getDouble(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Double.TYPE) {
-		return (getDouble0(obj));
-	}
-	else if (type == Float.TYPE) {
-		return ((double)getFloat0(obj));
-	}
-	else if (type == Long.TYPE) {
-		return ((double)getLong0(obj));
-	}
-	else if (type == Integer.TYPE) {
-		return ((double)getInt0(obj));
-	}
-	else if (type == Short.TYPE) {
-		return ((double)getShort0(obj));
-	}
-	else if (type == Byte.TYPE) {
-		return ((double)getByte0(obj));
-	}
-	else if (type == Character.TYPE) {
-		return ((double)getChar0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public float getFloat(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Float.TYPE) {
-		return (getFloat0(obj));
-	}
-	else if (type == Long.TYPE) {
-		return ((float)getLong0(obj));
-	}
-	else if (type == Integer.TYPE) {
-		return ((float)getInt0(obj));
-	}
-	else if (type == Short.TYPE) {
-		return ((float)getShort0(obj));
-	}
-	else if (type == Byte.TYPE) {
-		return ((float)getByte0(obj));
-	}
-	else if (type == Character.TYPE) {
-		return ((float)getChar0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Integer.TYPE) {
-		return (getInt0(obj));
-	}
-	else if (type == Short.TYPE) {
-		return ((int)getShort0(obj));
-	}
-	else if (type == Byte.TYPE) {
-		return ((int)getByte0(obj));
-	}
-	else if (type == Character.TYPE) {
-		return ((int)getChar0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Long.TYPE) {
-		return (getLong0(obj));
-	}
-	else if (type == Integer.TYPE) {
-		return ((long)getInt0(obj));
-	}
-	else if (type == Short.TYPE) {
-		return ((long)getShort0(obj));
-	}
-	else if (type == Byte.TYPE) {
-		return ((long)getByte0(obj));
-	}
-	else if (type == Character.TYPE) {
-		return ((long)getChar0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public short getShort(Object obj) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Short.TYPE) {
-		return (getShort0(obj));
-	}
-	else if (type == Integer.TYPE) {
-		return ((short)getInt0(obj));
-	}
-	else if (type == Long.TYPE) {
-		return ((short)getLong0(obj));
-	}
-	else if (type == Float.TYPE) {
-		return ((short)getFloat0(obj));
-	}
-	else if (type == Double.TYPE) {
-		return ((short)getDouble0(obj));
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-private void setInternal(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException {
-	if (type.isPrimitive()) {
-		if (value instanceof Boolean) {
-			setBooleanInternal(obj, ((Boolean)value).booleanValue());
-		}
-		else if (value instanceof Byte) {
-			setByteInternal(obj, ((Byte)value).byteValue());
-		}
-		else if (value instanceof Short) {
-			setShortInternal(obj, ((Short)value).shortValue());
-		}
-		else if (value instanceof Character) {
-			setCharInternal(obj, ((Character)value).charValue());
-		}
-		else if (value instanceof Integer) {
-			setIntInternal(obj, ((Integer)value).intValue());
-		}
-		else if (value instanceof Long) {
-			setLongInternal(obj, ((Long)value).longValue());
-		}
-		else if (value instanceof Float) {
-			setFloatInternal(obj, ((Float)value).floatValue());
-		}
-		else {
-			setDoubleInternal(obj, ((Double)value).doubleValue());
-		}
-	}
-	else {
-		if (value!=null && !type.isInstance(value)) {
-			throw new IllegalArgumentException("field type mismatch: Trying to assign a " + value.getClass().getName() + " to " + toString());
-		}
-
-		setObject0(obj, value);
-	}
-}
-
-public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException {
-	checkFinal();
-	setInternal(obj, value);
-}
-
-public void setBooleanInternal(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Boolean.TYPE) {
-		setBoolean0(obj, z);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setBooleanInternal(obj, z);
-}
-
-public void setByteInternal(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Byte.TYPE) {
-		setByte0(obj, b);
-	}
-	else if (type == Short.TYPE) {
-		setShort0(obj, (short)b);
-	}
-	else if (type == Integer.TYPE) {
-		setInt0(obj, (int)b);
-	}
-	else if (type == Long.TYPE) {
-		setLong0(obj, (long)b);
-	}
-	else if (type == Float.TYPE) {
-		setFloat0(obj, (float)b);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)b);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setByteInternal(obj, b);
-}
-
-public void setCharInternal(Object obj, char c) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Character.TYPE) {
-		setChar0(obj, c);
-	}
-	else if (type == Integer.TYPE) {
-		setInt0(obj, (int)c);
-	}
-	else if (type == Long.TYPE) {
-		setLong0(obj, (long)c);
-	}
-	else if (type == Float.TYPE) {
-		setFloat0(obj, (float)c);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)c);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setCharInternal(obj, c);
-}
-
-public void setDoubleInternal(Object obj, double d) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Double.TYPE) {
-		setDouble0(obj, d);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setDoubleInternal(obj, d);
-}
-
-public void setFloatInternal(Object obj, float f) throws IllegalArgumentException, IllegalAccessException {
-	if (type == Float.TYPE) {
-		setFloat0(obj, f);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)f);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setFloatInternal(obj, f);
-}
-
-public void setIntInternal(Object obj, int i) throws IllegalArgumentException, IllegalAccessException {
-        if (type == Integer.TYPE) {
-		setInt0(obj, i);
-	}
-	else if (type == Long.TYPE) {
-		setLong0(obj, (long)i);
-	}
-	else if (type == Float.TYPE) {
-		setFloat0(obj, (float)i);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)i);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setIntInternal(obj, i);
-}
-
-public void setLongInternal(Object obj, long l) throws IllegalArgumentException, IllegalAccessException {
-        if (type == Long.TYPE) {
-		setLong0(obj, l);
-	}
-	else if (type == Float.TYPE) {
-		setFloat0(obj, (float)l);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)l);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setLongInternal(obj, l);
-}
-
-public void setShortInternal(Object obj, short s) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	if (type == Short.TYPE) {
-		setShort0(obj, s);
-	}
-	else if (type == Integer.TYPE) {
-		setInt0(obj, (int)s);
-	}
-	else if (type == Long.TYPE) {
-		setLong0(obj, (long)s);
-	}
-	else if (type == Float.TYPE) {
-		setFloat0(obj, (float)s);
-	}
-	else if (type == Double.TYPE) {
-		setDouble0(obj, (double)s);
-	}
-	else {
-		throw new IllegalArgumentException();
-	}
-}
-
-public void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException {
-        checkFinal();
-	setShortInternal(obj, s);
-}
 
-public Class getDeclaringClass()
-{
-	return (clazz);
-}
+package java.lang.reflect;
 
-native public int getModifiers();
+import gnu.java.lang.ClassHelper;
 
-public String getName()
-{
-	return (name);
-}
+import gnu.java.lang.reflect.FieldSignatureParser;
 
-public Class getType()
+/**
+ * The Field class represents a member variable of a class. It also allows
+ * dynamic access to a member, via reflection. This works for both
+ * static and instance fields. Operations on Field objects know how to
+ * do widening conversions, but throw {@link IllegalArgumentException} if
+ * a narrowing conversion would be necessary. You can query for information
+ * on this Field regardless of location, but get and set access may be limited
+ * by Java language access controls. If you can't do it in the compiler, you
+ * can't normally do it here either.<p>
+ *
+ * <B>Note:</B> This class returns and accepts types as Classes, even
+ * primitive types; there are Class types defined that represent each
+ * different primitive type.  They are <code>java.lang.Boolean.TYPE,
+ * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
+ * byte.class</code>, etc.  These are not to be confused with the
+ * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
+ * real classes.<p>
+ *
+ * Also note that this is not a serializable class.  It is entirely feasible
+ * to make it serializable using the Externalizable interface, but this is
+ * on Sun, not me.
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9 at email.byu.edu>
+ * @see Member
+ * @see Class
+ * @see Class#getField(String)
+ * @see Class#getDeclaredField(String)
+ * @see Class#getFields()
+ * @see Class#getDeclaredFields()
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public final class Field
+extends AccessibleObject implements Member
 {
-	return (type);
-}
+  private Class declaringClass;
+  private String name;
+  private int slot;
+  private Class type;
+
+  private static final int FIELD_MODIFIERS
+    = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
+      | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
+      | Modifier.VOLATILE;
 
-public int hashCode()
-{
-	return (clazz.getName().hashCode() ^ name.hashCode());
-}
+  /**
+   * This class is uninstantiable except natively.
+   */
+  private Field(Class declaringClass, String name, int slot)
+  {
+    this.declaringClass = declaringClass;
+    this.name = name;
+    this.slot = slot;
+  }
 
-static String getPrettyName(Class cls) {
-        StringBuffer str = new StringBuffer();
-        for (int count = 0;; count++) {
-                if (!cls.isArray()) {
-                        str.append(cls.getName());
-                        for (; count > 0; count--) {
-                                str.append("[]");
-                        }
-                        return (str.toString());
-                }
-                cls = cls.getComponentType();
-        }
-}
+  /**
+   * Gets the class that declared this field, or the class where this field
+   * is a non-inherited member.
+   * @return the class that declared this member
+   */
+  public Class getDeclaringClass()
+  {
+    return declaringClass;
+  }
 
+  /**
+   * Gets the name of this field.
+   * @return the name of this field
+   */
+  public String getName()
+  {
+    return name;
+  }
 
-public String toString()
-{
-	StringBuffer str = new StringBuffer();
-	int mod = getModifiers();
+  /**
+   * Return the raw modifiers for this field.
+   * @return the field's modifiers
+   */
+  private native int getModifiersInternal();
 
-	// Modifier
-	if (mod != 0) {
-		str.append(Modifier.toString(mod));
-		str.append(' ');
-	}
-
-	// Type
-	str.append(getPrettyName(type));
-	str.append(' ');
-
-	// Class name
-	str.append(clazz.getName());
-	str.append('.');
-	// Field name
-	str.append(name);
-
-	return (str.toString());
-}
-
-native private boolean getBoolean0(Object obj);
-native private byte getByte0(Object obj);
-native private char getChar0(Object obj);
-native private short getShort0(Object obj);
-native private int getInt0(Object obj);
-native private long getLong0(Object obj);
-native private float getFloat0(Object obj);
-native private double getDouble0(Object obj);
-native private Object getObject0(Object obj);
-
-native private void setBoolean0(Object obj, boolean v);
-native private void setByte0(Object obj, byte v);
-native private void setChar0(Object obj, char v);
-native private void setShort0(Object obj, short v);
-native private void setInt0(Object obj, int v);
-native private void setLong0(Object obj, long v);
-native private void setFloat0(Object obj, float v);
-native private void setDouble0(Object obj, double v);
-native private void setObject0(Object obj, Object v);
+  /**
+   * Gets the modifiers this field uses.  Use the <code>Modifier</code>
+   * class to interpret the values.  A field can only have a subset of the
+   * following modifiers: public, private, protected, static, final,
+   * transient, and volatile.
+   *
+   * @return an integer representing the modifiers to this Member
+   * @see Modifier
+   */
+  public int getModifiers()
+  {
+    return getModifiersInternal() & FIELD_MODIFIERS;
+  }
 
-/* taken from GNU Classpath */
   /**
    * Return true if this field is synthetic, false otherwise.
    * @since 1.5
    */
   public boolean isSynthetic()
   {
-    return (getModifiers() & Modifier.SYNTHETIC) != 0;
+    return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
   }
 
   /**
@@ -526,6 +153,939 @@
    */
   public boolean isEnumConstant()
   {
-    return (getModifiers() & Modifier.ENUM) != 0;
+    return (getModifiersInternal() & Modifier.ENUM) != 0;
+  }
+
+  /**
+   * Gets the type of this field.
+   * @return the type of this field
+   */
+  public Class getType()
+  {
+    return type;
+  }
+
+  /**
+   * Compare two objects to see if they are semantically equivalent.
+   * Two Fields are semantically equivalent if they have the same declaring
+   * class, name, and type. Since you can't creat a Field except through
+   * the VM, this is just the == relation.
+   *
+   * @param o the object to compare to
+   * @return <code>true</code> if they are equal; <code>false</code> if not
+   */
+  public boolean equals(Object o)
+  {
+    if (!(o instanceof Field))
+      return false;
+    Field that = (Field)o; 
+    if (this.getDeclaringClass() != that.getDeclaringClass())
+      return false;
+    if (!this.getName().equals(that.getName()))
+      return false;
+    if (this.getType() != that.getType())
+      return false;
+    return true;
+  }
+
+  /**
+   * Get the hash code for the Field. The Field hash code is the hash code
+   * of its name XOR'd with the hash code of its class name.
+   *
+   * @return the hash code for the object.
+   */
+  public int hashCode()
+  {
+    return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
+  }
+
+  /**
+   * Get a String representation of the Field. A Field's String
+   * representation is "&lt;modifiers&gt; &lt;type&gt;
+   * &lt;class&gt;.&lt;fieldname&gt;".<br> Example:
+   * <code>public transient boolean gnu.parse.Parser.parseComplete</code>
+   *
+   * @return the String representation of the Field
+   */
+  public String toString()
+  {
+    // 64 is a reasonable buffer initial size for field
+    StringBuffer sb = new StringBuffer(64);
+    Modifier.toString(getModifiers(), sb).append(' ');
+    sb.append(ClassHelper.getUserName(getType())).append(' ');
+    sb.append(getDeclaringClass().getName()).append('.');
+    sb.append(getName());
+    return sb.toString();
+  }
+ 
+  public String toGenericString()
+  {
+    StringBuffer sb = new StringBuffer(64);
+    Modifier.toString(getModifiers(), sb).append(' ');
+    sb.append(getGenericType()).append(' ');
+    sb.append(getDeclaringClass().getName()).append('.');
+    sb.append(getName());
+    return sb.toString();
+  }
+
+  /**
+   * Get the value of this Field.  If it is primitive, it will be wrapped
+   * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
+   *
+   * If the field is static, <code>o</code> will be ignored. Otherwise, if
+   * <code>o</code> is null, you get a <code>NullPointerException</code>,
+   * and if it is incompatible with the declaring class of the field, you
+   * get an <code>IllegalArgumentException</code>.<p>
+   *
+   * Next, if this Field enforces access control, your runtime context is
+   * evaluated, and you may have an <code>IllegalAccessException</code> if
+   * you could not access this field in similar compiled code. If the field
+   * is static, and its class is uninitialized, you trigger class
+   * initialization, which may end in a
+   * <code>ExceptionInInitializerError</code>.<p>
+   *
+   * Finally, the field is accessed, and primitives are wrapped (but not
+   * necessarily in new objects). This method accesses the field of the
+   * declaring class, even if the instance passed in belongs to a subclass
+   * which declares another field to hide this one.
+   *
+   * @param o the object to get the value of this Field from
+   * @return the value of the Field
+   * @throws IllegalAccessException if you could not normally access this field
+   *         (i.e. it is not public)
+   * @throws IllegalArgumentException if <code>o</code> is not an instance of
+   *         the class or interface declaring this field
+   * @throws NullPointerException if <code>o</code> is null and this field
+   *         requires an instance
+   * @throws ExceptionInInitializerError if accessing a static field triggered
+   *         class initialization, which then failed
+   * @see #getBoolean(Object)
+   * @see #getByte(Object)
+   * @see #getChar(Object)
+   * @see #getShort(Object)
+   * @see #getInt(Object)
+   * @see #getLong(Object)
+   * @see #getFloat(Object)
+   * @see #getDouble(Object)
+   */
+  public Object get(Object o)
+    throws IllegalAccessException
+  {
+    if (type == Double.TYPE) {
+      return (new Double(getDouble0(o)));
+    }
+    else if (type == Float.TYPE) {
+      return (new Float(getFloat0(o)));
+    }
+    else if (type == Long.TYPE) {
+      return (new Long(getLong0(o)));
+    }
+    else if (type == Integer.TYPE) {
+      return (new Integer(getInt0(o)));
+    }
+    else if (type == Short.TYPE) {
+      return (new Short(getShort0(o)));
+    }
+    else if (type == Byte.TYPE) {
+      return (new Byte(getByte0(o)));
+    }
+    else if (type == Character.TYPE) {
+      return (new Character(getChar0(o)));
+    }
+    else if (type == Boolean.TYPE) {
+      return (new Boolean(getBoolean0(o)));
+    }
+    else {
+      return (getObject0(o));
+    }
+  }
+
+  /**
+   * Get the value of this boolean Field. If the field is static,
+   * <code>o</code> will be ignored.
+   *
+   * @param o the object to get the value of this Field from
+   * @return the value of the Field
+   * @throws IllegalAccessException if you could not normally access this field
+   *         (i.e. it is not public)
+   * @throws IllegalArgumentException if this is not a boolean field of
+   *         <code>o</code>, or if <code>o</code> is not an instance of the
+   *         declaring class of this field
+   * @throws NullPointerException if <code>o</code> is null and this field
+   *         requires an instance
+   * @throws ExceptionInInitializerError if accessing a static field triggered
+   *         class initialization, which then failed
+   * @see #get(Object)
+   */
+  public boolean getBoolean(Object o)
+    throws IllegalAccessException
+  {
+    if (type == Boolean.TYPE) {
+      return (getBoolean0(o));
+    }
+    else {
+      throw new IllegalArgumentException();
+    }
+  }
+
+  /**
+   * Get the value of this byte Field. If the field is static,
+   * <code>o</code> will be ignored.
+   *
+   * @param o the object to get the value of this Field from
+   * @return the value of the Field
+   * @throws IllegalAccessException if you could not normally access this field
+   *         (i.e. it is not public)
+   * @throws IllegalArgumentException if this is not a byte field of
+   *         <code>o</code>, or if <code>o</code> is not an instance of the
+   *         declaring class of this field
+   * @throws NullPointerException if <code>o</code> is null and this field
+   *         requires an instance
+   * @throws ExceptionInInitializerError if accessing a static field triggered

*** Patch too long, truncated ***




More information about the kaffe mailing list