[jboss-cvs] JBossAS SVN: r70888 - projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Mar 15 17:09:59 EDT 2008


Author: alesj
Date: 2008-03-15 17:09:59 -0400 (Sat, 15 Mar 2008)
New Revision: 70888

Modified:
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldBeanInfo.java
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldPropertyInfo.java
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/GetterAndFieldPropertyInfo.java
   projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/SetterAndFieldPropertyInfo.java
Log:
JBREFLECT-22; removing todos.

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -125,22 +125,7 @@
 
          for (PropertyInfo property : properties)
          {
-            PropertyInfo previous = replaceAndAddProperty(property);
-            if (previous != null)
-            {
-               NestedPropertyInfo nestedPropertyInfo;
-               if (previous instanceof NestedPropertyInfo)
-               {
-                  nestedPropertyInfo = (NestedPropertyInfo)previous;
-               }
-               else
-               {
-                  nestedPropertyInfo = new NestedPropertyInfo(previous.getName(), this);
-                  nestedPropertyInfo.addPropertyInfo(previous);
-                  propertiesByName.put(previous.getName(), nestedPropertyInfo);
-               }
-               nestedPropertyInfo.addPropertyInfo(property);
-            }
+            replaceAndAddProperty(property);
          }
       }
    }
@@ -180,10 +165,10 @@
     * @param property the property to add
     * @return previous property or null if it doesn't exist
     */
-   protected PropertyInfo replaceAndAddProperty(PropertyInfo property)
+   protected void replaceAndAddProperty(PropertyInfo property)
    {
       property = replaceProperty(property);
-      return addProperty(property);
+      addProperty(property);
    }
 
    /**
@@ -192,16 +177,30 @@
     * @param property the property to add
     * @return previous property or null if it doesn't exist
     */
