[weld-commits] Weld SVN: r6224 - in core/trunk/impl/src/main/java/org/jboss/weld: introspector and 3 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon May 10 12:58:41 EDT 2010


Author: dallen6
Date: 2010-05-10 12:58:39 -0400 (Mon, 10 May 2010)
New Revision: 6224

Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
   core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
   core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/HierarchyDiscovery.java
Log:
WELD-476 First phase; we get past reflection and start deploying many beans, but still too much memory is used

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -217,7 +217,7 @@
             }
          }
       }
-      annotatedDelegateItem = WeldClassImpl.of(delegateInjectionPoint.getJavaClass(), beanManager.getServices().get(ClassTransformer.class));
+      annotatedDelegateItem = beanManager.getServices().get(ClassTransformer.class).loadClass(delegateInjectionPoint.getJavaClass());
    }
 
    private void checkAbstractMethods()

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/ForwardingWeldClass.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -18,6 +18,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.Set;
 
 public abstract class ForwardingWeldClass<T> extends ForwardingWeldAnnotated<T, Class<T>> implements WeldClass<T>
@@ -26,17 +27,17 @@
    @Override
    protected abstract WeldClass<T> delegate();
 
-   public Set<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
+   public Collection<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
    {
       return delegate().getWeldConstructors(annotationType);
    }
 
-   public Set<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
+   public Collection<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
    {
       return delegate().getWeldFields(annotationType);
    }
 
-   public Set<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
    {
       return delegate().getWeldMethods(annotationType);
    }
@@ -46,27 +47,27 @@
       return delegate().getNoArgsWeldConstructor();
    }
    
-   public Set<WeldMethod<?, ?>> getWeldMethods()
+   public Collection<WeldMethod<?, ?>> getWeldMethods()
    {
       return delegate().getWeldMethods();
    }
 
-   public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
+   public Collection<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
    {
       return delegate().getDeclaredWeldFields(annotationType);
    }
 
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
    {
       return delegate().getDeclaredWeldMethods(annotationType);
    }
 
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
    {
       return delegate().getDeclaredWeldMethodsWithAnnotatedParameters(annotationType);
    }
 
-   public Set<WeldField<?, ?>> getWeldFields()
+   public Collection<WeldField<?, ?>> getWeldFields()
    {
       return delegate().getWeldFields();
    }
@@ -164,7 +165,7 @@
       return delegate().getSimpleName();
    }
    
-   public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
+   public Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
    {
       return delegate().getDeclaredMetaAnnotations(metaAnnotationType);
    }

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/WeldClass.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -18,6 +18,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.Set;
 
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -36,21 +37,21 @@
     * 
     * @return A set of abstracted fields
     */
-   public Set<WeldField<?, ?>> getWeldFields();
+   public Collection<WeldField<?, ?>> getWeldFields();
    
    /**
     * Gets all fields on the type
     * 
     * @return A set of abstracted fields
     */
-   public Set<WeldMethod<?, ?>> getWeldMethods();
+   public Collection<WeldMethod<?, ?>> getWeldMethods();
    
    /**
     * Gets all fields on the type
     * 
     * @return A set of abstracted fields
     */
-   public Set<WeldMethod<?, ?>> getDeclaredWeldMethods();
+   public Collection<WeldMethod<?, ?>> getDeclaredWeldMethods();
 
    /**
     * Get a field by name
@@ -69,7 +70,7 @@
     * @return A set of abstracted fields with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType);
+   public Collection<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType);
 
    /**
     * Gets all fields which are annotated with the given annotation type on this
@@ -79,7 +80,7 @@
     * @return A set of abstracted fields with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);
+   public Collection<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);
 
    /**
     * Gets all constructors which are annotated with annotationType
@@ -88,7 +89,7 @@
     * @return A set of abstracted fields with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType);
+   public Collection<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType);
 
    /**
     * Gets the no-args constructor
@@ -112,7 +113,7 @@
     * @return A set of abstracted methods with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType);
+   public Collection<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType);
 
    /**
     * Gets all methods annotated with annotationType
@@ -121,7 +122,7 @@
     * @return A set of abstracted methods with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);
 
    /**
     * Find the annotated method for a given methodDescriptor
@@ -163,7 +164,7 @@
     * @return A set of abstracted methods with the given annotation. Returns an
     *         empty set if there are no matches
     */
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
 
    /**
     * Gets the superclass.
@@ -210,6 +211,6 @@
     * @return A set of matching meta-annotations. Returns an empty set if there
     *         are no matches.
     */
