Added ReflectionUtils helper class to find Fields with @Interpolate annotation in superclasses (Interpolators didn't account for Fields in AdvancedPosition inherited by Position)

This commit is contained in:
CrushedPixel
2015-07-12 03:31:52 +02:00
parent 824c80d0d2
commit 6a6873c3d7
3 changed files with 30 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
package eu.crushedpixel.replaymod.interpolation;
import eu.crushedpixel.replaymod.utils.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -20,12 +22,7 @@ public class GenericLinearInterpolation<T extends KeyframeValue> implements Inte
public void addPoint(T point) {
points.add(point);
List<Field> fields = new ArrayList<Field>();
for(Field f : point.getClass().getDeclaredFields()) {
if(f.isAnnotationPresent(Interpolate.class)) {
fields.add(f);
}
}
List<Field> fields = ReflectionUtils.getFieldsToInterpolate(point.getClass());
this.fields = fields.toArray(new Field[fields.size()]);
}

View File

@@ -1,7 +1,8 @@
package eu.crushedpixel.replaymod.interpolation;
import eu.crushedpixel.replaymod.utils.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
@@ -19,12 +20,7 @@ public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSp
public void addPoint(T point) {
this.points.add(point);
List<Field> fields = new ArrayList<Field>();
for(Field f : point.getClass().getDeclaredFields()) {
if(f.isAnnotationPresent(Interpolate.class)) {
fields.add(f);
}
}
List<Field> fields = ReflectionUtils.getFieldsToInterpolate(point.getClass());
this.fields = fields.toArray(new Field[fields.size()]);
}

View File

@@ -0,0 +1,24 @@
package eu.crushedpixel.replaymod.utils;
import eu.crushedpixel.replaymod.interpolation.Interpolate;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
public class ReflectionUtils {
public static List<Field> getFieldsToInterpolate(Class clazz) {
List<Field> fields = new ArrayList<Field>();
for(Field f : clazz.getDeclaredFields()) {
if(f.isAnnotationPresent(Interpolate.class)) fields.add(f);
}
if(clazz.getSuperclass() != Object.class) {
fields.addAll(getFieldsToInterpolate(clazz.getSuperclass()));
}
return fields;
}
}