[jboss-cvs] JBossAS SVN: r63835 - projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 5 06:17:57 EDT 2007


Author: flavia.rainone at jboss.com
Date: 2007-07-05 06:17:57 -0400 (Thu, 05 Jul 2007)
New Revision: 63835

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Algorithm.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/VariableNode.java
Log:
[JBAOP-420] More bugs fixed.

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Algorithm.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Algorithm.java	2007-07-05 09:17:55 UTC (rev 63834)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/Algorithm.java	2007-07-05 10:17:57 UTC (rev 63835)
@@ -120,6 +120,31 @@
          }
          return inside;
       }
+      else if (fromType instanceof WildcardType)
+      {
+         WildcardType fromWildcard = (WildcardType) fromType;
+         boolean boundOk = false;
+         for (Type upperBound: fromWildcard.getUpperBounds())
+         {
+            if (isAssignable(classType, upperBound, variableHierarchy))
+            {
+               boundOk = true;
+               break;
+            }
+         }
+         if (!boundOk)
+         {
+            return false;
+         }
+         for (Type lowerBound: fromWildcard.getLowerBounds())
+         {
+            if (isAssignable(classType, lowerBound, variableHierarchy))
+            {
+               return true;
+            }
+         }
+         return fromWildcard.getLowerBounds().length == 0;
+      }
       // type instanceof GenericArrayType (ommitting check for performance
       // reasons)
       if (classType == Object.class)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/VariableNode.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/VariableNode.java	2007-07-05 09:17:55 UTC (rev 63834)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/VariableNode.java	2007-07-05 10:17:57 UTC (rev 63835)
