Example usage for java.lang.reflect Field getModifiers

List of usage examples for java.lang.reflect Field getModifiers

Introduction

In this page you can find the example usage for java.lang.reflect Field getModifiers.

Prototype

public int getModifiers() 

Source Link

Document

Returns the Java language modifiers for the field represented by this Field object, as an integer.

Usage

From source file:de.ks.flatadocdb.metamodel.Parser.java

protected boolean filterField(Field f) {
    int modifiers = f.getModifiers();
    return !Modifier.isStatic(modifiers);
}

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   w  w w  . j  a  v a2 s.com
            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:java2typescript.jackson.module.StaticFieldExporter.java

public void export(List<Class<?>> classesToConvert) throws IllegalArgumentException {
    for (Class<?> clazz : classesToConvert) {
        if (clazz.isEnum()) {
            continue;
        }//from  ww w  .  jav a2 s . c  o  m
        StaticClassType staticClass = new StaticClassType(clazz.getSimpleName() + CLASS_NAME_EXTENSION, clazz);

        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field field : declaredFields) {
            if (isPublicStaticFinal(field.getModifiers())) {
                Value value;
                try {
                    value = constructValue(module, field.getType(), field.get(null));
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to get value of field " + field, e);
                }
                if (value != null) {
                    staticClass.getStaticFields().put(field.getName(), value);
                }
            }
        }
        if (staticClass.getStaticFields().size() > 0) {
            module.getNamedTypes().put(staticClass.getName(), staticClass);
        }
    }
}

From source file:org.ext4spring.parameter.DefaultParameterBeanService.java

private List<Field> getSupportedFields(Class<?> clazz) {
    List<Field> supportedFields = new ArrayList<Field>();
    for (Field field : clazz.getDeclaredFields()) {
        int modifiers = field.getModifiers();
        if (!Modifier.isStatic(modifiers)) { //!Modifier.isFinal(modifiers) && 
            supportedFields.add(field);/*  w w w . j  a  v  a  2s.co  m*/
        }
    }
    return supportedFields;
}

From source file:net.mindengine.blogix.db.readers.ObjectReader.java

private Map<String, Field> convertOnlyNonStaticFieldsToMap(Field[] declaredFields) {
    Map<String, Field> fields = new HashMap<String, Field>();

    for (Field field : declaredFields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            fields.put(field.getName(), field);
        }/*from   w  ww  .  ja  v  a 2 s  .  co m*/
    }
    return fields;
}

From source file:io.fabric8.cxf.endpoint.BeanValidationAnnotationIntrospector.java

@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
    Member member = m.getMember();
    int modifiers = member.getModifiers();
    if (Modifier.isTransient(modifiers)) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Ignoring transient member " + m);
        }/*  w ww  . j ava  2  s.c  o  m*/
        return true;
    } else if (m instanceof AnnotatedMethod) {
        AnnotatedMethod method = (AnnotatedMethod) m;
        String methodName = method.getName();
        // lets see if there is a transient field of the same name as the getter
        if (methodName.startsWith("get") && method.getParameterCount() == 0) {
            String fieldName = Introspector.decapitalize(methodName.substring(3));
            Class<?> declaringClass = method.getDeclaringClass();
            Field field = findField(fieldName, declaringClass);
            if (field != null) {
                int fieldModifiers = field.getModifiers();
                if (Modifier.isTransient(fieldModifiers)) {
                    LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
                    return true;
                }
            }
        }
    }
    return super.hasIgnoreMarker(m);

}

From source file:com.ankang.report.pool.AbstractReportAliasPool.java