-   public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType);
+   public Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType);
 
 }
\ No newline at end of file

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/AbstractWeldAnnotated.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -42,9 +42,11 @@
 import org.jboss.weld.util.collections.HashSetSupplier;
 import org.jboss.weld.util.reflection.HierarchyDiscovery;
 
-import com.google.common.collect.BiMap;
+import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
+import com.google.common.collect.MutableClassToInstanceMap;
 import com.google.common.collect.SetMultimap;
 
 /**
@@ -100,7 +102,7 @@
    }
    
    
-   protected static void addMetaAnnotations(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Annotation[] metaAnnotations, boolean declared)
+   protected static void addMetaAnnotations(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Annotation[] metaAnnotations, boolean declared)
    {
       for (Annotation metaAnnotation : metaAnnotations)
       {
@@ -108,7 +110,7 @@
       }
    }
    
-   protected static void addMetaAnnotations(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Iterable<Annotation> metaAnnotations, boolean declared)
+   protected static void addMetaAnnotations(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Iterable<Annotation> metaAnnotations, boolean declared)
    {
       for (Annotation metaAnnotation : metaAnnotations)
       {
@@ -116,7 +118,7 @@
       }
    }
    
-   private static void addMetaAnnotation(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Class<? extends Annotation> metaAnnotationType, boolean declared)
+   private static void addMetaAnnotation(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Class<? extends Annotation> metaAnnotationType, boolean declared)
    {
       // Only map meta-annotations we are interested in
       if (declared ? MAPPED_DECLARED_METAANNOTATIONS.contains(metaAnnotationType) : MAPPED_METAANNOTATIONS.contains(metaAnnotationType))
@@ -126,7 +128,7 @@
    }
    
    // The annotation map (annotation type -> annotation) of the item
-   private final BiMap<Class<? extends Annotation>, Annotation> annotationMap;
+   private final Map<Class<? extends Annotation>, Annotation> annotationMap;
    // The meta-annotation map (annotation type -> set of annotations containing
    // meta-annotation) of the item
    private final SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
@@ -152,13 +154,12 @@
       {
          throw new WeldException(ANNOTATION_MAP_NULL);
       }
-      this.annotationMap = HashBiMap.create(annotationMap.size());
+      this.annotationMap = annotationMap;
       this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
       for (Annotation annotation : annotationMap.values())
       {
          addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
          addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getTypeStore().get(annotation.annotationType()), false);
-         this.annotationMap.put(annotation.annotationType(), annotation);
       }
       
       if (declaredAnnotationMap == null)
@@ -185,13 +186,12 @@
       {
          throw new WeldException(ANNOTATION_MAP_NULL);
       }
-      this.annotationMap = HashBiMap.create(annotationMap.size());
+      this.annotationMap = annotationMap;
       this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
       for (Annotation annotation : annotationMap.values())
       {
          addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
          addMetaAnnotations(metaAnnotationMap, annotation, typeStore.get(annotation.annotationType()), false);
-         this.annotationMap.put(annotation.annotationType(), annotation);
       }
       
       if (declaredAnnotationMap == null)
@@ -261,7 +261,7 @@
    
    public Set<Annotation> getAnnotations()
    {
-      return Collections.unmodifiableSet(annotationMap.values());
+      return Collections.unmodifiableSet(new HashSet<Annotation>(annotationMap.values()));
    }
 
    public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldClassImpl.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -48,13 +48,11 @@
 import org.jboss.weld.introspector.WeldMethod;
 import org.jboss.weld.resources.ClassTransformer;
 import org.jboss.weld.util.Names;
-import org.jboss.weld.util.collections.HashSetSupplier;
 import org.jboss.weld.util.reflection.HierarchyDiscovery;
 import org.jboss.weld.util.reflection.Reflections;
 import org.jboss.weld.util.reflection.SecureReflections;
 
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
+import com.google.common.collect.ArrayListMultimap;
 
 /**
  * Represents an annotated class
@@ -69,7 +67,7 @@
 public class WeldClassImpl<T> extends AbstractWeldAnnotated<T, Class<T>> implements WeldClass<T>
 {
 
-   private static <T> void mapConstructorAnnotations(SetMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors, WeldConstructor<T> annotatedConstructor)
+   private static <T> void mapConstructorAnnotations(ArrayListMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors, WeldConstructor<T> annotatedConstructor)
    {
       for (Annotation annotation : annotatedConstructor.getAnnotations())
       {
@@ -85,43 +83,43 @@
    private final WeldClass<?> superclass;
 
    // The set of abstracted fields
-   private final Set<WeldField<?, ?>> fields;
+   private final ArrayList<WeldField<?, ?>> fields;
    // The map from annotation type to abstracted field with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldField<?, ?>> annotatedFields;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldField<?, ?>> annotatedFields;
 
    // The set of abstracted fields
-   private final Set<WeldField<?, ?>> declaredFields;
+   private final ArrayList<WeldField<?, ?>> declaredFields;
    private final Map<String, WeldField<?, ?>> declaredFieldsByName;
    // The map from annotation type to abstracted field with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldField<?, ? super T>> declaredAnnotatedFields;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldField<?, ? super T>> declaredAnnotatedFields;
    // The map from annotation type to abstracted field with meta-annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldField<?, ?>> declaredMetaAnnotatedFields;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldField<?, ?>> declaredMetaAnnotatedFields;
 
    // The set of abstracted methods
-   private final Set<WeldMethod<?, ?>> methods;
+   private final ArrayList<WeldMethod<?, ?>> methods;
    private final Map<MethodSignature, WeldMethod<?, ?>> declaredMethodsBySignature;
    private final Map<MethodSignature, WeldMethod<?, ?>> methodsBySignature;
    // The map from annotation type to abstracted method with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, ?>> annotatedMethods;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldMethod<?, ?>> annotatedMethods;
 
    // The set of abstracted methods
-   private final Set<WeldMethod<?, ?>> declaredMethods;
+   private final ArrayList<WeldMethod<?, ?>> declaredMethods;
    // The map from annotation type to abstracted method with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredAnnotatedMethods;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredAnnotatedMethods;
    // The map from annotation type to method with a parameter with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredMethodsByAnnotatedParameters;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldMethod<?, ? super T>> declaredMethodsByAnnotatedParameters;
 
    // The set of abstracted constructors
-   private final Set<AnnotatedConstructor<T>> constructors;
+   private final ArrayList<AnnotatedConstructor<T>> constructors;
    private final Map<ConstructorSignature, WeldConstructor<?>> declaredConstructorsBySignature;
    // The map from annotation type to abstracted constructor with annotation
-   private final SetMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldConstructor<T>> annotatedConstructors;
    // The map from class list to abstracted constructor
    private final Map<List<Class<?>>, WeldConstructor<T>> constructorsByArgumentMap;
 
    // The meta-annotation map (annotation type -> set of annotations containing
    // meta-annotation) of the item
-   private final SetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
+   private final ArrayListMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap;
 
    private final boolean discovered;
 
@@ -163,12 +161,12 @@
       }
 
       // Assign class field information
-      this.fields = new HashSet<WeldField<?, ?>>();
-      this.annotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ?>>>(), HashSetSupplier.<WeldField<?, ?>> instance());
-      this.declaredFields = new HashSet<WeldField<?, ?>>();
+      this.fields = new ArrayList<WeldField<?, ?>>();
+      this.annotatedFields = ArrayListMultimap.<Class<? extends Annotation>, WeldField<?, ?>> create();
+      this.declaredFields = new ArrayList<WeldField<?, ?>>(rawType.getDeclaredFields().length);
       this.declaredFieldsByName = new HashMap<String, WeldField<?, ?>>();
-      this.declaredAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ? super T>>>(), HashSetSupplier.<WeldField<?, ? super T>> instance());
-      this.declaredMetaAnnotatedFields = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldField<?, ?>>>(), HashSetSupplier.<WeldField<?, ?>> instance());
+      this.declaredAnnotatedFields = ArrayListMultimap.<Class<? extends Annotation>, WeldField<?, ? super T>> create();
+      this.declaredMetaAnnotatedFields = ArrayListMultimap.<Class<? extends Annotation>, WeldField<?, ?>> create();
 
       if (annotatedType == null)
       {
@@ -226,11 +224,15 @@
             }
          }
       }
+      this.fields.trimToSize();
+      this.declaredFields.trimToSize();
+      this.declaredAnnotatedFields.trimToSize();
+      this.declaredMetaAnnotatedFields.trimToSize();
 
       // Assign constructor information
-      this.constructors = new HashSet<AnnotatedConstructor<T>>();
+      this.constructors = new ArrayList<AnnotatedConstructor<T>>();
       this.constructorsByArgumentMap = new HashMap<List<Class<?>>, WeldConstructor<T>>();
-      this.annotatedConstructors = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldConstructor<T>>>(), HashSetSupplier.<WeldConstructor<T>> instance());
+      this.annotatedConstructors = ArrayListMultimap.<Class<? extends Annotation>, WeldConstructor<T>> create();
 
       this.declaredConstructorsBySignature = new HashMap<ConstructorSignature, WeldConstructor<?>>();
       if (annotatedType == null)
@@ -265,13 +267,15 @@
             mapConstructorAnnotations(annotatedConstructors, weldConstructor);
          }
       }
+      this.constructors.trimToSize();
+      this.annotatedConstructors.trimToSize();
 
       // Assign method information
-      this.methods = new HashSet<WeldMethod<?, ?>>();
-      this.annotatedMethods = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, ?>>>(), HashSetSupplier.<WeldMethod<?, ?>> instance());
-      this.declaredMethods = new HashSet<WeldMethod<?, ?>>();
-      this.declaredAnnotatedMethods = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, ? super T>>>(), HashSetSupplier.<WeldMethod<?, ? super T>> instance());
-      this.declaredMethodsByAnnotatedParameters = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?,? super T>>>(), HashSetSupplier.<WeldMethod<?, ? super T>> instance());
+      this.methods = new ArrayList<WeldMethod<?, ?>>();
+      this.annotatedMethods = ArrayListMultimap.<Class<? extends Annotation>, WeldMethod<?, ?>> create();
+      this.declaredMethods = new ArrayList<WeldMethod<?, ?>>();
+      this.declaredAnnotatedMethods = ArrayListMultimap.<Class<? extends Annotation>, WeldMethod<?, ? super T>> create();
+      this.declaredMethodsByAnnotatedParameters = ArrayListMultimap.<Class<? extends Annotation>, WeldMethod<?, ? super T>> create();
       this.declaredMethodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
       this.methodsBySignature = new HashMap<MethodSignature, WeldMethod<?, ?>>();
 
@@ -342,8 +346,12 @@
             }
          }
       }
+      this.methods.trimToSize();
+      this.annotatedMethods.trimToSize();
+      this.declaredAnnotatedMethods.trimToSize();
+      this.declaredMethodsByAnnotatedParameters.trimToSize();
 
-      this.declaredMetaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation> instance());
+      this.declaredMetaAnnotationMap = ArrayListMultimap.<Class<? extends Annotation>, Annotation> create();
       for (Annotation declaredAnnotation : declaredAnnotationMap.values())
       {
          addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, declaredAnnotation.annotationType().getAnnotations(), true);
@@ -393,26 +401,28 @@
     * 
     * @return The set of abstracted fields
     */
