Example usage for java.lang.reflect Modifier isProtected

List of usage examples for java.lang.reflect Modifier isProtected

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isProtected.

Prototype

public static boolean isProtected(int mod) 

Source Link

Document

Return true if the integer argument includes the protected modifier, false otherwise.

Usage

From source file:com.urbancode.x2o.xml.XmlWrite.java

public List<Method> findMethodsForClass(String methodPrefix, Class clazz) throws ClassNotFoundException {
    List<Method> result = new ArrayList<Method>();
    for (Method method : clazz.getMethods()) {
        if (method.getName().startsWith(methodPrefix)) {
            if (!(method.getName().equals("getClass") || Modifier.isProtected(method.getModifiers()))) {
                result.add(method);/*from  w  ww . java2  s .c o  m*/
            }
        }
    }
    return result;
}

From source file:ClassFigure.java

public ClassFigure(Class cls) {
    setLayoutManager(new ToolbarLayout());
    setBorder(new LineBorder(ColorConstants.black));
    setBackgroundColor(ColorConstants.yellow);
    setOpaque(true);/*from  ww w  .  j av a  2 s .c  o  m*/

    for (int i = 0; i < keys.length; i++)
        registry.put(keys[i], ImageDescriptor.createFromFile(null, "icons/java/" + keys[i] + ".gif"));

    Label title = new Label(cls.getName(), registry.get(KEY_CLASS));
    add(title);
    add(fieldBox);
    add(methodBox);

    // fields.
    Field[] fields = cls.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        Image image = null;
        if (Modifier.isPublic(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PUBLIC);
        } else if (Modifier.isProtected(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PROTECTED);
        } else if (Modifier.isPrivate(field.getModifiers())) {
            image = registry.get(KEY_FIELD_PRIVATE);
        } else {
            image = registry.get(KEY_FIELD_DEFAULT);
        }
        fieldBox.add(new Label(fields[i].getName(), image));
    }

    // fields.
    Method[] methods = cls.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        Image image = null;
        if (Modifier.isPublic(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PUBLIC);
        } else if (Modifier.isProtected(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PROTECTED);
        } else if (Modifier.isPrivate(method.getModifiers())) {
            image = registry.get(KEY_METHOD_PRIVATE);
        } else {
            image = registry.get(KEY_METHOD_DEFAULT);
        }
        methodBox.add(new Label(methods[i].getName(), image));
    }

}

From source file:objenome.util.bytecode.SgUtils.java

private static void checkModifiers(int type, int modifiers) {
    for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) {
        if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) {
            throwIllegalArgument(type, PRIVATE);
        }/*ww w . ja v  a  2s  .  c o  m*/
        if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) {
            throwIllegalArgument(type, PROTECTED);
        }
        if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) {
            throwIllegalArgument(type, PUBLIC);
        }
        if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) {
            throwIllegalArgument(type, STATIC);
        }
        if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) {
            throwIllegalArgument(type, ABSTRACT);
        }
        if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) {
            throwIllegalArgument(type, FINAL);
        }
        if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) {
            throwIllegalArgument(type, NATIVE);
        }
        if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) {
            throwIllegalArgument(type, SYNCHRONIZED);
        }
        if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) {
            throwIllegalArgument(type, TRANSIENT);
        }
        if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) {
            throwIllegalArgument(type, VOLATILE);
        }
        if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) {
            throwIllegalArgument(type, STRICTFP);
        }
    }
}

From source file:com.github.jknack.handlebars.context.MemberValueResolver.java

/**
 * True if the member is protected./*  w  w w . j av a 2 s.co  m*/
 *
 * @param member The member object.
 * @return True if the member is protected.
 */
