Example usage for java.lang.reflect Modifier isPrivate

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

Introduction

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

Prototype

public static boolean isPrivate(int mod) 

Source Link

Document

Return true if the integer argument includes the private 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.isPrivate(modifier)) {
        System.out.println("isPrivate");
    }/*from   ww w . j a  v  a  2  s .c om*/
}

From source file:Main.java

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

    if (Modifier.isPrivate(modifier)) {
        System.out.println(clazz.getName() + " class modifier is private");
    }//www .j  a  v  a2s .co  m

}

From source file:DeclarationInfoDemo.java

public static void printModifiers(final Class dataType) {
    final int modifiers = dataType.getModifiers();
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }//from   w  ww  .  j a v a 2 s.  co  m
    if (Modifier.isPrivate(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isPublic(modifiers)) {
        System.out.print("private ");
    }
    if (Modifier.isAbstract(modifiers)) {
        System.out.print("abstract ");
    }
    if (Modifier.isFinal(modifiers)) {
        System.out.print("final ");
    }
    if (Modifier.isNative(modifiers)) {
        System.out.print("native ");
    }
    if (Modifier.isInterface(modifiers)) {
        System.out.print("interface ");
    }
    if (Modifier.isStatic(modifiers)) {
        System.out.print("static ");
    }
    if (Modifier.isStrict(modifiers)) {
        System.out.print("strict ");
    }
    if (Modifier.isSynchronized(modifiers)) {
        System.out.print("synchronized ");
    }
    if (Modifier.isTransient(modifiers)) {
        System.out.print("transient ");
    }
    if (Modifier.isVolatile(modifiers)) {
        System.out.print("volatile ");
    }
    System.out.println(dataType.getName());
}

From source file:ModifierUtil.java

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

From source file:Main.java

/**
 * Takes a class type and constructs it. If the class does not have an empty constructor this
 * will//w ww . j  a  va 2s.co m
 * find the parametrized constructor and use nulls and default values to construct the class.
 *
 * @param clazz The class to construct.
 * @param <T> The type of the class to construct.
 * @return The constructed object.
 */
public static <T> T createInstance(Class<T> clazz) {
    T created = null;
    Constructor<?>[] constructors = clazz.getConstructors();
    for (Constructor<?> constructor : constructors) {
        if (!Modifier.isPrivate(constructor.getModifiers())) {
            Class<?>[] parameterTypes = constructor.getParameterTypes();
            List<Object> params = new ArrayList<Object>();
            for (Class<?> parameterType : parameterTypes)
                if (!parameterType.isPrimitive()) {
                    params.add(null);
                } else {
                    if (parameterType == boolean.class) {
                        params.add(false);
                    } else {
                        params.add(0);
                    }
                }

            try {
                @SuppressWarnings("unchecked")
                T newObject = (T) constructor.newInstance(params.toArray());
                created = newObject;
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            break;
        }
    }
    return created;
}

From source file:ModifierUtil.java

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

From source file:com.yahoo.egads.data.JsonEncoder.java

public static void // modifies json_out
        toJson(Object object, JSONStringer json_out) throws Exception {
    json_out.object();//from   ww w  . ja  v a 2  s  . c  o  m
    // for each inherited class...
    for (Class c = object.getClass(); c != Object.class; c = c.getSuperclass()) {
        // for each member variable... 
        Field[] fields = c.getDeclaredFields();
        for (Field f : fields) {
            // if variable is static/private... skip it
            if (Modifier.isStatic(f.getModifiers())) {
                continue;
            }
            if (Modifier.isPrivate(f.getModifiers())) {
                continue;
            }
            Object value = f.get(object);

            // if variable is a complex type... recurse on sub-objects
            if (value instanceof JsonAble) {
                json_out.key(f.getName());
                ((JsonAble) value).toJson(json_out);
                // if variable is an array... recurse on sub-objects
            } else if (value instanceof ArrayList) {
                json_out.key(f.getName());
                json_out.array();
                for (Object e : (ArrayList) value) {
                    toJson(e, json_out);
                }
                json_out.endArray();
                // if variable is a simple type... convert to json
            } else {
                json_out.key(f.getName()).value(value);
            }
        }
    }
    json_out.endObject();
}

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  . j av a  2 s .co  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: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:org.apache.hadoop.fs.TestFilterFs.java

public void testFilterFileSystem() throws Exception {
    for (Method m : AbstractFileSystem.class.getDeclaredMethods()) {
        if (Modifier.isStatic(m.getModifiers()))
            continue;
        if (Modifier.isPrivate(m.getModifiers()))
            continue;
        if (Modifier.isFinal(m.getModifiers()))
            continue;

        try {//  w w  w . j  av a 2s .  c  o  m
            DontCheck.class.getMethod(m.getName(), m.getParameterTypes());
            LOG.info("Skipping " + m);
        } catch (NoSuchMethodException exc) {
            LOG.info("Testing " + m);
            try {
                FilterFs.class.getDeclaredMethod(m.getName(), m.getParameterTypes());
            } catch (NoSuchMethodException exc2) {
                LOG.error("FilterFileSystem doesn't implement " + m);
                throw exc2;
            }
        }
    }
}