本文整理汇总了Java中java.lang.reflect.Modifier.PROTECTED属性的典型用法代码示例。如果您正苦于以下问题:Java Modifier.PROTECTED属性的具体用法?Java Modifier.PROTECTED怎么用?Java Modifier.PROTECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.PROTECTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModifiers
private static int getModifiers(ClassInfo ci, int mIndex) {
int modifiers = 0;
if (ci.isMethodAbstract(mIndex)) {
modifiers += Modifier.ABSTRACT;
}
if (ci.isMethodPrivate(mIndex)) {
modifiers += Modifier.PRIVATE;
}
if (ci.isMethodProtected(mIndex)) {
modifiers += Modifier.PROTECTED;
}
if (ci.isMethodPublic(mIndex)) {
modifiers += Modifier.PUBLIC;
}
if (ci.isMethodFinal(mIndex)) {
modifiers += Modifier.FINAL;
}
if (ci.isMethodStatic(mIndex)) {
modifiers += Modifier.STATIC;
}
if (ci.isMethodNative(mIndex)) {
modifiers += Modifier.NATIVE;
}
return modifiers;
}
示例2: getSerializableConstructor
/**
* Returns subclass-accessible no-arg constructor of first non-serializable
* superclass, or null if none found. Access checks are disabled on the
* returned constructor (if any).
*/
private static Constructor getSerializableConstructor(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
try {
Constructor cons = initCl.getDeclaredConstructor(new Class<?>[0]);
int mods = cons.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
!packageEquals(cl, initCl)))
{
return null;
}
cons = bridge.newConstructorForSerialization(cl, cons);
cons.setAccessible(true);
return cons;
} catch (NoSuchMethodException ex) {
return null;
}
}
示例3: newConstructorForSerialization
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
Constructor<?> constructorToCall;
try {
constructorToCall = initCl.getDeclaredConstructor();
int mods = constructorToCall.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
!packageEquals(cl, initCl))) {
return null;
}
} catch (NoSuchMethodException ex) {
return null;
}
return generateConstructor(cl, constructorToCall);
}
示例4: getSerializableConstructor
/**
* Returns subclass-accessible no-arg constructor of first non-serializable
* superclass, or null if none found. Access checks are disabled on the
* returned constructor (if any).
*/
private static Constructor<?> getSerializableConstructor(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
try {
Constructor<?> cons = initCl.getDeclaredConstructor((Class<?>[]) null);
int mods = cons.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
!packageEquals(cl, initCl)))
{
return null;
}
cons = reflFactory.newConstructorForSerialization(cl, cons);
cons.setAccessible(true);
return cons;
} catch (NoSuchMethodException ex) {
return null;
}
}
示例5: newConstructorForSerialization
/**
* Returns an accessible no-arg constructor for a class.
* The no-arg constructor is found searching the class and its supertypes.
*
* @param cl the class to instantiate
* @return a no-arg constructor for the class or {@code null} if
* the class or supertypes do not have a suitable no-arg constructor
*/
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
return null;
}
}
Constructor<?> constructorToCall;
try {
constructorToCall = initCl.getDeclaredConstructor();
int mods = constructorToCall.getModifiers();
if ((mods & Modifier.PRIVATE) != 0 ||
((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
!packageEquals(cl, initCl))) {
return null;
}
} catch (NoSuchMethodException ex) {
return null;
}
return generateConstructor(cl, constructorToCall);
}
示例6: fireChanged
private void fireChanged() {
FormLoaderSettings options = FormLoaderSettings.getInstance();
boolean isChanged = false;
if (rbGenerateFields.isSelected()) {
switch (cbModifier.getSelectedIndex()) {
case 0:
isChanged = options.getVariablesModifier() != Modifier.PUBLIC;
break;
case 1:
isChanged = options.getVariablesModifier() != 0;
break;
case 2:
isChanged = options.getVariablesModifier() != Modifier.PROTECTED;
break;
case 3:
isChanged = options.getVariablesModifier() != Modifier.PRIVATE;
break;
}
}
try {
changed = isChanged || options.getFoldGeneratedCode() != cbFold.isSelected()
|| options.getAssistantShown() != cbAssistant.isSelected()
|| options.getGenerateFQN() != cbFQN.isSelected()
|| options.getListenerGenerationStyle() != cbListenerStyle.getSelectedIndex()
|| options.getLayoutCodeTarget() != cbLayoutStyle.getSelectedIndex()
|| options.getAutoSetComponentName() != cbComponentNames.getSelectedIndex()
|| options.getI18nAutoMode() != cbAutoI18n.getSelectedIndex()
|| options.getVariablesLocal() != rbGenerateLocals.isSelected()
|| options.getGridX() != (Integer) spGridSize.getValue()
|| options.getGridY() != (Integer) spGridSize.getValue()
|| !options.getGuidingLineColor().equals(guideLineColorProperty.getValue())
|| !options.getSelectionBorderColor().equals(selectionBorderColorProperty.getValue())
|| options.getPaintAdvancedLayoutInfo() != (cbPaintLayout.isSelected() ? 3 : 0);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
示例7: generateConstructors
private boolean generateConstructors() throws AdaptationException {
boolean gotCtor = false;
boolean canBeAutoConverted = false;
for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
final int modifier = ctor.getModifiers();
if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
canBeAutoConverted = generateConstructors(ctor) | canBeAutoConverted;
gotCtor = true;
}
}
if(!gotCtor) {
throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
}
return canBeAutoConverted;
}
示例8: getInheritableMethod
/**
* Returns non-static, non-abstract method with given signature provided it
* is defined by or accessible (via inheritance) by the given class, or
* null if no match found. Access checks are disabled on the returned
* method (if any).
*
* Copied from the Merlin java.io.ObjectStreamClass.
*/
private static Method getInheritableMethod(Class<?> cl, String name,
Class<?>[] argTypes,
Class<?> returnType)
{
Method meth = null;
Class<?> defCl = cl;
while (defCl != null) {
try {
meth = defCl.getDeclaredMethod(name, argTypes);
break;
} catch (NoSuchMethodException ex) {
defCl = defCl.getSuperclass();
}
}
if ((meth == null) || (meth.getReturnType() != returnType)) {
return null;
}
int mods = meth.getModifiers();
if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
return null;
} else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
return meth;
} else if ((mods & Modifier.PRIVATE) != 0) {
return (cl == defCl) ? meth : null;
} else {
return packageEquals(cl, defCl) ? meth : null;
}
}
示例9: main
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");
}
示例10: getModifiers
@Override
public int getModifiers() {
if (isArray()) {
return (getElementalType().getModifiers() & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED)) | Modifier.FINAL | Modifier.ABSTRACT;
} else {
return getAccessFlags() & jvmClassModifiers();
}
}
示例11: generateConstructors
private void generateConstructors() throws AdaptationException {
boolean gotCtor = false;
for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
final int modifier = ctor.getModifiers();
if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
generateConstructors(ctor);
gotCtor = true;
}
}
if(!gotCtor) {
throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
}
}
示例12: translateModifiers
/**
* 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;
}
示例13: getInheritableMethod
/**
* Returns non-static, non-abstract method with given signature provided it
* is defined by or accessible (via inheritance) by the given class, or
* null if no match found. Access checks are disabled on the returned
* method (if any).
*/
private static Method getInheritableMethod(Class<?> cl, String name,
Class<?>[] argTypes,
Class<?> returnType)
{
Method meth = null;
Class<?> defCl = cl;
while (defCl != null) {
try {
meth = defCl.getDeclaredMethod(name, argTypes);
break;
} catch (NoSuchMethodException ex) {
defCl = defCl.getSuperclass();
}
}
if ((meth == null) || (meth.getReturnType() != returnType)) {
return null;
}
meth.setAccessible(true);
int mods = meth.getModifiers();
if ((mods & (Modifier.STATIC | Modifier.ABSTRACT)) != 0) {
return null;
} else if ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0) {
return meth;
} else if ((mods & Modifier.PRIVATE) != 0) {
return (cl == defCl) ? meth : null;
} else {
return packageEquals(cl, defCl) ? meth : null;
}
}
示例14: renderModifiers
protected String renderModifiers( StringBuilder sb, long modifiers, boolean isDefault, int defModifier )
{
if( isDefault )
{
sb.append( "default " );
}
if( (modifiers & Modifier.PUBLIC) != 0 )
{
sb.append( "public " );
}
else if( (modifiers & Modifier.PROTECTED) != 0 )
{
sb.append( "protected " );
}
else if( (modifiers & Modifier.PRIVATE) != 0 )
{
sb.append( "private " );
}
else if( defModifier != 0 )
{
renderModifiers( sb, defModifier, false, 0 );
}
// Canonical order
if( (modifiers & Modifier.ABSTRACT) != 0 )
{
sb.append( "abstract " );
}
if( (modifiers & Modifier.STATIC) != 0 )
{
sb.append( "static " );
}
if( (modifiers & Modifier.FINAL) != 0 )
{
sb.append( "final " );
}
if( (modifiers & Modifier.TRANSIENT) != 0 )
{
sb.append( "transient " );
}
if( (modifiers & Modifier.VOLATILE) != 0 )
{
sb.append( "volatile " );
}
if( (modifiers & Modifier.SYNCHRONIZED) != 0 )
{
sb.append( "synchronized " );
}
if( (modifiers & Modifier.INTERFACE) != 0 )
{
sb.append( "interface " );
}
return "";
}
示例15: ensureMemberAccess
public static void ensureMemberAccess(Class currentClass,
Class memberClass,
Object target,
int modifiers)
throws IllegalAccessException
{
if (target == null && Modifier.isProtected(modifiers)) {
int mods = modifiers;
mods = mods & (~Modifier.PROTECTED);
mods = mods | Modifier.PUBLIC;
/*
* See if we fail because of class modifiers
*/
Reflection.ensureMemberAccess(currentClass,
memberClass,
target,
mods);
try {
/*
* We're still here so class access was ok.
* Now try with default field access.
*/
mods = mods & (~Modifier.PUBLIC);
Reflection.ensureMemberAccess(currentClass,
memberClass,
target,
mods);
/*
* We're still here so access is ok without
* checking for protected.
*/
return;
} catch (IllegalAccessException e) {
/*
* Access failed but we're 'protected' so
* if the test below succeeds then we're ok.
*/
if (isSubclassOf(currentClass, memberClass)) {
return;
} else {
throw e;
}
}
} else {
Reflection.ensureMemberAccess(currentClass,
memberClass,
target,
modifiers);
}
}