Example usage for java.lang.reflect Modifier STATIC

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

Introduction

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

Prototype

int STATIC

To view the source code for java.lang.reflect Modifier STATIC.

Click Source Link

Document

The int value representing the static modifier.

Usage

From source file:Main.java

public static void main(String... args) throws Exception {
    Class<?> c = Class.forName("java.lang.String");
    Constructor[] allConstructors = c.getDeclaredConstructors();
    for (Constructor ctor : allConstructors) {
        int searchMod = Modifier.STATIC;
        int mods = accessModifiers(ctor.getModifiers());
        if (searchMod == mods) {
            System.out.println(ctor);
        }/*from   w  w w .jav a2 s .  co  m*/
    }
}

From source file:Main.java

public static Gson getGson() {
    return new GsonBuilder().excludeFieldsWithModifiers(new int[] { Modifier.STATIC, Modifier.TRANSIENT //, Modifier.FINAL 
    }).excludeFieldsWithoutExposeAnnotation().create();
}

From source file:Main.java

public static Gson getGsonSimple() {
    return new GsonBuilder().excludeFieldsWithModifiers(new int[] { Modifier.STATIC, Modifier.TRANSIENT //, Modifier.FINAL 
    }).create();/*w  w  w. ja  v  a  2s. c  o m*/
}

From source file:Main.java

public static Gson getGsonWithPrettyPrinting() {
    return new GsonBuilder().excludeFieldsWithModifiers(new int[] { Modifier.STATIC, Modifier.TRANSIENT //, Modifier.FINAL 
    }).excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
}

From source file:Main.java

public static Gson getGsonSimpleWithPrettyPrinting() {
    return new GsonBuilder().excludeFieldsWithModifiers(new int[] { Modifier.STATIC, Modifier.TRANSIENT //, Modifier.FINAL 
    }).setPrettyPrinting().create();/*from w w w . j a  v  a  2  s  . c om*/
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Method getStaticMethod(Class clazz, String methodName, Class args[]) {
    try {/*from  w  ww.j  ava  2s. c om*/
        Method method = clazz.getDeclaredMethod(methodName, args);
        if ((method.getModifiers() & Modifier.STATIC) != 0)
            return method;
    } catch (NoSuchMethodException ex) {
    }
    return null;
}

From source file:Main.java

private static int accessModifiers(int m) {
    return m & Modifier.STATIC;
}

From source file:Main.java

/**
 * Stores the classes 'static final' field values as a map.
 * /*from   w  w  w .  j  a  v a  2  s .  c o m*/
 * @param clazz
 *            The class containing static field values.
 * @return A map keyed by static field name to value.
 */
public static Map<String, Object> constantsAsMap(Class<?> clazz) {
    try {
        final Map<String, Object> constants = new HashMap<String, Object>();
        final int staticFinalMods = Modifier.STATIC | Modifier.FINAL;
        for (Field field : clazz.getFields()) {
            if (staticFinalMods == (field.getModifiers() & staticFinalMods)) {
                // this is a constant!
                constants.put(field.getName(), field.get(null));
            }
        }

        return constants;
    } catch (Exception e) {
        // wrap in general error
        throw new IllegalStateException("Unable to initialize class constants for: " + clazz);
    }
}

From source file:Main.java

private static boolean isPublicNoStatic(int i) {
    return ((i & Modifier.PUBLIC) == Modifier.PUBLIC) && ((i & Modifier.STATIC) != Modifier.STATIC);
}

From source file:Main.java

/**
 * Key to lowercase String, extracts the effective key that was pressed
 * (without shift, control, alt)//w w w .j a v a  2 s .  c  om
 */
public static String getKeyText(KeyEvent e) {
    // special cases
    if (e.getKeyCode() == KeyEvent.VK_DELETE) {
        return "delete";
    }
    // prio 1: get text of unresolved code (shift-1 --> '1')
    String s = "" + e.getKeyChar();
    if (e.getKeyCode() > 0) {
        int flags = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
        for (Field f : KeyEvent.class.getFields()) {
            if ((f.getModifiers() & flags) == flags) {
                try {
                    if (f.getName().startsWith("VK_") && ((Integer) f.get(null)) == e.getKeyCode()) {
                        s = f.getName().substring(3).toLowerCase();
                        break;
                    }
                } catch (Throwable t) {
                    // nop
                }
            }
        }
    }
    if (s.length() != 1) {
        // prio 2: check if the resolved char is valid (shift-1 --> '+')
        if (e.getKeyChar() >= 32 && e.getKeyChar() < 128) {
            s = "" + e.getKeyChar();
        }
    }
    return s.toLowerCase();
}