This commit is contained in:
kamhung
2015-12-04 15:55:25 +08:00
parent 3aa995bf8b
commit 3966da6b7a

View File

@@ -53,14 +53,15 @@ public interface Attribute<T, F> {
public static <T, F> Attribute<T, F> create(String fieldname, final Field field) { public static <T, F> Attribute<T, F> create(String fieldname, final Field field) {
return create((Class<T>) field.getDeclaringClass(), fieldname, field, null, null); return create((Class<T>) field.getDeclaringClass(), fieldname, field, null, null);
} }
/** /**
* 根据一个Class和field名生成 Attribute 对象。 * 根据一个Class和field名生成 Attribute 对象。
* *
* @param <T> * @param <T>
* @param <F> * @param <F>
* @param clazz * @param clazz
* @param fieldname 字段名, 如果该字段不存在则抛异常 * @param fieldname 字段名, 如果该字段不存在则抛异常
* @return * @return
*/ */
public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldname) { public static <T, F> Attribute<T, F> create(Class<T> clazz, final String fieldname) {
try { try {
@@ -230,6 +231,7 @@ public interface Attribute<T, F> {
mv.visitFieldInsn(GETFIELD, interName, field.getName(), Type.getDescriptor(pcolumn)); mv.visitFieldInsn(GETFIELD, interName, field.getName(), Type.getDescriptor(pcolumn));
if (pcolumn != column) { if (pcolumn != column) {
mv.visitMethodInsn(INVOKESTATIC, columnName, "valueOf", "(" + Type.getDescriptor(pcolumn) + ")" + columnDesc, false); mv.visitMethodInsn(INVOKESTATIC, columnName, "valueOf", "(" + Type.getDescriptor(pcolumn) + ")" + columnDesc, false);
m = 2;
} }
} }
} else { } else {
@@ -257,6 +259,7 @@ public interface Attribute<T, F> {
try { try {
java.lang.reflect.Method pm = column.getMethod(pcolumn.getSimpleName() + "Value"); java.lang.reflect.Method pm = column.getMethod(pcolumn.getSimpleName() + "Value");
mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false); mv.visitMethodInsn(INVOKEVIRTUAL, columnName, pm.getName(), Type.getMethodDescriptor(pm), false);
m = 3;
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); //不可能会发生 throw new RuntimeException(ex); //不可能会发生
} }