List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
From source file:Main.java
public static Field[] getAllFiedFromClassAndSuper(Class clazz, boolean needStatic) { ArrayList<Field> fields = new ArrayList<>(); if (clazz != null) { Field[] classFields = clazz.getDeclaredFields(); if (classFields != null) { for (Field field : classFields) { boolean isStatic = Modifier.isStatic(field.getModifiers()); if (isStatic && !needStatic) { continue; }//from w w w. j av a 2 s .c om fields.add(field); } } Field[] superFields = getAllFiedFromClassAndSuper(clazz.getSuperclass(), needStatic); if (superFields != null) { for (Field field : superFields) { boolean isStatic = Modifier.isStatic(field.getModifiers()); if (isStatic && !needStatic) { continue; } fields.add(field); } } } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
public static Method getGetter(Object bean, String property) { Map<String, Method> cache = GETTER_CACHE.get(bean.getClass()); if (cache == null) { cache = new ConcurrentHashMap<String, Method>(); for (Method method : bean.getClass().getMethods()) { if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && !void.class.equals(method.getReturnType()) && method.getParameterTypes().length == 0) { String name = method.getName(); if (name.length() > 3 && name.startsWith("get")) { cache.put(name.substring(3, 4).toLowerCase() + name.substring(4), method); } else if (name.length() > 2 && name.startsWith("is")) { cache.put(name.substring(2, 3).toLowerCase() + name.substring(3), method); }/*from ww w . j a v a2 s. co m*/ } } Map<String, Method> old = GETTER_CACHE.putIfAbsent(bean.getClass(), cache); if (old != null) { cache = old; } } return cache.get(property); }
From source file:ReflectionUtils.java
/** * Determine whether the given field is a "public static final" constant. * @param field the field to check/*from ww w.j a v a2 s . c om*/ */ public static boolean isPublicStaticFinal(Field field) { int modifiers = field.getModifiers(); return (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)); }
From source file:com.yahoo.egads.data.JsonEncoder.java
public static void // modifies json_out toJson(Object object, JSONStringer json_out) throws Exception { json_out.object();//from w w w . j a va 2s. c o m // for each inherited class... for (Class c = object.getClass(); c != Object.class; c = c.getSuperclass()) { // for each member variable... Field[] fields = c.getDeclaredFields(); for (Field f : fields) { // if variable is static/private... skip it if (Modifier.isStatic(f.getModifiers())) { continue; } if (Modifier.isPrivate(f.getModifiers())) { continue; } Object value = f.get(object); // if variable is a complex type... recurse on sub-objects if (value instanceof JsonAble) { json_out.key(f.getName()); ((JsonAble) value).toJson(json_out); // if variable is an array... recurse on sub-objects } else if (value instanceof ArrayList) { json_out.key(f.getName()); json_out.array(); for (Object e : (ArrayList) value) { toJson(e, json_out); } json_out.endArray(); // if variable is a simple type... convert to json } else { json_out.key(f.getName()).value(value); } } } json_out.endObject(); }
From source file:Main.java
/** * get the method start with 'get' or 'is'. *///from ww w.ja va 2 s .c om public static Method getGetter(Object bean, String property) { Map<String, Method> cache = GETTER_CACHE.get(bean.getClass()); if (cache == null) { cache = new ConcurrentHashMap<>(); for (Method method : bean.getClass().getMethods()) { if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && !void.class.equals(method.getReturnType()) && method.getParameterTypes().length == 0) { String name = method.getName(); if (name.length() > 3 && name.startsWith("get")) { cache.put(name.substring(3, 4).toLowerCase() + name.substring(4), method); } else if (name.length() > 2 && name.startsWith("is")) { cache.put(name.substring(2, 3).toLowerCase() + name.substring(3), method); } } } Map<String, Method> old = GETTER_CACHE.putIfAbsent(bean.getClass(), cache); if (old != null) { cache = old; } } return cache.get(property); }
From source file:ReflectUtils.java
/** * Adds all static Fields (from Class.getFields) to the list * @param aClass/* ww w. j a va2 s. co m*/ * @param list * @return number of fields added */ public static int addStaticFields(Class aClass, List<Member> list) { Field[] fields = aClass.getFields(); for (Field f : fields) { if (Modifier.isStatic(f.getModifiers())) { list.add(f); } } return fields.length; }
From source file:ReflectUtils.java
/** * Adds all static methods (from Class.getMethodCalls) to the list * @param aClass/* ww w . j a v a 2 s. c om*/ * @param list * @return number of methods added */ public static int addStaticMethods(Class aClass, List<Member> list) { Method[] methods = aClass.getMethods(); for (Method m : methods) { if (Modifier.isStatic(m.getModifiers())) { list.add(m); } } return methods.length; }
From source file:com.greenline.hrs.admin.util.db.SchemaExport.java
public static String exportMySQL(Class type) { if (type == null) { return StringUtils.EMPTY; }//www . jav a2s . c om String tableName = type.getName().substring(type.getName().lastIndexOf('.') + 1); tableName = StringUtil.underscoreName(tableName); StringBuilder sb = new StringBuilder(); sb.append("DROP TABLE IF EXISTS `" + tableName + "`;" + LINUX_LINE_DELIMITER); sb.append("CREATE TABLE `"); sb.append(tableName); sb.append("` (" + LINUX_LINE_DELIMITER + LINUX_LINE_DELIMITER); sb.append("`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '',"); Field[] fields = type.getDeclaredFields(); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers())) { sb.append("`" + StringUtil.underscoreName(field.getName()) + "` " + JdbcColumnUtil.getColumeTypeDesc(field.getType()) + " NOT NULL COMMENT ''," + LINUX_LINE_DELIMITER); } } sb.append("PRIMARY KEY (`id`)" + LINUX_LINE_DELIMITER); sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;"); return sb.toString(); }
From source file:edu.temple.cis3238.wiki.parser.TagsFromContentParser.java
/** * * @param f * @return */ public static boolean isStaticField(Field f) { return Modifier.isStatic(f.getModifiers()); }
From source file:Main.java
/** * get all fields for a class/* w w w. j av a 2s . co m*/ * * @param type * @return all fields indexed by their names */ private static Map<String, Field> getAllFields(Class<?> type) { Map<String, Field> fields = new HashMap<String, Field>(); Class<?> currentType = type; while (!currentType.equals(Object.class)) { for (Field field : currentType.getDeclaredFields()) { int mod = field.getModifiers(); /* * by convention, our fields should not have any modifier */ if (mod == 0 || Modifier.isProtected(mod) && !Modifier.isStatic(mod)) { fields.put(field.getName(), field); } } currentType = currentType.getSuperclass(); } return fields; }