Author: pete.muir(a)jboss.org
Date: 2010-04-29 19:54:14 -0400 (Thu, 29 Apr 2010)
New Revision: 6205
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
Removed:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
Log:
minor
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-04-29
23:53:43 UTC (rev 6204)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java 2010-04-29
23:54:14 UTC (rev 6205)
@@ -32,7 +32,7 @@
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
-import org.jboss.weld.extensions.util.ReflectionUtils;
+import org.jboss.weld.extensions.util.Reflections;
/**
* Class for constructing a new AnnotatedType. A new instance of builder must be
@@ -100,7 +100,7 @@
typeAnnotations.add(annotation);
}
- for (Field field : ReflectionUtils.getFields(underlyingType))
+ for (Field field : Reflections.getFields(underlyingType))
{
AnnotationBuilder annotationBuilder = new AnnotationBuilder();
fields.put(field, annotationBuilder);
@@ -111,7 +111,7 @@
}
}
- for (Method method : ReflectionUtils.getMethods(underlyingType))
+ for (Method method : Reflections.getMethods(underlyingType))
{
AnnotationBuilder annotationBuilder = new AnnotationBuilder();
method.setAccessible(true);
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29
23:53:43 UTC (rev 6204)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanInjectionTargetWrapper.java 2010-04-29
23:54:14 UTC (rev 6205)
@@ -16,7 +16,7 @@
*/
package org.jboss.weld.extensions.bean.generic;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getField;
+import static org.jboss.weld.extensions.util.Reflections.getField;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29
23:53:43 UTC (rev 6204)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java 2010-04-29
23:54:14 UTC (rev 6205)
@@ -16,8 +16,8 @@
*/
package org.jboss.weld.extensions.core;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getAnnotationsWithMetatype;
-import static org.jboss.weld.extensions.util.ReflectionUtils.getMemberType;
+import static org.jboss.weld.extensions.util.Reflections.getAnnotationsWithMetatype;
+import static org.jboss.weld.extensions.util.Reflections.getMemberType;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
Deleted:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
---
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29
23:53:43 UTC (rev 6204)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-29
23:54:14 UTC (rev 6205)
@@ -1,201 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
-
-/**
- * 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 != null && 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 != null && p != Object.class)
- {
- try
- {
- return p.getDeclaredField(name);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static <X> AnnotatedField<? super X>
getField(AnnotatedType<X> annotatedType, Field field)
- {
- for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
- {
- if
(annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass())
&& annotatedField.getJavaMember().getName().equals(field.getName()))
- {
- return annotatedField;
- }
- }
- return null;
- }
-
- public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation>
annotations, Class<? extends Annotation> metaAnnotationType)
- {
- Set<Annotation> set = new HashSet<Annotation>();
- for (Annotation annotation : annotations)
- {
- if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
- {
- set.add(annotation);
- }
- }
- return set;
- }
-
-
- public static boolean methodExists(Class<?> parent, String name)
- {
- Class<?> p = parent;
- while (p != null && 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 != null && 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 != null && 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 != null && p != Object.class)
- {
- try
- {
- return p.getDeclaredConstructor(args);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static Set<Constructor<?>> getConstructors(Class<?> clazz)
- {
- HashSet<Constructor<?>> ret = new
HashSet<Constructor<?>>();
- Class<?> p = clazz;
- while (p != null && p != Object.class)
- {
- for (Constructor<?> c : p.getDeclaredConstructors())
- {
- ret.add(c);
- }
- p = p.getSuperclass();
- }
- return ret;
- }
-
- public static Class<?> getMemberType(Member member)
- {
- if (member instanceof Field)
- {
- return ((Field) member).getType();
- }
- else if (member instanceof Method)
- {
- return ((Method) member).getReturnType();
- }
- else if (member instanceof Constructor<?>)
- {
- return ((Constructor<?>) member).getDeclaringClass();
- }
- else
- {
- throw new UnsupportedOperationException("Cannot operate on a member of type
" + member.getClass());
- }
- }
-
-}
Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
(from rev 6200,
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
(rev 0)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-04-29
23:54:14 UTC (rev 6205)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * class that provides a way of retrieving all methods and fields from a class
+ *
+ * @author stuart
+ *
+ */
+public class Reflections
+{
+
+ private Reflections() {}
+
+ public static Set<Field> getFields(Class<?> clazz)
+ {
+ HashSet<Field> ret = new HashSet<Field>();
+ Class<?> p = clazz;
+ while (p != null && 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 != null && p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredField(name);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static <X> AnnotatedField<? super X>
getField(AnnotatedType<X> annotatedType, Field field)
+ {
+ for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
+ {
+ if
(annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass())
&& annotatedField.getJavaMember().getName().equals(field.getName()))
+ {
+ return annotatedField;
+ }
+ }
+ return null;
+ }
+
+ public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation>
annotations, Class<? extends Annotation> metaAnnotationType)
+ {
+ Set<Annotation> set = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ set.add(annotation);
+ }
+ }
+ return set;
+ }
+
+
+ public static boolean methodExists(Class<?> parent, String name)
+ {
+ Class<?> p = parent;
+ while (p != null && 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 != null && 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 != null && 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 != null && p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredConstructor(args);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+
+ public static Set<Constructor<?>> getConstructors(Class<?> clazz)
+ {
+ HashSet<Constructor<?>> ret = new
HashSet<Constructor<?>>();
+ Class<?> p = clazz;
+ while (p != null && p != Object.class)
+ {
+ for (Constructor<?> c : p.getDeclaredConstructors())
+ {
+ ret.add(c);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
+
+ public static Class<?> getMemberType(Member member)
+ {
+ if (member instanceof Field)
+ {
+ return ((Field) member).getType();
+ }
+ else if (member instanceof Method)
+ {
+ return ((Method) member).getReturnType();
+ }
+ else if (member instanceof Constructor<?>)
+ {
+ return ((Constructor<?>) member).getDeclaringClass();
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Cannot operate on a member of type
" + member.getClass());
+ }
+ }
+
+}