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

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Nov 27 08:33:35 EST 2008


Author: nickarls
Date: 2008-11-27 08:33:35 -0500 (Thu, 27 Nov 2008)
New Revision: 371

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/jlr/AnnotatedClassImpl.java
Log:
some javadocs/comments

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-11-27 11:00:34 UTC (rev 370)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java	2008-11-27 13:33:35 UTC (rev 371)
@@ -115,7 +115,7 @@
 
    /**
     * Checks if any of the types provided are assignable to this, using
-    * the extended assingablity algorithm provided by AnnotatedItem.
+    * the extended assignability algorithm provided by AnnotatedItem.
     * 
     * The types are assumed to contain their own actual type parameterization.
     * 

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-11-27 11:00:34 UTC (rev 370)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java	2008-11-27 13:33:35 UTC (rev 371)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.jboss.webbeans.introspector.jlr;
 
 import java.lang.annotation.Annotation;
@@ -19,29 +36,132 @@
 import org.jboss.webbeans.introspector.AnnotatedField;
 import org.jboss.webbeans.introspector.AnnotatedMethod;
 
+import com.google.common.collect.ForwardingMap;
+
 /**
- * Base class for implementing AnnotatedItem.
+ * Represents an annotated class
  * 
- * @author pmuir
+ * @author Pete Muir
  * 
+ * @param <T>
  */
 public class AnnotatedClassImpl<T> extends AbstractAnnotatedType<T> implements AnnotatedClass<T>
 {
 
+   protected static class AnnotatedFields extends ForwardingMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>
+   {
+      private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> delegate;
+
+      public AnnotatedFields()
+      {
+         delegate = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
+      }
+
+      @Override
+      protected Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> delegate()
+      {
+         return delegate;
+      }
+   }
+
+   protected static class MetaAnnotatedFields extends ForwardingMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>
+   {
+      private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> delegate;
+
+      public MetaAnnotatedFields()
+      {
+         delegate = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
+      }
+
+      @Override
+      protected Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> delegate()
+      {
+         return delegate;
+      }
+   }
+
+   protected class AnnotatedMethods extends ForwardingMap<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>>
+   {
+      private Map<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>> delegate;
+
+      public AnnotatedMethods()
+      {
+         delegate = new HashMap<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>>();
+      }
+
+      @Override
+      protected Map<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>> delegate()
+      {
+         return delegate;
+      }
+   }
+
+   protected class AnnotatedConstructors extends ForwardingMap<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>>
+   {
+      private Map<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>> delegate;
+
+      public AnnotatedConstructors()
+      {
+         delegate = new HashMap<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>>();
+      }
+
+      @Override
+      protected Map<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>> delegate()
+      {
+         return delegate;
+      }
+   }
+
+   protected class ConstructorsByArgument extends ForwardingMap<List<Class<?>>, AnnotatedConstructor<T>>
+   {
+      private Map<List<Class<?>>, AnnotatedConstructor<T>> delegate;
+
+      public ConstructorsByArgument()
+      {
+         delegate = new HashMap<List<Class<?>>, AnnotatedConstructor<T>>();
+      }
+
+      @Override
+      protected Map<List<Class<?>>, AnnotatedConstructor<T>> delegate()
+      {
+         return delegate;
+      }
+   }
+
+   // The implementing class
    private Class<T> clazz;
+   // The type arguments
    private Type[] actualTypeArguments;
 
+   // The set of abstracted fields
    private Set<AnnotatedField<Object>> fields;
-   private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> annotatedFields;
-   private Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> metaAnnotatedFields;
+   // The map from annotation type to abstracted field with annotation
+   private AnnotatedFields annotatedFields;
+   // The map from annotation type to abstracted field with meta-annotation
+   private MetaAnnotatedFields metaAnnotatedFields;
 
+   // The set of abstracted methods
    private Set<AnnotatedMethod<Object>> methods;
-   private Map<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>> annotatedMethods;
+   // The map from annotation type to abstracted method with annotation
+   private AnnotatedMethods annotatedMethods;
 
+   // The set of abstracted constructors
    private Set<AnnotatedConstructor<T>> constructors;
-   private Map<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>> annotatedConstructors;
-   private Map<List<Class<?>>, AnnotatedConstructor<T>> constructorsByArgumentMap;
+   // The map from annotation type to abstracted constructor with annotation
+   private AnnotatedConstructors annotatedConstructors;
+   // The map from class list to abstracted constructor
+   private ConstructorsByArgument constructorsByArgumentMap;
 
+   /**
+    * Constructor
+    * 
+    * Initializes superclass with built annotation map, sets the raw type and
+    * determines the actual type arguments
+    * 
+    * @param rawType The raw type of the class
+    * @param type The type of the class
+    * @param annotations The array of annotations on the class
+    */
    public AnnotatedClassImpl(Class<T> rawType, Type type, Annotation[] annotations)
    {
       super(buildAnnotationMap(annotations));
@@ -56,21 +176,45 @@
       }
    }
 
+   /**
+    * Constructor
+    * 
+    * Calls another constructor with the class annotations array
+    * 
+    * @param clazz The implementing class
+    */
    public AnnotatedClassImpl(Class<T> clazz)
    {
       this(clazz, clazz, clazz.getAnnotations());
    }
 
+   /**
+    * Gets the implementing class
+    * 
+    * @return The class
+    */
    public Class<? extends T> getAnnotatedClass()
    {
       return clazz;
    }
 
