From 799c3d8768696f19639ce3a7dd4777fc17d242d3 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 27 Mar 2006 01:49:13 +0000 Subject: * NEWS: Updated. * vm/reference/java/lang/reflect/Method.java (METHOD_MODIFIERS): New constant. (getModifiersInternal): Renamed from getModifiers. (getModifiers): New method. (isBridge): Likewise. (isSynthetic): Likewise. (isVarArgs): Likewise. * vm/reference/java/lang/reflect/Field.java (FIELD_MODIFIERS): New constant. (getModifiersInternal): Renamed from getModifiers. (getModifiers): New method. (isSynthetic): Likewise. (isEnumConstant): Likewise. * vm/reference/java/lang/reflect/Constructor.java (getModifiersInternal): Renamed from getModifiers. (getModifiers): New method (CONSTRUCTOR_MODIFIERS): New constant. (isSynthetic): New method. (isVarArgs): Likewise. * java/lang/reflect/Member.java (isSynthetic): New method. --- vm/reference/java/lang/reflect/Constructor.java | 36 ++++++++++++++++++- vm/reference/java/lang/reflect/Field.java | 35 ++++++++++++++++++- vm/reference/java/lang/reflect/Method.java | 46 ++++++++++++++++++++++++- 3 files changed, 114 insertions(+), 3 deletions(-) (limited to 'vm') diff --git a/vm/reference/java/lang/reflect/Constructor.java b/vm/reference/java/lang/reflect/Constructor.java index 3789fbb9a..4bc585266 100644 --- a/vm/reference/java/lang/reflect/Constructor.java +++ b/vm/reference/java/lang/reflect/Constructor.java @@ -81,6 +81,9 @@ extends AccessibleObject implements Member private Class clazz; private int slot; + private static final int CONSTRUCTOR_MODIFIERS + = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC; + /** * This class is uninstantiable except from native code. */ @@ -113,6 +116,13 @@ extends AccessibleObject implements Member return getDeclaringClass().getName(); } + /** + * Return the raw modifiers for this constructor. In particular + * this will include the synthetic and varargs bits. + * @return the constructor's modifiers + */ + private native int getModifiersInternal(); + /** * Gets the modifiers this constructor uses. Use the Modifier * class to interpret the values. A constructor can only have a subset of the @@ -121,7 +131,31 @@ extends AccessibleObject implements Member * @return an integer representing the modifiers to this Member * @see Modifier */ - public native int getModifiers(); + public int getModifiers() + { + return getModifiersInternal() & CONSTRUCTOR_MODIFIERS; + } + + /** + * Return true if this constructor is synthetic, false otherwise. + * A synthetic member is one which is created by the compiler, + * and which does not appear in the user's source code. + * @since 1.5 + */ + public boolean isSynthetic() + { + return (getModifiersInternal() & Modifier.SYNTHETIC) != 0; + } + + /** + * Return true if this is a varargs constructor, that is if + * the constructor takes a variable number of arguments. + * @since 1.5 + */ + public boolean isVarArgs() + { + return (getModifiersInternal() & Modifier.VARARGS) != 0; + } /** * Get the parameter list for this constructor, in declaration order. If the diff --git a/vm/reference/java/lang/reflect/Field.java b/vm/reference/java/lang/reflect/Field.java index 5475aa272..874b7da91 100644 --- a/vm/reference/java/lang/reflect/Field.java +++ b/vm/reference/java/lang/reflect/Field.java @@ -80,6 +80,11 @@ extends AccessibleObject implements Member private String name; private int slot; + private static final int FIELD_MODIFIERS + = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED + | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT + | Modifier.VOLATILE; + /** * This class is uninstantiable except natively. */ @@ -109,6 +114,12 @@ extends AccessibleObject implements Member return name; } + /** + * Return the raw modifiers for this field. + * @return the field's modifiers + */ + private native int getModifiersInternal(); + /** * Gets the modifiers this field uses. Use the Modifier * class to interpret the values. A field can only have a subset of the @@ -118,7 +129,29 @@ extends AccessibleObject implements Member * @return an integer representing the modifiers to this Member * @see Modifier */ - public native int getModifiers(); + public int getModifiers() + { + return getModifiersInternal() & FIELD_MODIFIERS; + } + + /** + * Return true if this field is synthetic, false otherwise. + * @since 1.5 + */ + public boolean isSynthetic() + { + return (getModifiersInternal() & Modifier.SYNTHETIC) != 0; + } + + /** + * Return true if this field represents an enum constant, + * false otherwise. + * @since 1.5 + */ + public boolean isEnumConstant() + { + return (getModifiersInternal() & Modifier.ENUM) != 0; + } /** * Gets the type of this field. diff --git a/vm/reference/java/lang/reflect/Method.java b/vm/reference/java/lang/reflect/Method.java index 4da8d5c66..7a4def9ae 100644 --- a/vm/reference/java/lang/reflect/Method.java +++ b/vm/reference/java/lang/reflect/Method.java @@ -82,6 +82,11 @@ extends AccessibleObject implements Member 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. */ @@ -111,6 +116,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 @@ -120,7 +131,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. -- cgit v1.2.1