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

/**
 * Finds a set of constant static byte field declarations in the class that have the given value
 * and whose name match the given pattern
 * @param cl class to search in/*from   w w w  .j  ava 2  s.c om*/
 * @param value value of constant static byte field declarations to match
 * @param regexPattern pattern to match against the name of the field     
 * @return a set of the names of fields, expressed as a string
 */
private static String findConstByteInClass(Class<?> cl, byte value, String regexPattern) {
    Field[] fields = cl.getDeclaredFields();
    Set<String> fieldSet = new HashSet<String>();
    for (Field f : fields) {
        try {
            if (f.getType() == Byte.TYPE && (f.getModifiers() & Modifier.STATIC) != 0
                    && f.getName().matches(regexPattern) && f.getByte(null) == value) {
                fieldSet.add(f.getName());
            }
        } catch (IllegalArgumentException e) {
            //  ignore
        } catch (IllegalAccessException e) {
            //  ignore
        }
    }
    return fieldSet.toString();
}

From source file:com.adaptc.mws.plugins.testing.transformations.LoggingTransformer.java

public static void addLogField(ClassNode classNode, String logName) {
    FieldNode logVariable = new FieldNode(LOG_PROPERTY, Modifier.STATIC | Modifier.PRIVATE,
            new ClassNode(Log.class), classNode,
            new MethodCallExpression(new ClassExpression(new ClassNode(LogFactory.class)), "getLog",
                    new ArgumentListExpression(new ConstantExpression(logName))));

    classNode.addField(logVariable);// w  w  w .  ja  v  a 2 s  . c  o  m
}

From source file:utils.LocoUtils.java

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

From source file:utils.LocoUtils.java

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

From source file:com.netflix.astyanax.util.StringUtils.java

public static <T> String joinClassAttributeValues(final T object, String name, Class<T> clazz) {
    Field[] fields = clazz.getDeclaredFields();

    StringBuilder sb = new StringBuilder();
    sb.append(name).append("[");
    sb.append(org.apache.commons.lang.StringUtils.join(Collections2.transform(
            // Filter any field that does not start with lower case
            // (we expect constants to start with upper case)
            Collections2.filter(Arrays.asList(fields), new Predicate<Field>() {
                @Override//from w  w w .  j  a v a2  s. co m
                public boolean apply(Field field) {
                    if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC)
                        return false;
                    return Character.isLowerCase(field.getName().charAt(0));
                }
            }),
            // Convert field to "name=value". value=*** on error
            new Function<Field, String>() {
                @Override
                public String apply(Field field) {
                    Object value;
                    try {
                        value = field.get(object);
                    } catch (Exception e) {
                        value = "***";
                    }
                    return field.getName() + "=" + value;
                }
            }), ","));
    sb.append("]");

    return sb.toString();
}

From source file:com.github.jiahut.demo.utils.LoggerPostProcessor.java

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

    List<Field> fields = Arrays.asList(bean.getClass().getDeclaredFields());

    for (Field field : fields) {
        if (Logger.class.isAssignableFrom(field.getType()) && field.getAnnotation(InjectLogger.class) != null) {

            logger.debug("Attempting to inject a SLF4J logger on bean: " + bean.getClass());

            if (field != null && (field.getModifiers() & Modifier.STATIC) == 0) {
                field.setAccessible(true);
                try {
                    field.set(bean, LoggerFactory.getLogger(bean.getClass()));
                    logger.debug("Successfully injected a SLF4J logger on bean: " + bean.getClass());
                } catch (IllegalArgumentException e) {
                    logger.warn("Could not inject logger for class: " + bean.getClass(), e);
                } catch (IllegalAccessException e) {
                    logger.warn("Could not inject logger for class: " + bean.getClass(), e);
                }/*from ww w  .  j  a  v a 2 s .c  om*/
            }
        }
    }

    return bean;
}

From source file:utils.LocoUtils.java

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

From source file:utils.LocoUtils.java

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

From source file:com.shenit.commons.utils.GsonUtils.java

private static final GsonBuilder createBuilder() {
    return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").disableHtmlEscaping()
            .excludeFieldsWithModifiers(Modifier.STATIC, Modifier.TRANSIENT);
}

From source file:Spy.java

private static int modifierFromString(String s) {
    int m = 0x0;//from w w  w .j a va 2s .  c  o  m
    if ("public".equals(s))
        m |= Modifier.PUBLIC;
    else if ("protected".equals(s))
        m |= Modifier.PROTECTED;
    else if ("private".equals(s))
        m |= Modifier.PRIVATE;
    else if ("static".equals(s))
        m |= Modifier.STATIC;
    else if ("final".equals(s))
        m |= Modifier.FINAL;
    else if ("transient".equals(s))
        m |= Modifier.TRANSIENT;
    else if ("volatile".equals(s))
        m |= Modifier.VOLATILE;
    return m;
}