protected boolean isProtected(final M member) {
    return Modifier.isProtected(member.getModifiers());
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

public void assertCanSubclass() {
    Class superclass = meta.getDescribedType();
    String name = superclass.getName();
    if (superclass.isInterface())
        addError(loc.get("subclasser-no-ifaces", name), meta);
    if (Modifier.isFinal(superclass.getModifiers()))
        addError(loc.get("subclasser-no-final-classes", name), meta);
    if (Modifier.isPrivate(superclass.getModifiers()))
        addError(loc.get("subclasser-no-private-classes", name), meta);
    if (PersistenceCapable.class.isAssignableFrom(superclass))
        addError(loc.get("subclasser-super-already-pc", name), meta);

    try {//  www.  j  av a  2 s.c om
        Constructor c = superclass.getDeclaredConstructor(new Class[0]);
        if (!(Modifier.isProtected(c.getModifiers()) || Modifier.isPublic(c.getModifiers())))
            addError(loc.get("subclasser-private-ctor", name), meta);
    } catch (NoSuchMethodException e) {
        addError(loc.get("subclasser-no-void-ctor", name), meta);
    }

    // if the BCClass we loaded is already pc and the superclass is not,
    // then we should never get here, so let's make sure that the
    // calling context is caching correctly by throwing an exception.
    if (pc.isInstanceOf(PersistenceCapable.class) && !PersistenceCapable.class.isAssignableFrom(superclass))
        throw new InternalException(loc.get("subclasser-class-already-pc", name));

    if (AccessCode.isProperty(meta.getAccessType()))
        checkPropertiesAreInterceptable();

    if (errors != null && !errors.isEmpty())
        throw new UserException(errors.toString());
    else if (contractViolations != null && !contractViolations.isEmpty() && log.isWarnEnabled())
        log.warn(contractViolations.toString());
}

From source file:uk.gov.gchq.gaffer.example.gettingstarted.walkthrough.WalkthroughRunner.java

private static void keepPublicConcreteClasses(final List classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        for (Class clazz = null; itr.hasNext(); clazz = itr.next()) {
            if (null != clazz) {
                final int modifiers = clazz.getModifiers();
                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)
                        || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
                    itr.remove();//from   w w w .  j  a  va2 s.c  o m
                }
            }
        }
    }
}

From source file:org.apache.axis2.transport.http.AbstractAgent.java

private void examineMethods(Method[] aDeclaredMethods) {
    for (int i = 0; i < aDeclaredMethods.length; i++) {
        Method method = aDeclaredMethods[i];

        Class[] parameterTypes = method.getParameterTypes();
        if ((Modifier.isProtected(method.getModifiers()) || Modifier.isPublic(method.getModifiers()))
                && method.getName().startsWith(METHOD_PREFIX) && parameterTypes.length == 2
                && parameterTypes[0].equals(HttpServletRequest.class)
                && parameterTypes[1].equals(HttpServletResponse.class)) {

            String key = method.getName().substring(METHOD_PREFIX.length()).toLowerCase();

            // ensure we don't overwrite existing method with superclass method
            if (!operationCache.containsKey(key)) {
                operationCache.put(key, method);
            }// ww  w .  j  ava2s  . com
        }
    }
}

From source file:org.elasticsearch.client.CustomRestHighLevelClientTests.java

/**
 * The {@link RestHighLevelClient} must declare the following execution methods using the <code>protected</code> modifier
 * so that they can be used by subclasses to implement custom logic.
 *///from  w  w w.ja  v  a2 s  .  c o m
@SuppressForbidden(reason = "We're forced to uses Class#getDeclaredMethods() here because this test checks protected methods")
public void testMethodsVisibility() throws ClassNotFoundException {
    final String[] methodNames = new String[] { "parseEntity", "parseResponseException", "performRequest",
            "performRequestAndParseEntity", "performRequestAsync", "performRequestAsyncAndParseEntity" };

    final Set<String> protectedMethods = Arrays.stream(RestHighLevelClient.class.getDeclaredMethods())
            .filter(method -> Modifier.isProtected(method.getModifiers())).map(Method::getName)
            .collect(Collectors.toCollection(TreeSet::new));

    assertThat(protectedMethods, contains(methodNames));
}

From source file:org.spring.guice.module.GuiceModuleMetadata.java

private boolean visible(Class<?> type) {
    Class<?> cls = type;/*from  ww w .j  a v  a  2 s . co  m*/
    while (cls != null && cls != Object.class) {
        if (!Modifier.isInterface(cls.getModifiers()) && !Modifier.isPublic(cls.getModifiers())
                && !Modifier.isProtected(cls.getModifiers())) {
            return false;
        }
        cls = cls.getDeclaringClass();
    }
    return true;
}

From source file:uk.gov.gchq.gaffer.schemabuilder.service.SchemaBuilderService.java

private static void keepPublicConcreteClasses(final Collection<Class> classes) {
    if (null != classes) {
        final Iterator<Class> itr = classes.iterator();
        for (Class clazz = null; itr.hasNext(); clazz = itr.next()) {
            if (null != clazz) {
                final int modifiers = clazz.getModifiers();
                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)
                        || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
                    itr.remove();/*from  ww w.j  av  a 2 s. com*/
                }
            }
        }
    }
}