当前位置: 首页>>代码示例>>Java>>正文


Java Modifier.PROTECTED属性代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ExternalPackages.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:ObjectStreamClass.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ReflectionFactory.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:ObjectStreamClass.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:ReflectionFactory.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:FormEditorCustomizer.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:JavaAdapterBytecodeGenerator.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:ObjectStreamClass.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ForInnerClass.java

示例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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:HotSpotResolvedObjectTypeImpl.java

示例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());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:JavaAdapterBytecodeGenerator.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:DocEnv.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:ObjectStreamClass.java

示例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 "";
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:56,代码来源:SrcAnnotated.java

示例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);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:51,代码来源:ReflectUtil.java


注:本文中的java.lang.reflect.Modifier.PROTECTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。