List of usage examples for java.lang.reflect Field getName
public String getName()
From source file:ShowClass.java
/** Print the modifiers, type, and name of a field */ public static void print_field(Field f) { System.out.println(" " + modifiers(f.getModifiers()) + typename(f.getType()) + " " + f.getName() + ";"); }
From source file:Main.java
public static String[] getClassStaticFieldNames(Class c, Type fieldType, String nameContains) { Field[] fields = c.getDeclaredFields(); List<String> list = new ArrayList<>(); for (Field field : fields) { try {//from w ww.j a v a2 s. com boolean isString = field.getType().equals(fieldType); boolean containsExtra = field.getName().contains(nameContains); boolean isStatic = Modifier.isStatic(field.getModifiers()); if (field.getType().equals(String.class) && field.getName().contains("EXTRA_") && Modifier.isStatic(field.getModifiers())) list.add(String.valueOf(field.get(null))); } catch (IllegalAccessException iae) { Log.d(TAG, "!!!!!!!!!!!! class Static field, illegal access exception message: " + iae.getMessage()); } } return list.toArray(new String[list.size()]); }
From source file:Main.java
public static String createTableSql(Class<?> classs, String tableName, String... extraColumns) { mBuffer.setLength(0);//w ww. j av a 2s . com mBuffer.append("CREATE TABLE IF NOT EXISTS "); if (!TextUtils.isEmpty(tableName)) { mBuffer.append(tableName); } else { String className = classs.getSimpleName(); if (className.contains("[]")) { throw new IllegalArgumentException("Can not create array class table"); } mBuffer.append(classs.getSimpleName()); } mBuffer.append("(" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "); Field[] fields = classs.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (field.getType() == Integer.class) { mBuffer.append(field.getName() + " INTEGER,"); } else if (field.getType() == Double.class || field.getType() == Float.class) { mBuffer.append(field.getName() + " REAL,"); } else if (field.getType() == String.class) { mBuffer.append(field.getName() + " TEXT,"); } else if (field.getType() == Boolean.class) { mBuffer.append(field.getName() + " INTEGER,"); } else if (field.getType() == List.class || field.getType() == ArrayList.class) { mBuffer.append(field.getName() + " TEXT,"); } } if (extraColumns != null && extraColumns.length != 0) { for (int i = 0; i < extraColumns.length; i++) { mBuffer.append(extraColumns[i]); if (i != extraColumns.length - 1) { mBuffer.append(","); } else { mBuffer.append(")"); } } } return mBuffer.toString(); }
From source file:org.granite.grails.integration.GrailsExternalizer.java
public static boolean isIgnored(Field field) { if (EVENTS.contains(field.getName())) return true; if (field.getName().equals("errors") && field.getType().getName().equals(ERRORS)) return true; return false; }
From source file:net.eledge.android.toolkit.db.internal.SQLBuilder.java
public static String getFieldName(Field field) { Column column = field.getAnnotation(Column.class); return StringUtils.defaultIfBlank(column.name(), field.getName().toLowerCase(Locale.ENGLISH)); }
From source file:com.google.code.simplestuff.bean.BusinessObjectAnnotationParser.java
/** * Retrieves a "field-value" map of all properties of the given * object annotated as <code>BusinessField</code>s. * <p>/*from w w w . j av a 2s .c o m*/ * These should constitute a "business key" for this object * * @param object the object whose properties should be examined * @return a map of all appropriately annotated fields */ static Map<String, Object> retrieveBusinessFields(Object object) { Map<String, Object> businessProperties = new HashMap<String, Object>(); for (Field field : collectAnnotatedFields(object.getClass())) { String propertyName = field.getName(); try { businessProperties.put(propertyName, PropertyUtils.getProperty(object, propertyName)); } catch (Exception exception) { // ignore any of the exceptions that can be thrown and simply // skip the property } } return businessProperties; }
From source file:com.prepaird.objectgraphdb.utils.Utils.java
public static String getSetterName(Field f) { return "set" + WordUtils.capitalize(f.getName()); }
From source file:com.xhsoft.framework.common.utils.ReflectUtil.java
/** * <p>Description:ReflectionMap?</p> * @param target/*ww w. ja v a2 s .c om*/ * @return Map<String,Object> * @author wanggq * @since 2009-9-9 */ @SuppressWarnings("unchecked") public static Map<String, Object> getMapFieldData(Object target) { Map<String, Object> map = new HashMap<String, Object>(); Class clazz = target.getClass(); Field[] fields = clazz.getDeclaredFields(); Method[] methods = clazz.getDeclaredMethods(); for (Field field : fields) { String fieldName = field.getName(); if ("messageTypeId".equals(fieldName)) { continue; } String getMethod = "get" + StringUtils.capitalize(fieldName); for (Method method : methods) { if (method.getName().equals(getMethod)) { try { Object ret = method.invoke(target, null); map.put(fieldName, ret); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } return map; }
From source file:eu.eubrazilcc.lvl.core.util.QueryUtils.java
public static List<FormattedQueryParam> formattedQuery(final ImmutableMap<String, String> params, final Class<?> target) { checkArgument(params != null, "Uninitialized parameters"); checkArgument(target != null, "Uninitialized target class"); final Field[] fields = target.getDeclaredFields(); final Function<String, Boolean> fieldValidator = new Function<String, Boolean>() { @Override/* ww w .jav a2 s . c o m*/ public Boolean apply(final String name) { for (final Field field : fields) { if (field.getName().equalsIgnoreCase(name)) { return true; } } return false; } }; return newArrayList(transformEntries(params, new EntryTransformer<String, String, FormattedQueryParam>() { @Override public FormattedQueryParam transformEntry(final String key, final String value) { final boolean isField = !TEXT_FIELD.equals(key); return FormattedQueryParam.builder() .term((isField ? escape(key) + KEYWORD_SEPARATOR : "") + escape(value)) .validity(isField ? fieldValidator.apply(key) : true).build(); } }).values()); }
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 ww . j a v a 2 s .co m * @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(); }