Type information is now available.
authorErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 12:59:05 +0000 (12:59 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 12:59:05 +0000 (12:59 +0000)
support/general/src/main/java/org/wamblee/reflection/Accessor.java
support/general/src/main/java/org/wamblee/reflection/FieldAccessor.java
support/general/src/main/java/org/wamblee/reflection/PropertyAccessor.java
support/general/src/test/java/org/wamblee/reflection/AnnotationUtilsTest.java

index 5285e738e79c4f663be161357e3fa4d82ba220f6..f3a4bd505139999120eea64b66484ab6f7b1fb16 100644 (file)
@@ -36,5 +36,11 @@ public interface Accessor<T> {
      * @return Value
      */
     T get(Object aObject);
+    
+    /**
+     * Gets the type of the value.
+     * @return
+     */
+    Class<T> getType();
 }
 
index 0157a71c60a69f9b63be301f501417f674d56181..bbc0a437791b129582760dc2e604b8e184f38ef6 100644 (file)
@@ -64,6 +64,11 @@ public class FieldAccessor<T> implements Accessor<T> {
         return field;
     }
     
+    @Override
+    public Class<T> getType() {
+        return (Class<T>)field.getType();
+    }
+    
     @Override
     public String toString() {
         return "fieldInjection(" + field + ")"; 
index 681665d172dc2a1e6e8ec834cf867f3f023e743b..4bf968cfadb7ccb05925fea1dc0f7aa7d94612e0 100644 (file)
@@ -77,4 +77,9 @@ public class PropertyAccessor<T> implements Accessor<T> {
     public String toString() {
         return "propertyInjection(" + getter + ", " + setter + ")"; 
     }
+    
+    @Override
+    public Class<T> getType() {
+        return (Class<T>)getter.getReturnType();
+    }
 }
\ No newline at end of file
index 0ab685cd0c181c3ae3a00b9f34b6091c8d3d0e12..3245d90715f1df9e523e717d7d512d2a07fbf712 100644 (file)
@@ -93,6 +93,7 @@ public class AnnotationUtilsTest {
         List<Accessor> 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<Accessor> 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);