Example usage for java.lang Class getModifiers

List of usage examples for java.lang Class getModifiers

Introduction

In this page you can find the example usage for java.lang Class getModifiers.

Prototype

@HotSpotIntrinsicCandidate
public native int getModifiers();

Source Link

Document

Returns the Java language modifiers for this class or interface, encoded in an integer.

Usage

From source file:ReflectApp.java

static void describeClassOrInterface(Class className, String name) {
    displayModifiers(className.getModifiers());
    displayFields(className.getDeclaredFields());
    displayMethods(className.getDeclaredMethods());

    if (className.isInterface()) {
        System.out.println("Interface: " + name);
    } else {//from w w w. j a  va 2 s  .co m
        System.out.println("Class: " + name);
        displayInterfaces(className.getInterfaces());
        displayConstructors(className.getDeclaredConstructors());
    }
}

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 ");
    }/*  www . j av  a2s . c om*/
    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:com.yahoo.flowetl.core.util.KlassUtils.java

/**
 * Checks if a class is an interface.//from  w  ww  .  j  a v  a2s  .  com
 * 
 * @param klass
 *            the class to check
 * 
 * @return true, if it is an interface
 */
public static boolean isInterface(Class<?> klass) {
    int modifiers = klass.getModifiers();
    if (Modifier.isInterface(modifiers)) {
        return true;
    }
    return false;
}

From source file:com.yahoo.flowetl.core.util.KlassUtils.java

/**
 * Checks if a class is abstract./*from  ww  w.j a  v  a 2s  .  c o  m*/
 * 
 * @param klass
 *            the class to check
 * @return true, if it is an abstract class
 */
public static boolean isAbstract(Class<?> klass) {
    int modifiers = klass.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
        return true;
    }
    return false;
}

From source file:Main.java

static java.util.Collection createConcreteJavaCollection(Class clazz)
        throws InstantiationException, IllegalAccessException {
    int modifiers = clazz.getModifiers();
    java.util.Collection result = null;
    if ((modifiers & ACC_ABSTRACT) == 0 && (modifiers & ACC_INTERFACE) == 0) {
        // class is concrete, we can instantiate it directly
        result = (java.util.Collection) clazz.newInstance();
    } else {/* w w  w  .j  a  va 2s .  co m*/
        // class is either abstract or an interface, we have to somehow choose a concrete collection :-(
        if (java.util.List.class.isAssignableFrom(clazz)) {
            result = new java.util.ArrayList();
        } else if (java.util.Set.class.isAssignableFrom(clazz)) {
            result = new java.util.HashSet();
        }
    }
    return result;
}

From source file:Main.java

public static void print_class(Class c) {
    if (c.isInterface()) {
        System.out.print(Modifier.toString(c.getModifiers()) + " " + typename(c));
    } else if (c.getSuperclass() != null) {
        System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c) + " extends "
                + typename(c.getSuperclass()));
    } else {/*  w ww  .  ja v  a2  s .c  om*/
        System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c));
    }

    Class[] interfaces = c.getInterfaces();
    if ((interfaces != null) && (interfaces.length > 0)) {
        if (c.isInterface())
            System.out.print(" extends ");
        else
            System.out.print(" implements ");
        for (int i = 0; i < interfaces.length; i++) {
            if (i > 0)
                System.out.print(", ");
            System.out.print(typename(interfaces[i]));
        }
    }

    System.out.println(" {");

    Constructor[] constructors = c.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++)
        print_method_or_constructor(constructors[i]);

    Field[] fields = c.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        print_field(fields[i]);
    }
    Method[] methods = c.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++)
        print_method_or_constructor(methods[i]);
    System.out.println("}");
}

From source file:ModifierUtil.java

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

From source file:ModifierUtil.java

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

From source file:ModifierUtil.java

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

From source file:ModifierUtil.java

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