JDK 8 code review request for JDK-8014249 Add Modifer.parameterModifiers()
Joe Darcy
joe.darcy at oracle.com
Thu May 9 03:18:08 UTC 2013
On 05/08/2013 03:26 PM, Mandy Chung wrote:
> The change looks good to me. I also think it's a good idea to swap
> out the comment for @jls tag for consistency.
Okay; you both convinced me :-)
Revised patch below, including a new comment explaining the
FOO_MODIFIERS fields and fooModifiers() method pattern.
Thanks,
-Joe
diff -r 2fba6ae13ed8 src/share/classes/java/lang/reflect/Modifier.java
--- a/src/share/classes/java/lang/reflect/Modifier.java Tue Apr 30
12:32:49 2013 -0700
+++ b/src/share/classes/java/lang/reflect/Modifier.java Wed May 08
20:16:21 2013 -0700
@@ -350,8 +350,19 @@
return (mod & MANDATED) != 0;
}
+ // Note on the FOO_MODIFIERS fields and fooModifiers() methods:
+ // the sets of modifiers are not guaranteed to be constants
+ // across time and Java SE releases. Therefore, it would not be
+ // appropriate to expose an external interface to this information
+ // that would allow the values to be treated as Java-level
+ // constants since the values could be constant folded and updates
+ // to the sets of modifiers missed. Thus, the fooModifiers()
+ // methods return an unchanging values for a given release, but a
+ // value that can change over time.
+
/**
- * See JLSv3 section 8.1.1.
+ * The Java source modifiers that can be applied to a class.
+ * @jls 8.1.1 Class Modifiers
*/
private static final int CLASS_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED |
Modifier.PRIVATE |
@@ -359,7 +370,8 @@
Modifier.STRICT;
/**
- * See JLSv3 section 9.1.1.
+ * The Java source modifiers that can be applied to an interface.
+ * @jls 9.1.1 Interface Modifiers
*/
private static final int INTERFACE_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED |
Modifier.PRIVATE |
@@ -367,13 +379,15 @@
/**
- * See JLSv3 section 8.8.3.
+ * The Java source modifiers that can be applied to a constructor.
+ * @jls 8.8.3 Constructor Modifiers
*/
private static final int CONSTRUCTOR_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED |
Modifier.PRIVATE;
/**
- * See JLSv3 section 8.4.3.
+ * The Java source modifiers that can be applied to a method.
+ * @jls8.4.3 Method Modifiers
*/
private static final int METHOD_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED |
Modifier.PRIVATE |
@@ -381,7 +395,8 @@
Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
/**
- * See JLSv3 section 8.3.1.
+ * The Java source modifiers that can be applied to a field.
+ * @jls 8.3.1 Field Modifiers
*/
private static final int FIELD_MODIFIERS =
Modifier.PUBLIC | Modifier.PROTECTED |
Modifier.PRIVATE |
@@ -389,6 +404,13 @@
Modifier.VOLATILE;
/**
+ * The Java source modifiers that can be applied to a method or
constructor parameter.
+ * @jls 8.4.1 Formal Parameters
+ */
+ private static final int PARAMETER_MODIFIERS =
+ Modifier.FINAL;
+
+ /**
*
*/
static final int ACCESS_MODIFIERS =
@@ -446,7 +468,6 @@
return METHOD_MODIFIERS;
}
-
/**
* Return an {@code int} value OR-ing together the source language
* modifiers that can be applied to a field.
@@ -459,4 +480,17 @@
public static int fieldModifiers() {
return FIELD_MODIFIERS;
}
+
+ /**
+ * Return an {@code int} value OR-ing together the source language
+ * modifiers that can be applied to a parameter.
+ * @return an {@code int} value OR-ing together the source language
+ * modifiers that can be applied to a parameter.
+ *
+ * @jls 8.4.1 Formal Parameters
+ * @since 1.8
+ */
+ public static int parameterModifiers() {
+ return PARAMETER_MODIFIERS;
+ }
}
More information about the core-libs-dev
mailing list