-   public Set<WeldField<?, ?>> getWeldFields()
+   public Collection<WeldField<?, ?>> getWeldFields()
    {
-      return Collections.unmodifiableSet(fields);
+      return Collections.unmodifiableCollection(fields);
    }
 
-   public Set<WeldField<?, ?>> getDeclaredFields()
+   public Collection<WeldField<?, ?>> getDeclaredFields()
    {
-      return Collections.unmodifiableSet(declaredFields);
+      return Collections.unmodifiableCollection(declaredFields);
    }
 
+   @SuppressWarnings("unchecked")
    public <F> WeldField<F, ?> getDeclaredWeldField(String fieldName)
    {
       return (WeldField<F, ?>) declaredFieldsByName.get(fieldName);
    }
 
-   public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
+   public Collection<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(declaredAnnotatedFields.get(annotationType));
+      return Collections.unmodifiableCollection(declaredAnnotatedFields.get(annotationType));
    }
 
+   @SuppressWarnings("unchecked")
    public WeldConstructor<T> getDeclaredWeldConstructor(ConstructorSignature signature)
    {
       return (WeldConstructor<T>) declaredConstructorsBySignature.get(signature);
@@ -427,9 +437,9 @@
     * @return A set of matching abstracted fields, null if none are found.
     * 
     */
-   public Set<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
+   public Collection<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(annotatedFields.get(annotationType));
+      return Collections.unmodifiableCollection(annotatedFields.get(annotationType));
    }
 
    public boolean isLocalClass()
