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:Main.java

public static void main(String[] args) throws Exception {
    Class<?> clazz = String.class;
    int modifier = clazz.getModifiers();

    if (Modifier.isProtected(modifier)) {
        System.out.println("isProtected");
    }//from w  ww  . j  a  v a 2  s  .  c o m
}

From source file:Main.java

private static void getClassModifier(Class clazz) {
    int modifier = clazz.getModifiers();

    if (Modifier.isProtected(modifier)) {
        System.out.println(clazz.getName() + " class modifier is protected");
    }/*from www.ja v a  2s . com*/

}

From source file:ModifierUtil.java

public static boolean isProtected(Member member) {
    return Modifier.isProtected(member.getModifiers());
}

From source file:ModifierUtil.java

public static boolean isProtected(Class<?> clazz) {
    return Modifier.isProtected(clazz.getModifiers());
}

From source file:Main.java

/**
 * get all fields for a class/*  w w w . j  a v a  2s  .  com*/
 *
 * @param type
 * @return all fields indexed by their names
 */
private static Map<String, Field> getAllFields(Class<?> type) {
    Map<String, Field> fields = new HashMap<String, Field>();
    Class<?> currentType = type;
    while (!currentType.equals(Object.class)) {
        for (Field field : currentType.getDeclaredFields()) {
            int mod = field.getModifiers();
            /*
             * by convention, our fields should not have any modifier
             */
            if (mod == 0 || Modifier.isProtected(mod) && !Modifier.isStatic(mod)) {
                fields.put(field.getName(), field);
            }
        }
        currentType = currentType.getSuperclass();
    }
    return fields;
}

From source file:IntrospectionUtil.java

public static boolean isInheritable(Package pack, Member member) {
    if (pack == null)
        return false;
    if (member == null)
        return false;

    int modifiers = member.getModifiers();
    if (Modifier.isPublic(modifiers))
        return true;
    if (Modifier.isProtected(modifiers))
        return true;
    if (!Modifier.isPrivate(modifiers) && pack.equals(member.getDeclaringClass().getPackage()))
        return true;

    return false;
}

From source file:Main.java

public static List<Field> getAccessibleFields(Class<?> clazz, Class<?> limit) {
    Package topPackage = clazz.getPackage();
    List<Field> fieldList = new ArrayList<Field>();
    int topPackageHash = topPackage == null ? 0 : topPackage.hashCode();
    boolean top = true;
    do {/*from   w ww  . ja v a2s . c  o m*/
        if (clazz == null) {
            break;
        }
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            if (top == true) { // add all top declared fields
                fieldList.add(field);
                continue;
            }
            int modifier = field.getModifiers();
            if (Modifier.isPrivate(modifier) == true) {
                continue; // ignore super private fields
            }
            if (Modifier.isPublic(modifier) == true) {
                addFieldIfNotExist(fieldList, field); // add super public methods
                continue;
            }
            if (Modifier.isProtected(modifier) == true) {
                addFieldIfNotExist(fieldList, field); // add super protected methods
                continue;
            }
            // add super default methods from the same package
            Package pckg = field.getDeclaringClass().getPackage();
            int pckgHash = pckg == null ? 0 : pckg.hashCode();
            if (pckgHash == topPackageHash) {
                addFieldIfNotExist(fieldList, field);
            }
        }
        top = false;
    } while ((clazz = clazz.getSuperclass()) != limit);

    return fieldList;
}

From source file:de.micromata.genome.util.runtime.ClassUtils.java

/**
 * Returns all 'visible' methods for the given class. Visible methods are:
 *
 * - own methods (clazz.getDeclaredMethods()) - all public and protected methods from it's inheritance hierarchy
 *
 * @param clazz the Class//from   w  ww . j a va  2 s  .  com
 * @return set of visible methods for that class
 */
public static Set<Method> getAllVisibleMethods(final Class<?> clazz) {
    Set<Method> allMethods = new HashSet<>();
    allMethods.addAll(Arrays.asList(clazz.getMethods()));
    allMethods.addAll(Arrays.asList(clazz.getDeclaredMethods()));

    for (Object obj : ClassUtils.getAllSuperclasses(clazz)) {
        Class aClass = (Class) obj;
        for (Method method : aClass.getDeclaredMethods()) {
            if (Modifier.isProtected(method.getModifiers())) {
                allMethods.add(method);
            }
        }
    }
    return allMethods;
}

From source file:MyJavaP.java

/**
 * Format the fields and methods of one class, given its name.
 *///from  www  . ja va2s.  c o  m
protected void doClass(String className) {

    try {
        Class c = Class.forName(className);
        System.out.println(Modifier.toString(c.getModifiers()) + ' ' + c + " {");

        int mods;
        Field fields[] = c.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (!Modifier.isPrivate(fields[i].getModifiers())
                    && !Modifier.isProtected(fields[i].getModifiers()))
                System.out.println("\t" + fields[i]);
        }
        Constructor[] constructors = c.getConstructors();
        for (int j = 0; j < constructors.length; j++) {
            Constructor constructor = constructors[j];
            System.out.println("\t" + constructor);

        }
        Method methods[] = c.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (!Modifier.isPrivate(methods[i].getModifiers())
                    && !Modifier.isProtected(methods[i].getModifiers()))
                System.out.println("\t" + methods[i]);
        }
        System.out.println("}");
    } catch (ClassNotFoundException e) {
        System.err.println("Error: Class " + className + " not found!");
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:com.judoscript.jamaica.parser.JamaicaDumpVisitor.java

public Object visit(ASTDefaultCtor node, Object data) throws Exception {
    out.print("\n  %default_constructor");
    int flags = node.getAccessFlags();
    if (Modifier.isPublic(flags))
        out.print(" <public>");
    else if (Modifier.isProtected(flags))
        out.print(" <protected>");
    else if (Modifier.isPrivate(flags))
        out.print(" <private>");
    out.println();/*from w  w  w  .  j  a  v  a  2s .c  o  m*/
    return null;
}