-   protected PropertyInfo addProperty(PropertyInfo property)
+   protected void addProperty(PropertyInfo property)
    {
       properties.add(property);
       PropertyInfo previous = propertiesByName.put(property.getName(), property);
+      if (previous != null)
+      {
+         NestedPropertyInfo nestedPropertyInfo;
+         if (previous instanceof NestedPropertyInfo)
+         {
+            nestedPropertyInfo = (NestedPropertyInfo)previous;
+         }
+         else
+         {
+            nestedPropertyInfo = new NestedPropertyInfo(previous.getName(), this);
+            nestedPropertyInfo.addPropertyInfo(previous);
+            propertiesByName.put(previous.getName(), nestedPropertyInfo);
+         }
+         nestedPropertyInfo.addPropertyInfo(property);
+      }
       if (property instanceof AbstractPropertyInfo)
       {
          AbstractPropertyInfo ainfo = (AbstractPropertyInfo) property;
          ainfo.setBeanInfo(this);
       }
-      return previous;
    }
 
    /**

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -309,17 +309,7 @@
             AnnotationValue[] setterAnnotations = null;
             if (setter != null)
                setterAnnotations = setter.getAnnotations();
-            if (annotations == null || annotations.length == 0)
-               annotations = setterAnnotations;
-            else if (setterAnnotations != null && setterAnnotations.length > 0)
-            {
-               HashSet<AnnotationValue> merged = new HashSet<AnnotationValue>();
-               for (AnnotationValue annotation : annotations)
-                  merged.add(annotation);
-               for (AnnotationValue annotation : setterAnnotations)
-                  merged.add(annotation);
-               annotations = merged.toArray(new AnnotationValue[merged.size()]);
-            }
+            annotations = mergeAnnotations(annotations, setterAnnotations);
             TypeInfo type = getPropertyType(getter, setter);
             properties.add(new DefaultPropertyInfo(lowerName, name, type, getter, setter, annotations));
          }
@@ -343,6 +333,22 @@
       return properties;
    }
 
+   static AnnotationValue[] mergeAnnotations(AnnotationValue[] first, AnnotationValue[] second)
+   {
+      if (first == null || first.length == 0)
+         first = second;
+      else if (second != null && second.length > 0)
+      {
+         HashSet<AnnotationValue> merged = new HashSet<AnnotationValue>();
+         for (AnnotationValue annotation : first)
+            merged.add(annotation);
+         for (AnnotationValue annotation : second)
+            merged.add(annotation);
+         first = merged.toArray(new AnnotationValue[merged.size()]);
+      }
+      return first;
+   }
+
    /**
     * Determine the type of PropertyInfo.
     *

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldBeanInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldBeanInfo.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldBeanInfo.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -65,7 +65,8 @@
       for(FieldInfo field : fieldsByName.values())
       {
          PropertyInfo previous = findPropertyInfo(field.getName());
-         if (previous == null)
+         // expecting that property type is less exact
+         if (previous == null || previous.getType().isAssignableFrom(field.getType()) == false)
             addProperty(new FieldPropertyInfo(field));
       }
    }
@@ -77,13 +78,13 @@
       if (original.isReadable() == false)
       {
          FieldInfo field = getField(name);
-         if (field != null) // TODO - match type?
+         if (field != null && original.getType().isAssignableFrom(field.getType()))
             return new SetterAndFieldPropertyInfo(original, field);
       }
       else if (original.isWritable() == false)
       {
          FieldInfo field = getField(name);
-         if (field != null) // TODO - match type?
+         if (field != null && original.getType().isAssignableFrom(field.getType()))
             return new GetterAndFieldPropertyInfo(original, field);
       }
       return original;
@@ -137,9 +138,9 @@
          FieldInfo[] finfos = classInfo.getDeclaredFields();
          if (finfos != null && finfos.length > 0)
          {
-            for (int i = 0; i < finfos.length; ++i)
-               if (filter.useField(finfos[i]))
-                  fields.add(finfos[i]);
+            for (FieldInfo field : finfos)
+               if (filter.useField(field))
+                  fields.add(field);
          }
          classInfo = classInfo.getSuperclass();
       }

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldPropertyInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldPropertyInfo.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/FieldPropertyInfo.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -39,12 +39,18 @@
 
    public FieldPropertyInfo(FieldInfo field)
    {
+      this(field, true);
+   }
+
+   protected FieldPropertyInfo(FieldInfo field, boolean setAnnotations)
+   {
       if (field == null)
          throw new IllegalArgumentException("Null field");
 
       this.field = field;
       init(field.getName(), field.getName(), field.getType());
-      setupAnnotations(field.getAnnotations());
+      if (setAnnotations)
+         setupAnnotations(field.getAnnotations());
    }
 
    public MethodInfo getGetter()

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/GetterAndFieldPropertyInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/GetterAndFieldPropertyInfo.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/GetterAndFieldPropertyInfo.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -24,6 +24,7 @@
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.reflect.spi.FieldInfo;
 import org.jboss.reflect.spi.MethodInfo;
+import static org.jboss.beans.info.plugins.AbstractBeanInfoFactory.mergeAnnotations;
 
 /**
  * Combined getter and field property info.
@@ -39,12 +40,12 @@
 
    public GetterAndFieldPropertyInfo(PropertyInfo previous, FieldInfo field)
    {
-      // TODO - what to do with annotations, merge?
-      super(field);
+      super(field, false);
 
       if (previous == null)
          throw new IllegalArgumentException("Null previous");
       this.previous = previous;
+      setupAnnotations(mergeAnnotations(field.getAnnotations(), previous.getAnnotations()));
    }
 
    public Object get(Object bean) throws Throwable

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/SetterAndFieldPropertyInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/SetterAndFieldPropertyInfo.java	2008-03-15 20:47:37 UTC (rev 70887)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/beans/info/plugins/SetterAndFieldPropertyInfo.java	2008-03-15 21:09:59 UTC (rev 70888)
@@ -24,6 +24,7 @@
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.reflect.spi.FieldInfo;
 import org.jboss.reflect.spi.MethodInfo;
+import static org.jboss.beans.info.plugins.AbstractBeanInfoFactory.mergeAnnotations;
 
 /**
  * Combined setter and field property info.
@@ -39,12 +40,12 @@
 
    public SetterAndFieldPropertyInfo(PropertyInfo previous, FieldInfo field)
    {
-      // TODO - what to do with annotations, merge?
-      super(field);
+      super(field, false);
 
       if (previous == null)
          throw new IllegalArgumentException("Null previous");
       this.previous = previous;
+      setupAnnotations(mergeAnnotations(field.getAnnotations(), previous.getAnnotations()));
    }
 
    public void set(Object bean, Object value) throws Throwable




More information about the jboss-cvs-commits mailing list