Commit 5aca4c41 by Tom Tromey Committed by Tom Tromey

re PR libgcj/27729 (Field, Method and Constructor need isSynthetic() implemetation)

gcc/java:
	PR libgcj/27729:
	* jcf.h (ACC_INVISIBLE): Changed value.
libjava:
	PR libgcj/27729:
	* java/lang/reflect/natField.cc (getAddr): Added parens.
	* java/lang/reflect/natConstructor.cc (getModifiersInternal):
	Renamed.  Don't mask flags.
	* java/lang/reflect/Constructor.java (CONSTRUCTOR_MODIFIERS): New
	constant.
	(getModifiersInternal): Renamed.
	(getModifiers): Rewrote.
	(isSynthetic, isVarArgs): New methods.
	(hashCode): Rewrote.
	(addTypeParameters, toGenericString): New methods.
	(getTypeParameters): Rewrote.
	(getSignature): New method.
	(getGenericParameterTypes, getGenericExceptionTypes): Likewise.
	* java/lang/reflect/natMethod.cc (getModifiersInternal):
	Renamed.  Don't mask flags.
	* java/lang/reflect/natField.cc (getModifiersInternal): Renamed.
	Don't mask flags.
	* java/lang/reflect/Modifier.java (BRIDGE, VARARGS, SYNTHETIC,
	ENUM): New constants.
	(INVISIBLE): Changed value.
	* java/lang/reflect/Method.java: Mostly merged with Classpath.
	(getModifiersInternal): Renamed.
	(getModifiers): Rewrote.
	(isBridge, isSynthetic, isVarArgs): New methods.
	(toGenericString): Likewise.
	(getTypeParameters): Likewise.
	(getSignature): Likewise.
	(getGenericExceptionTypes, getGenericParameterTypes,
	getGenericReturnType): Likewise.
	(METHOD_MODIFIERS): New constant.
	* java/lang/reflect/Field.java: Mostly merged with Classpath.
	Added javadoc everywhere.
	(getModifiersInternal): Renamed.
	(getModifiers, isSynthetic, isEnumConstant): Rewrote.
	(toGenericString): New method.
	(getGenericType, getSignature): Likewise.
	(FIELD_MODIFIERS): New constant.

