[webbeans-commits] Webbeans SVN: r393 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: introspector and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Dec 3 12:51:11 EST 2008


Author: pete.muir at jboss.org
Date: 2008-12-03 12:51:11 -0500 (Wed, 03 Dec 2008)
New Revision: 393

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
Log:
Make annotatedItem immutable

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -116,7 +116,7 @@
          for (AnnotatedMethod<Object> removeMethod : type.getAnnotatedMethods(REMOVE_ANNOTATION))
          {
             removeMethods.add(removeMethod);
-            if (removeMethod.getDelegate().getParameterTypes().length == 0)
+            if (removeMethod.getParameters().size() == 0)
             {
                noArgsRemoveMethods.add(removeMethod);
             }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -91,13 +91,6 @@
    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType);
 
    /**
-    * Gets the underlying element
-    * 
-    * @return The annotated item
-    */
-   public S getDelegate();
-
-   /**
     * Gets the type of the element
     * 
     * @return The type of the element

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -91,14 +91,6 @@
    /**
     * @see org.jboss.webbeans.introspector.AnnotatedItem
     */
-   public S getDelegate()
-   {
-      return delegate().getDelegate();
-   }
-
-   /**
-    * @see org.jboss.webbeans.introspector.AnnotatedItem
-    */
    public String getName()
    {
       return delegate().getName();

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -21,6 +21,7 @@
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Type;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -29,6 +30,9 @@
 import java.util.Set;
 
 import javax.webbeans.BindingType;
+import javax.webbeans.DeploymentType;
+import javax.webbeans.ScopeType;
+import javax.webbeans.Stereotype;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
@@ -44,6 +48,8 @@
  * Represents functionality common for all annotated items, mainly different
  * mappings of the annotations and meta-annotations
  * 
+ * AbstractAnnotatedItem is an immutable class and therefore threadsafe
+ * 
  * @author Pete Muir
  * @author Nicklas Karlsson
  * 
@@ -61,7 +67,7 @@
     */
    public static class AnnotationMap extends ForwardingMap<Class<? extends Annotation>, Annotation>
    {
-      private Map<Class<? extends Annotation>, Annotation> delegate;
+      private final Map<Class<? extends Annotation>, Annotation> delegate;
 
       public AnnotationMap()
       {
@@ -94,7 +100,7 @@
     */
    private static class MetaAnnotationMap extends ForwardingMap<Class<? extends Annotation>, Set<Annotation>>
    {
-      private Map<Class<? extends Annotation>, Set<Annotation>> delegate;
+      private final Map<Class<? extends Annotation>, Set<Annotation>> delegate;
 
       public MetaAnnotationMap()
       {
@@ -155,67 +161,11 @@
    private static final Annotation[] DEFAULT_BINDING_ARRAY = { new CurrentAnnotationLiteral() };
    // The set of default binding types
    private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
-   // The array of meta-annotations to map
-   private static final Annotation[] MAPPED_METAANNOTATIONS_ARRAY = {};
+   
    // The set of meta-annotations to map
-   private static final Set<Annotation> MAPPED_METAANNOTATIONS = new HashSet<Annotation>(Arrays.asList(MAPPED_METAANNOTATIONS_ARRAY));
-
-   // The annotation map (annotation type -> annotation) of the item
-   private AnnotationMap annotationMap;
-   // The meta-annotation map (annotation type -> set of annotations containing
-   // meta-annotation) of the item
-   private MetaAnnotationMap metaAnnotationMap;
-   // The set of all annotations on the item
-   private Set<Annotation> annotationSet;
-   // The array of all annotations on the item
-   private Annotation[] annotationArray;
-
+   private static final Set<Class<? extends Annotation>> MAPPED_METAANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(BindingType.class, DeploymentType.class, Stereotype.class, ScopeType.class));
+   
    /**
-    * Constructor
-    * 
-    * Also builds the meta-annotation map. Throws a NullPointerException if
-    * trying to register a null map
-    * 
-    * @param annotationMap A map of annotation to register
-    * 
-    */
-   public AbstractAnnotatedItem(AnnotationMap annotationMap)
-   {
-      if (annotationMap == null)
-      {
-         throw new NullPointerException("annotationMap cannot be null");
-      }
-      this.annotationMap = annotationMap;
-      buildMetaAnnotationMap(annotationMap);
-   }
-
-   /**
-    * Build the meta-annotation map
-    * 
-    * Iterates through the annotationMap values (annotations) and for each
-    * meta-annotation on the annotation register the annotation in the set under
-    * they key of the meta-annotation type.
-    * 
-    * @param annotationMap The annotation map to parse
-    */
-   private void buildMetaAnnotationMap(AnnotationMap annotationMap)
-   {
-      metaAnnotationMap = new MetaAnnotationMap();
-      for (Annotation annotation : annotationMap.values())
-      {
-         for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
-         {
-            // TODO: Check with Pete how to fill the array. Make annotation
-            // literals for all?
-            // if (MAPPED_METAANNOTATIONS.contains(metaAnnotation))
-            // {
-            metaAnnotationMap.put(metaAnnotation.annotationType(), annotation);
-            // }
-         }
-      }
-   }
-
-   /**
     * Static helper method for building annotation map from an annotated element
     * 
     * @param element The element to examine
@@ -241,7 +191,7 @@
       }
       return annotationMap;
    }
-
+   
    /**
     * Static helper method for getting the current parameter values from a list
     * of annotated parameters.
@@ -262,7 +212,47 @@
       return parameterValues;
    }
 
+   // The annotation map (annotation type -> annotation) of the item
+   private final AnnotationMap annotationMap;
+   // The meta-annotation map (annotation type -> set of annotations containing
+   // meta-annotation) of the item
+   private final MetaAnnotationMap metaAnnotationMap;
+   // The set of all annotations on the item
+   private final Set<Annotation> annotationSet;
+
    /**
+    * Constructor
+    * 
+    * Also builds the meta-annotation map. Throws a NullPointerException if
+    * trying to register a null map
+    * 
+    * @param annotationMap A map of annotation to register
+    * 
+    */
+   public AbstractAnnotatedItem(AnnotationMap annotationMap)
+   {
+      if (annotationMap == null)
+      {
+         throw new NullPointerException("annotationMap cannot be null");
+      }
+      this.annotationMap = annotationMap;
+      this.annotationSet = new HashSet<Annotation>();
+      this.metaAnnotationMap = new MetaAnnotationMap();
+      for (Annotation annotation : annotationMap.values())
+      {
+         for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
+         {
+            // Only map meta-annotations we are interested in
+            if (MAPPED_METAANNOTATIONS.contains(metaAnnotation.annotationType()))
+            {
+               metaAnnotationMap.put(metaAnnotation.annotationType(), annotation);
+            }
+         }
+         annotationSet.add(annotation);
+      }
+   }
+
+   /**
     * Gets the annotation for a given annotation type.
     * 
     * @param annotationType the annotation type to match
@@ -287,7 +277,7 @@
     */
    public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
    {
-      return metaAnnotationMap.get(metaAnnotationType);
+      return Collections.unmodifiableSet(metaAnnotationMap.get(metaAnnotationType));
    }
 
    /**
@@ -304,12 +294,7 @@
     */
    public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation> metaAnnotationType)
    {
-      if (annotationArray == null)
-      {
-         annotationArray = new Annotation[0];
-         annotationArray = getMetaAnnotations(metaAnnotationType).toArray(annotationArray);
-      }
-      return annotationArray;
+       return getMetaAnnotations(metaAnnotationType).toArray(new Annotation[0]);
    }
 
    /**
@@ -323,12 +308,7 @@
     */
    public Set<Annotation> getAnnotations()
    {
-      if (annotationSet == null)
-      {
-         annotationSet = new HashSet<Annotation>();
-         annotationSet.addAll(annotationMap.values());
-      }
-      return annotationSet;
+      return Collections.unmodifiableSet(annotationSet);
    }
 
    /**
@@ -349,9 +329,9 @@
     * 
     * @return The annotation map
     */
-   protected AnnotationMap getAnnotationMap()
+   protected Map<Class<? extends Annotation>, Annotation> getAnnotationMap()
    {
-      return annotationMap;
+      return Collections.unmodifiableMap(annotationMap);
    }
 
    /**
@@ -465,11 +445,11 @@
    {
       if (getMetaAnnotations(BindingType.class).size() > 0)
       {
-         return getMetaAnnotations(BindingType.class);
+         return Collections.unmodifiableSet(getMetaAnnotations(BindingType.class));
       }
       else
       {
-         return DEFAULT_BINDING;
+         return Collections.unmodifiableSet(DEFAULT_BINDING);
       }
    }
 
@@ -525,5 +505,7 @@
          return true;
       }
    }
+   
+   protected abstract S getDelegate();
 
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -36,6 +36,8 @@
 /**
  * Represents an abstract annotated memeber (field, method or constructor)
  * 
+ * This class is immutable, and therefore threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -87,20 +89,21 @@
    }
 
    // The name of the member
-   private String name;
+   private final String name;
 
    /**
     * Constructor
     * 
     * @param annotationMap The annotation map
     */
-   public AbstractAnnotatedMember(AnnotationMap annotationMap)
+   public AbstractAnnotatedMember(AnnotationMap annotationMap, Member member)
    {
       super(annotationMap);
+      name = member.getName();
    }
 
    /**
-    * Indicates if the member is static (through the delegate)
+    * Indicates if the member is static
     * 
     * @return True if static, false otherwise
     * 
@@ -112,7 +115,7 @@
    }
 
    /**
-    * Indicates if the member if final (through the delegate)
+    * Indicates if the member if final
     * 
     * @return True if final, false otherwise
     * 
@@ -137,16 +140,12 @@
    /**
     * Gets the name of the member
     * 
-    * @returns The name (or the name of the delegate if none is defined)
+    * @returns The name
     * 
     * @see org.jboss.webbeans.introspector.AnnotatedItem#getName()
     */
    public String getName()
    {
-      if (name == null)
-      {
-         name = getDelegate().getName();
-      }
       return name;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -23,6 +23,8 @@
 /**
  * Represents an abstract annotated type
  * 
+ * This class is immutable, and therefore threadsage
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -30,20 +32,31 @@
 public abstract class AbstractAnnotatedType<T> extends AbstractAnnotatedItem<T, Class<T>>
 {
    // The superclass abstraction of the type
-   private AnnotatedClass<Object> superclass;
+   private final AnnotatedClass<Object> superclass;
+   private final String name;
 
    /**
     * Constructor
     * 
     * @param annotationMap The annotation map
     */
-   public AbstractAnnotatedType(AnnotationMap annotationMap)
+   @SuppressWarnings("unchecked")
+   public AbstractAnnotatedType(AnnotationMap annotationMap, Class<T> type)
    {
       super(annotationMap);
+      this.name = type.getName();
+      if (type.getSuperclass() != null)
+      {
+         this.superclass = new AnnotatedClassImpl(type.getSuperclass());
+      }
+      else
+      {
+         this.superclass = null;
+      }
    }
 
    /**
-    * Indicates if the type is static (through the delegate)
+    * Indicates if the type is static
     * 
     * @return True if static, false otherwise
     * 
@@ -55,7 +68,7 @@
    }
 
    /**
-    * Indicates if the type if final (through the delegate)
+    * Indicates if the type if final
     * 
     * @return True if final, false otherwise
     * 
@@ -69,13 +82,13 @@
    /**
     * Gets the name of the type
     * 
-    * @returns The name (through the delegate)
+    * @returns The name
     * 
     * @see org.jboss.webbeans.introspector.AnnotatedItem#getName()
     */
    public String getName()
    {
-      return getDelegate().getName();
+      return name;
    }
 
    /**
@@ -84,13 +97,8 @@
     * @return The superclass abstraction
     */
    @SuppressWarnings("unchecked")
-   // TODO Fix this
    public AnnotatedClass<Object> getSuperclass()
    {
-      if (superclass == null)
-      {
-         superclass = new AnnotatedClassImpl(getDelegate().getSuperclass());
-      }
       return superclass;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -20,6 +20,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -34,6 +35,8 @@
 /**
  * Represents an annotated annotation
  * 
+ * This class is immutable and therefore threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -85,11 +88,11 @@
    }
 
    // The annotated members map (annotation -> member with annotation)
-   private AnnotatedMemberMap annotatedMembers;
+   private final AnnotatedMemberMap annotatedMembers;
    // The implementation class of the annotation
-   private Class<T> clazz;
+   private final Class<T> clazz;
    // The set of abstracted members
-   private Set<AnnotatedMethod<?>> members;
+   private final Set<AnnotatedMethod<?>> members;
 
    /**
     * Constructor
@@ -100,8 +103,19 @@
     */
    public AnnotatedAnnotationImpl(Class<T> annotationType)
    {
-      super(buildAnnotationMap(annotationType));
+      super(buildAnnotationMap(annotationType), annotationType);
       this.clazz = annotationType;
+      members = new HashSet<AnnotatedMethod<?>>();
+      annotatedMembers = new AnnotatedMemberMap();
+      for (Method member : clazz.getDeclaredMethods())
+      {
+         AnnotatedMethod<? extends Object> annotatedMethod = new AnnotatedMethodImpl<Object>(member, this);
+         members.add(annotatedMethod);
+         for (Annotation annotation : annotatedMethod.getAnnotations())
+         {
+            annotatedMembers.put(annotation.annotationType(), annotatedMethod);
+         }
+      }
    }
 
    /**
@@ -127,26 +141,10 @@
     */
    public Set<AnnotatedMethod<?>> getMembers()
    {
-      if (members == null)
-      {
-         initMembers();
-      }
-      return members;
+      return Collections.unmodifiableSet(members);
    }
 
    /**
-    * Gets the delegate
-    * 
-    * @return The delegate
-    * 
-    * @see org.jboss.webbeans.introspector.AnnotatedAnnotation#getDelegate()
-    */
-   public Class<T> getDelegate()
-   {
-      return clazz;
-   }
-
-   /**
     * Gets the type of the annotation
     * 
     * @see org.jboss.webbeans.introspector.AnnotatedAnnotation#getType()
@@ -157,21 +155,6 @@
    }
 
    /**
-    * Initializes the members
-    * 
-    * Iterates through the declared members, creates abstractions of them and
-    * adds them to the members set
-    */
-   private void initMembers()
-   {
-      members = new HashSet<AnnotatedMethod<?>>();
-      for (Method member : clazz.getDeclaredMethods())
-      {
-         members.add(new AnnotatedMethodImpl<Object>(member, this));
-      }
-   }
-
-   /**
     * Returns the annotated members with a given annotation type
     * 
     * If the annotated members are null, they are initialized first.
@@ -184,39 +167,10 @@
     */
    public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> annotationType)
    {
-      if (annotatedMembers == null)
-      {
-         initAnnotatedMembers();
-      }
-      return annotatedMembers.get(annotationType);
+      return Collections.unmodifiableSet(annotatedMembers.get(annotationType));
    }
 
    /**
-    * Initializes the annotated members
-    * 
-    * If the members are null, the are initialized first.
-    * 
-    * Iterates over the members and for each member, iterate over the
-    * annotations present, creating member abstractions and mapping them under
-    * the annotation in the annotatedMembers map.
-    */
-   private void initAnnotatedMembers()
-   {
-      if (members == null)
-      {
-         initMembers();
-      }
-      annotatedMembers = new AnnotatedMemberMap();
-      for (AnnotatedMethod<?> member : members)
-      {
-         for (Annotation annotation : member.getAnnotations())
-         {
-            annotatedMembers.put(annotation.annotationType(), member);
-         }
-      }
-   }
-
-   /**
     * Gets a string representation of the constructor
     * 
     * @return A string representation
@@ -239,4 +193,9 @@
       return buffer.toString();
    }
 
+   protected Class<T> getDelegate()
+   {
+      return clazz;
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -24,6 +24,7 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -41,6 +42,8 @@
 /**
  * Represents an annotated class
  * 
+ * This class is immutable, and thus threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -213,28 +216,28 @@
    }
 
    // The implementing class
-   private Class<T> clazz;
+   private final Class<T> clazz;
    // The type arguments
-   private Type[] actualTypeArguments;
+   private final Type[] actualTypeArguments;
 
    // The set of abstracted fields
-   private Set<AnnotatedField<Object>> fields;
+   private final Set<AnnotatedField<Object>> fields;
    // The map from annotation type to abstracted field with annotation
-   private AnnotatedFieldMap annotatedFields;
+   private final AnnotatedFieldMap annotatedFields;
    // The map from annotation type to abstracted field with meta-annotation
-   private AnnotatedFieldMap metaAnnotatedFields;
+   private final AnnotatedFieldMap metaAnnotatedFields;
 
    // The set of abstracted methods
-   private Set<AnnotatedMethod<Object>> methods;
+   private final Set<AnnotatedMethod<Object>> methods;
    // The map from annotation type to abstracted method with annotation
-   private AnnotatedMethodMap annotatedMethods;
+   private final AnnotatedMethodMap annotatedMethods;
 
    // The set of abstracted constructors
-   private Set<AnnotatedConstructor<T>> constructors;
+   private final Set<AnnotatedConstructor<T>> constructors;
    // The map from annotation type to abstracted constructor with annotation
-   private AnnotatedConstructorMap annotatedConstructors;
+   private final AnnotatedConstructorMap annotatedConstructors;
    // The map from class list to abstracted constructor
-   private ConstructorsByArgumentMap constructorsByArgumentMap;
+   private final ConstructorsByArgumentMap constructorsByArgumentMap;
 
    /**
     * Constructor
@@ -248,7 +251,7 @@
     */
    public AnnotatedClassImpl(Class<T> rawType, Type type, Annotation[] annotations)
    {
-      super(buildAnnotationMap(annotations));
+      super(buildAnnotationMap(annotations), rawType);
       this.clazz = rawType;
       if (type instanceof ParameterizedType)
       {
@@ -258,6 +261,78 @@
       {
          actualTypeArguments = new Type[0];
       }
+      
+      this.fields = new HashSet<AnnotatedField<Object>>();
+      this.annotatedFields = new AnnotatedFieldMap();
+      this.metaAnnotatedFields = new AnnotatedFieldMap();
+      for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass())
+      {
+         for (Field field : clazz.getDeclaredFields())
+         {
+            if (!field.isAccessible())
+            {
+               field.setAccessible(true);
+            }
+            AnnotatedField<Object> annotatedField = new AnnotatedFieldImpl<Object>(field, this); 
+            this.fields.add(annotatedField);
+            for (Annotation annotation : annotatedField.getAnnotations())
+            {
+               this.annotatedFields.put(annotation.annotationType(), annotatedField);
+               for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
+               {
+                  this.metaAnnotatedFields.put(metaAnnotation.annotationType(), annotatedField);
+               }
+            }
+            
+         }
+      }
+      
+      this.constructors = new HashSet<AnnotatedConstructor<T>>();
+      this.constructorsByArgumentMap = new ConstructorsByArgumentMap();
+      this.annotatedConstructors = new AnnotatedConstructorMap();
+      for (Constructor<?> constructor : clazz.getDeclaredConstructors())
+      {
+         AnnotatedConstructor<T> annotatedConstructor = new AnnotatedConstructorImpl<T>((Constructor<T>) constructor, this);
+         if (!constructor.isAccessible())
+         {
+            constructor.setAccessible(true);
+         }
+         this.constructors.add(annotatedConstructor);
+         this.constructorsByArgumentMap.put(Arrays.asList(constructor.getParameterTypes()), annotatedConstructor);
+         
+         for (Annotation annotation : annotatedConstructor.getAnnotations())
+         {
+            if (!annotatedConstructors.containsKey(annotation.annotationType()))
+            {
+               annotatedConstructors.put(annotation.annotationType(), new HashSet<AnnotatedConstructor<T>>());
+            }
+            annotatedConstructors.get(annotation.annotationType()).add(annotatedConstructor);
+         }
+      }
+      
+      this.methods = new HashSet<AnnotatedMethod<Object>>();
+      this.annotatedMethods = new AnnotatedMethodMap();
+      for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass())
+      {
+         for (Method method : clazz.getDeclaredMethods())
+         {
+            if (!method.isAccessible())
+            {
+               method.setAccessible(true);
+            }
+            
+            AnnotatedMethod<Object> annotatedMethod = new AnnotatedMethodImpl<Object>(method, this);
+            this.methods.add(annotatedMethod);
+            for (Annotation annotation : annotatedMethod.getAnnotations())
+            {
+               if (!annotatedMethods.containsKey(annotation.annotationType()))
+               {
+                  annotatedMethods.put(annotation.annotationType(), new HashSet<AnnotatedMethod<Object>>());
+               }
+               annotatedMethods.get(annotation.annotationType()).add(annotatedMethod);
+            }
+         }
+      }
    }
 
    /**
@@ -301,11 +376,7 @@
     */
    public Set<AnnotatedField<Object>> getFields()
    {
-      if (fields == null)
-      {
-         initFields();
-      }
-      return fields;
+      return Collections.unmodifiableSet(fields);
    }
 
    /**
@@ -317,37 +388,10 @@
     */
    public Set<AnnotatedConstructor<T>> getConstructors()
    {
-      if (constructors == null)
-      {
-         initConstructors();
-      }
-      return constructors;
+      return Collections.unmodifiableSet(constructors);
    }
 
    /**
-    * Initializes the fields
-    * 
-    * Iterates through the type hierarchy and adds the abstracted fields to the
-    * fields list
-    * 
-    */
-   private void initFields()
-   {
-      this.fields = new HashSet<AnnotatedField<Object>>();
-      for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass())
-      {
-         for (Field field : clazz.getDeclaredFields())
-         {
-            if (!field.isAccessible())
-            {
-               field.setAccessible(true);
-            }
-            fields.add(new AnnotatedFieldImpl<Object>(field, this));
-         }
-      }
-   }
-
-   /**
     * Gets abstracted fields with requested meta-annotation type present
     * 
     * If the meta-annotations map is null, it is initializes. If the annotated
@@ -361,11 +405,7 @@
     */
    public Set<AnnotatedField<Object>> getMetaAnnotatedFields(Class<? extends Annotation> metaAnnotationType)
    {
-      if (annotatedFields == null || metaAnnotatedFields == null)
-      {
-         initAnnotatedAndMetaAnnotatedFields();
-      }
-      return metaAnnotatedFields.get(metaAnnotationType);
+      return Collections.unmodifiableSet(metaAnnotatedFields.get(metaAnnotationType));
    }
 
    /**
@@ -379,44 +419,10 @@
     */
    public Set<AnnotatedField<Object>> getAnnotatedFields(Class<? extends Annotation> annotationType)
    {
-      if (annotatedFields == null)
-      {
-         initAnnotatedAndMetaAnnotatedFields();
-      }
-      return annotatedFields.get(annotationType);
+      return Collections.unmodifiableSet(annotatedFields.get(annotationType));
    }
 
    /**
-    * Initializes the annotated/meta-annotated fields map
-    * 
-    * If the fields set if empty, populate it first. Iterate through the fields,
-    * for each field, iterate over the annotations and map the field abstraction
-    * under the annotation type key. In the inner loop, iterate over the
-    * annotations of the annotations (the meta-annotations) and map the field
-    * under the meta-annotation type key.
-    */
-   private void initAnnotatedAndMetaAnnotatedFields()
-   {
-      if (fields == null)
-      {
-         initFields();
-      }
-      annotatedFields = new AnnotatedFieldMap();
-      metaAnnotatedFields = new AnnotatedFieldMap();
-      for (AnnotatedField<Object> field : fields)
-      {
-         for (Annotation annotation : field.getAnnotations())
-         {
-            annotatedFields.put(annotation.annotationType(), field);
-            for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
-            {
-               metaAnnotatedFields.put(metaAnnotation.annotationType(), field);
-            }
-         }
-      }
-   }
-
-   /**
     * Gets the type of the class
     * 
     * @return The type
@@ -439,28 +445,6 @@
    }
 
    /**
-    * Initializes the methods
-    * 
-    * Iterate over the class hierarchy and for each type, add all methods
-    * abstracted to the methods list
-    */
-   private void initMethods()
-   {
-      this.methods = new HashSet<AnnotatedMethod<Object>>();
-      for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass())
-      {
-         for (Method method : clazz.getDeclaredMethods())
-         {
-            if (!method.isAccessible())
-            {
-               method.setAccessible(true);
-            }
-            methods.add(new AnnotatedMethodImpl<Object>(method, this));
-         }
-      }
-   }
-
-   /**
     * Gets the abstracted methods that have a certain annotation type present
     * 
     * If the annotated methods map is null, initialize it first
@@ -473,66 +457,10 @@
     */
    public Set<AnnotatedMethod<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType)
    {
-      if (annotatedMethods == null)
-      {
-         initAnnotatedMethods();
-      }
-
-      return annotatedMethods.get(annotationType);
+      return Collections.unmodifiableSet(annotatedMethods.get(annotationType));
    }
 
    /**
-    * Initializes the annotated methods
-    * 
-    * If the methods set is null, initialize it first. Iterate over all method
-    * abstractions and for each annotation, map the method abstraction under the
-    * annotation type key.
-    */
-   private void initAnnotatedMethods()
-   {
-      if (methods == null)
-      {
-         initMethods();
-      }
-      annotatedMethods = new AnnotatedMethodMap();
-      for (AnnotatedMethod<Object> member : methods)
-      {
-         for (Annotation annotation : member.getAnnotations())
-         {
-            if (!annotatedMethods.containsKey(annotation.annotationType()))
-            {
-               annotatedMethods.put(annotation.annotationType(), new HashSet<AnnotatedMethod<Object>>());
-            }
-            annotatedMethods.get(annotation.annotationType()).add(member);
-         }
-      }
-   }
-
-   /**
-    * Initializes the constructors set and constructors-by-argument map
-    * 
-    * Iterate over the constructors and for each constructor, add an abstracted
-    * constructor to the constructors set and the same constructor abstraction
-    * to the constructors-by-argument map under the argument-list-key.
-    */
-   @SuppressWarnings("unchecked")
-   private void initConstructors()
-   {
-      this.constructors = new HashSet<AnnotatedConstructor<T>>();
-      this.constructorsByArgumentMap = new ConstructorsByArgumentMap();
-      for (Constructor<?> constructor : clazz.getDeclaredConstructors())
-      {
-         AnnotatedConstructor<T> annotatedConstructor = new AnnotatedConstructorImpl<T>((Constructor<T>) constructor, this);
-         if (!constructor.isAccessible())
-         {
-            constructor.setAccessible(true);
-         }
-         constructors.add(annotatedConstructor);
-         constructorsByArgumentMap.put(Arrays.asList(constructor.getParameterTypes()), annotatedConstructor);
-      }
-   }
-
-   /**
     * Gets constructors with given annotation type
     * 
     * @param annotationType The annotation type to match
@@ -544,42 +472,10 @@
     */
    public Set<AnnotatedConstructor<T>> getAnnotatedConstructors(Class<? extends Annotation> annotationType)
    {
-      if (annotatedConstructors == null)
-      {
-         initAnnotatedConstructors();
-      }
-
-      return annotatedConstructors.get(annotationType);
+      return Collections.unmodifiableSet(annotatedConstructors.get(annotationType));
    }
 
    /**
-    * Initializes the annotated constructors.
-    * 
-    * If the constructors set is empty, initialize it first. Iterate over all
-    * constructor abstractions and for each annotation on the constructor, map
-    * the constructor abstraction under the annotation key.
-    */
-   private void initAnnotatedConstructors()
-   {
-      if (constructors == null)
-      {
-         initConstructors();
-      }
-      annotatedConstructors = new AnnotatedConstructorMap();
-      for (AnnotatedConstructor<T> constructor : constructors)
-      {
-         for (Annotation annotation : constructor.getAnnotations())
-         {
-            if (!annotatedConstructors.containsKey(annotation.annotationType()))
-            {
-               annotatedConstructors.put(annotation.annotationType(), new HashSet<AnnotatedConstructor<T>>());
-            }
-            annotatedConstructors.get(annotation.annotationType()).add(constructor);
-         }
-      }
-   }
-
-   /**
     * Gets a constructor with given arguments
     * 
     * @param arguments The arguments to match

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -22,6 +22,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.webbeans.ExecutionException;
@@ -43,15 +44,15 @@
    // The type arguments
    private static final Type[] actualTypeArguments = new Type[0];
    // The underlying constructor
-   private Constructor<T> constructor;
+   private final Constructor<T> constructor;
 
    // The list of parameter abstractions
-   private List<AnnotatedParameter<Object>> parameters;
+   private final List<AnnotatedParameter<Object>> parameters;
    // The mapping of annotation -> parameter abstraction
-   private AnnotatedParameterMap annotatedParameters;
+   private final AnnotatedParameterMap annotatedParameters;
 
    // The declaring class abstraction
-   private AnnotatedType<T> declaringClass;
+   private final AnnotatedType<T> declaringClass;
 
    /**
     * Constructor
@@ -63,9 +64,37 @@
     */
    public AnnotatedConstructorImpl(Constructor<T> constructor, AnnotatedType<T> declaringClass)
    {
-      super(buildAnnotationMap(constructor));
+      super(buildAnnotationMap(constructor), constructor);
       this.constructor = constructor;
       this.declaringClass = declaringClass;
+      
+      this.parameters = new ArrayList<AnnotatedParameter<Object>>();
+      annotatedParameters = new AnnotatedParameterMap();
+      for (int i = 0; i < constructor.getParameterTypes().length; i++)
+      {
+         if (constructor.getParameterAnnotations()[i].length > 0)
+         {
+            Class<? extends Object> clazz = constructor.getParameterTypes()[i];
+            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(constructor.getParameterAnnotations()[i], (Class<Object>) clazz);
+            parameters.add(parameter);
+            
+            for (Annotation annotation : parameter.getAnnotations())
+            {
+               annotatedParameters.put(annotation.annotationType(), parameter);
+            }
+         }
+         else
+         {
+            Class<? extends Object> clazz = constructor.getParameterTypes()[i];
+            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
+            parameters.add(parameter);
+            
+            for (Annotation annotation : parameter.getAnnotations())
+            {
+               annotatedParameters.put(annotation.annotationType(), parameter);
+            }
+         }
+      }
    }
 
    /**
@@ -121,41 +150,10 @@
     */
    public List<AnnotatedParameter<Object>> getParameters()
    {
-      if (parameters == null)
-      {
-         initParameters();
-      }
-      return parameters;
+      return Collections.unmodifiableList(parameters);
    }
 
    /**
-    * Initializes the parameter abstractions
-    * 
-    * Iterates over the constructor parameters, adding the parameter abstraction
-    * to the parameters list.
-    */
-   @SuppressWarnings("unchecked")
-   private void initParameters()
-   {
-      parameters = new ArrayList<AnnotatedParameter<Object>>();
-      for (int i = 0; i < constructor.getParameterTypes().length; i++)
-      {
-         if (constructor.getParameterAnnotations()[i].length > 0)
-         {
-            Class<? extends Object> clazz = constructor.getParameterTypes()[i];
-            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(constructor.getParameterAnnotations()[i], (Class<Object>) clazz);
-            parameters.add(parameter);
-         }
-         else
-         {
-            Class<? extends Object> clazz = constructor.getParameterTypes()[i];
-            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
-            parameters.add(parameter);
-         }
-      }
-   }
-
-   /**
     * Gets the parameter abstractions with a given annotation type
     * 
     * if the annotated parameters map is null, it is initialized first.
@@ -166,37 +164,10 @@
     */
    public List<AnnotatedParameter<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType)
    {
-      if (annotatedParameters == null)
-      {
-         initAnnotatedParameters();
-      }
-      return annotatedParameters.get(annotationType);
+      return Collections.unmodifiableList(annotatedParameters.get(annotationType));
    }
 
    /**
-    * Initializes the annotated parameters
-    * 
-    * If the parameters are null, they are initialized first. Iterate over the
-    * parameters and for each parameter annotation map it under the annotation
-    * type.
-    */
-   private void initAnnotatedParameters()
-   {
-      if (parameters == null)
-      {
-         initParameters();
-      }
-      annotatedParameters = new AnnotatedParameterMap();
-      for (AnnotatedParameter<Object> parameter : parameters)
-      {
-         for (Annotation annotation : parameter.getAnnotations())
-         {
-            annotatedParameters.put(annotation.annotationType(), parameter);
-         }
-      }
-   }
-
-   /**
     * Gets parameter abstractions with a given annotation type.
     * 
     * If the parameters are null, they are initializes first.
@@ -209,11 +180,7 @@
     */
    public List<AnnotatedParameter<Object>> getAnnotatedParameters(Class<? extends Annotation> annotationType)
    {
-      if (annotatedParameters == null)
-      {
-         initAnnotatedParameters();
-      }
-      return annotatedParameters.get(annotationType);
+      return Collections.unmodifiableList(annotatedParameters.get(annotationType));
    }
 
    /**
@@ -262,7 +229,7 @@
       if (super.equals(other) && other instanceof AnnotatedConstructor)
       {
          AnnotatedConstructor<?> that = (AnnotatedConstructor<?>) other;
-         return this.getDelegate().equals(that.getDelegate());
+         return this.getDeclaringClass().equals(that.getDeclaringClass()) && this.getParameters().equals(that.getParameters());
       }
       return false;
    }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -29,6 +29,8 @@
 /**
  * Represents an annotated field
  * 
+ * This class is immutable, and thus threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -36,11 +38,11 @@
 public class AnnotatedFieldImpl<T> extends AbstractAnnotatedMember<T, Field> implements AnnotatedField<T>
 {
    // The actual type arguments
-   private Type[] actualTypeArguments = new Type[0];
+   private final Type[] actualTypeArguments;
    // The underlying field
-   private Field field;
+   private final Field field;
    // The abstraction of the declaring class
-   private AnnotatedType<?> declaringClass;
+   private final AnnotatedType<?> declaringClass;
 
    /**
     * Constructor
@@ -53,7 +55,7 @@
     */
    public AnnotatedFieldImpl(Field field, AnnotatedType<?> declaringClass)
    {
-      super(buildAnnotationMap(field));
+      super(buildAnnotationMap(field), field);
       this.field = field;
       this.declaringClass = declaringClass;
       if (field.getGenericType() instanceof ParameterizedType)
@@ -61,6 +63,10 @@
          ParameterizedType type = (ParameterizedType) field.getGenericType();
          actualTypeArguments = type.getActualTypeArguments();
       }
