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:com.manydesigns.elements.forms.AbstractFormBuilder.java

protected boolean skippableProperty(PropertyAccessor propertyAccessor) {
    // static field?
    if (Modifier.isStatic(propertyAccessor.getModifiers())) {
        return true;
    }/* w ww .j  a  v  a  2 s .c  om*/
    // blacklisted?
    if (ArrayUtils.contains(PROPERTY_NAME_BLACKLIST, propertyAccessor.getName())) {
        return true;
    }
    return false;
}

From source file:io.mandrel.common.schema.SchemaTest.java

public void inspect(int level, Type clazz, String name) {

    if (level > 6)
        return;//from  w  ww  .j  av a2s  . c om
    if (clazz instanceof Class && clazz.equals(LinkFilter.class))
        return;

    if (clazz instanceof Class && !((Class<?>) clazz).isEnum() && ((Class<?>) clazz).getPackage() != null
            && ((Class<?>) clazz).getPackage().getName().startsWith("io.mandrel")) {
        int newLevel = level + 1;

        List<Field> fields = new ArrayList<Field>();
        Class<?> i = ((Class<?>) clazz);
        while (i != null && i != Object.class) {
            fields.addAll(Arrays.asList(i.getDeclaredFields()));
            i = i.getSuperclass();
        }

        for (Field field : fields) {
            Class<?> fieldType = field.getType();
            String text;
            if (!field.isAnnotationPresent(JsonIgnore.class) && !Modifier.isStatic(field.getModifiers())) {
                if (List.class.equals(fieldType) || Map.class.equals(fieldType)) {
                    Type type = field.getGenericType();
                    if (type instanceof ParameterizedType) {
                        ParameterizedType pType = (ParameterizedType) type;
                        for (Type paramType : pType.getActualTypeArguments()) {
                            if (paramType instanceof Class
                                    && NamedDefinition.class.isAssignableFrom((Class) paramType)) {
                                text = field.getName() + "(container of " + paramType + " oneOf)";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                        .getType();
                                Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                map.forEach((k, v) -> {
                                    String text2 = k;
                                    System.err.println(StringUtils.leftPad(text2, text2.length() + newLevel * 5,
                                            "\t-   "));
                                    inspect(newLevel, v.getClass(), field.getName());
                                });
                            } else if (paramType instanceof ParameterizedType && NamedDefinition.class
                                    .isAssignableFrom((Class) ((ParameterizedType) paramType).getRawType())) {
                                text = field.getName() + "(container of " + paramType + " oneOf2)";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) ((ParameterizedType) paramType)
                                        .getRawType();
                                Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                map.forEach((k, v) -> {
                                    String text2 = k;
                                    System.err.println(StringUtils.leftPad(text2, text2.length() + newLevel * 5,
                                            "\t-   "));
                                    inspect(newLevel, v.getClass(), field.getName());
                                });
                            } else if (paramType instanceof WildcardType) {
                                for (Type wildType : ((WildcardType) paramType).getUpperBounds()) {
                                    if (wildType instanceof Class
                                            && NamedDefinition.class.isAssignableFrom((Class) wildType)) {
                                        text = field.getName() + "(container of " + wildType + " oneOf)";
                                        System.err.println(StringUtils.leftPad(text,
                                                text.length() + newLevel * 5, "\t-   "));
                                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                                .getType();
                                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                        map.forEach((k, v) -> {
                                            String text2 = k;
                                            System.err.println(StringUtils.leftPad(text2,
                                                    text2.length() + newLevel * 5, "\t-   "));
                                            inspect(newLevel, v.getClass(), field.getName());
                                        });
                                    } else if (wildType instanceof ParameterizedType
                                            && NamedDefinition.class.isAssignableFrom(
                                                    (Class) ((ParameterizedType) wildType).getRawType())) {
                                        text = field.getName() + "(container of " + wildType + " oneOf2)";
                                        System.err.println(StringUtils.leftPad(text,
                                                text.length() + newLevel * 5, "\t-   "));
                                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) ((ParameterizedType) wildType)
                                                .getRawType();
                                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                                        map.forEach((k, v) -> {
                                            String text2 = k;
                                            System.err.println(StringUtils.leftPad(text2,
                                                    text2.length() + newLevel * 5, "\t-   "));
                                            inspect(newLevel, v.getClass(), field.getName());
                                        });
                                    }
                                }
                            } else {
                                text = field.getName() + "(container of " + paramType + ")";
                                System.err.println(
                                        StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                                inspect(newLevel, paramType, "");
                            }
                        }
                    }
                } else {
                    if (NamedDefinition.class.isAssignableFrom(field.getType())) {
                        text = field.getName() + " oneOf";
                        System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                        Class<? extends NamedDefinition> nd = (Class<? extends NamedDefinition>) field
                                .getType();
                        Map<String, ? extends NamedDefinition> map = NamedProviders.get(nd);
                        map.forEach((k, v) -> {
                            String text2 = k;
                            System.err.println(
                                    StringUtils.leftPad(text2, text2.length() + newLevel * 5, "\t-   "));
                            inspect(newLevel, v.getClass(), field.getName());
                        });
                    } else {
                        text = field.getName()
                                + (field.getType().isPrimitive() || field.getType().equals(String.class)
                                        || field.getType().equals(LocalDateTime.class)
                                                ? " (" + field.getType().getName() + ")"
                                                : "");
                        System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                        inspect(newLevel, fieldType, field.getName());
                    }
                }

                // JsonSubTypes subtype =
                // fieldType.getAnnotation(JsonSubTypes.class);
                // if (subtype != null) {
                // int subLevel = level + 2;
                // text = "subtypes:";
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + subLevel * 5, "\t-   "));
                // for (JsonSubTypes.Type type : subtype.value()) {
                // text = "subtype:" + type.name();
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + (subLevel + 1) * 5, "\t-   "));
                // inspect((subLevel + 1), type.value(), type.name());
                // }
                // }
            }
        }

        JsonSubTypes subtype = ((Class<?>) clazz).getAnnotation(JsonSubTypes.class);
        if (subtype != null) {
            int subLevel = level + 1;
            String text = "subtypes:";
            System.err.println(StringUtils.leftPad(text, text.length() + subLevel * 5, "\t-   "));
            for (JsonSubTypes.Type type : subtype.value()) {
                text = "subtype:" + type.name();
                System.err.println(StringUtils.leftPad(text, text.length() + (subLevel + 1) * 5, "\t-   "));
                inspect((subLevel + 1), type.value(), type.name());
            }
        }
    }
}

