diff options
Diffstat (limited to 'libjava/java/lang/reflect')
34 files changed, 1502 insertions, 42 deletions
diff --git a/libjava/java/lang/reflect/AccessibleObject.h b/libjava/java/lang/reflect/AccessibleObject.h new file mode 100644 index 00000000000..d140e300c58 --- /dev/null +++ b/libjava/java/lang/reflect/AccessibleObject.h @@ -0,0 +1,36 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_AccessibleObject__ +#define __java_lang_reflect_AccessibleObject__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::AccessibleObject : public ::java::lang::Object +{ + +public: // actually protected + AccessibleObject(); +public: + virtual jboolean isAccessible(); + static void setAccessible(JArray< ::java::lang::reflect::AccessibleObject * > *, jboolean); + virtual void setAccessible(jboolean); +private: + static void checkPermission(); + void secureSetAccessible(jboolean); +public: + virtual ::java::lang::annotation::Annotation * getAnnotation(::java::lang::Class *); + virtual JArray< ::java::lang::annotation::Annotation * > * getAnnotations(); + virtual JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotations(); + virtual jboolean isAnnotationPresent(::java::lang::Class *); +public: // actually package-private + jboolean __attribute__((aligned(__alignof__( ::java::lang::Object)))) flag; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_AccessibleObject__ diff --git a/libjava/java/lang/reflect/AnnotatedElement.h b/libjava/java/lang/reflect/AnnotatedElement.h new file mode 100644 index 00000000000..5792b75e0cc --- /dev/null +++ b/libjava/java/lang/reflect/AnnotatedElement.h @@ -0,0 +1,24 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_AnnotatedElement__ +#define __java_lang_reflect_AnnotatedElement__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::AnnotatedElement : public ::java::lang::Object +{ + +public: + virtual ::java::lang::annotation::Annotation * getAnnotation(::java::lang::Class *) = 0; + virtual JArray< ::java::lang::annotation::Annotation * > * getAnnotations() = 0; + virtual JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotations() = 0; + virtual jboolean isAnnotationPresent(::java::lang::Class *) = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_AnnotatedElement__ diff --git a/libjava/java/lang/reflect/Array.h b/libjava/java/lang/reflect/Array.h new file mode 100644 index 00000000000..48df7d3fa50 --- /dev/null +++ b/libjava/java/lang/reflect/Array.h @@ -0,0 +1,46 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Array__ +#define __java_lang_reflect_Array__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::Array : public ::java::lang::Object +{ + + Array(); +public: + static ::java::lang::Object * newInstance(::java::lang::Class *, jint); + static ::java::lang::Object * newInstance(::java::lang::Class *, JArray< jint > *); + static jint getLength(::java::lang::Object *); + static ::java::lang::Object * get(::java::lang::Object *, jint); + static jboolean getBoolean(::java::lang::Object *, jint); + static jbyte getByte(::java::lang::Object *, jint); + static jchar getChar(::java::lang::Object *, jint); + static jshort getShort(::java::lang::Object *, jint); + static jint getInt(::java::lang::Object *, jint); + static jlong getLong(::java::lang::Object *, jint); + static jfloat getFloat(::java::lang::Object *, jint); + static jdouble getDouble(::java::lang::Object *, jint); +private: + static ::java::lang::Class * getElementType(::java::lang::Object *, jint); + static void set(::java::lang::Object *, jint, ::java::lang::Object *, ::java::lang::Class *); +public: + static void set(::java::lang::Object *, jint, ::java::lang::Object *); + static void setBoolean(::java::lang::Object *, jint, jboolean); + static void setByte(::java::lang::Object *, jint, jbyte); + static void setChar(::java::lang::Object *, jint, jchar); + static void setShort(::java::lang::Object *, jint, jshort); + static void setInt(::java::lang::Object *, jint, jint); + static void setLong(::java::lang::Object *, jint, jlong); + static void setFloat(::java::lang::Object *, jint, jfloat); + static void setDouble(::java::lang::Object *, jint, jdouble); + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Array__ diff --git a/libjava/java/lang/reflect/Constructor.h b/libjava/java/lang/reflect/Constructor.h new file mode 100644 index 00000000000..5a200bc114d --- /dev/null +++ b/libjava/java/lang/reflect/Constructor.h @@ -0,0 +1,65 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Constructor__ +#define __java_lang_reflect_Constructor__ + +#pragma interface + +#include <java/lang/reflect/AccessibleObject.h> +#include <gcj/array.h> + + +jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *); +jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean); + +class java::lang::reflect::Constructor : public ::java::lang::reflect::AccessibleObject +{ + + Constructor(); +public: + ::java::lang::Class * getDeclaringClass(); + ::java::lang::String * getName(); +private: + jint getModifiersInternal(); +public: + jint getModifiers(); + jboolean isSynthetic(); + jboolean isVarArgs(); + JArray< ::java::lang::Class * > * getParameterTypes(); + JArray< ::java::lang::Class * > * getExceptionTypes(); + jboolean equals(::java::lang::Object *); + jint hashCode(); + ::java::lang::String * toString(); +public: // actually package-private + static void addTypeParameters(::java::lang::StringBuilder *, JArray< ::java::lang::reflect::TypeVariable * > *); +public: + ::java::lang::String * toGenericString(); + ::java::lang::Object * newInstance(JArray< ::java::lang::Object * > *); + JArray< ::java::lang::reflect::TypeVariable * > * getTypeParameters(); +private: + ::java::lang::String * getSignature(); +public: + JArray< ::java::lang::reflect::Type * > * getGenericExceptionTypes(); + JArray< ::java::lang::reflect::Type * > * getGenericParameterTypes(); + ::java::lang::annotation::Annotation * getAnnotation(::java::lang::Class *); + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotations(); + JArray< JArray< ::java::lang::annotation::Annotation * > * > * getParameterAnnotations(); +private: + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotationsInternal(); + JArray< JArray< ::java::lang::annotation::Annotation * > * > * getParameterAnnotationsInternal(); + void getType(); + static const jint CONSTRUCTOR_MODIFIERS = 7; + ::java::lang::Class * __attribute__((aligned(__alignof__( ::java::lang::reflect::AccessibleObject)))) declaringClass; + JArray< ::java::lang::Class * > * exception_types; + JArray< ::java::lang::Class * > * parameter_types; + jint offset; +public: + static ::java::lang::Class class$; + + friend jmethodID (::_Jv_FromReflectedConstructor) (java::lang::reflect::Constructor *); + friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean); + friend class java::lang::Class; +}; + +#endif // __java_lang_reflect_Constructor__ diff --git a/libjava/java/lang/reflect/Constructor.java b/libjava/java/lang/reflect/Constructor.java index 68b2d3985cf..83aae3b48ce 100644 --- a/libjava/java/lang/reflect/Constructor.java +++ b/libjava/java/lang/reflect/Constructor.java @@ -40,6 +40,7 @@ exception statement from your version. */ package java.lang.reflect; import gnu.java.lang.reflect.MethodSignatureParser; +import java.lang.annotation.Annotation; /** * The Constructor class represents a constructor of a class. It also allows @@ -75,7 +76,7 @@ import gnu.java.lang.reflect.MethodSignatureParser; * @since 1.1 * @status updated to 1.4 */ -public final class Constructor extends AccessibleObject +public final class Constructor<T> extends AccessibleObject implements Member, GenericDeclaration { private static final int CONSTRUCTOR_MODIFIERS @@ -92,7 +93,7 @@ public final class Constructor extends AccessibleObject * Gets the class that declared this constructor. * @return the class that declared this member */ - public Class getDeclaringClass() + public Class<T> getDeclaringClass () { return declaringClass; } @@ -235,8 +236,8 @@ public final class Constructor extends AccessibleObject return b.toString(); } - /* FIXME[GENERICS]: Add X extends GenericDeclaration and TypeVariable<X> */ - static void addTypeParameters(StringBuilder sb, TypeVariable[] typeArgs) + static <X extends GenericDeclaration> + void addTypeParameters(StringBuilder sb, TypeVariable<X>[] typeArgs) { if (typeArgs.length == 0) return; @@ -320,8 +321,7 @@ public final class Constructor extends AccessibleObject * specification, version 3. * @since 1.5 */ - /* FIXME[GENERICS]: Add <Constructor<T>> */ - public TypeVariable[] getTypeParameters() + public TypeVariable<Constructor<T>>[] getTypeParameters() { String sig = getSignature(); if (sig == null) @@ -334,11 +334,7 @@ public final class Constructor extends AccessibleObject * Return the String in the Signature attribute for this constructor. If there * is no Signature attribute, return null. */ - private String getSignature() - { - // FIXME: libgcj doesn't record this information yet. - return null; - } + private native String getSignature(); /** * Returns an array of <code>Type</code> objects that represents @@ -382,11 +378,41 @@ public final class Constructor extends AccessibleObject return p.getGenericParameterTypes(); } + public <T extends Annotation> T getAnnotation(Class<T> annoClass) + { + Annotation[] annos = getDeclaredAnnotations(); + for (int i = 0; i < annos.length; ++i) + if (annos[i].annotationType() == annoClass) + return (T) annos[i]; + return null; + } + + public Annotation[] getDeclaredAnnotations() + { + Annotation[] result = getDeclaredAnnotationsInternal(); + if (result == null) + result = new Annotation[0]; + return result; + } + + public Annotation[][] getParameterAnnotations() + { + // FIXME: should check that we have the right number + // of parameters ...? + Annotation[][] result = getParameterAnnotationsInternal(); + if (result == null) + result = new Annotation[0][0]; + return result; + } + + private native Annotation[] getDeclaredAnnotationsInternal(); + private native Annotation[][] getParameterAnnotationsInternal(); + // Update cached values from method descriptor in class. private native void getType (); // Declaring class. - private Class declaringClass; + private Class<T> declaringClass; // Exception types. private Class[] exception_types; diff --git a/libjava/java/lang/reflect/Field.h b/libjava/java/lang/reflect/Field.h new file mode 100644 index 00000000000..3e39fb2bad1 --- /dev/null +++ b/libjava/java/lang/reflect/Field.h @@ -0,0 +1,96 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Field__ +#define __java_lang_reflect_Field__ + +#pragma interface + +#include <java/lang/reflect/AccessibleObject.h> +#include <gcj/array.h> + + +jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *); +jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean); + +class java::lang::reflect::Field : public ::java::lang::reflect::AccessibleObject +{ + +public: // actually package-private + Field(); +public: + ::java::lang::Class * getDeclaringClass(); + ::java::lang::String * getName(); +private: + jint getModifiersInternal(); +public: + jint getModifiers(); + jboolean isSynthetic(); + jboolean isEnumConstant(); + ::java::lang::Class * getType(); + jboolean equals(::java::lang::Object *); + jint hashCode(); + ::java::lang::String * toString(); + ::java::lang::String * toGenericString(); + ::java::lang::Object * get(::java::lang::Object *); + jboolean getBoolean(::java::lang::Object *); + jbyte getByte(::java::lang::Object *); + jchar getChar(::java::lang::Object *); + jshort getShort(::java::lang::Object *); + jint getInt(::java::lang::Object *); + jlong getLong(::java::lang::Object *); + jfloat getFloat(::java::lang::Object *); + jdouble getDouble(::java::lang::Object *); +private: + jboolean getBoolean(::java::lang::Class *, ::java::lang::Object *); + jchar getChar(::java::lang::Class *, ::java::lang::Object *); + jbyte getByte(::java::lang::Class *, ::java::lang::Object *); + jshort getShort(::java::lang::Class *, ::java::lang::Object *); + jint getInt(::java::lang::Class *, ::java::lang::Object *); + jlong getLong(::java::lang::Class *, ::java::lang::Object *); + jfloat getFloat(::java::lang::Class *, ::java::lang::Object *); + jdouble getDouble(::java::lang::Class *, ::java::lang::Object *); + ::java::lang::Object * get(::java::lang::Class *, ::java::lang::Object *); +public: + void set(::java::lang::Object *, ::java::lang::Object *); + void setBoolean(::java::lang::Object *, jboolean); + void setByte(::java::lang::Object *, jbyte); + void setChar(::java::lang::Object *, jchar); + void setShort(::java::lang::Object *, jshort); + void setInt(::java::lang::Object *, jint); + void setLong(::java::lang::Object *, jlong); + void setFloat(::java::lang::Object *, jfloat); + void setDouble(::java::lang::Object *, jdouble); + ::java::lang::reflect::Type * getGenericType(); + ::java::lang::annotation::Annotation * getAnnotation(::java::lang::Class *); + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotations(); +private: + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotationsInternal(); + ::java::lang::String * getSignature(); +public: // actually package-private + void setByte(::java::lang::Class *, ::java::lang::Object *, jbyte, jboolean); + void setShort(::java::lang::Class *, ::java::lang::Object *, jshort, jboolean); + void setInt(::java::lang::Class *, ::java::lang::Object *, jint, jboolean); + void setLong(::java::lang::Class *, ::java::lang::Object *, jlong, jboolean); + void setFloat(::java::lang::Class *, ::java::lang::Object *, jfloat, jboolean); + void setDouble(::java::lang::Class *, ::java::lang::Object *, jdouble, jboolean); + void setChar(::java::lang::Class *, ::java::lang::Object *, jchar, jboolean); + void setBoolean(::java::lang::Class *, ::java::lang::Object *, jboolean, jboolean); + void set(::java::lang::Class *, ::java::lang::Object *, ::java::lang::Object *, ::java::lang::Class *, jboolean); +private: + void set(::java::lang::Class *, ::java::lang::Object *, ::java::lang::Object *); + ::java::lang::Class * __attribute__((aligned(__alignof__( ::java::lang::reflect::AccessibleObject)))) declaringClass; + ::java::lang::String * name; + jint offset; + ::java::lang::Class * type; +public: // actually package-private + static const jint FIELD_MODIFIERS = 223; +public: + static ::java::lang::Class class$; + + friend jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *); + friend jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean); + friend class java::lang::Class; +}; + +#endif // __java_lang_reflect_Field__ diff --git a/libjava/java/lang/reflect/Field.java b/libjava/java/lang/reflect/Field.java index 134ff132ecf..61db14df576 100644 --- a/libjava/java/lang/reflect/Field.java +++ b/libjava/java/lang/reflect/Field.java @@ -41,6 +41,7 @@ package java.lang.reflect; import gnu.java.lang.ClassHelper; import gnu.java.lang.reflect.FieldSignatureParser; +import java.lang.annotation.Annotation; /** * The Field class represents a member variable of a class. It also allows @@ -88,7 +89,7 @@ public final class Field // The Class (or primitive TYPE) of this field. private Class type; - private static final int FIELD_MODIFIERS + static final int FIELD_MODIFIERS = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT | Modifier.VOLATILE; @@ -104,7 +105,7 @@ public final class Field * is a non-inherited member. * @return the class that declared this member */ - public Class getDeclaringClass() + public Class<?> getDeclaringClass() { return declaringClass; } @@ -158,7 +159,7 @@ public final class Field * Gets the type of this field. * @return the type of this field */ - public native Class getType(); + public native Class<?> getType(); /** * Compare two objects to see if they are semantically equivalent. @@ -733,15 +734,30 @@ public final class Field return p.getFieldType(); } + public <T extends Annotation> T getAnnotation(Class<T> annoClass) + { + Annotation[] annos = getDeclaredAnnotations(); + for (int i = 0; i < annos.length; ++i) + if (annos[i].annotationType() == annoClass) + return (T) annos[i]; + return null; + } + + public Annotation[] getDeclaredAnnotations() + { + Annotation[] result = getDeclaredAnnotationsInternal(); + if (result == null) + result = new Annotation[0]; + return result; + } + + private native Annotation[] getDeclaredAnnotationsInternal(); + /** * Return the String in the Signature attribute for this field. If there * is no Signature attribute, return null. */ - private String getSignature() - { - // FIXME: libgcj doesn't record Signature attributes yet. - return null; - } + private native String getSignature(); native void setByte (Class caller, Object obj, byte b, boolean checkFinal) throws IllegalArgumentException, IllegalAccessException; diff --git a/libjava/java/lang/reflect/GenericArrayType.h b/libjava/java/lang/reflect/GenericArrayType.h new file mode 100644 index 00000000000..cdeb0b2a328 --- /dev/null +++ b/libjava/java/lang/reflect/GenericArrayType.h @@ -0,0 +1,19 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_GenericArrayType__ +#define __java_lang_reflect_GenericArrayType__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::lang::reflect::GenericArrayType : public ::java::lang::Object +{ + +public: + virtual ::java::lang::reflect::Type * getGenericComponentType() = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_GenericArrayType__ diff --git a/libjava/java/lang/reflect/GenericDeclaration.h b/libjava/java/lang/reflect/GenericDeclaration.h new file mode 100644 index 00000000000..5c484ea96ea --- /dev/null +++ b/libjava/java/lang/reflect/GenericDeclaration.h @@ -0,0 +1,21 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_GenericDeclaration__ +#define __java_lang_reflect_GenericDeclaration__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::GenericDeclaration : public ::java::lang::Object +{ + +public: + virtual JArray< ::java::lang::reflect::TypeVariable * > * getTypeParameters() = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_GenericDeclaration__ diff --git a/libjava/java/lang/reflect/GenericSignatureFormatError.h b/libjava/java/lang/reflect/GenericSignatureFormatError.h new file mode 100644 index 00000000000..c46c9264ad3 --- /dev/null +++ b/libjava/java/lang/reflect/GenericSignatureFormatError.h @@ -0,0 +1,22 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_GenericSignatureFormatError__ +#define __java_lang_reflect_GenericSignatureFormatError__ + +#pragma interface + +#include <java/lang/ClassFormatError.h> + +class java::lang::reflect::GenericSignatureFormatError : public ::java::lang::ClassFormatError +{ + +public: + GenericSignatureFormatError(); +private: + static const jlong serialVersionUID = 6709919147137911034LL; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_GenericSignatureFormatError__ diff --git a/libjava/java/lang/reflect/InvocationHandler.h b/libjava/java/lang/reflect/InvocationHandler.h new file mode 100644 index 00000000000..7221953217a --- /dev/null +++ b/libjava/java/lang/reflect/InvocationHandler.h @@ -0,0 +1,21 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_InvocationHandler__ +#define __java_lang_reflect_InvocationHandler__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::InvocationHandler : public ::java::lang::Object +{ + +public: + virtual ::java::lang::Object * invoke(::java::lang::Object *, ::java::lang::reflect::Method *, JArray< ::java::lang::Object * > *) = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_InvocationHandler__ diff --git a/libjava/java/lang/reflect/InvocationTargetException.h b/libjava/java/lang/reflect/InvocationTargetException.h new file mode 100644 index 00000000000..37e229c2957 --- /dev/null +++ b/libjava/java/lang/reflect/InvocationTargetException.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_InvocationTargetException__ +#define __java_lang_reflect_InvocationTargetException__ + +#pragma interface + +#include <java/lang/Exception.h> + +class java::lang::reflect::InvocationTargetException : public ::java::lang::Exception +{ + +public: // actually protected + InvocationTargetException(); +public: + InvocationTargetException(::java::lang::Throwable *); + InvocationTargetException(::java::lang::Throwable *, ::java::lang::String *); + virtual ::java::lang::Throwable * getTargetException(); + virtual ::java::lang::Throwable * getCause(); +private: + static const jlong serialVersionUID = 4085088731926701167LL; + ::java::lang::Throwable * __attribute__((aligned(__alignof__( ::java::lang::Exception)))) target; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_InvocationTargetException__ diff --git a/libjava/java/lang/reflect/MalformedParameterizedTypeException.h b/libjava/java/lang/reflect/MalformedParameterizedTypeException.h new file mode 100644 index 00000000000..a48f669c0c1 --- /dev/null +++ b/libjava/java/lang/reflect/MalformedParameterizedTypeException.h @@ -0,0 +1,22 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_MalformedParameterizedTypeException__ +#define __java_lang_reflect_MalformedParameterizedTypeException__ + +#pragma interface + +#include <java/lang/RuntimeException.h> + +class java::lang::reflect::MalformedParameterizedTypeException : public ::java::lang::RuntimeException +{ + +public: + MalformedParameterizedTypeException(); +private: + static const jlong serialVersionUID = -5696557788586220964LL; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_MalformedParameterizedTypeException__ diff --git a/libjava/java/lang/reflect/Member.h b/libjava/java/lang/reflect/Member.h new file mode 100644 index 00000000000..9e3522be0d6 --- /dev/null +++ b/libjava/java/lang/reflect/Member.h @@ -0,0 +1,24 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Member__ +#define __java_lang_reflect_Member__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::lang::reflect::Member : public ::java::lang::Object +{ + +public: + virtual ::java::lang::Class * getDeclaringClass() = 0; + virtual ::java::lang::String * getName() = 0; + virtual jint getModifiers() = 0; + virtual jboolean isSynthetic() = 0; + static const jint DECLARED = 1; + static const jint PUBLIC = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_Member__ diff --git a/libjava/java/lang/reflect/Method.h b/libjava/java/lang/reflect/Method.h new file mode 100644 index 00000000000..7d4b46d3e27 --- /dev/null +++ b/libjava/java/lang/reflect/Method.h @@ -0,0 +1,76 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Method__ +#define __java_lang_reflect_Method__ + +#pragma interface + +#include <java/lang/reflect/AccessibleObject.h> +#include <gcj/array.h> + + +jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *); +jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean); + +class java::lang::reflect::Method : public ::java::lang::reflect::AccessibleObject +{ + + Method(); +public: + ::java::lang::Class * getDeclaringClass(); + ::java::lang::String * getName(); +private: + jint getModifiersInternal(); +public: + jint getModifiers(); + jboolean isBridge(); + jboolean isSynthetic(); + jboolean isVarArgs(); + ::java::lang::Class * getReturnType(); + JArray< ::java::lang::Class * > * getParameterTypes(); + JArray< ::java::lang::Class * > * getExceptionTypes(); + jboolean equals(::java::lang::Object *); + jint hashCode(); + ::java::lang::String * toString(); + ::java::lang::String * toGenericString(); + ::java::lang::Object * invoke(::java::lang::Object *, JArray< ::java::lang::Object * > *); + JArray< ::java::lang::reflect::TypeVariable * > * getTypeParameters(); +private: + ::java::lang::String * getSignature(); +public: + JArray< ::java::lang::reflect::Type * > * getGenericExceptionTypes(); + JArray< ::java::lang::reflect::Type * > * getGenericParameterTypes(); + ::java::lang::reflect::Type * getGenericReturnType(); + ::java::lang::Object * getDefaultValue(); + ::java::lang::annotation::Annotation * getAnnotation(::java::lang::Class *); + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotations(); + JArray< JArray< ::java::lang::annotation::Annotation * > * > * getParameterAnnotations(); +private: + JArray< ::java::lang::annotation::Annotation * > * getDeclaredAnnotationsInternal(); + JArray< JArray< ::java::lang::annotation::Annotation * > * > * getParameterAnnotationsInternal(); + void getType(); +public: // actually package-private + static void appendClassName(::java::lang::StringBuffer *, ::java::lang::Class *); + static const jint METHOD_MODIFIERS = 3391; +private: + ::java::lang::Class * __attribute__((aligned(__alignof__( ::java::lang::reflect::AccessibleObject)))) declaringClass; +public: // actually package-private + JArray< ::java::lang::Class * > * exception_types; +private: + ::java::lang::String * name; +public: // actually package-private + JArray< ::java::lang::Class * > * parameter_types; + ::java::lang::Class * return_type; +private: + jint offset; +public: + static ::java::lang::Class class$; + + friend jmethodID (::_Jv_FromReflectedMethod) (java::lang::reflect::Method *); + friend jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean); + friend class java::lang::Class; + friend class java::io::ObjectInputStream; +}; + +#endif // __java_lang_reflect_Method__ diff --git a/libjava/java/lang/reflect/Method.java b/libjava/java/lang/reflect/Method.java index 3142d64944f..fc0bf106440 100644 --- a/libjava/java/lang/reflect/Method.java +++ b/libjava/java/lang/reflect/Method.java @@ -12,6 +12,7 @@ package java.lang.reflect; import gnu.gcj.RawData; import gnu.java.lang.reflect.MethodSignatureParser; +import java.lang.annotation.Annotation; /** * The Method class represents a member method of a class. It also allows @@ -50,7 +51,7 @@ import gnu.java.lang.reflect.MethodSignatureParser; public final class Method extends AccessibleObject implements Member, GenericDeclaration { - private static final int METHOD_MODIFIERS + static final int METHOD_MODIFIERS = Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC | Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED; @@ -132,7 +133,7 @@ public final class Method * Gets the return type of this method. * @return the type of this method */ - public Class getReturnType () + public Class<?> getReturnType () { if (return_type == null) getType(); @@ -145,11 +146,11 @@ public final class Method * * @return a list of the types of the method's parameters */ - public Class[] getParameterTypes () + public Class<?>[] getParameterTypes () { if (parameter_types == null) getType(); - return (Class[]) parameter_types.clone(); + return (Class<?>[]) parameter_types.clone(); } /** @@ -159,11 +160,11 @@ public final class Method * * @return a list of the types in the method's throws clause */ - public Class[] getExceptionTypes () + public Class<?>[] getExceptionTypes () { if (exception_types == null) getType(); - return (Class[]) exception_types.clone(); + return (Class<?>[]) exception_types.clone(); } /** @@ -309,7 +310,7 @@ public final class Method * @throws ExceptionInInitializerError if accessing a static method triggered * class initialization, which then failed */ - public native Object invoke (Object obj, Object[] args) + public native Object invoke (Object obj, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException; @@ -325,8 +326,7 @@ public final class Method * 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) @@ -339,11 +339,7 @@ public final class Method * Return the String in the Signature attribute for this method. If there * is no Signature attribute, return null. */ - private String getSignature() - { - // FIXME: libgcj doesn't record this information yet. - return null; - } + private native String getSignature(); /** * Returns an array of <code>Type</code> objects that represents @@ -405,6 +401,49 @@ public final class Method return p.getGenericReturnType(); } + /** + * If this method is an annotation method, returns the default + * value for the method. If there is no default value, or if the + * method is not a member of an annotation type, returns null. + * Primitive types are wrapped. + * + * @throws TypeNotPresentException if the method returns a Class, + * and the class cannot be found + * + * @since 1.5 + */ + public native Object getDefaultValue(); + + public <T extends Annotation> T getAnnotation(Class<T> annoClass) + { + Annotation[] annos = getDeclaredAnnotations(); + for (int i = 0; i < annos.length; ++i) + if (annos[i].annotationType() == annoClass) + return (T) annos[i]; + return null; + } + + public Annotation[] getDeclaredAnnotations() + { + Annotation[] result = getDeclaredAnnotationsInternal(); + if (result == null) + result = new Annotation[0]; + return result; + } + + public Annotation[][] getParameterAnnotations() + { + // FIXME: should check that we have the right number + // of parameters ...? + Annotation[][] result = getParameterAnnotationsInternal(); + if (result == null) + result = new Annotation[0][0]; + return result; + } + + private native Annotation[] getDeclaredAnnotationsInternal(); + private native Annotation[][] getParameterAnnotationsInternal(); + private native void getType (); // Append a class name to a string buffer. We try to print the @@ -431,13 +470,13 @@ public final class Method private Class declaringClass; // Exception types. - private Class[] exception_types; + Class[] exception_types; // Name cache. (Initially null.) private String name; // Parameter types. - private Class[] parameter_types; + Class[] parameter_types; // Return type. - private Class return_type; + Class return_type; // Offset in bytes from the start of declaringClass's methods array. private int offset; diff --git a/libjava/java/lang/reflect/Modifier.h b/libjava/java/lang/reflect/Modifier.h new file mode 100644 index 00000000000..4ee474a9500 --- /dev/null +++ b/libjava/java/lang/reflect/Modifier.h @@ -0,0 +1,58 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Modifier__ +#define __java_lang_reflect_Modifier__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::lang::reflect::Modifier : public ::java::lang::Object +{ + +public: + Modifier(); + static jboolean isAbstract(jint); + static jboolean isFinal(jint); + static jboolean isInterface(jint); + static jboolean isNative(jint); + static jboolean isPrivate(jint); + static jboolean isProtected(jint); + static jboolean isPublic(jint); + static jboolean isStatic(jint); + static jboolean isStrict(jint); + static jboolean isSynchronized(jint); + static jboolean isTransient(jint); + static jboolean isVolatile(jint); + static ::java::lang::String * toString(jint); +public: // actually package-private + static ::java::lang::StringBuilder * toString(jint, ::java::lang::StringBuilder *); + static ::java::lang::StringBuffer * toString(jint, ::java::lang::StringBuffer *); +public: + static const jint PUBLIC = 1; + static const jint PRIVATE = 2; + static const jint PROTECTED = 4; + static const jint STATIC = 8; + static const jint FINAL = 16; + static const jint SYNCHRONIZED = 32; + static const jint VOLATILE = 64; + static const jint TRANSIENT = 128; + static const jint NATIVE = 256; + static const jint INTERFACE = 512; + static const jint ABSTRACT = 1024; + static const jint STRICT = 2048; +public: // actually package-private + static const jint SUPER = 32; + static const jint ALL_FLAGS = 4095; + static const jint BRIDGE = 64; + static const jint VARARGS = 128; + static const jint SYNTHETIC = 4096; + static const jint ENUM = 16384; + static const jint INVISIBLE = 32768; + static const jint INTERPRETED = 4096; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Modifier__ diff --git a/libjava/java/lang/reflect/ParameterizedType.h b/libjava/java/lang/reflect/ParameterizedType.h new file mode 100644 index 00000000000..dab9ad953b6 --- /dev/null +++ b/libjava/java/lang/reflect/ParameterizedType.h @@ -0,0 +1,23 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_ParameterizedType__ +#define __java_lang_reflect_ParameterizedType__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::ParameterizedType : public ::java::lang::Object +{ + +public: + virtual JArray< ::java::lang::reflect::Type * > * getActualTypeArguments() = 0; + virtual ::java::lang::reflect::Type * getOwnerType() = 0; + virtual ::java::lang::reflect::Type * getRawType() = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_ParameterizedType__ diff --git a/libjava/java/lang/reflect/Proxy$ClassFactory.h b/libjava/java/lang/reflect/Proxy$ClassFactory.h new file mode 100644 index 00000000000..c4cfb883d4c --- /dev/null +++ b/libjava/java/lang/reflect/Proxy$ClassFactory.h @@ -0,0 +1,78 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Proxy$ClassFactory__ +#define __java_lang_reflect_Proxy$ClassFactory__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::Proxy$ClassFactory : public ::java::lang::Object +{ + +public: // actually package-private + Proxy$ClassFactory(::java::lang::reflect::Proxy$ProxyData *); +private: + void emitMethod(jint, JArray< ::java::lang::Class * > *); +public: // actually package-private + ::java::lang::Class * generate(::java::lang::ClassLoader *); +private: + void putU1(jint); + void putU2(jint); + void putU4(jint); + void putConst(jint); + void putLoad(jint, ::java::lang::Class *); + ::java::lang::String * wrapper(::java::lang::Class *); + jchar utf8Info(::java::lang::String *); + jchar classInfo(::java::lang::String *); + jchar classInfo(::java::lang::Class *); + jchar refInfo(jbyte, ::java::lang::String *, ::java::lang::String *, ::java::lang::String *); + jchar nameAndTypeInfo(::java::lang::String *, ::java::lang::String *); + ::java::lang::String * toUtf8(::java::lang::String *); + jchar poolIndex(::java::lang::String *); + static const jbyte FIELD = 1; + static const jbyte METHOD = 2; + static const jbyte INTERFACE = 3; + static ::java::lang::String * CTOR_SIG; + static ::java::lang::String * INVOKE_SIG; + static const jchar ACONST_NULL = 1; + static const jchar ICONST_0 = 3; + static const jchar BIPUSH = 16; + static const jchar SIPUSH = 17; + static const jchar ILOAD = 21; + static const jchar ILOAD_0 = 26; + static const jchar ALOAD_0 = 42; + static const jchar ALOAD_1 = 43; + static const jchar AALOAD = 50; + static const jchar AASTORE = 83; + static const jchar DUP = 89; + static const jchar DUP_X1 = 90; + static const jchar SWAP = 95; + static const jchar IRETURN = 172; + static const jchar LRETURN = 173; + static const jchar FRETURN = 174; + static const jchar DRETURN = 175; + static const jchar ARETURN = 176; + static const jchar RETURN = 177; + static const jchar GETSTATIC = 178; + static const jchar GETFIELD = 180; + static const jchar INVOKEVIRTUAL = 182; + static const jchar INVOKESPECIAL = 183; + static const jchar INVOKEINTERFACE = 185; + static const jchar NEW = 187; + static const jchar ANEWARRAY = 189; + static const jchar ATHROW = 191; + static const jchar CHECKCAST = 192; + ::java::lang::StringBuffer * __attribute__((aligned(__alignof__( ::java::lang::Object)))) pool; + ::java::lang::StringBuffer * stream; + ::java::util::Map * poolEntries; + ::java::lang::String * qualName; + JArray< ::java::lang::reflect::Method * > * methods; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Proxy$ClassFactory__ diff --git a/libjava/java/lang/reflect/Proxy$ProxyData.h b/libjava/java/lang/reflect/Proxy$ProxyData.h new file mode 100644 index 00000000000..2c0d91e5e5a --- /dev/null +++ b/libjava/java/lang/reflect/Proxy$ProxyData.h @@ -0,0 +1,37 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Proxy$ProxyData__ +#define __java_lang_reflect_Proxy$ProxyData__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::Proxy$ProxyData : public ::java::lang::Object +{ + +public: // actually package-private + Proxy$ProxyData(); +private: + static ::java::lang::String * getPackage(::java::lang::Class *); +public: // actually package-private + static ::java::lang::reflect::Proxy$ProxyData * getProxyData(::java::lang::reflect::Proxy$ProxyType *); +private: + static jboolean isCoreObjectMethod(::java::lang::reflect::Method *); +public: // actually package-private + ::java::lang::String * __attribute__((aligned(__alignof__( ::java::lang::Object)))) pack; + JArray< ::java::lang::Class * > * interfaces; + JArray< ::java::lang::reflect::Method * > * methods; + JArray< JArray< ::java::lang::Class * > * > * exceptions; +private: + static jint count; +public: // actually package-private + jint id; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Proxy$ProxyData__ diff --git a/libjava/java/lang/reflect/Proxy$ProxySignature.h b/libjava/java/lang/reflect/Proxy$ProxySignature.h new file mode 100644 index 00000000000..ae0f028deb0 --- /dev/null +++ b/libjava/java/lang/reflect/Proxy$ProxySignature.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Proxy$ProxySignature__ +#define __java_lang_reflect_Proxy$ProxySignature__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::lang::reflect::Proxy$ProxySignature : public ::java::lang::Object +{ + +public: // actually package-private + Proxy$ProxySignature(::java::lang::reflect::Method *); + void checkCompatibility(::java::lang::reflect::Proxy$ProxySignature *); +public: + jint hashCode(); + jboolean equals(::java::lang::Object *); +public: // actually package-private + static ::java::util::HashMap * coreMethods; + ::java::lang::reflect::Method * __attribute__((aligned(__alignof__( ::java::lang::Object)))) method; + ::java::util::Set * exceptions; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Proxy$ProxySignature__ diff --git a/libjava/java/lang/reflect/Proxy$ProxyType.h b/libjava/java/lang/reflect/Proxy$ProxyType.h new file mode 100644 index 00000000000..da7653539f4 --- /dev/null +++ b/libjava/java/lang/reflect/Proxy$ProxyType.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Proxy$ProxyType__ +#define __java_lang_reflect_Proxy$ProxyType__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::Proxy$ProxyType : public ::java::lang::Object +{ + +public: // actually package-private + Proxy$ProxyType(::java::lang::ClassLoader *, JArray< ::java::lang::Class * > *); +public: + jint hashCode(); + jboolean equals(::java::lang::Object *); +public: // actually package-private + ::java::lang::ClassLoader * __attribute__((aligned(__alignof__( ::java::lang::Object)))) loader; + JArray< ::java::lang::Class * > * interfaces; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Proxy$ProxyType__ diff --git a/libjava/java/lang/reflect/Proxy.h b/libjava/java/lang/reflect/Proxy.h new file mode 100644 index 00000000000..4dad2cffd2d --- /dev/null +++ b/libjava/java/lang/reflect/Proxy.h @@ -0,0 +1,32 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Proxy__ +#define __java_lang_reflect_Proxy__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::Proxy : public ::java::lang::Object +{ + +public: // actually protected + Proxy(::java::lang::reflect::InvocationHandler *); +public: + static ::java::lang::Class * getProxyClass(::java::lang::ClassLoader *, JArray< ::java::lang::Class * > *); + static ::java::lang::Object * newProxyInstance(::java::lang::ClassLoader *, JArray< ::java::lang::Class * > *, ::java::lang::reflect::InvocationHandler *); + static jboolean isProxyClass(::java::lang::Class *); + static ::java::lang::reflect::InvocationHandler * getInvocationHandler(::java::lang::Object *); +private: + static const jlong serialVersionUID = -2222568056686623797LL; + static ::java::util::Map * proxyClasses; +public: // actually protected + ::java::lang::reflect::InvocationHandler * __attribute__((aligned(__alignof__( ::java::lang::Object)))) h; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_Proxy__ diff --git a/libjava/java/lang/reflect/ReflectPermission.h b/libjava/java/lang/reflect/ReflectPermission.h new file mode 100644 index 00000000000..0e6a7c32e79 --- /dev/null +++ b/libjava/java/lang/reflect/ReflectPermission.h @@ -0,0 +1,23 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_ReflectPermission__ +#define __java_lang_reflect_ReflectPermission__ + +#pragma interface + +#include <java/security/BasicPermission.h> + +class java::lang::reflect::ReflectPermission : public ::java::security::BasicPermission +{ + +public: + ReflectPermission(::java::lang::String *); + ReflectPermission(::java::lang::String *, ::java::lang::String *); +private: + static const jlong serialVersionUID = 7412737110241507485LL; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_ReflectPermission__ diff --git a/libjava/java/lang/reflect/Type.h b/libjava/java/lang/reflect/Type.h new file mode 100644 index 00000000000..55c317fa425 --- /dev/null +++ b/libjava/java/lang/reflect/Type.h @@ -0,0 +1,18 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_Type__ +#define __java_lang_reflect_Type__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::lang::reflect::Type : public ::java::lang::Object +{ + +public: + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_Type__ diff --git a/libjava/java/lang/reflect/TypeVariable.h b/libjava/java/lang/reflect/TypeVariable.h new file mode 100644 index 00000000000..6029c01903d --- /dev/null +++ b/libjava/java/lang/reflect/TypeVariable.h @@ -0,0 +1,23 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_TypeVariable__ +#define __java_lang_reflect_TypeVariable__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::TypeVariable : public ::java::lang::Object +{ + +public: + virtual JArray< ::java::lang::reflect::Type * > * getBounds() = 0; + virtual ::java::lang::reflect::GenericDeclaration * getGenericDeclaration() = 0; + virtual ::java::lang::String * getName() = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_TypeVariable__ diff --git a/libjava/java/lang/reflect/UndeclaredThrowableException.h b/libjava/java/lang/reflect/UndeclaredThrowableException.h new file mode 100644 index 00000000000..01b969b0e43 --- /dev/null +++ b/libjava/java/lang/reflect/UndeclaredThrowableException.h @@ -0,0 +1,26 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_UndeclaredThrowableException__ +#define __java_lang_reflect_UndeclaredThrowableException__ + +#pragma interface + +#include <java/lang/RuntimeException.h> + +class java::lang::reflect::UndeclaredThrowableException : public ::java::lang::RuntimeException +{ + +public: + UndeclaredThrowableException(::java::lang::Throwable *); + UndeclaredThrowableException(::java::lang::Throwable *, ::java::lang::String *); + virtual ::java::lang::Throwable * getUndeclaredThrowable(); + virtual ::java::lang::Throwable * getCause(); +private: + static const jlong serialVersionUID = 330127114055056639LL; + ::java::lang::Throwable * __attribute__((aligned(__alignof__( ::java::lang::RuntimeException)))) undeclaredThrowable; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_UndeclaredThrowableException__ diff --git a/libjava/java/lang/reflect/VMProxy.h b/libjava/java/lang/reflect/VMProxy.h new file mode 100644 index 00000000000..e48e8e4e875 --- /dev/null +++ b/libjava/java/lang/reflect/VMProxy.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_VMProxy__ +#define __java_lang_reflect_VMProxy__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::VMProxy : public ::java::lang::Object +{ + +public: // actually package-private + VMProxy(); + static ::java::lang::Class * getProxyClass(::java::lang::ClassLoader *, JArray< ::java::lang::Class * > *); + static ::java::lang::reflect::Proxy$ProxyData * getProxyData(::java::lang::ClassLoader *, JArray< ::java::lang::Class * > *); + static ::java::lang::Class * generateProxyClass(::java::lang::ClassLoader *, ::java::lang::reflect::Proxy$ProxyData *); + static jboolean HAVE_NATIVE_GET_PROXY_CLASS; + static jboolean HAVE_NATIVE_GET_PROXY_DATA; + static jboolean HAVE_NATIVE_GENERATE_PROXY_CLASS; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_lang_reflect_VMProxy__ diff --git a/libjava/java/lang/reflect/VMProxy.java b/libjava/java/lang/reflect/VMProxy.java index b3641cf17d9..ea1c8850625 100644 --- a/libjava/java/lang/reflect/VMProxy.java +++ b/libjava/java/lang/reflect/VMProxy.java @@ -65,7 +65,7 @@ final class VMProxy * If this is true, HAVE_NATIVE_GET_PROXY_CLASS should be false. * @see java.lang.reflect.Proxy */ - static boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = false; + static boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = true; /** * Optional native method to replace (and speed up) the pure Java @@ -136,8 +136,5 @@ final class VMProxy * @see #getProxyClass(ClassLoader, Class[]) * @see ProxyData#generateProxyClass(ClassLoader) */ - static Class generateProxyClass(ClassLoader loader, Proxy.ProxyData data) - { - return null; - } + static native Class generateProxyClass(ClassLoader loader, Proxy.ProxyData data); } diff --git a/libjava/java/lang/reflect/WildcardType.h b/libjava/java/lang/reflect/WildcardType.h new file mode 100644 index 00000000000..2c5b93d65e7 --- /dev/null +++ b/libjava/java/lang/reflect/WildcardType.h @@ -0,0 +1,22 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_lang_reflect_WildcardType__ +#define __java_lang_reflect_WildcardType__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::lang::reflect::WildcardType : public ::java::lang::Object +{ + +public: + virtual JArray< ::java::lang::reflect::Type * > * getLowerBounds() = 0; + virtual JArray< ::java::lang::reflect::Type * > * getUpperBounds() = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_lang_reflect_WildcardType__ diff --git a/libjava/java/lang/reflect/natConstructor.cc b/libjava/java/lang/reflect/natConstructor.cc index 35cf7f817ef..953d86dd411 100644 --- a/libjava/java/lang/reflect/natConstructor.cc +++ b/libjava/java/lang/reflect/natConstructor.cc @@ -23,12 +23,33 @@ details. */ #include <java/lang/InstantiationException.h> #include <gcj/method.h> +typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t; +typedef JArray< JArray< ::java::lang::annotation::Annotation * > *> * anno_aa_t; + jint java::lang::reflect::Constructor::getModifiersInternal () { return _Jv_FromReflectedConstructor (this)->accflags; } +jstring +java::lang::reflect::Constructor::getSignature() +{ + return declaringClass->getReflectionSignature (this); +} + +anno_a_t +java::lang::reflect::Constructor::getDeclaredAnnotationsInternal() +{ + return (anno_a_t) declaringClass->getDeclaredAnnotations(this, false); +} + +anno_aa_t +java::lang::reflect::Constructor::getParameterAnnotationsInternal() +{ + return (anno_aa_t) declaringClass->getDeclaredAnnotations(this, true); +} + void java::lang::reflect::Constructor::getType () { diff --git a/libjava/java/lang/reflect/natField.cc b/libjava/java/lang/reflect/natField.cc index 487f62ab0e2..b107ab851b7 100644 --- a/libjava/java/lang/reflect/natField.cc +++ b/libjava/java/lang/reflect/natField.cc @@ -29,6 +29,8 @@ details. */ #include <java/lang/Boolean.h> #include <java/lang/Character.h> +typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t; + jint java::lang::reflect::Field::getModifiersInternal () { @@ -36,6 +38,18 @@ java::lang::reflect::Field::getModifiersInternal () } jstring +java::lang::reflect::Field::getSignature() +{ + return declaringClass->getReflectionSignature (this); +} + +anno_a_t +java::lang::reflect::Field::getDeclaredAnnotationsInternal() +{ + return (anno_a_t) declaringClass->getDeclaredAnnotations(this); +} + +jstring java::lang::reflect::Field::getName () { if (name == NULL) diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc index eb7170a02be..6dcd4ec518a 100644 --- a/libjava/java/lang/reflect/natMethod.cc +++ b/libjava/java/lang/reflect/natMethod.cc @@ -48,6 +48,11 @@ details. */ #include <java/lang/UnsupportedOperationException.h> #endif +typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t; +typedef JArray< JArray< ::java::lang::annotation::Annotation * > *> * anno_aa_t; + + + struct cpair { jclass prim; @@ -189,6 +194,30 @@ java::lang::reflect::Method::getModifiersInternal () } jstring +java::lang::reflect::Method::getSignature() +{ + return declaringClass->getReflectionSignature (this); +} + +jobject +java::lang::reflect::Method::getDefaultValue() +{ + return declaringClass->getMethodDefaultValue(this); +} + +anno_a_t +java::lang::reflect::Method::getDeclaredAnnotationsInternal() +{ + return (anno_a_t) declaringClass->getDeclaredAnnotations(this, false); +} + +anno_aa_t +java::lang::reflect::Method::getParameterAnnotationsInternal() +{ + return (anno_aa_t) declaringClass->getDeclaredAnnotations(this, true); +} + +jstring java::lang::reflect::Method::getName () { if (name == NULL) diff --git a/libjava/java/lang/reflect/natVMProxy.cc b/libjava/java/lang/reflect/natVMProxy.cc new file mode 100644 index 00000000000..8d803a85971 --- /dev/null +++ b/libjava/java/lang/reflect/natVMProxy.cc @@ -0,0 +1,394 @@ +// natVMProxy.cc -- Implementation of VMProxy methods. + +/* Copyright (C) 2006 + Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +// The idea of behind this code is to utilize libffi's ability to +// create closures to provide a fast "cut-through" way to generate +// proxy classes. Instead of generating bytecode and then +// interpreting that, we copy the method definitions for each of the +// methods we're supposed to be prxying and generate a libffi closure +// for each one. + +#include <config.h> +#include <platform.h> +#include <sysdep/descriptor.h> + +#include <limits.h> +#include <string.h> +#include <stddef.h> +#include <stdio.h> + +#include <gcj/cni.h> +#include <gcj/javaprims.h> +#include <jvm.h> +#include <jni.h> +#include <java-threads.h> +#include <java-interp.h> +#include <ffi.h> +#include <execution.h> +#include <gcj/method.h> + +#include <gnu/gcj/runtime/BootClassLoader.h> +#include <java/lang/Class.h> +#include <java/lang/ClassCastException.h> +#include <java/lang/Error.h> +#include <java/lang/IllegalArgumentException.h> +#include <java/lang/Integer.h> +#include <java/lang/StringBuffer.h> +#include <java/lang/VMClassLoader.h> +#include <java/lang/VMCompiler.h> +#include <java/lang/reflect/InvocationHandler.h> +#include <java/lang/reflect/Method.h> +#include <java/lang/reflect/Proxy$ClassFactory.h> +#include <java/lang/reflect/Proxy$ProxyData.h> +#include <java/lang/reflect/Proxy.h> +#include <java/lang/reflect/UndeclaredThrowableException.h> +#include <java/lang/reflect/VMProxy.h> + +#include <java/lang/Byte.h> +#include <java/lang/Short.h> +#include <java/lang/Integer.h> +#include <java/lang/Long.h> +#include <java/lang/Float.h> +#include <java/lang/Double.h> +#include <java/lang/Boolean.h> +#include <java/lang/Character.h> + + +using namespace java::lang::reflect; +using namespace java::lang; + +typedef void (*closure_fun) (ffi_cif*, void*, void**, void*); +static void *ncode (_Jv_Method *self, closure_fun fun, Method *meth); +static void run_proxy (ffi_cif*, void*, void**, void*); + +typedef jobject invoke_t (jobject, Proxy *, Method *, JArray< jobject > *); + +// True if pc points to a proxy frame. + +bool +_Jv_is_proxy (void *pc) +{ + return pc == UNWRAP_FUNCTION_DESCRIPTOR ((void*)&run_proxy); +} + +// Generate a proxy class by using libffi closures for each entry +// point. + +jclass +java::lang::reflect::VMProxy::generateProxyClass + (ClassLoader *loader, Proxy$ProxyData *d) +{ + // If we're precompiling, generate bytecode and allow VMCompiler to + // precompile it. + if (VMCompiler::precompiles ()) + return (new Proxy$ClassFactory(d))->generate(loader); + + jclass klass = new Class (); + klass->superclass = &Proxy::class$; + klass->engine = &_Jv_soleIndirectCompiledEngine; + klass->size_in_bytes = Proxy::class$.size_in_bytes; + klass->vtable_method_count = -1; + + // Synchronize on the class, so that it is not attempted initialized + // until we're done. + JvSynchronize sync (klass); + + // Record the defining loader. For the bootstrap class loader, + // we record NULL. + if (loader != VMClassLoader::bootLoader) + klass->loader = loader; + + { + StringBuffer *sb = new StringBuffer(); + sb->append(JvNewStringLatin1 ("$Proxy")); + sb->append(Integer::toString (d->id)); + klass->name = _Jv_makeUtf8Const (sb->toString()); + } + + // Allocate space for the interfaces. + klass->interface_count = d->interfaces->length; + klass->interfaces = (jclass*) _Jv_AllocRawObj (klass->interface_count + *sizeof (jclass)); + for (int i = 0; i < klass->interface_count; i++) + klass->interfaces[i] = elements(d->interfaces)[i]; + + size_t count = d->methods->length; + + { + size_t total_count = count + Proxy::class$.method_count + 1; + if (total_count >= 65536) + throw new IllegalArgumentException (); + // Allocate space for the methods. This is a worst case + // estimate. + klass->methods + = (_Jv_Method *) _Jv_AllocRawObj (sizeof (_Jv_Method) + * total_count); + } + + jshort &method_count = klass->method_count; + + // Copy all reachable methods from Proxy. + for (int i = 0; i < Proxy::class$.method_count; i++) + { + if (_Jv_CheckAccess (klass, &Proxy::class$, + Proxy::class$.methods[i].accflags)) + { + klass->methods[method_count] = Proxy::class$.methods[i]; + method_count++; + } + } + + _Jv_Method *init_method + = (_Jv_Linker::search_method_in_class + (klass, klass, + _Jv_makeUtf8Const ("<init>"), + _Jv_makeUtf8Const ("(Ljava.lang.reflect.InvocationHandler;)V"), + false)); + init_method->accflags |= Modifier::PUBLIC; + + // Create the methods for all of the interfaces. + for (size_t i = 0; i < count; i++) + { + _Jv_Method &method = klass->methods[method_count++]; + const _Jv_Method &imethod = *_Jv_FromReflectedMethod (elements(d->methods)[i]); + // We use a shallow copy of IMETHOD rather than a deep copy; + // this means that the pointer fields of METHOD point into the + // interface. As long as this subclass of Proxy is reachable, + // the interfaces of which it is a proxy will also be reachable, + // so this is safe. + method = imethod; + method.ncode = ncode (&method, run_proxy, elements(d->methods)[i]); + method.accflags &= ~Modifier::ABSTRACT; + } + + _Jv_Linker::layout_vtable_methods (klass); + _Jv_RegisterInitiatingLoader (klass, klass->loader); + + return klass; +} + + +// Box things with primitive types. +static inline jobject +box (void *thing, jclass klass, FFI_TYPE type) +{ + jobject o; + + switch (type) + { + case FFI_TYPE_VOID: + return NULL; + + case FFI_TYPE_POINTER: + o = *(jobject*)thing; + return o; + + default: + ; + } + + if (klass == JvPrimClass (byte)) + o = new Byte (*(jbyte*)thing); + else if (klass == JvPrimClass (short)) + o = new Short (*(jshort*)thing); + else if (klass == JvPrimClass (int)) + o = new Integer (*(jint*)thing); + else if (klass == JvPrimClass (long)) + o = new Long (*(jlong*)thing); + else if (klass == JvPrimClass (float)) + o = new Float (*(jfloat*)thing); + else if (klass == JvPrimClass (double)) + o = new Double (*(jdouble*)thing); + else if (klass == JvPrimClass (boolean)) + o = new Boolean (*(jboolean*)thing); + else if (klass == JvPrimClass (char)) + o = new Character (*(jchar*)thing); + else + JvFail ("Bad ffi type in proxy"); + + return o; +} + + +// Unbox things with primitive types. +static inline void +unbox (jobject o, jclass klass, void *rvalue, FFI_TYPE type) +{ + switch (type) + { + case FFI_TYPE_VOID: + return; + + case FFI_TYPE_POINTER: + _Jv_CheckCast (klass, o); + *(jobject*)rvalue = o; + return; + + default: + ; + } + + // If the value returned ... is null and the interface method's + // return type is primitive, then a NullPointerException will be + // thrown ... + if (klass == JvPrimClass (byte)) + { + _Jv_CheckCast (&Byte::class$, o); + *(jbyte*)rvalue = ((Byte*)o)->byteValue(); + } + else if (klass == JvPrimClass (short)) + { + _Jv_CheckCast (&Short::class$, o); + *(jshort*)rvalue = ((Short*)o)->shortValue(); + } + else if (klass == JvPrimClass (int)) + { + _Jv_CheckCast (&Integer::class$, o); + *(jint*)rvalue = ((Integer*)o)->intValue(); + } + else if (klass == JvPrimClass (long)) + { + _Jv_CheckCast (&Long::class$, o); + *(jlong*)rvalue = ((Long*)o)->longValue(); + } + else if (klass == JvPrimClass (float)) + { + _Jv_CheckCast (&Float::class$, o); + *(jfloat*)rvalue = ((Float*)o)->floatValue(); + } + else if (klass == JvPrimClass (double)) + { + _Jv_CheckCast (&Double::class$, o); + *(jdouble*)rvalue = ((Double*)o)->doubleValue(); + } + else if (klass == JvPrimClass (boolean)) + { + _Jv_CheckCast (&Boolean::class$, o); + *(jboolean*)rvalue = ((Boolean*)o)->booleanValue(); + } + else if (klass == JvPrimClass (char)) + { + _Jv_CheckCast (&Character::class$, o); + *(jchar*)rvalue = ((Character*)o)->charValue(); + } + else + JvFail ("Bad ffi type in proxy"); +} + + +// run_proxy is the entry point for all proxy methods. It boxes up +// all the arguments and then invokes the invocation handler's invoke() +// method. Exceptions are caught and propagated. + +typedef struct { + ffi_closure closure; + ffi_cif cif; + Method *meth; + _Jv_Method *self; + ffi_type *arg_types[0]; +} ncode_closure; + +static void +run_proxy (ffi_cif *cif, + void *rvalue, + void **args, + void*user_data) +{ + Proxy *proxy = *(Proxy**)args[0]; + ncode_closure *self = (ncode_closure *) user_data; + + // FRAME_DESC registers this particular invocation as the top-most + // interpreter frame. This lets the stack tracing code (for + // Throwable) print information about the Proxy being run rather + // than about Proxy.class itself. FRAME_DESC has a destructor so it + // cleans up automatically when this proxy invocation returns. + Thread *thread = Thread::currentThread(); + _Jv_InterpFrame frame_desc (self->self, thread, proxy->getClass()); + + InvocationHandler *handler = proxy->h; + void *poo + = _Jv_NewObjectArray (self->meth->parameter_types->length, &Object::class$, NULL); + JArray<jobject> *argsArray = (JArray<jobject> *) poo; + jobject *jargs = elements(argsArray); + + // FIXME: It must be possible to use fast interface dispatch here, + // but I've not quite figured out how to do it. + invoke_t *invoke + = (invoke_t *)(_Jv_LookupInterfaceMethod + (handler->getClass (), + _Jv_makeUtf8Const ("invoke"), + (_Jv_makeUtf8Const + ("(Ljava.lang.Object;Ljava.lang.reflect.Method;[Ljava.lang.Object;)" + "Ljava.lang.Object;")))); + + // Copy and box all the args. + int index = 1; + for (int i = 0; i < self->meth->parameter_types->length; i++, index++) + jargs[i] = box (args[index], elements(self->meth->parameter_types)[i], + cif->arg_types[index]->type); + + jobject ret; + try + { + ret = invoke (handler, proxy, self->meth, argsArray); + } + catch (Throwable *t) + { + if (_Jv_IsInstanceOf (t, &RuntimeException::class$) + || _Jv_IsInstanceOf (t, &Error::class$)) + throw t; + + Class **throwables = elements (self->meth->exception_types); + for (int i = 0; i < self->meth->exception_types->length; i++) + if (_Jv_IsInstanceOf (t, throwables[i])) + throw t; + + throw new UndeclaredThrowableException (t); + } + + unbox (ret, self->meth->return_type, rvalue, cif->rtype->type); +} + + +// Given a method and a closure function, create libffi CIF and return +// the address of its closure. + +static void * +ncode (_Jv_Method *self, closure_fun fun, Method *meth) +{ + using namespace java::lang::reflect; + + jboolean staticp = (self->accflags & Modifier::STATIC) != 0; + int arg_count = _Jv_count_arguments (self->signature, staticp); + + ncode_closure *closure = + (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure) + + arg_count * sizeof (ffi_type*)); + + _Jv_init_cif (self->signature, + arg_count, + staticp, + &closure->cif, + &closure->arg_types[0], + NULL); + closure->meth = meth; + closure->self = self; + + JvAssert ((self->accflags & Modifier::NATIVE) == 0); + + ffi_prep_closure (&closure->closure, + &closure->cif, + fun, + (void*)closure); + + self->ncode = (void*)closure; + return self->ncode; +} |