@@ -473,14 +483,14 @@
     * 
     * @see org.jboss.weld.introspector.WeldClass#getWeldMethods(Class)
     */
-   public Set<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(annotatedMethods.get(annotationType));
+      return Collections.unmodifiableCollection(annotatedMethods.get(annotationType));
    }
 
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(declaredAnnotatedMethods.get(annotationType));
+      return Collections.unmodifiableCollection(declaredAnnotatedMethods.get(annotationType));
    }
 
    /**
@@ -493,9 +503,9 @@
     * 
     * @see org.jboss.weld.introspector.WeldClass#getWeldConstructors(Class)
     */
-   public Set<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
+   public Collection<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(annotatedConstructors.get(annotationType));
+      return Collections.unmodifiableCollection(annotatedConstructors.get(annotationType));
    }
 
    public WeldConstructor<T> getNoArgsWeldConstructor()
@@ -503,9 +513,9 @@
       return constructorsByArgumentMap.get(Collections.emptyList());
    }
 
-   public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
+   public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
    {
-      return Collections.unmodifiableSet(declaredMethodsByAnnotatedParameters.get(annotationType));
+      return Collections.unmodifiableCollection(declaredMethodsByAnnotatedParameters.get(annotationType));
    }
 
    public WeldMethod<?, ?> getWeldMethod(Method methodDescriptor)