From source file:net.duckling.falcon.api.orm.DAOUtils.java

/**
 * ??//from   w w w.jav a 2  s.c o m
 * 
 * @param objClass
 *            ?.class
 * */
public DAOUtils(Class<?> objClass) {
    this.objClass = objClass;
    Field[] allFields = objClass.getDeclaredFields();
    List<Field> privateFields = new ArrayList<Field>();
    for (int i = 0; i < allFields.length; i++) {
        if (!Modifier.isStatic(allFields[i].getModifiers()) && Modifier.isPrivate(allFields[i].getModifiers())
                && allFields[i].getAnnotation(TempField.class) == null) {
            privateFields.add(allFields[i]);
        }
    }
    this.fields = new Field[privateFields.size()];
    int index = 0;
    for (Field field : privateFields) {
        this.fields[index++] = field;
    }
}

From source file:com.jetyun.pgcd.rpc.reflect.ClassAnalyzer.java

/**
 * Analyze a class and create a ClassData object containing all of the
 * public methods (both static and non-static) in the class.
 * //from w  w  w.  j a  va  2 s  .  c  o  m
 * @param clazz
 *            class to be analyzed.
 * 
 * @return a ClassData object containing all the public static and
 *         non-static methods that can be invoked on the class.
 */
private static ClassData analyzeClass(Class clazz) {
    log.info("analyzing " + clazz.getName());
    Method methods[] = clazz.getMethods();
    ClassData cd = new ClassData();
    cd.clazz = clazz;

    // Create temporary method map
    HashMap staticMethodMap = new HashMap();
    HashMap methodMap = new HashMap();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getDeclaringClass() == Object.class) {
            continue;
        }
        int mod = methods[i].getModifiers();
        if (!Modifier.isPublic(mod)) {
            continue;
        }
        Class param[] = method.getParameterTypes();

        // don't count locally resolved args
        int argCount = 0;
        for (int n = 0; n < param.length; n++) {
            if (LocalArgController.isLocalArg(param[n])) {
                continue;
            }
            argCount++;
        }

        MethodKey mk = new MethodKey(method.getName(), argCount);
        ArrayList marr = (ArrayList) methodMap.get(mk);
        if (marr == null) {
            marr = new ArrayList();
            methodMap.put(mk, marr);
        }
        marr.add(method);
        if (Modifier.isStatic(mod)) {
            marr = (ArrayList) staticMethodMap.get(mk);
            if (marr == null) {
                marr = new ArrayList();
                staticMethodMap.put(mk, marr);
            }
            marr.add(method);
        }
    }
    cd.methodMap = new HashMap();
    cd.staticMethodMap = new HashMap();
    // Convert ArrayLists to arrays
    Iterator i = methodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.methodMap.put(mk, marr.get(0));
        } else {
            cd.methodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    i = staticMethodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.staticMethodMap.put(mk, marr.get(0));
        } else {
            cd.staticMethodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    return cd;
}

