[jboss-cvs] JBossAS SVN: r68919 - projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 12 08:55:40 EST 2008


Author: flavia.rainone at jboss.com
Date: 2008-01-12 08:55:40 -0500 (Sat, 12 Jan 2008)
New Revision: 68919

Modified:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ConstructorMatcher.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/FieldMatcher.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/MethodMatcher.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/Util.java
Log:
Refactoring: extracted method matchModifiers from matchers and added it to Util.

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ConstructorMatcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ConstructorMatcher.java	2008-01-12 13:54:00 UTC (rev 68918)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ConstructorMatcher.java	2008-01-12 13:55:40 UTC (rev 68919)
@@ -78,13 +78,9 @@
 
    public Boolean matches(ASTConstructor node)
    {
-      if (node.getAttributes().size() > 0)
+      if (!Util.matchModifiers(node.getAttributes(), conModifiers))
       {
-         for (int i = 0; i < node.getAttributes().size(); i++)
-         {
-            ASTAttribute attr = (ASTAttribute) node.getAttributes().get(i);
-            if (!Util.matchModifiers(attr, conModifiers)) return Boolean.FALSE;
-         }
+         return Boolean.FALSE;
       }
 
       if (ctCon != null)

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/FieldMatcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/FieldMatcher.java	2008-01-12 13:54:00 UTC (rev 68918)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/FieldMatcher.java	2008-01-12 13:55:40 UTC (rev 68919)
@@ -84,17 +84,9 @@
 
    public Object visit(ASTField node, Object data)
    {
-
-      if (node.getAttributes().size() > 0)
+      if (!Util.matchModifiers(node.getAttributes(), fieldModifiers))
       {
-         for (int i = 0; i < node.getAttributes().size(); i++)
-         {
-            ASTAttribute attr = (ASTAttribute) node.getAttributes().get(i);
-            if (!Util.matchModifiers(attr, fieldModifiers))
-            {
-               return Boolean.FALSE;
-            }
-         }
+         return Boolean.FALSE;
       }
       
       try

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/MethodMatcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/MethodMatcher.java	2008-01-12 13:54:00 UTC (rev 68918)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/MethodMatcher.java	2008-01-12 13:55:40 UTC (rev 68919)
@@ -102,7 +102,10 @@
 
    public Boolean matches(ASTMethod node)
    {
-      if (!matchesModifiers(node)) return Boolean.FALSE;
+      if (!Util.matchModifiers(node.getAttributes(), this.methodModifiers))
+      {
+         return Boolean.FALSE;
+      }
       if (!matchesClass(node)) return Boolean.FALSE;
       if (!matchesIdentifier(node))return Boolean.FALSE;
       if (!matchesExceptions(node))return Boolean.FALSE;
@@ -220,19 +223,6 @@
       return Boolean.TRUE;
    }
    
-   protected boolean matchesModifiers(ASTMethod node)
-   {
-      if (node.getAttributes().size() > 0)
-      {
-         for (int i = 0; i < node.getAttributes().size(); i++)
-         {
-            ASTAttribute attr = (ASTAttribute) node.getAttributes().get(i);
-            if (!Util.matchModifiers(attr, methodModifiers)) return false;
-         }
-      }
-      return true;
-   }
-
    protected boolean matchesClass(ASTMethod node)
    {
       if (ctMethod != null)

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/Util.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/Util.java	2008-01-12 13:54:00 UTC (rev 68918)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/Util.java	2008-01-12 13:55:40 UTC (rev 68919)
@@ -568,44 +568,65 @@
       return typedef.matches(advisor, clazz);
    }
 
-   public static boolean matchModifiers(ASTAttribute need, int have)
+   public static boolean matchModifiers(ArrayList<ASTAttribute> attributes, int have)
    {
-      switch (need.attribute)
+      for (ASTAttribute need: attributes)
       {
-         case Modifier.ABSTRACT:
-            return Modifier.isAbstract(have) != need.not;
-         case Modifier.FINAL:
-            return Modifier.isFinal(have) != need.not;
-         case Modifier.INTERFACE:
-            return Modifier.isInterface(have) != need.not;
-         case Modifier.NATIVE:
-            return Modifier.isNative(have) != need.not;
-         case Modifier.PRIVATE:
-            return Modifier.isPrivate(have) != need.not;
-         case Modifier.PROTECTED:
-            return Modifier.isProtected(have) != need.not;
-         case Modifier.PUBLIC:
-            return Modifier.isPublic(have) != need.not;
-         case Modifier.STATIC:
-            return Modifier.isStatic(have) != need.not;
-         case Modifier.STRICT:
-            return Modifier.isStrict(have) != need.not;
-         case Modifier.SYNCHRONIZED:
-            return Modifier.isSynchronized(have) != need.not;
-         case Modifier.TRANSIENT:
-            return Modifier.isTransient(have) != need.not;
-         case Modifier.VOLATILE:
-            return Modifier.isVolatile(have) != need.not;
-         default:
-            throw new RuntimeException("Unexpected modifier value: " + need.attribute);
+         boolean matches = false;
+         switch (need.attribute)
+         {
+            case Modifier.ABSTRACT:
+               matches = Modifier.isAbstract(have) != need.not;
+               break;
+            case Modifier.FINAL:
+               matches = Modifier.isFinal(have) != need.not;
+               break;
+            case Modifier.INTERFACE:
+               matches = Modifier.isInterface(have) != need.not;
+               break;
+            case Modifier.NATIVE:
+               matches = Modifier.isNative(have) != need.not;
+               break;
+            case Modifier.PRIVATE:
+               matches = Modifier.isPrivate(have) != need.not;
+               break;
+            case Modifier.PROTECTED:
+               matches = Modifier.isProtected(have) != need.not;
+               break;
+            case Modifier.PUBLIC:
+               matches = Modifier.isPublic(have) != need.not;
+               break;
+            case Modifier.STATIC:
+               matches = Modifier.isStatic(have) != need.not;
+               break;
+            case Modifier.STRICT:
+               matches = Modifier.isStrict(have) != need.not;
+               break;
+            case Modifier.SYNCHRONIZED:
+               matches = Modifier.isSynchronized(have) != need.not;
+               break;
+            case Modifier.TRANSIENT:
+               matches = Modifier.isTransient(have) != need.not;
+               break;
+            case Modifier.VOLATILE:
+               matches = Modifier.isVolatile(have) != need.not;
+               break;
+            default:
+               throw new RuntimeException("Unexpected modifier value: " + need.attribute);
+         }
+         if (!matches)
+         {
+            return false;
+         }
       }
+      return true;
    }
 
    /**
     * @param nodeExceptions  ArrayList of ASTException entries for a given ASTMethod or ASTConstructor
     * @param foundExceptions Array of Exceptions found for a method/constructor
     */
-   public static boolean matchExceptions(ArrayList nodeExceptions, CtClass[] foundExceptions)
+   public static boolean matchExceptions(ArrayList<ASTException> nodeExceptions, CtClass[] foundExceptions)
    {
       if (nodeExceptions.size() > foundExceptions.length) return false;
       for (Iterator it = nodeExceptions.iterator(); it.hasNext();)
@@ -698,13 +719,13 @@
       return matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), con.getParameterTypes());
    }
 
