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
This commit is contained in:
Tom Tromey
2006-05-24 17:21:52 +00:00
committed by Tom Tromey
parent f32f60c997
commit 5aca4c41f7
10 changed files with 1074 additions and 169 deletions
+176 -34
View File
@@ -1,6 +1,6 @@
// 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.
@@ -11,6 +11,7 @@ details. */
package java.lang.reflect;
import gnu.gcj.RawData;
import gnu.java.lang.reflect.MethodSignatureParser;
/**
* The Method class represents a member method of a class. It also allows
@@ -39,16 +40,21 @@ import gnu.gcj.RawData;
* @author Tom Tromey <tromey@redhat.com>
* @see Member
* @see Class
* @see java.lang.Class#getMethod(String,Object[])
* @see java.lang.Class#getDeclaredMethod(String,Object[])
* @see java.lang.Class#getMethod(String,Class[])
* @see java.lang.Class#getDeclaredMethod(String,Class[])
* @see java.lang.Class#getMethods()
* @see java.lang.Class#getDeclaredMethods()
* @since 1.1
* @status updated to 1.4
*/
public final class Method extends AccessibleObject
implements Member, GenericDeclaration
public final class Method
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.
*/
@@ -61,7 +67,7 @@ public final class Method extends AccessibleObject
* is a non-inherited member.
* @return the class that declared this member
*/
public Class getDeclaringClass ()
public Class getDeclaringClass()
{
return declaringClass;
}
@@ -72,6 +78,12 @@ public final class Method extends AccessibleObject
*/
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>
* class to interpret the values. A method can only have a subset of the
@@ -81,7 +93,40 @@ public final class Method extends AccessibleObject
* @return an integer representing the modifiers to this Member
* @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.
@@ -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
*/
public int hashCode ()
public int hashCode()
{
// FIXME.
return getName().hashCode() + declaringClass.getName().hashCode();
return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
}
/**
@@ -158,7 +203,7 @@ public final class Method extends AccessibleObject
*
* @return the String representation of the Method
*/
public String toString ()
public String toString()
{
if (parameter_types == null)
getType ();
@@ -196,6 +241,33 @@ public final class Method extends AccessibleObject
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,
* and the result is automatically wrapped, if needed.<p>
@@ -241,6 +313,98 @@ public final class Method extends AccessibleObject
throws IllegalAccessException, IllegalArgumentException,
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 ();
// Append a class name to a string buffer. We try to print the
@@ -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.
private Class declaringClass;