@@ -521,9 +531,9 @@
       return null;
    }
 
-   public Set<WeldMethod<?, ?>> getWeldMethods()
+   public Collection<WeldMethod<?, ?>> getWeldMethods()
    {
-      return Collections.unmodifiableSet(methods);
+      return Collections.unmodifiableCollection(methods);
    }
 
    public WeldMethod<?, ?> getDeclaredWeldMethod(Method method)
@@ -539,7 +549,7 @@
       return null;
    }
 
-   public Set<WeldMethod<?, ?>> getDeclaredWeldMethods()
+   public Collection<WeldMethod<?, ?>> getDeclaredWeldMethods()
    {
       return declaredMethods;
    }
@@ -660,26 +670,28 @@
       return (S) object;
    }
 
+   @SuppressWarnings("unchecked")
    public Set<AnnotatedConstructor<T>> getConstructors()
    {
-      return constructors;
+      return new HashSet(constructors);
    }
 
    @SuppressWarnings("unchecked")
    public Set<AnnotatedField<? super T>> getFields()
    {
-      return (Set) fields;
+      return new HashSet(fields);
    }
 
    @SuppressWarnings("unchecked")
    public Set<AnnotatedMethod<? super T>> getMethods()
    {
-      return (Set) methods;
+      return new HashSet(methods);
    }
 
+   @SuppressWarnings("unchecked")
    public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
    {
-      return Collections.unmodifiableSet(declaredMetaAnnotationMap.get(metaAnnotationType));
+      return Collections.unmodifiableSet(new HashSet(declaredMetaAnnotationMap.get(metaAnnotationType)));
    }
 
    public boolean isDiscovered()

Modified: core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/introspector/jlr/WeldMethodImpl.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -22,9 +22,7 @@
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -40,13 +38,11 @@
 import org.jboss.weld.logging.messages.ReflectionMessage;
 import org.jboss.weld.resources.ClassTransformer;
 import org.jboss.weld.util.Names;
