Example usage for java.lang.reflect Modifier classModifiers

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

Introduction

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

Prototype

public static int classModifiers() 

Source Link

Document

Return an int value OR-ing together the source language modifiers that can be applied to a class.

Usage

From source file:Main.java

public static void main(String... args) throws Exception {
    System.out.println(Modifier.toString(Modifier.classModifiers()));
}

From source file:MyClass.java

public static String getClassDescription(Class c) {
    StringBuilder classDesc = new StringBuilder();
    int modifierBits = 0;
    String keyword = "";
    if (c.isInterface()) {
        modifierBits = c.getModifiers() & Modifier.interfaceModifiers();
        if (c.isAnnotation()) {
            keyword = "@interface";
        } else {/*from w w w  .j av  a 2 s.c om*/
            keyword = "interface";
        }
    } else if (c.isEnum()) {
        modifierBits = c.getModifiers() & Modifier.classModifiers();
        keyword = "enum";
    }
    modifierBits = c.getModifiers() & Modifier.classModifiers();
    keyword = "class";

    String modifiers = Modifier.toString(modifierBits);
    classDesc.append(modifiers);
    classDesc.append(" " + keyword);
    String simpleName = c.getSimpleName();
    classDesc.append(" " + simpleName);

    String genericParms = getGenericTypeParams(c);
    classDesc.append(genericParms);

    Class superClass = c.getSuperclass();
    if (superClass != null) {
        String superClassSimpleName = superClass.getSimpleName();
        classDesc.append("  extends " + superClassSimpleName);
    }
    String interfaces = Main.getClassInterfaces(c);
    if (interfaces != null) {
        classDesc.append("  implements " + interfaces);
    }
    return classDesc.toString();
}