提交 dbd16ef0 编写于 作者: D darcy

6261502: (reflect) Add the functionality to screen out the "inappropriate" modifier bits

Reviewed-by: alanb
上级 f7ac9fd8
......@@ -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) + " ");
}
......
......@@ -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) + " ");
}
......
......@@ -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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册