下面列出了java.lang.reflect.Modifier#SYNCHRONIZED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String [] argv) {
int allMods = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED |
Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE;
String allModsString = "public protected private abstract static " +
"final transient volatile synchronized native strictfp interface";
/* zero should have an empty string */
testString(0, "");
/* test to make sure all modifiers print out in the proper order */
testString(allMods, allModsString);
/* verify no extraneous modifiers are printed */
testString(~0, allModsString);
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
/**
* Convert modifier bits from private coding used by
* the compiler to that of java.lang.reflect.Modifier.
*/
static int translateModifiers(long flags) {
int result = 0;
if ((flags & Flags.ABSTRACT) != 0)
result |= Modifier.ABSTRACT;
if ((flags & Flags.FINAL) != 0)
result |= Modifier.FINAL;
if ((flags & Flags.INTERFACE) != 0)
result |= Modifier.INTERFACE;
if ((flags & Flags.NATIVE) != 0)
result |= Modifier.NATIVE;
if ((flags & Flags.PRIVATE) != 0)
result |= Modifier.PRIVATE;
if ((flags & Flags.PROTECTED) != 0)
result |= Modifier.PROTECTED;
if ((flags & Flags.PUBLIC) != 0)
result |= Modifier.PUBLIC;
if ((flags & Flags.STATIC) != 0)
result |= Modifier.STATIC;
if ((flags & Flags.SYNCHRONIZED) != 0)
result |= Modifier.SYNCHRONIZED;
if ((flags & Flags.TRANSIENT) != 0)
result |= Modifier.TRANSIENT;
if ((flags & Flags.VOLATILE) != 0)
result |= Modifier.VOLATILE;
return result;
}
public static void main(String[] args) throws Exception {
/* We are not testing for the ACC_SUPER bug, so strip we strip
* synchorized. */
int m = 0;
m = Inner.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PRIVATE)
throw new Exception("Access bits for innerclass not from " +
"InnerClasses attribute");
m = Protected.class.getModifiers() & (~Modifier.SYNCHRONIZED);
if (m != Modifier.PROTECTED)
throw new Exception("Protected inner class wronged modifiers");
}
public static long modifiersFrom( Set<javax.lang.model.element.Modifier> modifiers )
{
long mods = 0;
for( javax.lang.model.element.Modifier mod : modifiers )
{
switch( mod )
{
case PUBLIC:
mods |= Modifier.PUBLIC;
break;
case PROTECTED:
mods |= Modifier.PROTECTED;
break;
case PRIVATE:
mods |= Modifier.PRIVATE;
break;
case ABSTRACT:
mods |= Modifier.ABSTRACT;
break;
case DEFAULT:
mods |= Flags.DEFAULT;
break;
case STATIC:
mods |= Modifier.STATIC;
break;
case FINAL:
mods |= Modifier.FINAL;
break;
case TRANSIENT:
mods |= Modifier.TRANSIENT;
break;
case VOLATILE:
mods |= Modifier.VOLATILE;
break;
case SYNCHRONIZED:
mods |= Modifier.SYNCHRONIZED;
break;
case NATIVE:
mods |= Modifier.NATIVE;
break;
case STRICTFP:
mods |= Flags.STRICTFP;
break;
}
}
return mods;
}
@Override
protected String modifierString(MemberDoc member) {
final int ms = member.modifierSpecifier();
final int no = Modifier.FINAL | Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}
/**
* Return a string describing the access modifier flags.
* Don't include native or synchronized.
*
* The modifier names are returned in canonical order, as
* specified by <em>The Java Language Specification</em>.
*/
protected String modifierString(MemberDoc member) {
int ms = member.modifierSpecifier();
int no = Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}
/**
* Return a string describing the access modifier flags.
* Don't include native or synchronized.
*
* The modifier names are returned in canonical order, as
* specified by <em>The Java Language Specification</em>.
*/
protected String modifierString(MemberDoc member) {
int ms = member.modifierSpecifier();
int no = Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}
/**
* Return a string describing the access modifier flags.
* Don't include native or synchronized.
*
* The modifier names are returned in canonical order, as
* specified by <em>The Java Language Specification</em>.
*/
protected String modifierString(MemberDoc member) {
int ms = member.modifierSpecifier();
int no = Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}
/**
* Return a string describing the access modifier flags.
* Don't include native or synchronized.
*
* The modifier names are returned in canonical order, as
* specified by <em>The Java Language Specification</em>.
*/
protected String modifierString(MemberDoc member) {
int ms = member.modifierSpecifier();
int no = Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}
/**
* Return a string describing the access modifier flags.
* Don't include native or synchronized.
*
* The modifier names are returned in canonical order, as
* specified by <em>The Java Language Specification</em>.
*/
protected String modifierString(MemberDoc member) {
int ms = member.modifierSpecifier();
int no = Modifier.NATIVE | Modifier.SYNCHRONIZED;
return Modifier.toString(ms & ~no);
}