diff --git a/src/share/classes/java/lang/reflect/Constructor.java b/src/share/classes/java/lang/reflect/Constructor.java index 0c101ccacb8596bad591d09fd5fda9a4beaa540f..bdd158a3eb8b167b2b068afc8ac68fe44b7c3377 100644 --- a/src/share/classes/java/lang/reflect/Constructor.java +++ b/src/share/classes/java/lang/reflect/Constructor.java @@ -82,10 +82,6 @@ public final // remembering the last Class for which the check succeeded. private volatile Class securityCheckCache; - // Modifiers that can be applied to a constructor in source code - private static final int LANGUAGE_MODIFIERS = - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; - // Generics infrastructure // Accessor for factory private GenericsFactory getFactory() { @@ -359,7 +355,7 @@ public final public String toString() { try { StringBuffer sb = new StringBuffer(); - int mod = getModifiers() & LANGUAGE_MODIFIERS; + int mod = getModifiers() & Modifier.constructorModifiers(); if (mod != 0) { sb.append(Modifier.toString(mod) + " "); } @@ -423,7 +419,7 @@ public final public String toGenericString() { try { StringBuilder sb = new StringBuilder(); - int mod = getModifiers() & LANGUAGE_MODIFIERS; + int mod = getModifiers() & Modifier.constructorModifiers(); if (mod != 0) { sb.append(Modifier.toString(mod) + " "); } diff --git a/src/share/classes/java/lang/reflect/Method.java b/src/share/classes/java/lang/reflect/Method.java index c638869cd38e81b8eeafde35d60d1cfa955e9349..1c660f2dca8bc695fc29eb211faff2f8d5b51388 100644 --- a/src/share/classes/java/lang/reflect/Method.java +++ b/src/share/classes/java/lang/reflect/Method.java @@ -88,12 +88,6 @@ public final private Class securityCheckCache; private Class securityCheckTargetClassCache; - // Modifiers that can be applied to a method in source code - private static final int LANGUAGE_MODIFIERS = - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | - Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | - Modifier.SYNCHRONIZED | Modifier.NATIVE; - // Generics infrastructure private String getGenericSignature() {return signature;} @@ -408,12 +402,12 @@ public final * {@code public}, {@code protected} or {@code private} first, * and then other modifiers in the following order: * {@code abstract}, {@code static}, {@code final}, - * {@code synchronized}, {@code native}. + * {@code synchronized}, {@code native}, {@code strictfp}. */ public String toString() { try { StringBuffer sb = new StringBuffer(); - int mod = getModifiers() & LANGUAGE_MODIFIERS; + int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { sb.append(Modifier.toString(mod) + " "); } @@ -473,7 +467,7 @@ public final * {@code public}, {@code protected} or {@code private} first, * and then other modifiers in the following order: * {@code abstract}, {@code static}, {@code final}, - * {@code synchronized} {@code native}. + * {@code synchronized}, {@code native}, {@code strictfp}. * * @return a string describing this {@code Method}, * include type parameters @@ -483,7 +477,7 @@ public final public String toGenericString() { try { StringBuilder sb = new StringBuilder(); - int mod = getModifiers() & LANGUAGE_MODIFIERS; + int mod = getModifiers() & Modifier.methodModifiers(); if (mod != 0) { sb.append(Modifier.toString(mod) + " "); } diff --git a/src/share/classes/java/lang/reflect/Modifier.java b/src/share/classes/java/lang/reflect/Modifier.java index 2882f04722f4a1d2f1beec798997457c0eeac709..f32822c2f09e8f7eeeb28a734ab99b92b2180334 100644 --- a/src/share/classes/java/lang/reflect/Modifier.java +++ b/src/share/classes/java/lang/reflect/Modifier.java @@ -235,6 +235,11 @@ class Modifier { * possible validity of the combination of modifiers represented * by the input. * + * Note that to perform such checking for a known kind of entity, + * such as a constructor or method, first AND the argument of + * {@code toString} with the appropriate mask from a method like + * {@link #constructorModifiers} or {@link #methodModifiers}. + * * @param mod a set of modifiers * @return a string representation of the set of modifiers * represented by {@code mod} @@ -353,4 +358,108 @@ class Modifier { static boolean isSynthetic(int mod) { return (mod & SYNTHETIC) != 0; } + + /** + * See JLSv3 section 8.1.1. + */ + private static final int CLASS_MODIFIERS = + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | + Modifier.STRICT; + + /** + * See JLSv3 section 9.1.1. + */ + private static final int INTERFACE_MODIFIERS = + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | + Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT; + + + /** + * See JLSv3 section 8.8.3. + */ + private static final int CONSTRUCTOR_MODIFIERS = + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; + + /** + * See JLSv3 section 8.4.3. + */ + private static final int METHOD_MODIFIERS = + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | + Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT; + + /** + * See JLSv3 section 8.3.1. + */ + private static final int FIELD_MODIFIERS = + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | + Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | + Modifier.VOLATILE; + + /** + * Return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a class. + * @return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a class. + * + * @jls3 8.1.1 Class Modifiers + * @since 1.7 + */ + public static int classModifiers() { + return CLASS_MODIFIERS; + } + + /** + * Return an {@code int} value OR-ing together the source language + * modifiers that can be applied to an interface. + * @return an {@code int} value OR-ing together the source language + * modifiers that can be applied to an inteface. + * + * @jls3 9.1.1 Interface Modifiers + * @since 1.7 + */ + public static int interfaceModifiers() { + return INTERFACE_MODIFIERS; + } + + /** + * Return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a constructor. + * @return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a constructor. + * + * @jls3 8.8.3 Constructor Modifiers + * @since 1.7 + */ + public static int constructorModifiers() { + return CONSTRUCTOR_MODIFIERS; + } + + /** + * Return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a method. + * @return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a method. + * + * @jls3 8.4.3 Method Modifiers + * @since 1.7 + */ + public static int methodModifiers() { + return METHOD_MODIFIERS; + } + + + /** + * Return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a field. + * @return an {@code int} value OR-ing together the source language + * modifiers that can be applied to a field. + * + * @jls3 8.3.1 Field Modifiers + * @since 1.7 + */ + public static int fieldModifiers() { + return FIELD_MODIFIERS; + } }