From 4f9533c7722fa07511a94d005227961f4a4dec23 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 18 May 2006 17:29:21 +0000 Subject: Imported GNU Classpath 0.90 Imported GNU Classpath 0.90 * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. From-SVN: r113887 --- .../vm/reference/java/lang/reflect/Method.java | 213 ++++++++++++++++----- 1 file changed, 164 insertions(+), 49 deletions(-) (limited to 'libjava/classpath/vm/reference/java/lang/reflect/Method.java') diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Method.java b/libjava/classpath/vm/reference/java/lang/reflect/Method.java index 27256770e52..a9920241b17 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Method.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Method.java @@ -1,5 +1,5 @@ /* java.lang.reflect.Method - reflection of Java methods - Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,10 @@ exception statement from your version. */ package java.lang.reflect; +import gnu.java.lang.ClassHelper; + +import gnu.java.lang.reflect.MethodSignatureParser; + import java.util.Arrays; /** @@ -74,12 +78,17 @@ import java.util.Arrays; * @status updated to 1.4 */ public final class Method -extends AccessibleObject implements Member +extends AccessibleObject implements Member, GenericDeclaration { Class declaringClass; String name; int slot; + 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. */ @@ -109,6 +118,12 @@ extends AccessibleObject implements Member return name; } + /** + * Return the raw modifiers for this method. + * @return the method's modifiers + */ + private native int getModifiersInternal(); + /** * Gets the modifiers this method uses. Use the Modifier * class to interpret the values. A method can only have a subset of the @@ -118,7 +133,40 @@ extends AccessibleObject implements Member * @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. @@ -210,17 +258,17 @@ extends AccessibleObject implements Member public String toString() { // 128 is a reasonable buffer initial size for constructor - StringBuffer sb = new StringBuffer(128); + StringBuilder sb = new StringBuilder(128); Modifier.toString(getModifiers(), sb).append(' '); - sb.append(getUserTypeName(getReturnType().getName())).append(' '); + sb.append(ClassHelper.getUserName(getReturnType())).append(' '); sb.append(getDeclaringClass().getName()).append('.'); sb.append(getName()).append('('); Class[] c = getParameterTypes(); if (c.length > 0) { - sb.append(getUserTypeName(c[0].getName())); + sb.append(ClassHelper.getUserName(c[0])); for (int i = 1; i < c.length; i++) - sb.append(',').append(getUserTypeName(c[i].getName())); + sb.append(',').append(ClassHelper.getUserName(c[i])); } sb.append(')'); c = getExceptionTypes(); @@ -233,53 +281,31 @@ extends AccessibleObject implements Member return sb.toString(); } - private static String getUserTypeName(String typeSpec) + public String toGenericString() { - int pos = 0; - String typeName = ""; - String arrayPart = ""; - - while (typeSpec.charAt(pos) == '[') + // 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) { - arrayPart += "[]"; - ++pos; + sb.append(types[0]); + for (int i = 1; i < types.length; i++) + sb.append(',').append(types[i]); } - - switch (typeSpec.charAt(pos)) + sb.append(')'); + types = getGenericExceptionTypes(); + if (types.length > 0) { - case 'Z': - typeName = "boolean"; - break; - case 'B': - typeName = "byte"; - break; - case 'C': - typeName = "char"; - break; - case 'D': - typeName = "double"; - break; - case 'F': - typeName = "float"; - break; - case 'I': - typeName = "int"; - break; - case 'J': - typeName = "long"; - break; - case 'S': - typeName = "short"; - break; - case 'L': - typeName = typeSpec.substring(pos + 1, typeSpec.length() - 1); - break; - default: - typeName = typeSpec; - break; + sb.append(" throws ").append(types[0]); + for (int i = 1; i < types.length; i++) + sb.append(',').append(types[i]); } - - return typeName + arrayPart; + return sb.toString(); } /** @@ -336,4 +362,93 @@ extends AccessibleObject implements Member private native Object invokeNative(Object o, Object[] args, Class declaringClass, int slot) throws IllegalAccessException, InvocationTargetException; + + /** + * Returns an array of TypeVariable 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[] */ + 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 native String getSignature(); + + /** + * Returns an array of Type 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 Type 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(); + } } + -- cgit v1.2.3