From: Erik Brakkee Date: Sat, 31 Jul 2010 12:59:05 +0000 (+0000) Subject: Type information is now available. X-Git-Tag: wamblee-utils-0.7~128 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=a6d2f5e212134ea10d8026875653d6b0d3a199ea;hp=f9f37d08a2c8703b5b112ba07baa7ecd47937b04;p=utils Type information is now available. --- diff --git a/support/general/src/main/java/org/wamblee/reflection/Accessor.java b/support/general/src/main/java/org/wamblee/reflection/Accessor.java index 5285e738..f3a4bd50 100644 --- a/support/general/src/main/java/org/wamblee/reflection/Accessor.java +++ b/support/general/src/main/java/org/wamblee/reflection/Accessor.java @@ -36,5 +36,11 @@ public interface Accessor { * @return Value */ T get(Object aObject); + + /** + * Gets the type of the value. + * @return + */ + Class getType(); } diff --git a/support/general/src/main/java/org/wamblee/reflection/FieldAccessor.java b/support/general/src/main/java/org/wamblee/reflection/FieldAccessor.java index 0157a71c..bbc0a437 100644 --- a/support/general/src/main/java/org/wamblee/reflection/FieldAccessor.java +++ b/support/general/src/main/java/org/wamblee/reflection/FieldAccessor.java @@ -64,6 +64,11 @@ public class FieldAccessor implements Accessor { return field; } + @Override + public Class getType() { + return (Class)field.getType(); + } + @Override public String toString() { return "fieldInjection(" + field + ")"; diff --git a/support/general/src/main/java/org/wamblee/reflection/PropertyAccessor.java b/support/general/src/main/java/org/wamblee/reflection/PropertyAccessor.java index 681665d1..4bf968cf 100644 --- a/support/general/src/main/java/org/wamblee/reflection/PropertyAccessor.java +++ b/support/general/src/main/java/org/wamblee/reflection/PropertyAccessor.java @@ -77,4 +77,9 @@ public class PropertyAccessor implements Accessor { public String toString() { return "propertyInjection(" + getter + ", " + setter + ")"; } + + @Override + public Class getType() { + return (Class)getter.getReturnType(); + } } \ No newline at end of file diff --git a/support/general/src/test/java/org/wamblee/reflection/AnnotationUtilsTest.java b/support/general/src/test/java/org/wamblee/reflection/AnnotationUtilsTest.java index 0ab685cd..3245d907 100644 --- a/support/general/src/test/java/org/wamblee/reflection/AnnotationUtilsTest.java +++ b/support/general/src/test/java/org/wamblee/reflection/AnnotationUtilsTest.java @@ -93,6 +93,7 @@ public class AnnotationUtilsTest { List accessors = AnnotationUtils.analyse(X1.class, MyAnnotation.class); assertEquals(1, accessors.size()); assertTrue(accessors.get(0) instanceof FieldAccessor); + assertEquals(int.class, accessors.get(0).getType()); X1 obj = new X1(); assertEquals(0, obj.x); @@ -116,6 +117,7 @@ public class AnnotationUtilsTest { List accessors = AnnotationUtils.analyse(X3.class, MyAnnotation.class); assertEquals(1, accessors.size()); assertTrue(accessors.get(0) instanceof PropertyAccessor); + assertEquals(int.class, accessors.get(0).getType()); X3 obj = new X3(); assertEquals(0, obj.x); accessors.get(0).set(obj, 100);