+      else
+      {
+         actualTypeArguments = new Type[0];
+      }
    }
 
    /**

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -18,14 +18,13 @@
 package org.jboss.webbeans.introspector.jlr;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 
-import javax.webbeans.TypeLiteral;
-
 /**
  * Represents an annotated item
  * 
+ * This class is immutable, and thus threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -34,115 +33,24 @@
 public class AnnotatedItemImpl<T, S> extends AbstractAnnotatedItem<T, S>
 {
    // The actual type arguments
-   private Type[] actualTypeArguments = new Type[0];
+   private final Type[] actualTypeArguments;
    // The type of the item
-   private Class<T> type;
+   private final Class<T> type;
    // The actual annotations
-   private Annotation[] actualAnnotations;
+   private final Annotation[] actualAnnotations;
 
    /**
     * Constructor
     * 
-    * Initializes the superclass with the annotation map
-    * 
-    * @param annotationMap The annotated map
-    */
-   private AnnotatedItemImpl(AnnotationMap annotationMap)
-   {
-      super(annotationMap);
-   }
-
-   /**
-    * Constructor
-    * 
-    * Initializes the superclass with the annotation map and sets the type
-    * 
-    * @param annotationMap The annotation map
-    * @param type The type of the item
-    */
-   private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type)
-   {
-      super(annotationMap);
-      this.type = type;
-   }
-
-   /**
-    * Constructor
-    * 
-    * Initializes the superclass with the annotation map, sets the api type and
-    * determines the type arguments
-    * 
-    * @param annotationMap The annotation map
-    * @param apiType The api type
-    */
-   private AnnotatedItemImpl(AnnotationMap annotationMap, TypeLiteral<T> apiType)
-   {
-      super(annotationMap);
-      this.type = apiType.getRawType();
-      if (apiType.getType() instanceof ParameterizedType)
-      {
-         actualTypeArguments = ((ParameterizedType) apiType.getType()).getActualTypeArguments();
-      }
-   }
-
-   /**
-    * Constructor
-    * 
-    * @param annotationMap The annotation map
-    * @param type The type
-    * @param actualTypeArguments The actual type arguments
-    */
-   private AnnotatedItemImpl(AnnotationMap annotationMap, Class<T> type, Type[] actualTypeArguments)
-   {
-      this(annotationMap, type);
-      this.actualTypeArguments = actualTypeArguments;
-   }
-
-   /**
-    * Constructor
-    * 
     * @param annotations The annotations array of the type
-    */
-   public AnnotatedItemImpl(Annotation[] annotations)
-   {
-      this(buildAnnotationMap(annotations));
-      this.actualAnnotations = annotations;
-   }
-
-   /**
-    * Constructor
-    * 
-    * @param annotations The annotations array of the type
-    * @param type The type
-    */
-   public AnnotatedItemImpl(Annotation[] annotations, Class<T> type)
-   {
-      this(buildAnnotationMap(annotations), type);
-      this.actualAnnotations = annotations;
-   }
-
-   /**
-    * Constructor
-    * 
-    * @param annotations The annotations array of the type
-    * @param apiType The API typeliteral
-    */
-   public AnnotatedItemImpl(Annotation[] annotations, TypeLiteral<T> apiType)
-   {
-      this(buildAnnotationMap(annotations), apiType);
-      this.actualAnnotations = annotations;
-   }
-
-   /**
-    * Constructor
-    * 
-    * @param annotations The annotations array of the type
     * @param type The type of the item
     * @param actualTypeArguments The actual type arguments array
     */
    public AnnotatedItemImpl(Annotation[] annotations, Class<T> type, Type[] actualTypeArguments)
    {
-      this(buildAnnotationMap(annotations), type, actualTypeArguments);
+      super(buildAnnotationMap(annotations));
+      this.type = type;
+      this.actualTypeArguments = actualTypeArguments;
       this.actualAnnotations = annotations;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -22,6 +22,7 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.jboss.webbeans.ManagerImpl;
@@ -33,6 +34,8 @@
 /**
  * Represents an annotated method
  * 
+ * This class is immutable and thus threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -40,21 +43,21 @@
 public class AnnotatedMethodImpl<T> extends AbstractAnnotatedMember<T, Method> implements AnnotatedMethod<T>
 {
    // The actual type arguments
-   private Type[] actualTypeArguments = new Type[0];
+   private final Type[] actualTypeArguments;
    // The underlying method
-   private Method method;
+   private final Method method;
 
    // The abstracted parameters
-   private List<AnnotatedParameter<Object>> parameters;
+   private final List<AnnotatedParameter<Object>> parameters;
    // A mapping from annotation type to parameter abstraction with that
    // annotation present
-   private AnnotatedParameterMap annotatedParameters;
+   private final AnnotatedParameterMap annotatedParameters;
 
    // The property name
-   private String propertyName;
+   private final String propertyName;
 
    // The abstracted declaring class
-   private AnnotatedType<?> declaringClass;
+   private final AnnotatedType<?> declaringClass;
 
    /**
     * Constructor
@@ -67,13 +70,53 @@
     */
    public AnnotatedMethodImpl(Method method, AnnotatedType<?> declaringClass)
    {
-      super(buildAnnotationMap(method));
+      super(buildAnnotationMap(method), method);
       this.method = method;
       this.declaringClass = declaringClass;
       if (method.getGenericReturnType() instanceof ParameterizedType)
       {
-         actualTypeArguments = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments();
+         this.actualTypeArguments = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments();
       }
+      else
+      {
+         this.actualTypeArguments = new Type[0];
+      }
+      
+      this.parameters = new ArrayList<AnnotatedParameter<Object>>();
+      this.annotatedParameters = new AnnotatedParameterMap();
+      for (int i = 0; i < method.getParameterTypes().length; i++)
+      {
+         if (method.getParameterAnnotations()[i].length > 0)
+         {
+            Class<? extends Object> clazz = method.getParameterTypes()[i];
+            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(method.getParameterAnnotations()[i], (Class<Object>) clazz);
+            this.parameters.add(parameter);
+            for (Annotation annotation : parameter.getAnnotations())
+            {
+               annotatedParameters.put(annotation.annotationType(), parameter);
+            }
+         }
+         else
+         {
+            Class<? extends Object> clazz = method.getParameterTypes()[i];
+            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
+            this.parameters.add(parameter);
+            for (Annotation annotation : parameter.getAnnotations())
+            {
+               annotatedParameters.put(annotation.annotationType(), parameter);
+            }
+         }
+      }
+      
+      String propertyName = Reflections.getPropertyName(getDelegate());
+      if (propertyName == null)
+      {
+         this.propertyName = getName();
+      }
+      else
+      {
+         this.propertyName = propertyName;
+      }
    }
 
    /**
@@ -130,83 +173,10 @@
     */
    public List<AnnotatedParameter<Object>> getParameters()
    {
-      if (parameters == null)
-      {
-         initParameters();
-      }
-      return parameters;
+      return Collections.unmodifiableList(parameters);
    }
 
    /**
-    * Initializes the parameter abstractions
-    * 
-    * Iterates over the method abstraction parameters and creates an abstraction
-    * of the parameter
-    */
-   @SuppressWarnings("unchecked")
-   private void initParameters()
-   {
-      this.parameters = new ArrayList<AnnotatedParameter<Object>>();
-      for (int i = 0; i < method.getParameterTypes().length; i++)
-      {
-         if (method.getParameterAnnotations()[i].length > 0)
-         {
-            Class<? extends Object> clazz = method.getParameterTypes()[i];
-            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(method.getParameterAnnotations()[i], (Class<Object>) clazz);
-            parameters.add(parameter);
-         }
-         else
-         {
-            Class<? extends Object> clazz = method.getParameterTypes()[i];
-            AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
-            parameters.add(parameter);
-         }
-      }
-   }
-
-   // TODO: Don't get this one - NIK
-   // public List<AnnotatedParameter<Object>> getAnnotatedMethods(Class<?
-   // extends Annotation> annotationType)
-   // {
-   // if (annotatedParameters == null)
-   // {
-   // initAnnotatedParameters();
-   // }
-   //
-   // if (!annotatedParameters.containsKey(annotationType))
-   // {
-   // return new ArrayList<AnnotatedParameter<Object>>();
-   // }
-   // else
-   // {
-   // return annotatedParameters.get(annotationType);
-   // }
-   // }
-
-   /**
-    * Initializes the annotated parameters
-    * 
-    * If the parameters are null, they are initialized first. Iterates over the
-    * parameter abstractions and for each annotation present, maps the parameter
-    * abstraction under that annotation type key.
-    */
-   private void initAnnotatedParameters()
-   {
-      if (parameters == null)
-      {
-         initParameters();
-      }
-      annotatedParameters = new AnnotatedParameterMap();
-      for (AnnotatedParameter<Object> parameter : parameters)
-      {
-         for (Annotation annotation : parameter.getAnnotations())
-         {
-            annotatedParameters.put(annotation.annotationType(), parameter);
-         }
-      }
-   }
-
-   /**
     * Gets the parameter abstractions with a given annotation type
     * 
     * If the parameter abstractions are null, they are initialized first
@@ -217,11 +187,7 @@
     */
    public List<AnnotatedParameter<Object>> getAnnotatedParameters(Class<? extends Annotation> annotationType)
    {
-      if (annotatedParameters == null)
-      {
-         initAnnotatedParameters();
-      }
-      return annotatedParameters.get(annotationType);
+      return Collections.unmodifiableList(annotatedParameters.get(annotationType));
    }
 
    /**
@@ -235,7 +201,7 @@
       if (other instanceof AnnotatedMethod)
       {
          AnnotatedMethod<?> that = (AnnotatedMethod<?>) other;
-         return this.getDelegate().equals(that.getDelegate());
+         return this.getDeclaringClass().equals(that.getDeclaringClass()) && this.getName().equals(that.getName()) && this.getParameters().equals(that.getParameters());
       }
       else
       {
@@ -293,14 +259,6 @@
     */
    public String getPropertyName()
    {
-      if (propertyName == null)
-      {
-         propertyName = Reflections.getPropertyName(getDelegate());
-         if (propertyName == null)
-         {
-            propertyName = getName();
-         }
-      }
       return propertyName;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java	2008-12-03 11:46:14 UTC (rev 392)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java	2008-12-03 17:51:11 UTC (rev 393)
@@ -28,6 +28,8 @@
 /**
  * Represents a parameter
  * 
+ * This class is immutable and thus threadsafe
+ * 
  * @author Pete Muir
  * 
  * @param <T>
@@ -35,13 +37,13 @@
 public class AnnotatedParameterImpl<T> extends AbstractAnnotatedItem<T, Object> implements AnnotatedParameter<T>
 {
    // The type
-   private Class<T> type;
+   private final Class<T> type;
    // The actual type arguments
-   private Type[] actualTypeArguments = new Type[0];
+   private final Type[] actualTypeArguments = new Type[0];
    // The final state
-   private boolean _final;
+   private final boolean _final = false;
    // The static state
-   private boolean _static;
+   private final boolean _static = false;
 
    /**
     * Constructor




More information about the weld-commits mailing list