-   private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList parameters, Class[] params)
+   private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList<ASTParameter> parameters, Class[] params)
    {
       RefParameterMatcher matcher = new RefParameterMatcher(advisor, parameters, params);
       return matcher.matches();
    }
 
-   private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList parameters, CtClass[] params)
+   private static boolean matchesParameters(Advisor advisor, boolean hasAnyZeroOrMoreParameters, ArrayList<ASTParameter> parameters, CtClass[] params)
    {
       CtParameterMatcher matcher = new CtParameterMatcher(advisor, parameters, params);
       return matcher.matches();
@@ -713,12 +734,12 @@
    private static abstract class ParameterMatcher
    {
       Advisor advisor;
-      ArrayList astParameters;
+      ArrayList<ASTParameter> astParameters;
       final long paramsLength;
       private int asti;
       private int actuali;
       
-      ParameterMatcher(Advisor advisor, ArrayList parameters, Object[] params)
+      ParameterMatcher(Advisor advisor, ArrayList<ASTParameter> parameters, Object[] params)
       {
          this.advisor = advisor;
          this.astParameters = parameters;
@@ -760,7 +781,7 @@
       
       private boolean isAnyZeroOrMoreParameters(int index)
       {
-         return ((ASTParameter)astParameters.get(index)).isAnyZeroOrMoreParameters();
+         return (astParameters.get(index)).isAnyZeroOrMoreParameters();
       }
       
       abstract boolean doMatch(int astIndex, int actualIndex);
@@ -818,7 +839,7 @@
    private static class RefParameterMatcher extends ParameterMatcher
    {
       Class[] params;
-      public RefParameterMatcher(Advisor advisor, ArrayList parameters, Class[] params)
+      public RefParameterMatcher(Advisor advisor, ArrayList<ASTParameter> parameters, Class[] params)
       {
          super(advisor, parameters, params);
          this.params = params;
@@ -826,7 +847,7 @@
       
       boolean doMatch(int astIndex, int actualIndex)
       {
-         ASTParameter ast = (ASTParameter) astParameters.get(astIndex);
+         ASTParameter ast = astParameters.get(astIndex);
          ClassExpression exp = ast.getType();
 
          if (exp.isSimple())
@@ -846,7 +867,7 @@
    private static class CtParameterMatcher extends ParameterMatcher
    {
       CtClass[] params;
-      public CtParameterMatcher(Advisor advisor, ArrayList parameters, CtClass[] params)
+      public CtParameterMatcher(Advisor advisor, ArrayList<ASTParameter> parameters, CtClass[] params)
       {
          super(advisor, parameters, params);
          this.params = params;
@@ -854,7 +875,7 @@
       
       boolean doMatch(int astIndex, int actualIndex)
       {
-         ASTParameter ast = (ASTParameter) astParameters.get(astIndex);
+         ASTParameter ast = astParameters.get(astIndex);
          ClassExpression exp = ast.getType();
          if (!matchesClassExpr(exp, params[actualIndex], advisor)) return false;
          return true;




More information about the jboss-cvs-commits mailing list