[weld-commits] Weld SVN: r5204 - extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Thu Dec 3 10:56:39 EST 2009
Author: pete.muir at jboss.org
Date: 2009-12-03 10:56:38 -0500 (Thu, 03 Dec 2009)
New Revision: 5204
Added:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
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/TypeClosureBuilder.java
Removed:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeStore.java
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
Log:
WELDX-55
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedCallable.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -1,11 +1,10 @@
package org.jboss.weld.extensions.util.annotated;
-import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedParameter;
@@ -16,58 +15,43 @@
* @author Stuart Douglas
*
*/
-public abstract class AbstractNewAnnotatedCallable<X, Y extends Member> extends AbstractNewAnnotatedMember<X, Y> implements AnnotatedCallable<X>
+abstract class AbstractNewAnnotatedCallable<X, Y extends Member> extends AbstractNewAnnotatedMember<X, Y> implements AnnotatedCallable<X>
{
- private final List<NewAnnotatedParameter<X>> parameters = new ArrayList<NewAnnotatedParameter<X>>();
+ private final List<AnnotatedParameter<X>> parameters;
- protected AbstractNewAnnotatedCallable(AnnotatedType<X> type, Method method, boolean readAnnotations)
+ protected AbstractNewAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations)
{
- super(type, (Y) method, method.getReturnType(), readAnnotations);
- int len = method.getTypeParameters().length;
- for (int i = 0; i < len; ++i)
- {
- NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(this, method.getParameterTypes()[i], i, readAnnotations);
- parameters.add(p);
- }
+ super(declaringType, member, memberType, annotations);
+ this.parameters = getAnnotatedParameters(this, parameterTypes, parameterAnnotations);
}
- protected AbstractNewAnnotatedCallable(AnnotatedType<X> type, Constructor<X> constructor, boolean readAnnotations)
- {
- super(type, (Y) constructor, constructor.getDeclaringClass(), readAnnotations);
- int len = constructor.getTypeParameters().length;
- for (int i = 0; i < len; ++i)
- {
- NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(this, constructor.getParameterTypes()[i], i, readAnnotations);
- parameters.add(p);
- }
- }
-
-
- @Override
- public void clearAllAnnotations()
- {
- super.clearAllAnnotations();
- for (NewAnnotatedParameter<X> p : parameters)
- {
- p.clearAllAnnotations();
- }
- }
-
public List<AnnotatedParameter<X>> getParameters()
{
- return (List) Collections.unmodifiableList(parameters);
- }
-
- public List<NewAnnotatedParameter<X>> getNewAnnotatedParameters()
- {
return Collections.unmodifiableList(parameters);
}
- public NewAnnotatedParameter<X> getParameter(int index)
+ public AnnotatedParameter<X> getParameter(int index)
{
return parameters.get(index);
+ }
+
+ private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractNewAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Map<Integer, AnnotationStore> parameterAnnotations)
+ {
+ List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+ int len = parameterTypes.length;
+ for (int i = 0; i < len; ++i)
+ {
+ AnnotationBuilder builder = new AnnotationBuilder();
+ if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+ {
+ builder.addAll(parameterAnnotations.get(i));
+ }
+ NewAnnotatedParameter<X> p = new NewAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create());
+ parameters.add(p);
+ }
+ return parameters;
}
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedElement.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -2,6 +2,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Collections;
import java.util.Set;
import javax.enterprise.inject.spi.Annotated;
@@ -12,44 +13,27 @@
* @author Stuart Douglas
*
*/
-public abstract class AbstractNewAnnotatedElement implements Annotated
+abstract class AbstractNewAnnotatedElement implements Annotated
{
private final Class<?> type;
+ private final Set<Type> typeClosure;
+ private final AnnotationStore annotations;
- private final TypeStore typeStore = new TypeStore();
- private final AnnotationStore annotations = new AnnotationStore();
-
- /**
- * Clears all annotation data from the the class. Useful if we are not
- * interested in the annotations that are actually on the class but instead
- * want to apply our own
- */
- public void clearAllAnnotations()
+ protected AbstractNewAnnotatedElement(Class<?> type, AnnotationStore annotations)
{
- annotations.clear();
- }
-
- protected AbstractNewAnnotatedElement(Class<?> type, boolean readAnnotations)
- {
- typeStore.add(type);
- this.type = type;
- if (readAnnotations)
+ this.typeClosure = new TypeClosureBuilder().add(type).getTypes();
+ if (annotations == null)
{
- annotations.addAll(type);
+ this.annotations = new AnnotationStore();
}
+ else
+ {
+ this.annotations = annotations;
+ }
+ this.type = type;
}
- public void addAnnotation(Annotation a)
- {
- annotations.addAnnotation(a);
- }
-
- public void removeAnnotation(Class<? extends Annotation> c)
- {
- annotations.removeAnnotation(c);
- }
-
public <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
return annotations.getAnnotation(annotationType);
@@ -67,11 +51,12 @@
public Set<Type> getTypeClosure()
{
- return typeStore.getTypes();
+ return Collections.unmodifiableSet(typeClosure);
}
public Type getBaseType()
{
return type;
}
+
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AbstractNewAnnotatedMember.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -11,14 +11,14 @@
* @author Stuart Douglas
*
*/
-public abstract class AbstractNewAnnotatedMember<X, M extends Member> extends AbstractNewAnnotatedElement implements AnnotatedMember<X>
+abstract class AbstractNewAnnotatedMember<X, M extends Member> extends AbstractNewAnnotatedElement implements AnnotatedMember<X>
{
private final AnnotatedType<X> declaringType;
private final M javaMember;
- protected AbstractNewAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, boolean readAnnotations)
+ protected AbstractNewAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, AnnotationStore annotations)
{
- super(memberType, readAnnotations);
+ super(memberType, annotations);
this.declaringType = declaringType;
this.javaMember = member;
}
Copied: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java (from rev 5190, extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java)
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -0,0 +1,58 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+class AnnotationBuilder
+{
+ private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ private Set<Annotation> annotationSet = new HashSet<Annotation>();
+
+ public AnnotationBuilder add(Annotation a)
+ {
+ annotationSet.add(a);
+ annotationMap.put(a.getClass(), a);
+ return this;
+ }
+
+ public AnnotationStore create()
+ {
+ return new AnnotationStore(annotationMap, annotationSet);
+ }
+
+ public AnnotationBuilder addAll(Set<Annotation> annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public AnnotationBuilder addAll(AnnotationStore annotations)
+ {
+ for (Annotation annotation : annotations.getAnnotations())
+ {
+ add(annotation);
+ }
+ return this;
+ }
+
+ public AnnotationBuilder addAll(AnnotatedElement element)
+ {
+ for (Annotation a : element.getAnnotations())
+ {
+ add(a);
+ }
+ return this;
+ }
+
+}
Property changes on: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationStore.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -1,7 +1,6 @@
package org.jboss.weld.extensions.util.annotated;
import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -14,52 +13,35 @@
*/
class AnnotationStore
{
- HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
- Set<Annotation> annotations = new HashSet<Annotation>();
+
+ private final HashMap<Class<? extends Annotation>, Annotation> annotationMap;
+ private final Set<Annotation> annotationSet;
- public void clear()
+ AnnotationStore(HashMap<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
{
- annotationMap.clear();
- annotations.clear();
+ this.annotationMap = annotationMap;
+ this.annotationSet = annotationSet;
}
-
- public void addAnnotation(Annotation a)
+
+ AnnotationStore()
{
- annotations.add(a);
- annotationMap.put(a.getClass(), a);
+ this.annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ this.annotationSet = new HashSet<Annotation>();
}
- public void removeAnnotation(Class a)
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
- Annotation an = annotationMap.get(a);
- if (an != null)
- {
- annotations.remove(an);
- annotationMap.remove(a);
- }
+ return annotationType.cast(annotationMap.get(annotationType));
}
- public <T extends Annotation> T getAnnotation(Class<T> type)
- {
- return (T) annotationMap.get(type);
- }
-
public Set<Annotation> getAnnotations()
{
- return Collections.unmodifiableSet(annotations);
+ return Collections.unmodifiableSet(annotationSet);
}
- public boolean isAnnotationPresent(Class<? extends Annotation> type)
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
- return annotationMap.containsKey(type);
+ return annotationMap.containsKey(annotationType);
}
- public void addAll(AnnotatedElement element)
- {
- for (Annotation a : element.getAnnotations())
- {
- addAnnotation(a);
- }
- }
-
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedConstructor.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -1,21 +1,21 @@
package org.jboss.weld.extensions.util.annotated;
import java.lang.reflect.Constructor;
+import java.util.Map;
import javax.enterprise.inject.spi.AnnotatedConstructor;
/**
*
* @author Stuart Douglas
- *
+ *
*/
-class NewAnnotatedConstructor<X> extends AbstractNewAnnotatedCallable<X, Constructor<X>>
- implements AnnotatedConstructor<X>
+class NewAnnotatedConstructor<X> extends AbstractNewAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
{
- NewAnnotatedConstructor(NewAnnotatedType<X> type, Constructor<?> constructor, boolean readAnnotations)
+ NewAnnotatedConstructor(NewAnnotatedType<X> type, Constructor<?> constructor, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations)
{
- super(type, (Constructor<X>) constructor, readAnnotations);
+ super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), annotations, parameterAnnotations);
}
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedField.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -10,13 +10,12 @@
* @author Stuart Douglas
*
*/
-class NewAnnotatedField<X> extends AbstractNewAnnotatedMember<X, Field> implements
- AnnotatedField<X>
+class NewAnnotatedField<X> extends AbstractNewAnnotatedMember<X, Field> implements AnnotatedField<X>
{
- NewAnnotatedField(AnnotatedType<X> declaringType, Field field, boolean readAnnotations)
+ NewAnnotatedField(AnnotatedType<X> declaringType, Field field, AnnotationStore annotations)
{
- super(declaringType, field, field.getType(), readAnnotations);
+ super(declaringType, field, field.getType(), annotations);
}
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedMethod.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -1,6 +1,7 @@
package org.jboss.weld.extensions.util.annotated;
import java.lang.reflect.Method;
+import java.util.Map;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
@@ -12,14 +13,9 @@
*/
class NewAnnotatedMethod<X> extends AbstractNewAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
{
- NewAnnotatedMethod(AnnotatedType<X> type, Method method, boolean readAnnotations)
+ NewAnnotatedMethod(AnnotatedType<X> type, Method method, AnnotationStore annotations, Map<Integer, AnnotationStore> parameterAnnotations)
{
- super(type, method, readAnnotations);
- int count = 0;
- for (Class<?> c : method.getParameterTypes())
- {
- NewAnnotatedParameter<X> mp = new NewAnnotatedParameter<X>(this, c, count++, readAnnotations);
- getParameters().add(mp);
- }
+ super(type, method, method.getReturnType(), method.getParameterTypes(), annotations, parameterAnnotations);
}
+
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedParameter.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -14,9 +14,9 @@
private final int position;
private final AnnotatedCallable<X> declaringCallable;
- NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class type, int position, boolean readAnnotations)
+ NewAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, AnnotationStore annotations)
{
- super(type, readAnnotations);
+ super(type, annotations);
this.declaringCallable = declaringCallable;
this.position = position;
}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -4,7 +4,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -21,72 +20,47 @@
* @author Stuart Douglas
*
*/
-public class NewAnnotatedType<X> extends AbstractNewAnnotatedElement implements AnnotatedType<X>
+class NewAnnotatedType<X> extends AbstractNewAnnotatedElement implements AnnotatedType<X>
{
- private final Set<NewAnnotatedConstructor<X>> constructors = new HashSet<NewAnnotatedConstructor<X>>();
- private final Set<NewAnnotatedField<? super X>> fields = new HashSet<NewAnnotatedField<? super X>>();
- private final Set<NewAnnotatedMethod<? super X>> methods = new HashSet<NewAnnotatedMethod<? super X>>();
+ private final Set<AnnotatedConstructor<X>> constructors;
+ private final Set<AnnotatedField<? super X>> fields;
+ private final Set<AnnotatedMethod<? super X>> methods;
- // maps fields to the field objects
- private final Map<Field, NewAnnotatedField<X>> fieldMap = new HashMap<Field, NewAnnotatedField<X>>();
- // maps method names to the method objects
- private final Map<Method, NewAnnotatedMethod<X>> methodMap = new HashMap<Method, NewAnnotatedMethod<X>>();
-
private final Class<X> javaClass;
- public NewAnnotatedType(Class<X> clazz, boolean readAnnotations)
+ NewAnnotatedType(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, AnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnotations)
{
- super(clazz, readAnnotations);
- javaClass = clazz;
+ super(clazz, typeAnnotations);
+ this.javaClass = clazz;
+ this.constructors = new HashSet<AnnotatedConstructor<X>>();
for (Constructor<?> c : clazz.getConstructors())
{
- constructors.add(new NewAnnotatedConstructor<X>(this, c, readAnnotations));
+ NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
+ constructors.add(nc);
}
+ this.methods = new HashSet<AnnotatedMethod<? super X>>();
for (Method m : clazz.getMethods())
{
- NewAnnotatedMethod<X> met = new NewAnnotatedMethod<X>(this, m, readAnnotations);
+ NewAnnotatedMethod<X> met = new NewAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
methods.add(met);
- methodMap.put(m, met);
}
+ this.fields = new HashSet<AnnotatedField<? super X>>();
for (Field f : clazz.getFields())
{
- NewAnnotatedField<X> b = new NewAnnotatedField<X>(this, f, readAnnotations);
+ NewAnnotatedField<X> b = new NewAnnotatedField<X>(this, f, fieldAnnotations.get(f));
fields.add(b);
- fieldMap.put(f, b);
}
-
}
- /**
- * clears all existing annotation data from a type
- */
- @Override
- public void clearAllAnnotations()
- {
- super.clearAllAnnotations();
- for (AbstractNewAnnotatedElement c : constructors)
- {
- c.clearAllAnnotations();
- }
- for (AbstractNewAnnotatedElement c : fields)
- {
- c.clearAllAnnotations();
- }
- for (AbstractNewAnnotatedElement c : methods)
- {
- c.clearAllAnnotations();
- }
- }
-
public Set<AnnotatedConstructor<X>> getConstructors()
{
- return (Set) Collections.unmodifiableSet(constructors);
+ return Collections.unmodifiableSet(constructors);
}
public Set<AnnotatedField<? super X>> getFields()
{
- return (Set) Collections.unmodifiableSet(fields);
+ return Collections.unmodifiableSet(fields);
}
public Class<X> getJavaClass()
@@ -96,17 +70,7 @@
public Set<AnnotatedMethod<? super X>> getMethods()
{
- return (Set) Collections.unmodifiableSet(methods);
+ return Collections.unmodifiableSet(methods);
}
- public NewAnnotatedField<X> getField(Field field)
- {
- return fieldMap.get(field);
- }
-
- public NewAnnotatedMethod<X> getMethod(Method m)
- {
- return methodMap.get(m);
- }
-
}
Added: 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 (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -0,0 +1,161 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Class for constructing a new AnnotatedType. A new instance of builder must be
+ * used for each annotated type.
+ *
+ * No annotations will be read from the underlying class definition, all
+ * annotations must be added explicitly
+ *
+ * @author Stuart Douglas
+ * @author Pete Muir
+ *
+ */
+public class NewAnnotatedTypeBuilder<X>
+{
+ private Map<Field, AnnotationBuilder> fields = new HashMap<Field, AnnotationBuilder>();
+ private Map<Method, AnnotationBuilder> methods = new HashMap<Method, AnnotationBuilder>();
+ private Map<Method, Map<Integer, AnnotationBuilder>> methodParameters = new HashMap<Method, Map<Integer, AnnotationBuilder>>();
+ private Map<Constructor<X>, AnnotationBuilder> constructors = new HashMap<Constructor<X>, AnnotationBuilder>();
+ private Map<Constructor<X>, Map<Integer, AnnotationBuilder>> constructorParameters = new HashMap<Constructor<X>, Map<Integer, AnnotationBuilder>>();
+ private AnnotationBuilder typeAnnotations = new AnnotationBuilder();
+ private Class<X> underlying;
+
+ public NewAnnotatedTypeBuilder(Class<X> underlying)
+ {
+ this.underlying = underlying;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
+ {
+ typeAnnotations.add(a);
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
+ {
+ AnnotationBuilder annotations = fields.get(field);
+ if (annotations == null)
+ {
+ annotations = new AnnotationBuilder();
+ fields.put(field, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
+ {
+ AnnotationBuilder annotations = methods.get(method);
+ if (annotations == null)
+ {
+ annotations = new AnnotationBuilder();
+ methods.put(method, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
+ {
+ Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
+ if (anmap == null)
+ {
+ anmap = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(method, anmap);
+ }
+ AnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations == null)
+ {
+ annotations = new AnnotationBuilder();
+ anmap.put(parameter, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
+ {
+ AnnotationBuilder annotations = constructors.get(constructor);
+ if (annotations == null)
+ {
+ annotations = new AnnotationBuilder();
+ constructors.put(constructor, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
+ {
+ Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
+ if (anmap == null)
+ {
+ anmap = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put(constructor, anmap);
+ }
+ AnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations == null)
+ {
+ annotations = new AnnotationBuilder();
+ anmap.put(parameter, annotations);
+ }
+ annotations.add(a);
+ return this;
+ }
+
+ public AnnotatedType<X> create()
+ {
+ Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,AnnotationStore>>();
+ Map<Constructor<X>, AnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, AnnotationStore>();
+ Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer,AnnotationStore>>();
+ Map<Method, AnnotationStore> methodAnnotations = new HashMap<Method, AnnotationStore>();
+ Map<Field, AnnotationStore> fieldAnnotations = new HashMap<Field, AnnotationStore>();
+
+ for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
+ {
+ fieldAnnotations.put(e.getKey(), e.getValue().create());
+ }
+
+ for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
+ {
+ methodAnnotations.put(e.getKey(), e.getValue().create());
+ }
+ for (Entry<Method, Map<Integer, AnnotationBuilder>> e : methodParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ methodParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
+ {
+ parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+ }
+ }
+
+ for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
+ {
+ constructorAnnotations.put(e.getKey(), e.getValue().create());
+ }
+ for (Entry<Constructor<X>, Map<Integer, AnnotationBuilder>> e : constructorParameters.entrySet())
+ {
+ Map<Integer, AnnotationStore> parameterAnnotations = new HashMap<Integer, AnnotationStore>();
+ constructorParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+ for (Entry<Integer, AnnotationBuilder> pe : e.getValue().entrySet())
+ {
+ parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+ }
+ }
+
+ return new NewAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations);
+ }
+
+}
Property changes on: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java (from rev 5190, extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeStore.java)
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -0,0 +1,48 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A type closure builder
+ *
+ * @author Stuart Douglas
+ *
+ */
+class TypeClosureBuilder
+{
+
+ final Set<Type> types = new HashSet<Type>();
+
+ public TypeClosureBuilder add(Class<?> beanType)
+ {
+ Class<?> c = beanType;
+ do
+ {
+ types.add(c);
+ c = c.getSuperclass();
+ }
+ while (c != null);
+ for (Class<?> i : beanType.getInterfaces())
+ {
+ types.add(i);
+ }
+ return this;
+ }
+
+ public TypeClosureBuilder addInterfaces(Class<?> beanType)
+ {
+ for (Class<?> i : beanType.getInterfaces())
+ {
+ types.add(i);
+ }
+ return this;
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+}
Property changes on: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeClosureBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeStore.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeStore.java 2009-12-03 15:10:58 UTC (rev 5203)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/TypeStore.java 2009-12-03 15:56:38 UTC (rev 5204)
@@ -1,45 +0,0 @@
-package org.jboss.weld.extensions.util.annotated;
-
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- *
- * @author Stuart Douglas
- *
- */
-class TypeStore
-{
-
- final Set<Type> types = new HashSet<Type>();
-
- public void add(Class<?> beanType)
- {
- Class<?> c = beanType;
- do
- {
- types.add(c);
- c = c.getSuperclass();
- }
- while (c != null);
- for (Class<?> i : beanType.getInterfaces())
- {
- types.add(i);
- }
- }
-
- public void addInterfaces(Class<?> beanType)
- {
- for (Class<?> i : beanType.getInterfaces())
- {
- types.add(i);
- }
- }
-
- public Set<Type> getTypes()
- {
- return types;
- }
-
-}
More information about the weld-commits
mailing list