+   /**
+    * Gets the delegate (class)
+    * 
+    * @return The class
+    */
    public Class<T> getDelegate()
    {
       return clazz;
    }
 
+   /**
+    * Gets the abstracted fields of the class
+    * 
+    * Initializes the fields if they are null
+    * 
+    * @return The set of abstracted fields
+    */
    public Set<AnnotatedField<Object>> getFields()
    {
       if (fields == null)
@@ -80,6 +224,13 @@
       return fields;
    }
 
+   /**
+    * Gets the abstracted constructors of the class
+    * 
+    * Initializes the constructors if they are null
+    * 
+    * @return The set of abstracted constructors
+    */
    public Set<AnnotatedConstructor<T>> getConstructors()
    {
       if (constructors == null)
@@ -89,25 +240,46 @@
       return 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 (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
+    * fields are null, it is initialized The meta-annotated field map is then
+    * populated for the requested meta-annotation type and the result is
+    * returned
+    * 
+    * @param metaAnnotationType The meta-annotation type to match
+    * @return The set of abstracted fields with meta-annotation present. Returns
+    *         an empty set if no matches are found.
+    */
    public Set<AnnotatedField<Object>> getMetaAnnotatedFields(Class<? extends Annotation> metaAnnotationType)
    {
       if (metaAnnotatedFields == null)
       {
-         metaAnnotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
+         metaAnnotatedFields = new MetaAnnotatedFields();
       }
       if (annotatedFields == null)
       {
@@ -117,7 +289,16 @@
       return metaAnnotatedFields.get(metaAnnotationType);
    }
 
-   protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> populateMetaAnnotatedFieldMap(Class<T> metaAnnotationType, Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> annotatedFields, Map<Class<? extends Annotation>, Set<AnnotatedField<Object>>> metaAnnotatedFields)
+   /**
+    * Populates the meta annotated fields map for a meta-annotation type
+    * 
+    * @param <T>
+    * @param metaAnnotationType The meta-annotation to examine
+    * @param annotatedFields The annotated fields
+    * @param metaAnnotatedFields The meta-annotated fields
+    * @return The meta-annotated fields map
+    */
+   protected static <T extends Annotation> MetaAnnotatedFields populateMetaAnnotatedFieldMap(Class<T> metaAnnotationType, AnnotatedFields annotatedFields, MetaAnnotatedFields metaAnnotatedFields)
    {
       if (!metaAnnotatedFields.containsKey(metaAnnotationType))
       {
@@ -134,6 +315,15 @@
       return metaAnnotatedFields;
    }
 
+   /**
+    * Gets the abstracted field annotated with a specific annotation type
+    * 
+    * If the fields map is null, initialize it first
+    * 
+    * @param annotationType The annotation type to match
+    * @return A set of matching abstracted fields, null if none are found.
+    * 
+    */
    public Set<AnnotatedField<Object>> getAnnotatedFields(Class<? extends Annotation> annotationType)
    {
       if (annotatedFields == null)
@@ -143,13 +333,20 @@
       return annotatedFields.get(annotationType);
    }
 
+   /**
+    * Initializes the 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.
+    */
    private void initAnnotatedFields()
    {
       if (fields == null)
       {
          initFields();
       }
-      annotatedFields = new HashMap<Class<? extends Annotation>, Set<AnnotatedField<Object>>>();
+      annotatedFields = new AnnotatedFields();
       for (AnnotatedField<Object> field : fields)
       {
          for (Annotation annotation : field.getAnnotations())
@@ -163,30 +360,57 @@
       }
    }
 
+   /**
+    * Gets the type of the class
+    * 
+    * @return The type
+    */
    public Class<T> getType()
    {
       return clazz;
    }
 
+   /**
+    * Gets the actual type arguments
+    * 
+    * @return The type arguments
+    */
    public Type[] getActualTypeArguments()
    {
       return actualTypeArguments;
    }
 
+   /**
+    * 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 (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
+    * 
+    * @param annotationType The annotation type to match
+    * @return A set of matching method abstractions. Returns an empty set if no
+    *         matches are found.
+    */
    public Set<AnnotatedMethod<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType)
    {
       if (annotatedMethods == null)
@@ -204,13 +428,20 @@
       }
    }
 
+   /**
+    * 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 HashMap<Class<? extends Annotation>, Set<AnnotatedMethod<Object>>>();
+      annotatedMethods = new AnnotatedMethods();
       for (AnnotatedMethod<Object> member : methods)
       {
          for (Annotation annotation : member.getAnnotations())
@@ -224,20 +455,38 @@
       }
    }
 
+   /**
+    * 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 HashMap<List<Class<?>>, AnnotatedConstructor<T>>();
+      this.constructorsByArgumentMap = new ConstructorsByArgument();
       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
+    * @return A set of abstracted constructors with given annotation type. If
+    *         the constructors set is empty, initialize it first .Returns an
+    *         empty set if there are no matches.
+    */
    public Set<AnnotatedConstructor<T>> getAnnotatedConstructors(Class<? extends Annotation> annotationType)
    {
       if (annotatedConstructors == null)
@@ -255,13 +504,20 @@
       }
    }
 
+   /**
+    * 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 HashMap<Class<? extends Annotation>, Set<AnnotatedConstructor<T>>>();
+      annotatedConstructors = new AnnotatedConstructors();
       for (AnnotatedConstructor<T> constructor : constructors)
       {
          for (Annotation annotation : constructor.getAnnotations())




More information about the weld-commits mailing list