@@ -40,6 +40,8 @@
  */
 public class VariableNode
 {
+   private static int boundComparation = 0;
+   private Map<String, VariableNode> map;
    private VariableNode previous;
    private VariableNode next;
    private Collection<Type> lowerBounds;
@@ -48,6 +50,7 @@
    
    public VariableNode(TypeVariable content, Map<String, VariableNode> map)
    {
+      this.map = map;
       this.variable = content;
       lowerBounds = new HashSet<Type>();
       Type[] bounds = content.getBounds();
@@ -69,9 +72,15 @@
    
    public final boolean assignValue(Type value)
    {
+      if (boundComparation > 0 && !(value instanceof Class)
+            && !(value instanceof ParameterizedType))
+      {
+         return false;
+      }
       if (this.assignedValue != null)
       {
-         return isSame(this.assignedValue, value, true);
+         // TODO HERE1 HERE HERE HERE HERE
+         return isSame(value, this.assignedValue, true);
       }
       
       // TODO fix this
@@ -100,14 +109,7 @@
       if (lowerBound instanceof TypeVariable)
       {
          Type[] bounds = ((TypeVariable) lowerBound).getBounds();
-         if (bounds.length == 1)
-         {
-            this.lowerBounds.add(bounds[0]);
-         }
-         else
-         {
-            this.lowerBounds.add(new ChoiceBound(bounds));
-         }
+         this.lowerBounds.add(new ChoiceBound((TypeVariable) lowerBound, bounds));
       }
       else
       {
@@ -146,7 +148,7 @@
       {
          for (Type bound: this.lowerBounds)
          {
-            if (!isAssignable(lowerBound, bound))
+            if (!isAssignable(bound, lowerBound))
             {
                return false;
             }
@@ -155,67 +157,81 @@
       if (next == null)
       {
          Type[] bounds = variable.getBounds();
+         boundComparation ++;
          for (int i = 0; i < bounds.length; i++)
          {
-            if (isAssignable(bounds[i], lowerBound))
+            // TODO HERE HERE HERE HERE
+            if (!Algorithm.getInstance().isAssignable(bounds[i], lowerBound, map))
             {
-               return true;
+               boundComparation --;
+               return false;
             }
          }
-         return false;
+         boundComparation --;
+         return true;
       }
       return next.isInsideBounds(lowerBound, true);
    }
    
+   private boolean isAssignable(TypeVariable type, TypeVariable fromType)
+   {
+      Type[] fromBounds = fromType.getBounds();
+      if (type == fromType)
+      {
+         return true;
+      }
+      while (fromBounds.length == 1 && fromBounds[0] instanceof TypeVariable)
+      {
+         if (fromBounds[0] == type)
+         {
+            return true;
+         }
+         fromType = (TypeVariable) fromBounds[0];
+         fromBounds = fromType.getBounds();
+      }
+      TypeVariable variable = (TypeVariable) type;
+      Type[] bounds = variable.getBounds();
+      while (bounds.length == 1 && bounds[0] instanceof TypeVariable)
+      {
+         if (bounds[0] == fromType)
+         {
+            return false;
+         }
+         variable = (TypeVariable) bounds[0];
+         bounds = variable.getBounds();
+      }
+      // TODO check if this should really be removed
+      /*outer: for (int i = 0; i < bounds.length; i++)
+      {
+         for (int j = 0; j < fromBounds.length; j++)
+         {
+            if (isAssignable(bounds[i], fromBounds[j]))
+            {
+               continue outer;
+            }
+         }
+         return false;
+      }
+      return true;*/
+      return false;
+   }
+   
    // both type and bound belong to the same context
    private boolean isAssignable(Type type, Type fromType)
    {
       if (fromType instanceof TypeVariable)
       {
          TypeVariable fromVariable = (TypeVariable) fromType;
-         Type[] fromBounds = fromVariable.getBounds();
          if (type instanceof TypeVariable)
          {
-            if (type == fromType)
-            {
-               return true;
-            }
-            while (fromBounds.length == 1 && fromBounds[0] instanceof TypeVariable)
-            {
-               if (fromBounds[0] == type)
-               {
-                  return true;
-               }
-               fromType = (TypeVariable) fromBounds[0];
-               fromBounds = fromVariable.getBounds();
-            }
-            TypeVariable variable = (TypeVariable) type;
-            Type[] bounds = variable.getBounds();
-            while (bounds.length == 1 && bounds[0] instanceof TypeVariable)
-            {
-               if (bounds[0] == fromType)
-               {
-                  return false;
-               }
-               variable = (TypeVariable) bounds[0];
-               bounds = variable.getBounds();
-            }
-            outer: for (int i = 0; i < bounds.length; i++)
-            {
-               for (int j = 0; j < fromBounds.length; j++)
-               {
-                  if (isAssignable(bounds[i], fromBounds[j]))
-                  {
-                     continue outer;
-                  }
-               }
-               return false;
-            }
-            return true;
+            return isAssignable((TypeVariable) type, fromVariable);
          }
+         Type[] fromBounds = fromVariable.getBounds();
+         TypeVariable temp = fromVariable;
          while (fromBounds.length == 1 && fromBounds[0] instanceof TypeVariable)
          {
-            fromBounds = fromVariable.getBounds();
+            temp = (TypeVariable) fromBounds[0];
+            fromBounds = temp.getBounds();            
          }
          for (Type fromBound: fromBounds)
          {
@@ -226,6 +242,24 @@
          }
          return false;
       }
+      if (fromType instanceof ChoiceBound)
+      {
+         ChoiceBound fromChoiceBound = (ChoiceBound) fromType;
+         if (type instanceof TypeVariable &&
+               !isAssignable((TypeVariable) type, fromChoiceBound.variable))
+         {
+            return false;
+         }
+         for (Iterator<Type> it = fromChoiceBound.bounds.iterator(); it.hasNext();)
+         {
+            Type fromOption = it.next();
+            if (!isAssignable(type, fromOption))
+            {
+               it.remove();
+            }
+         }
+         return !fromChoiceBound.bounds.isEmpty();
+      }
       if (type instanceof Class)
       {
          if (type == Object.class)
@@ -257,7 +291,7 @@
             {
                return false;
             }
-            for (Type lowerBound: fromWildcard.getUpperBounds())
+            for (Type lowerBound: fromWildcard.getLowerBounds())
             {
                if (isAssignable(type, lowerBound))
                {
@@ -297,6 +331,11 @@
          return true;
       }
       ChoiceBound choiceBound = (ChoiceBound) type;
+      if (fromType instanceof TypeVariable &&
+            !isAssignable(choiceBound.variable, (TypeVariable) fromType))
+      {
+         return false;
+      }
       for (Iterator<Type> it = choiceBound.bounds.iterator(); it.hasNext();)
       {
          Type boundOption = it.next();
@@ -403,18 +442,19 @@
       {
          public boolean isSame(Type argument, Type fromArgument, VariableNode node, boolean boundLevel)
          {
-            return node.isSame(fromArgument, argument, false);
+            return node.isSame(argument, fromArgument, false);
          }
       };
 }
 
 class ChoiceBound implements Type
 {
-   public ChoiceBound(Type[] bounds)
+   public ChoiceBound(TypeVariable variable, Type[] bounds)
    {
+      this.variable = variable;
       this.bounds = new LinkedList<Type>();
       Collections.addAll(this.bounds, bounds);
    }
-   
+   TypeVariable variable;
    Collection<Type> bounds;
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list