private void mountPrams(LinkedHashMap<String, Class<?>> paramsType, Method method) {

    Class<?>[] parameterTypes = method.getParameterTypes();

    Annotation[][] annotations = method.getParameterAnnotations();

    for (int i = 0; i < parameterTypes.length; i++) {

        if (annotations.length < i) {
            throw new ReportException(
                    "Please add an effective note for the argument, such as: HTTPParam, RequestParam");
        }/*w w w. j a  va  2s.  com*/
        if ((ReportRequest.class.isAssignableFrom(parameterTypes[i]))
                || (!parameterTypes[i].isPrimitive() && !parameterTypes[i].toString().matches("^.+java\\..+$")
                        && parameterTypes[i].toString().matches("^class.+$"))) {

            Field[] fields = parameterTypes[i].getDeclaredFields();
            for (Field field : fields) {
                if (!Modifier.isFinal(field.getModifiers()) || !Modifier.isStatic(field.getModifiers())) {

                    paramsType.put(field.getName(), field.getType());
                }
            }
        } else {
            if (annotations.length >= i && annotations[i].length > 0) {

                paramsType.put(matchPrams(annotations[i][0]), parameterTypes[i]);
            }
        }
    }
}

From source file:com.glaf.core.util.ReflectUtils.java

public static void setFieldValue(Object target, String name, Class<?> type, Object value) {
    if (target == null || StringUtils.isEmpty(name)
            || (value != null && !type.isAssignableFrom(value.getClass()))) {
        return;/*ww w . j a  v a  2s .c  om*/
    }
    Class<?> clazz = target.getClass();
    try {
        Method method = clazz
                .getDeclaredMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), type);
        if (!Modifier.isPublic(method.getModifiers())) {
            method.setAccessible(true);
        }
        method.invoke(target, value);
    } catch (Exception ex) {
        if (LogUtils.isDebug()) {
            logger.debug(ex);
        }
        try {
            Field field = clazz.getDeclaredField(name);
            if (!Modifier.isPublic(field.getModifiers())) {
                field.setAccessible(true);
            }
            field.set(target, value);
        } catch (Exception e) {
            if (LogUtils.isDebug()) {
                logger.debug(e);
            }
        }
    }
}

From source file:com.glaf.core.util.ReflectUtils.java

public static Object getFieldValue(Object object, String fieldName) {
    try {/*w  ww.  j ava  2s. c om*/
        Field field = ReflectionUtils.findField(object.getClass(), fieldName);
        if (!Modifier.isPublic(field.getModifiers())) {
            field.setAccessible(true);
        }
        return ReflectionUtils.getField(field, object);
    } catch (Exception ex) {
        try {
            return BeanUtils.getProperty(object, fieldName);
        } catch (Exception e) {
        }
    }
    return null;
}

From source file:org.apache.drill.exec.store.dfs.FormatPluginOptionsDescriptor.java

/**
 * Uses reflection to extract options based on the fields of the provided config class
 * ("List extensions" field is ignored, pending removal, Char is turned into String)
 * The class must be annotated with {@code @JsonTypeName("type name")}
 * @param pluginConfigClass the config class we want to extract options from through reflection
 *//* ww  w  . jav a2 s  .  c o  m*/
FormatPluginOptionsDescriptor(Class<? extends FormatPluginConfig> pluginConfigClass) {
    this.pluginConfigClass = pluginConfigClass;
    Map<String, TableParamDef> paramsByName = new LinkedHashMap<>();
    Field[] fields = pluginConfigClass.getDeclaredFields();
    // @JsonTypeName("text")
    JsonTypeName annotation = pluginConfigClass.getAnnotation(JsonTypeName.class);
    this.typeName = annotation != null ? annotation.value() : null;
    if (this.typeName != null) {
        paramsByName.put("type", new TableParamDef("type", String.class));
    }
    for (Field field : fields) {
        if (Modifier.isStatic(field.getModifiers())
                // we want to deprecate this field
                || (field.getName().equals("extensions") && field.getType() == List.class)) {
            continue;
        }
        Class<?> fieldType = field.getType();
        if (fieldType == char.class) {
            // calcite does not like char type. Just use String and enforce later that length == 1
            fieldType = String.class;
        }
        paramsByName.put(field.getName(), new TableParamDef(field.getName(), fieldType).optional());
    }
    this.functionParamsByName = unmodifiableMap(paramsByName);
}