[weld-commits] Weld SVN: r5651 - in core/trunk/tests/src/test/java/org/jboss/weld/tests: util and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Jan 27 22:51:15 EST 2010


Author: swd847
Date: 2010-01-27 22:51:14 -0500 (Wed, 27 Jan 2010)
New Revision: 5651

Added:
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java
Log:
Added an implementation of AnnotatedType to test the SPI. This implementation was ripped from weld-extensions


Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedCallable.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,57 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Member;
+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;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+abstract class AbstractTestAnnotatedCallable<X, Y extends Member> extends AbstractTestAnnotatedMember<X, Y> implements AnnotatedCallable<X>
+{
+
+   private final List<AnnotatedParameter<X>> parameters;
+
+   protected AbstractTestAnnotatedCallable(AnnotatedType<X> declaringType, Y member, Class<?> memberType, Class<?>[] parameterTypes, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+   {
+      super(declaringType, member, memberType, annotations);
+      this.parameters = getAnnotatedParameters(this, parameterTypes, parameterAnnotations);
+   }
+
+   public List<AnnotatedParameter<X>> getParameters()
+   {
+      return Collections.unmodifiableList(parameters);
+   }
+
+   public AnnotatedParameter<X> getParameter(int index)
+   {
+      return parameters.get(index);
+
+   }  
+   
+   private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AbstractTestAnnotatedCallable<X, Y> callable, Class<?>[] parameterTypes, Map<Integer, TestAnnotationStore> parameterAnnotations)
+   {
+      List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>();
+      int len = parameterTypes.length;
+      for (int i = 0; i < len; ++i)
+      {
+         TestAnnotationBuilder builder = new TestAnnotationBuilder();
+         if (parameterAnnotations != null && parameterAnnotations.containsKey(i))
+         {
+            builder.addAll(parameterAnnotations.get(i));
+         }
+         TestAnnotatedParameter<X> p = new TestAnnotatedParameter<X>(callable, parameterTypes[i], i, builder.create());
+         parameters.add(p);
+      }
+      return parameters;
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedElement.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,62 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+
+/**
+ * The base class for all New Annotated types.
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+abstract class AbstractTestAnnotatedElement implements Annotated
+{
+
+   private final Class<?> type;
+   private final Set<Type> typeClosure;
+   private final TestAnnotationStore annotations;
+
+   protected AbstractTestAnnotatedElement(Class<?> type, TestAnnotationStore annotations)
+   {
+      this.typeClosure = new TestTypeClosureBuilder().add(type).getTypes();
+      if (annotations == null)
+      {
+         this.annotations = new TestAnnotationStore();
+      }
+      else
+      {
+         this.annotations = annotations;
+      }
+      this.type = type;
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+   {
+      return annotations.getAnnotation(annotationType);
+   }
+
+   public Set<Annotation> getAnnotations()
+   {
+      return annotations.getAnnotations();
+   }
+
+   public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+   {
+      return annotations.isAnnotationPresent(annotationType);
+   }
+
+   public Set<Type> getTypeClosure()
+   {
+      return Collections.unmodifiableSet(typeClosure);
+   }
+
+   public Type getBaseType()
+   {
+      return type;
+   }
+   
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/AbstractTestAnnotatedMember.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,41 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+abstract class AbstractTestAnnotatedMember<X, M extends Member> extends AbstractTestAnnotatedElement implements AnnotatedMember<X>
+{
+   private final AnnotatedType<X> declaringType;
+   private final M javaMember;
+
+   protected AbstractTestAnnotatedMember(AnnotatedType<X> declaringType, M member, Class<?> memberType, TestAnnotationStore annotations)
+   {
+      super(memberType, annotations);
+      this.declaringType = declaringType;
+      this.javaMember = member;
+   }
+
+   public AnnotatedType<X> getDeclaringType()
+   {
+      return declaringType;
+   }
+
+   public M getJavaMember()
+   {
+      return javaMember;
+   }
+
+   public boolean isStatic()
+   {
+      return Modifier.isStatic(javaMember.getModifiers());
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedConstructor.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+
+/**
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+class TestAnnotatedConstructor<X> extends AbstractTestAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>
+{
+
+   TestAnnotatedConstructor(TestAnnotatedType<X> type, Constructor<?> constructor, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+   {
+      super(type, (Constructor<X>) constructor, constructor.getDeclaringClass(), constructor.getParameterTypes(), annotations, parameterAnnotations);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedField.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Field;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * 
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotatedField<X> extends AbstractTestAnnotatedMember<X, Field> implements AnnotatedField<X>
+{
+
+   TestAnnotatedField(AnnotatedType<X> declaringType, Field field, TestAnnotationStore annotations)
+   {
+      super(declaringType, field, field.getType(), annotations);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedMethod.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+class TestAnnotatedMethod<X> extends AbstractTestAnnotatedCallable<X, Method> implements AnnotatedMethod<X>
+{
+   TestAnnotatedMethod(AnnotatedType<X> type, Method method, TestAnnotationStore annotations, Map<Integer, TestAnnotationStore> parameterAnnotations)
+   {
+      super(type, method, method.getReturnType(), method.getParameterTypes(), annotations, parameterAnnotations);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedParameter.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,34 @@
+package org.jboss.weld.tests.util.annotated;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+/**
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+class TestAnnotatedParameter<X> extends AbstractTestAnnotatedElement implements AnnotatedParameter<X>
+{
+
+   private final int position;
+   private final AnnotatedCallable<X> declaringCallable;
+
+   TestAnnotatedParameter(AnnotatedCallable<X> declaringCallable, Class<?> type, int position, TestAnnotationStore annotations)
+   {
+      super(type, annotations);
+      this.declaringCallable = declaringCallable;
+      this.position = position;
+   }
+
+   public AnnotatedCallable<X> getDeclaringCallable()
+   {
+      return declaringCallable;
+   }
+
+   public int getPosition()
+   {
+      return position;
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedType.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,76 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * AnnotatedType implementation for adding beans in the BeforeBeanDiscovery
+ * event
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+class TestAnnotatedType<X> extends AbstractTestAnnotatedElement implements AnnotatedType<X>
+{
+
+   private final Set<AnnotatedConstructor<X>> constructors;
+   private final Set<AnnotatedField<? super X>> fields;
+   private final Set<AnnotatedMethod<? super X>> methods;
+
+   private final Class<X> javaClass;
+
+   TestAnnotatedType(Class<X> clazz, TestAnnotationStore typeAnnotations, Map<Field, TestAnnotationStore> fieldAnnotations, Map<Method, TestAnnotationStore> methodAnnotations, Map<Method, Map<Integer, TestAnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, TestAnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, TestAnnotationStore>> constructorParameterAnnotations)
+   {
+      super(clazz, typeAnnotations);
+      this.javaClass = clazz;
+      this.constructors = new HashSet<AnnotatedConstructor<X>>();
+      for (Constructor<?> c : clazz.getConstructors())
+      {
+         TestAnnotatedConstructor<X> nc = new TestAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
+         constructors.add(nc);
+      }
+      this.methods = new HashSet<AnnotatedMethod<? super X>>();
+      for (Method m : clazz.getMethods())
+      {
+         TestAnnotatedMethod<X> met = new TestAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
+         methods.add(met);
+      }
+      this.fields = new HashSet<AnnotatedField<? super X>>();
+      for (Field f : clazz.getFields())
+      {
+         TestAnnotatedField<X> b = new TestAnnotatedField<X>(this, f, fieldAnnotations.get(f));
+         fields.add(b);
+      }
+   }
+
+   public Set<AnnotatedConstructor<X>> getConstructors()
+   {
+      return Collections.unmodifiableSet(constructors);
+   }
+
+   public Set<AnnotatedField<? super X>> getFields()
+   {
+      return Collections.unmodifiableSet(fields);
+   }
+
+   public Class<X> getJavaClass()
+   {
+      return javaClass;
+   }
+
+   public Set<AnnotatedMethod<? super X>> getMethods()
+   {
+      return Collections.unmodifiableSet(methods);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotatedTypeBuilder.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,161 @@
+package org.jboss.weld.tests.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 TestAnnotatedTypeBuilder<X>
+{
+   private Map<Field, TestAnnotationBuilder> fields = new HashMap<Field, TestAnnotationBuilder>();
+   private Map<Method, TestAnnotationBuilder> methods = new HashMap<Method, TestAnnotationBuilder>();
+   private Map<Method, Map<Integer, TestAnnotationBuilder>> methodParameters = new HashMap<Method, Map<Integer, TestAnnotationBuilder>>();
+   private Map<Constructor<X>, TestAnnotationBuilder> constructors = new HashMap<Constructor<X>, TestAnnotationBuilder>();
+   private Map<Constructor<X>, Map<Integer, TestAnnotationBuilder>> constructorParameters = new HashMap<Constructor<X>, Map<Integer, TestAnnotationBuilder>>();
+   private TestAnnotationBuilder typeAnnotations = new TestAnnotationBuilder();
+   private Class<X> underlying;
+
+   public TestAnnotatedTypeBuilder(Class<X> underlying)
+   {
+      this.underlying = underlying;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToClass(Annotation a)
+   {
+      typeAnnotations.add(a);
+      return this;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
+   {
+      TestAnnotationBuilder annotations = fields.get(field);
+      if (annotations == null)
+      {
+         annotations = new TestAnnotationBuilder();
+         fields.put(field, annotations);
+      }
+      annotations.add(a);
+      return this;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
+   {
+      TestAnnotationBuilder annotations = methods.get(method);
+      if (annotations == null)
+      {
+         annotations = new TestAnnotationBuilder();
+         methods.put(method, annotations);
+      }
+      annotations.add(a);
+      return this;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
+   {
+      Map<Integer, TestAnnotationBuilder> anmap = methodParameters.get(method);
+      if (anmap == null)
+      {
+         anmap = new HashMap<Integer, TestAnnotationBuilder>();
+         methodParameters.put(method, anmap);
+      }
+      TestAnnotationBuilder annotations = anmap.get(parameter);
+      if (annotations == null)
+      {
+         annotations = new TestAnnotationBuilder();
+         anmap.put(parameter, annotations);
+      }
+      annotations.add(a);
+      return this;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
+   {
+      TestAnnotationBuilder annotations = constructors.get(constructor);
+      if (annotations == null)
+      {
+         annotations = new TestAnnotationBuilder();
+         constructors.put(constructor, annotations);
+      }
+      annotations.add(a);
+      return this;
+   }
+
+   public TestAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
+   {
+      Map<Integer, TestAnnotationBuilder> anmap = constructorParameters.get(constructor);
+      if (anmap == null)
+      {
+         anmap = new HashMap<Integer, TestAnnotationBuilder>();
+         constructorParameters.put(constructor, anmap);
+      }
+      TestAnnotationBuilder annotations = anmap.get(parameter);
+      if (annotations == null)
+      {
+         annotations = new TestAnnotationBuilder();
+         anmap.put(parameter, annotations);
+      }
+      annotations.add(a);
+      return this;
+   }
+
+   public AnnotatedType<X> create()
+   {
+      Map<Constructor<X>, Map<Integer, TestAnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,TestAnnotationStore>>();
+      Map<Constructor<X>, TestAnnotationStore> constructorAnnotations = new HashMap<Constructor<X>, TestAnnotationStore>();
+      Map<Method, Map<Integer, TestAnnotationStore>> methodParameterAnnnotations = new HashMap<Method, Map<Integer,TestAnnotationStore>>();
+      Map<Method, TestAnnotationStore> methodAnnotations = new HashMap<Method, TestAnnotationStore>();
+      Map<Field, TestAnnotationStore> fieldAnnotations = new HashMap<Field, TestAnnotationStore>();
+      
+      for (Entry<Field, TestAnnotationBuilder> e : fields.entrySet())
+      {
+         fieldAnnotations.put(e.getKey(), e.getValue().create());
+      }
+      
+      for (Entry<Method, TestAnnotationBuilder> e : methods.entrySet())
+      {
+         methodAnnotations.put(e.getKey(), e.getValue().create());
+      }
+      for (Entry<Method, Map<Integer, TestAnnotationBuilder>> e : methodParameters.entrySet())
+      {
+         Map<Integer, TestAnnotationStore> parameterAnnotations = new HashMap<Integer, TestAnnotationStore>();
+         methodParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+         for (Entry<Integer, TestAnnotationBuilder> pe : e.getValue().entrySet())
+         {
+            parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+         }
+      }
+      
+      for (Entry<Constructor<X>, TestAnnotationBuilder> e : constructors.entrySet())
+      {
+         constructorAnnotations.put(e.getKey(), e.getValue().create());
+      }
+      for (Entry<Constructor<X>, Map<Integer, TestAnnotationBuilder>> e : constructorParameters.entrySet())
+      {
+         Map<Integer, TestAnnotationStore> parameterAnnotations = new HashMap<Integer, TestAnnotationStore>();
+         constructorParameterAnnnotations.put(e.getKey(), parameterAnnotations);
+         for (Entry<Integer, TestAnnotationBuilder> pe : e.getValue().entrySet())
+         {
+            parameterAnnotations.put(pe.getKey(), pe.getValue().create());
+         }
+      }
+
+      return new TestAnnotatedType<X>(underlying, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationBuilder.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,58 @@
+package org.jboss.weld.tests.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 TestAnnotationBuilder
+{
+   private HashMap<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+   private Set<Annotation> annotationSet = new HashSet<Annotation>();
+
+   public TestAnnotationBuilder add(Annotation a)
+   {
+      annotationSet.add(a);
+      annotationMap.put(a.getClass(), a);
+      return this;
+   }
+
+   public TestAnnotationStore create()
+   {
+      return new TestAnnotationStore(annotationMap, annotationSet);
+   }
+   
+   public TestAnnotationBuilder addAll(Set<Annotation> annotations)
+   {
+      for (Annotation annotation : annotations)
+      {
+         add(annotation);
+      }
+      return this;
+   }
+   
+   public TestAnnotationBuilder addAll(TestAnnotationStore annotations)
+   {
+      for (Annotation annotation : annotations.getAnnotations())
+      {
+         add(annotation);
+      }
+      return this;
+   }
+
+   public TestAnnotationBuilder addAll(AnnotatedElement element)
+   {
+      for (Annotation a : element.getAnnotations())
+      {
+         add(a);
+      }
+      return this;
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestAnnotationStore.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,47 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 
+ * @author Stuart Douglas
+ *
+ */
+class TestAnnotationStore
+{
+   
+   private final HashMap<Class<? extends Annotation>, Annotation> annotationMap;
+   private final Set<Annotation> annotationSet;
+
+   TestAnnotationStore(HashMap<Class<? extends Annotation>, Annotation> annotationMap, Set<Annotation> annotationSet)
+   {
+      this.annotationMap = annotationMap;
+      this.annotationSet = annotationSet;
+   }
+   
+   TestAnnotationStore()
+   {
+      this.annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+      this.annotationSet = new HashSet<Annotation>();
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+   {
+      return annotationType.cast(annotationMap.get(annotationType));
+   }
+
+   public Set<Annotation> getAnnotations()
+   {
+      return Collections.unmodifiableSet(annotationSet);
+   }
+
+   public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+   {
+      return annotationMap.containsKey(annotationType);
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/util/annotated/TestTypeClosureBuilder.java	2010-01-28 03:51:14 UTC (rev 5651)
@@ -0,0 +1,48 @@
+package org.jboss.weld.tests.util.annotated;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A type closure builder
+ * 
+ * @author Stuart Douglas
+ * 
+ */
+class TestTypeClosureBuilder
+{
+
+   final Set<Type> types = new HashSet<Type>();
+
+   public TestTypeClosureBuilder 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 TestTypeClosureBuilder addInterfaces(Class<?> beanType)
+   {
+      for (Class<?> i : beanType.getInterfaces())
+      {
+         types.add(i);
+      }
+      return this;
+   }
+
+   public Set<Type> getTypes()
+   {
+      return types;
+   }
+
+}



More information about the weld-commits mailing list