List of usage examples for java.lang Class getDeclaredFields
@CallerSensitive public Field[] getDeclaredFields() throws SecurityException
From source file:com.mmj.app.common.file.ExcelUtils.java
public static Field[] getAllFields(List<Field> fields, Class<?> type) { for (Field field : type.getDeclaredFields()) { fields.add(field);//from ww w . jav a2 s .c om } if (type.getSuperclass() != null) { fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass()))); } return fields.toArray(new Field[fields.size()]); }
From source file:ClassUtil.java
/** * Retrieving fields list of specified class * If recursively is true, retrieving fields from all class hierarchy * * @param clazz where fields are searching * @param recursively param/*from w w w .ja va 2s.c om*/ * @return list of fields */ public static Field[] getDeclaredFields(Class clazz, boolean recursively) { List<Field> fields = new LinkedList<Field>(); Field[] declaredFields = clazz.getDeclaredFields(); Collections.addAll(fields, declaredFields); Class superClass = clazz.getSuperclass(); if (superClass != null && recursively) { Field[] declaredFieldsOfSuper = getDeclaredFields(superClass, recursively); if (declaredFieldsOfSuper.length > 0) Collections.addAll(fields, declaredFieldsOfSuper); } return fields.toArray(new Field[fields.size()]); }
From source file:io.tilt.minka.utils.Defaulter.java
private static List<Field> getStaticDefaults(Class<?> clas) { final Field[] declaredFields = clas.getDeclaredFields(); final List<Field> staticFields = new ArrayList<Field>(); for (Field field : declaredFields) { if (Modifier.isStatic(field.getModifiers())) { staticFields.add(field);/*from w w w.j av a 2 s. c o m*/ } } return staticFields; }
From source file:com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials.java
static private <T> String getFieldVersion(Class<T> clazz, T obj, String artifactName) { Optional<Field> field = Arrays.stream(clazz.getDeclaredFields()).filter(f -> { boolean nameMatches = f.getName().equals(artifactName); boolean propertyMatches = false; JsonProperty property = f.getDeclaredAnnotation(JsonProperty.class); if (property != null) { propertyMatches = property.value().equals(artifactName); }// w w w . j av a 2 s . com return nameMatches || propertyMatches; }).findFirst(); try { return ((Artifact) field.orElseThrow(() -> new NoKnownArtifact(artifactName)).get(obj)).getVersion(); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NullPointerException e) { throw new RuntimeException("Versioned artifact " + artifactName + " is not listed in the BOM"); } }
From source file:ea.compoment.db.util.sql.UpdateSqlBuilder.java
/** * ,?/*from ww w .java 2 s .c o m*/ * * @return * @throws DBException * @throws IllegalArgumentException * @throws IllegalAccessException */ public static NVArrayList getFieldsAndValue(Object entity) throws DBException, IllegalArgumentException, IllegalAccessException { NVArrayList arrayList = new NVArrayList(); if (entity == null) { throw new DBException("?"); } Class<?> clazz = entity.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!DBAnnoUtils.isTransient(field)) { if (DBAnnoUtils.isBaseDateType(field)) { PrimaryKey annotation = field.getAnnotation(PrimaryKey.class); if (annotation == null || !annotation.autoIncrement()) { String columnName = DBAnnoUtils.getColumnByField(field); field.setAccessible(true); arrayList.add((columnName != null && !columnName.equals("")) ? columnName : field.getName(), field.get(entity) == null ? null : field.get(entity).toString()); } } } } return arrayList; }
From source file:io.apiman.plugins.keycloak_oauth_policy.ClaimLookup.java
private static void getProperties(Class<?> klazz, String path, Deque<Field> fieldChain) { for (Field f : klazz.getDeclaredFields()) { f.setAccessible(true);/*w ww . jav a2s. c om*/ JsonProperty jsonProperty = f.getAnnotation(JsonProperty.class); if (jsonProperty != null) { fieldChain.push(f); // If the inspected type has nested @JsonProperty annotations, we need to inspect it if (hasJsonPropertyAnnotation(f)) { getProperties(f.getType(), f.getName() + ".", fieldChain); // Add "." when traversing into new object. } else { // Otherwise, just assume it's simple as the best we can do is #toString List<Field> fieldList = new ArrayList<>(fieldChain); Collections.reverse(fieldList); STANDARD_CLAIMS_FIELD_MAP.put(path + jsonProperty.value(), fieldList); fieldChain.pop(); // Pop, as we have now reached end of this chain. } } } }
From source file:cn.xdf.thinkutils.db2.util.sql.UpdateSqlBuilder.java
/** * ,?/*from w ww . j a v a 2 s . c o m*/ * * @return * @throws DBException * @throws IllegalArgumentException * @throws IllegalAccessException */ public static ArrayListEx getFieldsAndValue(Object entity) throws DBException, IllegalArgumentException, IllegalAccessException { // TODO Auto-generated method stub ArrayListEx arrayList = new ArrayListEx(); if (entity == null) { throw new DBException("?"); } Class<?> clazz = entity.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!DBUtils.isTransient(field)) { if (DBUtils.isBaseDateType(field)) { PrimaryKey annotation = field.getAnnotation(PrimaryKey.class); if (annotation == null || !annotation.autoIncrement()) { String columnName = DBUtils.getColumnByField(field); field.setAccessible(true); arrayList.add((columnName != null && !columnName.equals("")) ? columnName : field.getName(), field.get(entity) == null ? null : field.get(entity).toString()); } } } } return arrayList; }
From source file:com.alading.library.util.db.util.sql.TAUpdateSqlBuilder.java
/** * ,?//from w ww . jav a 2 s . c o m * * @return * @throws TADBException * @throws IllegalArgumentException * @throws IllegalAccessException */ public static TAArrayList getFieldsAndValue(Object entity) throws TADBException, IllegalArgumentException, IllegalAccessException { // TODO Auto-generated method stub TAArrayList arrayList = new TAArrayList(); if (entity == null) { throw new TADBException("?"); } Class<?> clazz = entity.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!TADBUtils.isTransient(field)) { if (TADBUtils.isBaseDateType(field)) { TAPrimaryKey annotation = field.getAnnotation(TAPrimaryKey.class); if (annotation == null || !annotation.autoIncrement()) { String columnName = TADBUtils.getColumnByField(field); field.setAccessible(true); arrayList.add((columnName != null && !columnName.equals("")) ? columnName : field.getName(), field.get(entity) == null ? null : field.get(entity).toString()); } } } } return arrayList; }
From source file:com.witness.utils.db.util.sql.TAUpdateSqlBuilder.java
/** * ,?//from w ww .j av a2s . c o m * * @return * @throws TADBException * @throws IllegalArgumentException * @throws IllegalAccessException */ public static TAArrayList getFieldsAndValue(Object entity) throws TADBException, IllegalArgumentException, IllegalAccessException { // TODO Auto-generated method stub TAArrayList arrayList = new TAArrayList(); if (entity == null) { throw new TADBException("?"); } Class<?> clazz = entity.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!TADBUtils.isTransient(field)) { if (TADBUtils.isBaseDateType(field)) { DBPrimaryKey annotation = field.getAnnotation(DBPrimaryKey.class); if (annotation == null || !annotation.autoIncrement()) { String columnName = TADBUtils.getColumnByField(field); field.setAccessible(true); arrayList.add((columnName != null && !columnName.equals("")) ? columnName : field.getName(), field.get(entity) == null ? null : field.get(entity).toString()); } } } } return arrayList; }
From source file:ch.ifocusit.plantuml.utils.ClassUtils.java
public static Optional<Field> getField(Class container, Class aClass) { return Stream.of(container.getDeclaredFields()) .filter(attr -> getConcernedTypes(attr).stream().anyMatch(fieldType -> fieldType.equals(aClass))) .findFirst();/*from w w w . jav a 2 s . c o m*/ }