From a02113269ce07446a4be0f209d9ad52874825892 Mon Sep 17 00:00:00 2001 From: gabrikid Date: Fri, 29 Nov 2013 19:30:42 +0000 Subject: [PATCH] Update FieldAccess.java --- .../reflectasm/FieldAccess.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/com/esotericsoftware/reflectasm/FieldAccess.java b/src/com/esotericsoftware/reflectasm/FieldAccess.java index 2fad277..c98bd16 100644 --- a/src/com/esotericsoftware/reflectasm/FieldAccess.java +++ b/src/com/esotericsoftware/reflectasm/FieldAccess.java @@ -1,4 +1,3 @@ - package com.esotericsoftware.reflectasm; import java.lang.reflect.Field; @@ -14,6 +13,9 @@ import static org.objectweb.asm.Opcodes.*; public abstract class FieldAccess { private String[] fieldNames; + + //added + private Class[] fieldTypes; public int getIndex (String fieldName) { for (int i = 0, n = fieldNames.length; i < n; i++) @@ -32,6 +34,31 @@ public abstract class FieldAccess { public String[] getFieldNames () { return fieldNames; } + + //added + public Class[] getFieldTypes() { + return fieldTypes; + } + + //added + public Class getFieldType(String fieldName) { + return getFieldType(getIndex(fieldName)); + } + + //added + public int getFieldCount() { + return fieldNames.length; + } + + //added + public Class getFieldType(int fieldIndex) { + return fieldTypes[fieldIndex]; + } + + //added + public String getFieldName(int fieldIndex) { + return fieldNames[fieldIndex]; + } abstract public void set (Object instance, int fieldIndex, Object value); @@ -87,8 +114,11 @@ public abstract class FieldAccess { } String[] fieldNames = new String[fields.size()]; - for (int i = 0, n = fieldNames.length; i < n; i++) + Class[] fieldTypes = new Class[fields.size()]; //added + for (int i = 0, n = fieldNames.length; i < n; i++) { fieldNames[i] = fields.get(i).getName(); + fieldTypes[i] = fields.get(i).getType(); //added + } String className = type.getName(); String accessClassName = className + "FieldAccess"; @@ -133,6 +163,7 @@ public abstract class FieldAccess { try { FieldAccess access = (FieldAccess)accessClass.newInstance(); access.fieldNames = fieldNames; + access.fieldTypes = fieldTypes; //added return access; } catch (Exception ex) { throw new RuntimeException("Error constructing field access class: " + accessClassName, ex);