Example usage for java.lang.reflect Modifier isStatic

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

Introduction

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

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

Return true if the integer argument includes the static modifier, false otherwise.

Usage

From source file:edu.txstate.dmlab.clusteringwiki.util.StaticInitializerBeanFactoryPostProcessor.java

/**
 * Look for a static setter method for field named fieldName in Method[].
 * Return null if none found./*from  ww  w  .java  2  s .  c om*/
 * @param methods
 * @param fieldName
 * @return
 */
private Method findStaticSetter(Method[] methods, String fieldName) {
    String methodName = setterName(fieldName);
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals(methodName) && Modifier.isStatic(methods[i].getModifiers())) {
            return methods[i];
        }
    }
    return null;
}

From source file:com.github.braully.web.DescriptorHtmlEntity.java

private void addHtmlFormElement(Field field) {
    if (elementsForm == null) {
        elementsForm = new ArrayList<>();
    }//from ww w . j a v a  2  s.  c om
    final int modifiers = field.getModifiers();
    if (!Modifier.isStatic(modifiers) && !hiddenFormProperties.contains(field.getName())) {
        DescriptorHtmlEntity htmlElement = buildDescriptorHtmlEntity(field);
        elementsForm.add(htmlElement);
    }
}

From source file:adalid.core.Tab.java

private void finaliseFields() {
    String name;/*from   w  w  w  . j ava 2  s. c o m*/
    Class<?> type;
    int modifiers;
    boolean restricted;
    Object o;
    int depth = depth();
    int round = round();
    for (Field field : XS1.getFields(getClass(), Tab.class)) { // getClass().getDeclaredFields()
        field.setAccessible(true);
        logger.trace(field);
        name = field.getName();
        type = field.getType();
        if (!TabField.class.isAssignableFrom(type)) {
            continue;
        }
        modifiers = field.getModifiers();
        restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers);
        if (restricted) {
            continue;
        }
        String errmsg = "failed to initialize field \"" + field + "\" at " + this;
        try {
            o = field.get(this);
            if (o == null) {
                logger.debug(message(type, name, o, depth, round));
            } else if (o instanceof TabField) {
                finaliseTabField(field, (TabField) o);
            }
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            logger.error(errmsg, ThrowableUtils.getCause(ex));
            TLC.getProject().getParser().increaseErrorCount();
        }
    }
}

From source file:org.echocat.redprecursor.annotations.utils.AccessAlsoProtectedMembersReflectivePropertyAccessor.java

@Override
protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) {
    Method result = null;/*  ww w.j  av a2  s  .c  o m*/
    final PropertyDescriptor propertyDescriptor = findPropertyDescriptorFor(clazz, propertyName);
    if (propertyDescriptor != null) {
        result = propertyDescriptor.getWriteMethod();
    }
    if (result == null) {
        Class<?> current = clazz;
        final String setterName = "set" + StringUtils.capitalize(propertyName);
        while (result == null && !Object.class.equals(current)) {
            final Method[] potentialMethods = current.getDeclaredMethods();
            for (Method potentialMethod : potentialMethods) {
                if (setterName.equals(potentialMethod.getName())) {
                    if (potentialMethod.getParameterTypes().length == 1) {
                        if (!mustBeStatic || Modifier.isStatic(potentialMethod.getModifiers())) {
                            if (!potentialMethod.isAccessible()) {
                                potentialMethod.setAccessible(true);
                            }
                            result = potentialMethod;
                        }
                    }
                }
            }
            current = current.getSuperclass();
        }
    }
    return result;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void notAllowdModifiers() throws IllegalAccessException {
    Field[] declaredFields = Modifier.class.getDeclaredFields();
    int maxModifierValue = 0;
    for (Field field : declaredFields) {
        int modifiers = field.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)
                && field.getType().equals(Integer.TYPE)) {
            try {
                Integer value = (Integer) field.get(Modifier.class);
                maxModifierValue = Math.max(maxModifierValue, value.intValue());
            } catch (IllegalArgumentException e) {
                throw new AssertionError(e);
            }/*  w  w w . j a v a2  s  .  c o m*/
        }
    }
    maxModifierValue = maxModifierValue << 2;
    try {
        memberCriteria.withModifiers(maxModifierValue);
        throw new AssertionError("modifiers are not allowed");
    } catch (IllegalArgumentException e) {
        String message = e.getMessage();
        assertTrue(message.startsWith("modifiers must be"));
    }
}

From source file:org.apache.brooklyn.util.javalang.MethodAccessibleReflections.java

/**
 * @see {@link Reflections#findAccessibleMethod(Method)}
 *//*from ww  w  .jav a2  s . c  o  m*/