From source file:net.abhinavsarkar.spelhelper.ImplicitMethodResolver.java

@Override
public MethodExecutor resolve(final EvaluationContext context, final Object targetObject, final String name,
        final List<TypeDescriptor> argumentTypes) throws AccessException {
    if (targetObject == null) {
        return null;
    }//from   w w  w .  j a  va 2  s  .c  o m
    Class<?> type = targetObject.getClass();
    String cacheKey = type.getName() + "." + name;
    if (CACHE.containsKey(cacheKey)) {
        MethodExecutor executor = CACHE.get(cacheKey);
        return executor == NULL_ME ? null : executor;
    }

    Method method = lookupMethod(context, type, name);
    if (method != null) {
        int modifiers = method.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            Class<?> firstParamType = parameterTypes[0];
            if (parameterTypes.length > 0 && firstParamType.isAssignableFrom(type)) {
                List<TypeDescriptor> newArgumentTypes = new ArrayList<TypeDescriptor>();
                newArgumentTypes.add(TypeDescriptor.valueOf(firstParamType));
                newArgumentTypes.addAll(argumentTypes);

                MethodExecutor executor = delegate.resolve(context, method.getDeclaringClass(), name,
                        newArgumentTypes);
                MethodExecutor wrappedExecutor = executor == null ? null : new ImplicitMethodExecutor(executor);
                if (wrappedExecutor == null) {
                    CACHE.putIfAbsent(cacheKey, NULL_ME);
                }
                return wrappedExecutor;
            }
        }
    }
    CACHE.putIfAbsent(cacheKey, NULL_ME);
    return null;
}

From source file:adalid.core.Key.java

private void finaliseFields() {
    String name;/*from  www.  j  av a  2s . com*/
    Class<?> type;
    int modifiers;
    boolean restricted;
    Object o;
    int depth = depth();
    int round = round();
    for (Field field : XS1.getFields(getClass(), Key.class)) { // getClass().getDeclaredFields()
        field.setAccessible(true);
        logger.trace(field);
        name = field.getName();
        type = field.getType();
        if (!KeyField.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 KeyField) {
                finaliseKeyField(field, (KeyField) o);
            }
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            logger.error(errmsg, ThrowableUtils.getCause(ex));
            TLC.getProject().getParser().increaseErrorCount();
        }
    }
}

From source file:org.al.swagger.v2.AbstractSpecCollector.java

