Author: swd847
Date: 2010-03-06 17:07:00 -0500 (Sat, 06 Mar 2010)
New Revision: 6014
Added:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
updated NewAnnotatedTypeBuilder t read annotation data from all fields, not just public
ones
Added:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
---
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
(rev 0)
+++
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-03-06
22:07:00 UTC (rev 6014)
@@ -0,0 +1,118 @@
+package org.jboss.weld.extensions.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * class that provides a way of retrieving all methods and fields from a class
+ *
+ * @author stuart
+ *
+ */
+public class ReflectionUtils
+{
+
+ public static Set<Field> getFields(Class<?> clazz)
+ {
+ HashSet<Field> ret = new HashSet<Field>();
+ Class<?> p = clazz;
+ while (p != Object.class)
+ {
+ for (Field a : p.getDeclaredFields())
+ {
+ ret.add(a);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Field getField(Class<?> parent, String name)
+ {
+ Class<?> p = parent;
+ while (p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredField(name);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static boolean methodExists(Class<?> parent, String name)
+ {
+ Class<?> p = parent;
+ while (p != Object.class)
+ {
+ for (Method m : p.getDeclaredMethods())
+ {
+ if (m.getName().equals(name))
+ {
+ return true;
+ }
+ }
+ p = p.getSuperclass();
+ }
+ return false;
+ }
+
+ public static Set<Method> getMethods(Class<?> clazz)
+ {
+ HashSet<Method> ret = new HashSet<Method>();
+ Class<?> p = clazz;
+ while (p != Object.class)
+ {
+ for (Method a : p.getDeclaredMethods())
+ {
+ ret.add(a);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Method getMethod(Class<?> parent, String name, Class<?>...
args)
+ {
+ Class<?> p = parent;
+ while (p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredMethod(name, args);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static Constructor<?> getConstructor(Class<?> parent,
Class<?>... args)
+ {
+ Class<?> p = parent;
+ while (p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredConstructor(args);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+}
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
===================================================================
---
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-06
21:09:27 UTC (rev 6013)
+++
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-06
22:07:00 UTC (rev 6014)
@@ -15,6 +15,8 @@
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
+import org.jboss.weld.extensions.util.ReflectionUtils;
+
/**
* Class for constructing a new AnnotatedType. A new instance of builder must be
* used for each annotated type.
@@ -51,7 +53,7 @@
typeAnnotations.add(a);
}
- for (Field f : underlying.getFields())
+ for (Field f : ReflectionUtils.getFields(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
fields.put(f, ab);
@@ -61,7 +63,7 @@
}
}
- for (Method m : underlying.getMethods())
+ for (Method m : ReflectionUtils.getMethods(underlying))
{
AnnotationBuilder ab = new AnnotationBuilder();
methods.put(m, ab);
Show replies by date