// Similar to org.apache.commons.lang3.reflect.MethodUtils.getAccessibleMethod
// We could delegate to that, but currently brooklyn-utils-common doesn't depend on commons-lang3; maybe it should?
static Maybe<Method> findAccessibleMethod(Method method) {
    if (!isAccessible(method)) {
        String err = "Method is not public, so not normally accessible for " + method;
        if (FIND_ACCESSIBLE_FAILED_LOGGED_METHODS.add(method.toString())) {
            LOG.warn(err + "; usage may subsequently fail");
        }
        return Maybe.absent(err);
    }

    boolean declaringClassAccessible = isAccessible(method.getDeclaringClass());
    if (declaringClassAccessible) {
        return Maybe.of(method);
    }

    // reflectively calling a public method on a private class can fail (unless one first 
    // calls setAccessible). Check if this overrides a public method on a public super-type
    // that we can call instead!

    if (Modifier.isStatic(method.getModifiers())) {
        String err = "Static method not declared on a public class, so not normally accessible for " + method;
        if (FIND_ACCESSIBLE_FAILED_LOGGED_METHODS.add(method.toString())) {
            LOG.warn(err + "; usage may subsequently fail");
        }
        return Maybe.absent(err);
    }

    Maybe<Method> altMethod = tryFindAccessibleEquivalent(method);

    if (altMethod.isPresent()) {
        LOG.debug("Switched method for publicly accessible equivalent: method={}; origMethod={}",
                altMethod.get(), method);
        return altMethod;
    } else {
        String err = "No accessible (overridden) method found in public super-types for method " + method;
        if (FIND_ACCESSIBLE_FAILED_LOGGED_METHODS.add(method.toString())) {
            LOG.warn(err);
        }
        return Maybe.absent(err);
    }
}

From source file:ninja.eivind.hotsreplayuploader.ClientTest.java

@Test
public void testClientIsMainClass() throws Exception {
    String className = parse.select("project > properties > mainClass").text();

    LOG.info("Loading class " + className);
    Class<?> mainClass = Class.forName(className);

    Method main = mainClass.getDeclaredMethod("main", String[].class);
    int modifiers = main.getModifiers();

    Class<?> returnType = main.getReturnType();

    assertEquals("Client is mainClass", Client.class, mainClass);
    assertSame("Main method returns void", returnType, Void.TYPE);
    assertTrue("Main method is static", Modifier.isStatic(modifiers));
    assertTrue("Main method is public", Modifier.isPublic(modifiers));
}

From source file:com.xutils.view.ViewInjectorImpl.java

@SuppressWarnings("ConstantConditions")
private static void injectObject(Object handler, Class<?> handlerType, ViewFinder finder) {

    if (handlerType == null || IGNORED.contains(handlerType)) {
        return;/*from  w  ww  .j av  a  2 s . co m*/
    }

    // inject view
    Field[] fields = handlerType.getDeclaredFields();
    if (fields != null && fields.length > 0) {
        for (Field field : fields) {

            Class<?> fieldType = field.getType();
            if (
            /* ??? */ Modifier.isStatic(field.getModifiers()) ||
            /* ?final */ Modifier.isFinal(field.getModifiers()) ||
            /* ? */ fieldType.isPrimitive() ||
            /* ? */ fieldType.isArray()) {
                continue;
            }

            ViewInject viewInject = field.getAnnotation(ViewInject.class);
            if (viewInject != null) {
                try {
                    View view = finder.findViewById(viewInject.value(), viewInject.parentId());
                    if (view != null) {
                        field.setAccessible(true);
                        field.set(handler, view);
                    } else {
                        throw new RuntimeException("Invalid id(" + viewInject.value() + ") for @ViewInject!"
                                + handlerType.getSimpleName());
                    }
                } catch (Throwable ex) {
                    LogUtil.e(ex.getMessage(), ex);
                }
            }
        }
    }

    // inject event
    Method[] methods = handlerType.getDeclaredMethods();
    if (methods != null && methods.length > 0) {
        for (Method method : methods) {

            if (Modifier.isStatic(method.getModifiers()) || !Modifier.isPrivate(method.getModifiers())) {
                continue;
            }

            //??event
            Event event = method.getAnnotation(Event.class);
            if (event != null) {
                try {
                    // id?
                    int[] values = event.value();
                    int[] parentIds = event.parentId();
                    int parentIdsLen = parentIds == null ? 0 : parentIds.length;
                    //id?ViewInfo???
                    for (int i = 0; i < values.length; i++) {
                        int value = values[i];
                        if (value > 0) {
                            ViewInfo info = new ViewInfo();
                            info.value = value;
                            info.parentId = parentIdsLen > i ? parentIds[i] : 0;
                            method.setAccessible(true);
                            EventListenerManager.addEventMethod(finder, info, event, handler, method);
                        }
                    }
                } catch (Throwable ex) {
                    LogUtil.e(ex.getMessage(), ex);
                }
            }
        }
    }

    injectObject(handler, handlerType.getSuperclass(), finder);
}

From source file:io.github.huherto.springyRecords.BaseTable.java

public Number insert(R record) {

    Field[] fields = recordClass().getFields();
    String autoIncrementFieldName = null;
    if (autoIncrementField != null)
        autoIncrementFieldName = autoIncrementField.getName();
    Map<String, Object> parameters = new HashMap<String, Object>(fields.length);
    for (Field field : fields) {
        int mod = field.getModifiers();
        if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            Column col = field.getAnnotation(Column.class);
            if (col != null && !field.getName().equals(autoIncrementFieldName)) {
                Object value;/*ww  w  .  ja  va2  s .c  om*/
                try {
                    value = field.get(record);
                    parameters.put(col.name(), value);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    if (autoIncrementField != null)
        return insertCommand.executeAndReturnKey(parameters);
    insertCommand.execute(parameters);
    return null;
}

From source file:com.github.geequery.codegen.ast.JavaMethod.java

public boolean isStatic() {
    return Modifier.isStatic(modifier);
}