public Object createSchemaObject(Class<?> aClass) {
    if (aClass.isArray()) {
        GenericSwaggerSchema schema = new GenericSwaggerSchema();
        schema.setType("array");
        schema.setCollectionFormat("csv");
        schema.setItems(createSchemaObject(aClass.getComponentType()));
        return schema;

    } else if (JDKPrimitiveType.isPrimitiveType(aClass)) {

        SchemaGenerator generator = SimpleTypeFactory.getInstance().getSchemaGenerator(aClass);
        if (generator != null) {
            return generator.generateSchema(aClass);
        } else {//from   ww w .  ja va  2 s  .c o  m
            throw new RuntimeException("Type " + aClass + " not supporeted");

        }

    } else {

        Map<String, Object> schemaMap = new LinkedHashMap<>();

        Map<String, Object> properties = new LinkedHashMap<>();
        schemaMap.put("properties", properties);

        List<Field> fields = Stream.of(aClass.getDeclaredFields())
                .filter(f -> !f.isAnnotationPresent(JsonIgnore.class) && !Modifier.isStatic(f.getModifiers()))
                .collect(Collectors.toList());
        for (Field f : fields) {
            if (f.getName().equalsIgnoreCase("rowId")) {
                properties.put(f.getName(), SimpleTypeFactory.getInstance().getSchemaGenerator(String.class)
                        .generateSchema(String.class));
            } else {
                Object schemaObject = createSchemaObject(f.getType());
                properties.put(f.getName(), schemaObject);
            }

        }

        return schemaMap;
    }

}

From source file:com.evolveum.midpoint.repo.sql.query2.definition.ClassDefinitionParser.java

private JpaEntityDefinition parseClass(Class jpaClass) {

    Class jaxbClass = getJaxbClassForEntity(jpaClass);
    JpaEntityDefinition entity = new JpaEntityDefinition(jpaClass, jaxbClass);
    LOGGER.trace("### {}", entity);

    addVirtualDefinitions(jpaClass, entity);
    Method[] methods = jpaClass.getMethods();

    for (Method method : methods) {
        String methodName = method.getName();
        if (Modifier.isStatic(method.getModifiers()) || "getClass".equals(methodName)
                || (!methodName.startsWith("is") && !methodName.startsWith("get"))
                || method.getAnnotation(NotQueryable.class) != null) {
            //it's not getter for queryable property
            continue;
        }/*from   www. jav a  2 s  .co m*/

        if (method.isAnnotationPresent(Transient.class)) {
            continue;
        }

        LOGGER.trace("# {}", method);

        JpaLinkDefinition linkDefinition;
        OwnerGetter ownerGetter = method.getAnnotation(OwnerGetter.class);
        if (ownerGetter != null) {
            String jpaName = getJpaName(method);
            JpaDataNodeDefinition nodeDefinition = new JpaEntityPointerDefinition(ownerGetter.ownerClass());
            // Owner is considered as not embedded, so we generate left outer join to access it
            // (instead of implicit inner join that would be used if we would do x.owner.y = '...')
            linkDefinition = new JpaLinkDefinition(new ParentPathSegment(), jpaName, null, false,
                    nodeDefinition);
        } else {
            linkDefinition = parseMethod(method);
        }
        entity.addDefinition(linkDefinition);
    }
    return entity;
}

From source file:org.apache.syncope.client.console.wizards.AbstractMappingPanel.java

private static void initFieldNames(final Class<?> entityClass, final Set<String> keys) {
    List<Class<?>> classes = ClassUtils.getAllSuperclasses(entityClass);
    classes.add(entityClass);/* w ww .  j a v a 2 s. c  o m*/
    classes.forEach(clazz -> {
        for (Field field : clazz.getDeclaredFields()) {
            if (!Modifier.isStatic(field.getModifiers()) && !Collection.class.isAssignableFrom(field.getType())
                    && !Map.class.isAssignableFrom(field.getType())) {

                keys.add(field.getName());
            }
        }
    });
}

From source file:com.happyblueduck.lembas.datastore.LembasEntity.java

/**
 * copies values from  lembasEntity to this entity. skip objectKey from that.
 * @param that//from   w ww .ja  v  a2s  .c o  m
 */
public void copy(LembasEntity that) {

    ArrayList<Field> fields = Lists.newArrayList(that.getClass().getFields());
    for (Field f : fields) {
        try {

            int modifiers = f.getModifiers();
            if (Modifier.isPrivate(modifiers))
                continue;
            if (Modifier.isStatic(modifiers))
                continue;
            if (Modifier.isTransient(modifiers))
                continue;
            if (Modifier.isFinal(modifiers))
                continue;
            if (Modifier.isVolatile(modifiers))
                continue;

            if (f.getName().equalsIgnoreCase(LembasUtil.objectKey))
                continue;

            Object value = f.get(that);
            if (value != null)
                this.setField(f, value);

        } catch (IllegalAccessException exception) {
            exception.printStackTrace();
        }
    }
}