-import org.jboss.weld.util.collections.ArrayListSupplier;
 import org.jboss.weld.util.reflection.HierarchyDiscovery;
 import org.jboss.weld.util.reflection.Reflections;
 import org.jboss.weld.util.reflection.SecureReflections;
 
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Multimaps;
+import com.google.common.collect.ArrayListMultimap;
 
 /**
  * Represents an annotated method
@@ -64,10 +60,10 @@
    private final Method method;
 
    // The abstracted parameters
-   private final List<WeldParameter<?, X>> parameters;
+   private final ArrayList<WeldParameter<?, X>> parameters;
    // A mapping from annotation type to parameter abstraction with that
    // annotation present
-   private final ListMultimap<Class<? extends Annotation>, WeldParameter<?, X>> annotatedParameters;
+   private final ArrayListMultimap<Class<? extends Annotation>, WeldParameter<?, X>> annotatedParameters;
 
    // The property name
    private final String propertyName;
@@ -99,7 +95,7 @@
       super(annotationMap, declaredAnnotationMap, classTransformer, method, rawType, type, typeClosure, declaringClass);
       this.method = method;
       this.parameters = new ArrayList<WeldParameter<?, X>>();
-      this.annotatedParameters = Multimaps.newListMultimap(new HashMap<Class<? extends Annotation>, Collection<WeldParameter<?, X>>>(), ArrayListSupplier.<WeldParameter<?, X>>instance());
+      this.annotatedParameters = ArrayListMultimap.<Class<? extends Annotation>, WeldParameter<?, X>> create();
 
       if (annotatedMethod == null)
       {
@@ -151,8 +147,9 @@
          }
          
       }
+      this.parameters.trimToSize();
+      this.annotatedParameters.trimToSize();
 
-      
 
       String propertyName = Reflections.getPropertyName(getDelegate());
       if (propertyName == null)

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -241,7 +241,7 @@
       List<WeldMethod<?, ? super T>> methods = new ArrayList<WeldMethod<?, ? super T>>();
       while (!t.getJavaClass().equals(Object.class))
       {
-         Set<WeldMethod<?, ? super T>> declaredMethods = (Set) t.getDeclaredWeldMethods(PostConstruct.class);
+         Collection<WeldMethod<?, ? super T>> declaredMethods = (Collection) t.getDeclaredWeldMethods(PostConstruct.class);
          log.trace(FOUND_POST_CONSTRUCT_METHODS, declaredMethods, type);
          if (declaredMethods.size() > 1)
          {
@@ -264,7 +264,7 @@
       List<WeldMethod<?, ? super T>> methods = new ArrayList<WeldMethod<?, ? super T>>();
       while (!t.getJavaClass().equals(Object.class))
       {
-         Set<WeldMethod<?, ? super T>> declaredMethods = (Set) t.getDeclaredWeldMethods(PreDestroy.class);
+         Collection<WeldMethod<?, ? super T>> declaredMethods = (Collection) t.getDeclaredWeldMethods(PreDestroy.class);
          log.trace(FOUND_PRE_DESTROY_METHODS, declaredMethods, type);
          if (declaredMethods.size() > 1)
          {
@@ -685,7 +685,7 @@
    public static <T> ConstructorInjectionPoint<T> getBeanConstructor(Bean<T> declaringBean, WeldClass<T> type)
    {
       ConstructorInjectionPoint<T> constructor = null;
-      Set<WeldConstructor<T>> initializerAnnotatedConstructors = type.getWeldConstructors(Inject.class);
+      Collection<WeldConstructor<T>> initializerAnnotatedConstructors = type.getWeldConstructors(Inject.class);
       log.trace(FOUND_INJECTABLE_CONSTRUCTORS, initializerAnnotatedConstructors, type);
       if (initializerAnnotatedConstructors.size() > 1)
       {

Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/HierarchyDiscovery.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/HierarchyDiscovery.java	2010-05-10 14:26:25 UTC (rev 6223)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/HierarchyDiscovery.java	2010-05-10 16:58:39 UTC (rev 6224)
@@ -22,6 +22,7 @@
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.security.AccessControlException;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -53,9 +54,10 @@
       {
          init();
       }
-      return types.keySet();
+      // Return an independent set with no ties to the BiMap used
+      return new HashSet<Type>(types.keySet());
    }
-   
+
    public Map<Class<?>, Type> getTypeMap()
    {
       if (types == null)
@@ -64,7 +66,7 @@
       }
       return types.inverse();
    }
-   
+
    private void init()
    {
       this.types = HashBiMap.create();



More information about the weld-commits mailing list