From-SVN: r114046
parent f32f60c9
2006-05-24 Tom Tromey <tromey@redhat.com>
PR libgcj/27729:
* jcf.h (ACC_INVISIBLE): Changed value.
2006-05-24 Andrew Haley <aph@redhat.com> 2006-05-24 Andrew Haley <aph@redhat.com>
PR java/27754 PR java/27754
......
/* Utility macros to read Java(TM) .class files and byte codes. /* Utility macros to read Java(TM) .class files and byte codes.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of GCC. This file is part of GCC.
...@@ -231,8 +231,8 @@ typedef struct JCF GTY(()) { ...@@ -231,8 +231,8 @@ typedef struct JCF GTY(()) {
#define ACC_ABSTRACT 0x0400 #define ACC_ABSTRACT 0x0400
#define ACC_STRICT 0x0800 #define ACC_STRICT 0x0800
/* "Invisible" refers to Miranda methods inserted into an abstract /* "Invisible" refers to Miranda methods inserted into an abstract
#class. It is also used in the runtime. */ class. It is also used in the runtime. */
#define ACC_INVISIBLE 0x1000 #define ACC_INVISIBLE 0x8000
#define ACC_VISIBILITY (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED) #define ACC_VISIBILITY (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED)
......
2006-05-24 Tom Tromey <tromey@redhat.com> 2006-05-24 Tom Tromey <tromey@redhat.com>
PR libgcj/27729:
* java/lang/reflect/natField.cc (getAddr): Added parens.
* java/lang/reflect/natConstructor.cc (getModifiersInternal):
Renamed. Don't mask flags.
* java/lang/reflect/Constructor.java (CONSTRUCTOR_MODIFIERS): New
constant.
(getModifiersInternal): Renamed.
(getModifiers): Rewrote.
(isSynthetic, isVarArgs): New methods.
(hashCode): Rewrote.
(addTypeParameters, toGenericString): New methods.
(getTypeParameters): Rewrote.
(getSignature): New method.
(getGenericParameterTypes, getGenericExceptionTypes): Likewise.
* java/lang/reflect/natMethod.cc (getModifiersInternal):
Renamed. Don't mask flags.
* java/lang/reflect/natField.cc (getModifiersInternal): Renamed.
Don't mask flags.
* java/lang/reflect/Modifier.java (BRIDGE, VARARGS, SYNTHETIC,
ENUM): New constants.
(INVISIBLE): Changed value.
* java/lang/reflect/Method.java: Mostly merged with Classpath.
(getModifiersInternal): Renamed.
(getModifiers): Rewrote.
(isBridge, isSynthetic, isVarArgs): New methods.
(toGenericString): Likewise.
(getTypeParameters): Likewise.
(getSignature): Likewise.
(getGenericExceptionTypes, getGenericParameterTypes,
getGenericReturnType): Likewise.
(METHOD_MODIFIERS): New constant.
* java/lang/reflect/Field.java: Mostly merged with Classpath.
Added javadoc everywhere.
(getModifiersInternal): Renamed.
(getModifiers, isSynthetic, isEnumConstant): Rewrote.
(toGenericString): New method.
(getGenericType, getSignature): Likewise.
(FIELD_MODIFIERS): New constant.
2006-05-24 Tom Tromey <tromey@redhat.com>
PR libgcj/27731: PR libgcj/27731:
* java/lang/natMath.cc (cbrt, cosh, expm1, hypot, log1p, sinh, * java/lang/natMath.cc (cbrt, cosh, expm1, hypot, log1p, sinh,
tanh): New methods. tanh): New methods.
......
// Method.java - Represent method of class or interface. // Method.java - Represent method of class or interface.
/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2006 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -11,6 +11,7 @@ details. */ ...@@ -11,6 +11,7 @@ details. */
package java.lang.reflect; package java.lang.reflect;
import gnu.gcj.RawData; import gnu.gcj.RawData;
import gnu.java.lang.reflect.MethodSignatureParser;
/** /**
* The Method class represents a member method of a class. It also allows * The Method class represents a member method of a class. It also allows
...@@ -39,16 +40,21 @@ import gnu.gcj.RawData; ...@@ -39,16 +40,21 @@ import gnu.gcj.RawData;
* @author Tom Tromey <tromey@redhat.com> * @author Tom Tromey <tromey@redhat.com>
* @see Member * @see Member
* @see Class * @see Class
* @see java.lang.Class#getMethod(String,Object[]) * @see java.lang.Class#getMethod(String,Class[])
* @see java.lang.Class#getDeclaredMethod(String,Object[]) * @see java.lang.Class#getDeclaredMethod(String,Class[])
* @see java.lang.Class#getMethods() * @see java.lang.Class#getMethods()
* @see java.lang.Class#getDeclaredMethods() * @see java.lang.Class#getDeclaredMethods()
* @since 1.1 * @since 1.1
* @status updated to 1.4 * @status updated to 1.4
*/ */
public final class Method extends AccessibleObject public final class Method
implements Member, GenericDeclaration extends AccessibleObject implements Member, GenericDeclaration
{ {
private static final int METHOD_MODIFIERS
= Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
| Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
| Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
/** /**
* This class is uninstantiable. * This class is uninstantiable.
*/ */
...@@ -61,7 +67,7 @@ public final class Method extends AccessibleObject ...@@ -61,7 +67,7 @@ public final class Method extends AccessibleObject
* is a non-inherited member. * is a non-inherited member.
* @return the class that declared this member * @return the class that declared this member
*/ */
public Class getDeclaringClass () public Class getDeclaringClass()
{ {
return declaringClass; return declaringClass;
} }
...@@ -73,6 +79,12 @@ public final class Method extends AccessibleObject ...@@ -73,6 +79,12 @@ public final class Method extends AccessibleObject
public native String getName (); public native String getName ();
/** /**
* Return the raw modifiers for this method.
* @return the method's modifiers
*/
private native int getModifiersInternal();
/**
* Gets the modifiers this method uses. Use the <code>Modifier</code> * Gets the modifiers this method uses. Use the <code>Modifier</code>
* class to interpret the values. A method can only have a subset of the * class to interpret the values. A method can only have a subset of the
* following modifiers: public, private, protected, abstract, static, * following modifiers: public, private, protected, abstract, static,
...@@ -81,7 +93,40 @@ public final class Method extends AccessibleObject ...@@ -81,7 +93,40 @@ public final class Method extends AccessibleObject
* @return an integer representing the modifiers to this Member * @return an integer representing the modifiers to this Member
* @see Modifier * @see Modifier
*/ */
public native int getModifiers (); public int getModifiers()
{
return getModifiersInternal() & METHOD_MODIFIERS;
}
/**
* Return true if this method is a bridge method. A bridge method
* is generated by the compiler in some situations involving
* generics and inheritance.
* @since 1.5
*/
public boolean isBridge()
{
return (getModifiersInternal() & Modifier.BRIDGE) != 0;
}
/**
* Return true if this method is synthetic, false otherwise.
* @since 1.5
*/
public boolean isSynthetic()
{
return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
}
/**
* Return true if this is a varargs method, that is if
* the method takes a variable number of arguments.
* @since 1.5
*/
public boolean isVarArgs()
{
return (getModifiersInternal() & Modifier.VARARGS) != 0;
}
/** /**
* Gets the return type of this method. * Gets the return type of this method.
...@@ -139,14 +184,14 @@ public final class Method extends AccessibleObject ...@@ -139,14 +184,14 @@ public final class Method extends AccessibleObject
} }
/** /**
* Get the hash code for the Method. * Get the hash code for the Method. The Method 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 * @return the hash code for the object
*/ */
public int hashCode () public int hashCode()
{ {
// FIXME. return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
return getName().hashCode() + declaringClass.getName().hashCode();
} }
/** /**
...@@ -158,7 +203,7 @@ public final class Method extends AccessibleObject ...@@ -158,7 +203,7 @@ public final class Method extends AccessibleObject
* *
* @return the String representation of the Method * @return the String representation of the Method
*/ */
public String toString () public String toString()
{ {
if (parameter_types == null) if (parameter_types == null)
getType (); getType ();
...@@ -196,6 +241,33 @@ public final class Method extends AccessibleObject ...@@ -196,6 +241,33 @@ public final class Method extends AccessibleObject
return b.toString(); return b.toString();
} }
public String toGenericString()
{
// 128 is a reasonable buffer initial size for constructor
StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
Constructor.addTypeParameters(sb, getTypeParameters());
sb.append(getGenericReturnType()).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName()).append('(');
Type[] types = getGenericParameterTypes();
if (types.length > 0)
{
sb.append(types[0]);
for (int i = 1; i < types.length; i++)
sb.append(',').append(types[i]);
}
sb.append(')');
types = getGenericExceptionTypes();
if (types.length > 0)
{
sb.append(" throws ").append(types[0]);
for (int i = 1; i < types.length; i++)
sb.append(',').append(types[i]);
}
return sb.toString();
}
/** /**
* Invoke the method. Arguments are automatically unwrapped and widened, * Invoke the method. Arguments are automatically unwrapped and widened,
* and the result is automatically wrapped, if needed.<p> * and the result is automatically wrapped, if needed.<p>
...@@ -241,6 +313,98 @@ public final class Method extends AccessibleObject ...@@ -241,6 +313,98 @@ public final class Method extends AccessibleObject
throws IllegalAccessException, IllegalArgumentException, throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException; InvocationTargetException;
/**
* Returns an array of <code>TypeVariable</code> objects that represents
* the type variables declared by this constructor, in declaration order.
* An array of size zero is returned if this class has no type
* variables.
*
* @return the type variables associated with this class.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
/* FIXME[GENERICS]: Should be TypeVariable<Method>[] */
public TypeVariable[] getTypeParameters()
{
String sig = getSignature();
if (sig == null)
return new TypeVariable[0];
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getTypeParameters();
}
/**
* 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;
}
/**
* Returns an array of <code>Type</code> objects that represents
* the exception types declared by this method, in declaration order.
* An array of size zero is returned if this method declares no
* exceptions.
*
* @return the exception types declared by this method.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericExceptionTypes()
{
String sig = getSignature();
if (sig == null)
return getExceptionTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericExceptionTypes();
}
/**
* Returns an array of <code>Type</code> objects that represents
* the parameter list for this method, in declaration order.
* An array of size zero is returned if this method takes no
* parameters.
*
* @return a list of the types of the method's parameters
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericParameterTypes()
{
String sig = getSignature();
if (sig == null)
return getParameterTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericParameterTypes();
}
/**
* Returns the return type of this method.
*
* @return the return type of this method
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type getGenericReturnType()
{
String sig = getSignature();
if (sig == null)
return getReturnType();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericReturnType();
}
private native void getType (); private native void getType ();
// Append a class name to a string buffer. We try to print the // Append a class name to a string buffer. We try to print the
...@@ -263,28 +427,6 @@ public final class Method extends AccessibleObject ...@@ -263,28 +427,6 @@ public final class Method extends AccessibleObject
} }
} }
// FIXME - Write a real implementation
public boolean isSynthetic() { return false; }
/**
* Returns an array of <code>TypeVariable</code> objects that represents
* the type variables declared by this constructor, in declaration order.
* An array of size zero is returned if this class has no type
* variables.
*
* @return the type variables associated with this class.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
/* FIXME[GENERICS]: Should be TypeVariable<Method>[] */
public TypeVariable[] getTypeParameters()
{
// FIXME - write a real implementation
return new TypeVariable[0];
}
// Declaring class. // Declaring class.
private Class declaringClass; private Class declaringClass;
......
/* java.lang.reflect.Modifier /* java.lang.reflect.Modifier
Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. Copyright (C) 1998, 1999, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -158,10 +158,30 @@ public class Modifier ...@@ -158,10 +158,30 @@ public class Modifier
static final int ALL_FLAGS = 0xfff; static final int ALL_FLAGS = 0xfff;
/** /**
* Flag indicating a bridge method.
*/
static final int BRIDGE = 0x40;
/**
* Flag indicating a varargs method.
*/
static final int VARARGS = 0x80;
/**
* Flag indicating a synthetic member.
*/
static final int SYNTHETIC = 0x1000;
/**
* Flag indicating an enum constant or an enum class.
*/
static final int ENUM = 0x4000;
/**
* GCJ-LOCAL: This access flag is set on methods we declare * GCJ-LOCAL: This access flag is set on methods we declare
* internally but which must not be visible to reflection. * internally but which must not be visible to reflection.
*/ */
static final int INVISIBLE = 0x1000; static final int INVISIBLE = 0x8000;
/** /**
* GCJ-LOCAL: This access flag is set on interpreted classes. * GCJ-LOCAL: This access flag is set on interpreted classes.
...@@ -303,6 +323,18 @@ public class Modifier ...@@ -303,6 +323,18 @@ public class Modifier
} }
/** /**
* Package helper method that can take a StringBuilder.
* @param mod the modifier
* @param r the StringBuilder to which the String representation is appended
* @return r, with information appended
*/
static StringBuilder toString(int mod, StringBuilder r)
{
r.append(toString(mod, new StringBuffer()));
return r;
}
/**
* Package helper method that can take a StringBuffer. * Package helper method that can take a StringBuffer.
* @param mod the modifier * @param mod the modifier
* @param r the StringBuffer to which the String representation is appended * @param r the StringBuffer to which the String representation is appended
......
// natConstructor.cc - Native code for Constructor class. // natConstructor.cc - Native code for Constructor class.
/* Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -24,10 +24,9 @@ details. */ ...@@ -24,10 +24,9 @@ details. */
#include <gcj/method.h> #include <gcj/method.h>
jint jint
java::lang::reflect::Constructor::getModifiers () java::lang::reflect::Constructor::getModifiersInternal ()
{ {
// Ignore all unknown flags. return _Jv_FromReflectedConstructor (this)->accflags;
return _Jv_FromReflectedConstructor (this)->accflags & Modifier::ALL_FLAGS;
} }
void void
......
// natField.cc - Implementation of java.lang.reflect.Field native methods. // natField.cc - Implementation of java.lang.reflect.Field native methods.
/* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -30,9 +30,9 @@ details. */ ...@@ -30,9 +30,9 @@ details. */
#include <java/lang/Character.h> #include <java/lang/Character.h>
jint jint
java::lang::reflect::Field::getModifiers () java::lang::reflect::Field::getModifiersInternal ()
{ {
return _Jv_FromReflectedField (this)->getModifiers (); return _Jv_FromReflectedField (this)->flags;
} }
jstring jstring
...@@ -72,7 +72,7 @@ getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj, ...@@ -72,7 +72,7 @@ getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj,
// Setting a final field is usually not allowed. // Setting a final field is usually not allowed.
if (checkFinal if (checkFinal
&& field->getModifiers() & java::lang::reflect::Modifier::FINAL) && (field->getModifiers() & java::lang::reflect::Modifier::FINAL))
throw new java::lang::IllegalAccessException(JvNewStringUTF throw new java::lang::IllegalAccessException(JvNewStringUTF
("Field is final")); ("Field is final"));
......
// natMethod.cc - Native code for Method class. // natMethod.cc - Native code for Method class.
/* Copyright (C) 1998, 1999, 2000, 2001 , 2002, 2003, 2004, 2005 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001 , 2002, 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -183,10 +183,9 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args) ...@@ -183,10 +183,9 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
} }
jint jint
java::lang::reflect::Method::getModifiers () java::lang::reflect::Method::getModifiersInternal ()
{ {
// Ignore all unknown flags. return _Jv_FromReflectedMethod (this)->accflags;
return _Jv_FromReflectedMethod (this)->accflags & Modifier::ALL_FLAGS;
} }
jstring jstring
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment