This commit is contained in:
@@ -185,8 +185,7 @@ public interface Attribute<T, F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据一个getter和setter方法生成 Attribute 对象。
|
* 根据一个getter和setter方法生成 Attribute 对象。 tgetter、setter不能同时为null
|
||||||
* tgetter、setter不能同时为null
|
|
||||||
*
|
*
|
||||||
* @param <T> 依附类的类型
|
* @param <T> 依附类的类型
|
||||||
* @param <F> 字段类型
|
* @param <F> 字段类型
|
||||||
@@ -200,8 +199,7 @@ public interface Attribute<T, F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据Class、getter和setter方法生成 Attribute 对象。
|
* 根据Class、getter和setter方法生成 Attribute 对象。 tgetter、setter不能同时为null
|
||||||
* tgetter、setter不能同时为null
|
|
||||||
*
|
*
|
||||||
* @param <T> 依附类的类型
|
* @param <T> 依附类的类型
|
||||||
* @param <F> 字段类型
|
* @param <F> 字段类型
|
||||||
@@ -223,22 +221,22 @@ public interface Attribute<T, F> {
|
|||||||
*/
|
*/
|
||||||
public static <T> Attribute<T, ?>[] create(Class<T> clazz) {
|
public static <T> Attribute<T, ?>[] create(Class<T> clazz) {
|
||||||
List<Attribute<T, ?>> list = new ArrayList<>();
|
List<Attribute<T, ?>> list = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : clazz.getFields()){
|
for (java.lang.reflect.Field field : clazz.getFields()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
||||||
if(java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
||||||
list.add(create(clazz, field));
|
list.add(create(clazz, field));
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method setter : clazz.getDeclaredMethods()){
|
for (java.lang.reflect.Method setter : clazz.getDeclaredMethods()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(setter.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(setter.getModifiers())) continue;
|
||||||
if(!setter.getName().startsWith("set")) continue;
|
if (!setter.getName().startsWith("set")) continue;
|
||||||
if(setter.getReturnType() != void.class) continue;
|
if (setter.getReturnType() != void.class) continue;
|
||||||
if(setter.getParameterCount() != 1) continue;
|
if (setter.getParameterCount() != 1) continue;
|
||||||
Class t = setter.getParameterTypes()[0];
|
Class t = setter.getParameterTypes()[0];
|
||||||
String prefix = t == boolean.class || t == Boolean.class ? "is" : "get";
|
String prefix = t == boolean.class || t == Boolean.class ? "is" : "get";
|
||||||
java.lang.reflect.Method getter = null;
|
java.lang.reflect.Method getter = null;
|
||||||
try {
|
try {
|
||||||
clazz.getMethod(setter.getName().replaceFirst("set", prefix));
|
getter = clazz.getMethod(setter.getName().replaceFirst("set", prefix));
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list.add(create(clazz, getter, setter));
|
list.add(create(clazz, getter, setter));
|
||||||
@@ -255,16 +253,16 @@ public interface Attribute<T, F> {
|
|||||||
*/
|
*/
|
||||||
public static <T> Attribute<T, ?>[] createGetters(Class<T> clazz) {
|
public static <T> Attribute<T, ?>[] createGetters(Class<T> clazz) {
|
||||||
List<Attribute<T, ?>> list = new ArrayList<>();
|
List<Attribute<T, ?>> list = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : clazz.getFields()){
|
for (java.lang.reflect.Field field : clazz.getFields()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
||||||
if(java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
||||||
list.add(create(clazz, field));
|
list.add(create(clazz, field));
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method method : clazz.getDeclaredMethods()){
|
for (java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(method.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(method.getModifiers())) continue;
|
||||||
if(!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue;
|
if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue;
|
||||||
if(method.getReturnType() == void.class) continue;
|
if (method.getReturnType() == void.class) continue;
|
||||||
if(method.getParameterCount() != 0) continue;
|
if (method.getParameterCount() != 0) continue;
|
||||||
list.add(create(clazz, method, null));
|
list.add(create(clazz, method, null));
|
||||||
}
|
}
|
||||||
return list.toArray(new Attribute[list.size()]);
|
return list.toArray(new Attribute[list.size()]);
|
||||||
@@ -279,24 +277,23 @@ public interface Attribute<T, F> {
|
|||||||
*/
|
*/
|
||||||
public static <T> Attribute<T, ?>[] createSetters(Class<T> clazz) {
|
public static <T> Attribute<T, ?>[] createSetters(Class<T> clazz) {
|
||||||
List<Attribute<T, ?>> list = new ArrayList<>();
|
List<Attribute<T, ?>> list = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : clazz.getFields()){
|
for (java.lang.reflect.Field field : clazz.getFields()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) continue;
|
||||||
if(java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isFinal(field.getModifiers())) continue;
|
||||||
list.add(create(clazz, field));
|
list.add(create(clazz, field));
|
||||||
}
|
}
|
||||||
for(java.lang.reflect.Method method : clazz.getDeclaredMethods()){
|
for (java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
|
||||||
if(java.lang.reflect.Modifier.isStatic(method.getModifiers())) continue;
|
if (java.lang.reflect.Modifier.isStatic(method.getModifiers())) continue;
|
||||||
if(!method.getName().startsWith("set")) continue;
|
if (!method.getName().startsWith("set")) continue;
|
||||||
if(method.getReturnType() != void.class) continue;
|
if (method.getReturnType() != void.class) continue;
|
||||||
if(method.getParameterCount() != 1) continue;
|
if (method.getParameterCount() != 1) continue;
|
||||||
list.add(create(clazz, null, method));
|
list.add(create(clazz, null, method));
|
||||||
}
|
}
|
||||||
return list.toArray(new Attribute[list.size()]);
|
return list.toArray(new Attribute[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据Class、字段别名、getter和setter方法生成 Attribute 对象。
|
* 根据Class、字段别名、getter和setter方法生成 Attribute 对象。 tgetter、setter不能同时为null
|
||||||
* tgetter、setter不能同时为null
|
|
||||||
*
|
*
|
||||||
* @param <T> 依附类的类型
|
* @param <T> 依附类的类型
|
||||||
* @param <F> 字段类型
|
* @param <F> 字段类型
|
||||||
@@ -311,8 +308,7 @@ public interface Attribute<T, F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据Class、字段别名、Field、getter和setter方法生成 Attribute 对象。
|
* 根据Class、字段别名、Field、getter和setter方法生成 Attribute 对象。 Field、tgetter、setter不能同时为null
|
||||||
* Field、tgetter、setter不能同时为null
|
|
||||||
*
|
*
|
||||||
* @param <T> 依附类的类型
|
* @param <T> 依附类的类型
|
||||||
* @param <F> 字段类型
|
* @param <F> 字段类型
|
||||||
|
|||||||
Reference in New Issue
Block a user