[jboss-cvs] JBossAS SVN: r70721 - in projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut: ast and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 11 00:36:50 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-03-11 00:36:50 -0400 (Tue, 11 Mar 2008)
New Revision: 70721

Added:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTBehaviour.java
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/ast/ASTConstructor.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTMethod.java
Log:
[JBAOP-502] Refactoring: added ASTBehaviour as superclass of ASTConstructor and ASTMethod. Added also some adjustments to Util.

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-03-11 04:27:49 UTC (rev 70720)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/Util.java	2008-03-11 04:36:50 UTC (rev 70721)
@@ -26,11 +26,13 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 
 import javassist.ClassPool;
+import javassist.CtBehavior;
 import javassist.CtClass;
 import javassist.CtConstructor;
 import javassist.CtField;
@@ -43,6 +45,7 @@
 import org.jboss.aop.annotation.PortableAnnotationElement;
 import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.pointcut.ast.ASTAttribute;
+import org.jboss.aop.pointcut.ast.ASTBehaviour;
 import org.jboss.aop.pointcut.ast.ASTConstructor;
 import org.jboss.aop.pointcut.ast.ASTException;
 import org.jboss.aop.pointcut.ast.ASTField;
@@ -568,7 +571,7 @@
       return typedef.matches(advisor, clazz);
    }
 
-   public static boolean matchModifiers(ArrayList<ASTAttribute> attributes, int have)
+   public static boolean matchModifiers(Collection<ASTAttribute> attributes, int have)
    {
       for (ASTAttribute need: attributes)
       {
@@ -626,8 +629,9 @@
     * @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<ASTException> nodeExceptions, CtClass[] foundExceptions)
+   public static boolean matchExceptions(Collection<ASTException> nodeExceptions, CtClass[] foundExceptions)
    {
+      if (nodeExceptions.size() == 0) return true;
       if (nodeExceptions.size() > foundExceptions.length) return false;
       for (Iterator it = nodeExceptions.iterator(); it.hasNext();)
       {
@@ -652,7 +656,7 @@
     * @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<ASTException> nodeExceptions, Class[] foundExceptions)
+   public static boolean matchExceptions(Collection<ASTException> nodeExceptions, Class[] foundExceptions)
    {
       if (nodeExceptions.size() > foundExceptions.length) return false;
       for (Iterator<ASTException> it = nodeExceptions.iterator(); it.hasNext();)
@@ -674,12 +678,12 @@
       return true;
    }
 
-   public static boolean matchesParameters(Advisor advisor, ASTMethod node, CtMethod ctMethod)
+   public static boolean matchesParameters(Advisor advisor, ASTBehaviour node, CtBehavior ctBehavior)
    {
       if (node.isAnyParameters()) return true;
       try
       {
-         return Util.matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), ctMethod.getParameterTypes());
+         return Util.matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), ctBehavior.getParameterTypes());
       }
       catch (NotFoundException e)
       {
@@ -688,22 +692,6 @@
       }
    }
 
-   public static boolean matchesParameters(Advisor advisor, ASTConstructor node, CtConstructor ctConstructor)
-   {
-      int i = 0;
-      if (node.isAnyParameters()) return true;
-      try
-      {
-         CtClass[] params = ctConstructor.getParameterTypes();
-         return Util.matchesParameters(advisor, node.hasAnyZeroOrMoreParameters(), node.getParameters(), params);
-      }
-      catch (NotFoundException e)
-      {
-         // AutoGenerated
-         throw new RuntimeException(e);
-      }
-   }
-
    public static boolean matchesParameters(Advisor advisor, ASTMethod node, Method method) 
    {
       if (node.isAnyParameters()) return true;

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTBehaviour.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTBehaviour.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTBehaviour.java	2008-03-11 04:36:50 UTC (rev 70721)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.pointcut.ast;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a method or constructor node in the AST tree.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class ASTBehaviour extends SimpleNode
+{
+   String classExpr;
+   ClassExpression clazz;
+   boolean anyParameters = false;
+   boolean hasAnyZeroOrMoreParameters = false;
+
+   ArrayList<ASTParameter> parameters = new ArrayList<ASTParameter>();
+   ArrayList<ASTAttribute> attributes = new ArrayList<ASTAttribute>();
+   ArrayList<ASTException> exceptions = new ArrayList<ASTException>();
+ 
+   public ASTBehaviour(int id)
+   {
+      super(id);
+   }
+
+   public ASTBehaviour(PointcutExpressionParser p, int id)
+   {
+      super(p, id);
+   }
+ 
+   public void jjtAddChild(Node n, int i)
+   {
+      if (n instanceof ASTAttribute) attributes.add((ASTAttribute) n);
+      else if (n instanceof ASTException) exceptions.add((ASTException) n);
+      else if (n instanceof ASTAllParameter) anyParameters = true;
+      else if (n instanceof ASTParameter && !anyParameters)
+      {
+         ASTParameter param = (ASTParameter) n;
+         parameters.add(0, param);
+         if (!hasAnyZeroOrMoreParameters && param.isAnyZeroOrMoreParameters())
+         {
+            hasAnyZeroOrMoreParameters = true;
+         }
+      }
+      else super.jjtAddChild(n, i);
+   }
+   
+   /** Accept the visitor. **/
+   public Object jjtAccept(PointcutExpressionParserVisitor visitor, Object data)
+   {
+      return visitor.visit(this, data);
+   }
+   /** Accept the visitor. **/
+   public Object jjtAccept(TypeExpressionParserVisitor visitor, Object data)
+   {
+      return visitor.visit(this, data);
+   }
+
+   
+   public void setClassExpression(String exp)
+   {
+      classExpr = exp;
+      clazz = new ClassExpression(exp);
+   }
+   
+   public String getClassExpr()
+   {
+      return classExpr;
+   }
+
+   public ArrayList<ASTAttribute> getAttributes()
+   {
+      return attributes;
+   }
+   
+   public ArrayList<ASTException> getExceptions()
+   {
+      return exceptions;
+   }
+
+   public ArrayList<ASTParameter> getParameters()
+   {
+      return parameters;
+   }
+
+
+   public boolean isAnyParameters()
+   {
+      return anyParameters;
+   }
+
+   public boolean hasAnyZeroOrMoreParameters()
+   {
+      return hasAnyZeroOrMoreParameters;
+   }
+   
+   public ClassExpression getClazz()
+   {
+      return clazz;
+   }
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTConstructor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTConstructor.java	2008-03-11 04:27:49 UTC (rev 70720)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTConstructor.java	2008-03-11 04:36:50 UTC (rev 70721)
@@ -21,9 +21,8 @@
  */
 package org.jboss.aop.pointcut.ast;
 
-import java.util.ArrayList;
 
-public class ASTConstructor extends SimpleNode
+public class ASTConstructor extends ASTBehaviour
 {
    public ASTConstructor(int id)
    {
@@ -35,89 +34,13 @@
       super(p, id);
    }
 
-
-   /** Accept the visitor. **/
-   public Object jjtAccept(PointcutExpressionParserVisitor visitor, Object data)
-   {
-      return visitor.visit(this, data);
-   }
-   /** Accept the visitor. **/
-   public Object jjtAccept(TypeExpressionParserVisitor visitor, Object data)
-   {
-      return visitor.visit(this, data);
-   }
-
-   String classExpr;
-   ClassExpression clazz;
    IdentifierExpression annotation;
-   ArrayList<ASTAttribute> attributes = new ArrayList<ASTAttribute>();
-   ArrayList<ASTParameter> parameters = new ArrayList<ASTParameter>();
-   boolean anyParameters = false;
-   boolean hasAnyZeroOrMoreParameters = false;
-   ArrayList<ASTException> exceptions = new ArrayList<ASTException>();
-
-   public void jjtAddChild(Node n, int i)
-   {
-      if (n instanceof ASTAttribute) attributes.add((ASTAttribute) n);
-      else if (n instanceof ASTException) exceptions.add((ASTException) n);
-      else if (n instanceof ASTAllParameter) anyParameters = true;
-      else if (n instanceof ASTParameter && !anyParameters) 
-      {
-         ASTParameter param = (ASTParameter) n;
-         parameters.add(0, param);
-         if (!hasAnyZeroOrMoreParameters && param.isAnyZeroOrMoreParameters())
-         {
-            hasAnyZeroOrMoreParameters = true;
-         }
-      }
-      else super.jjtAddChild(n, i);
-   }
-   public void setClassExpression(String expression)
-   {
-      classExpr = expression;
-      clazz = new ClassExpression(classExpr);
-   }
-
+   
    public void setNewExpression(String expr)
    {
       if (expr.startsWith("@")) annotation = new IdentifierExpression(expr);
    }
 
-   public String getClassExpr()
-   {
-      return classExpr;
-   }
-
-   public ArrayList<ASTAttribute> getAttributes()
-   {
-      return attributes;
-   }
-   
-   public ArrayList<ASTException> getExceptions()
-   {
-      return exceptions;
-   }
-
-   public ArrayList<ASTParameter> getParameters()
-   {
-      return parameters;
-   }
-
-   public boolean isAnyParameters()
-   {
-      return anyParameters;
-   }
-
-   public boolean hasAnyZeroOrMoreParameters()
-   {
-      return hasAnyZeroOrMoreParameters;
-   }
-   
-   public ClassExpression getClazz()
-   {
-      return clazz;
-   }
-
    /**
     *
     * @return NULL if a constructor specific annotation was not defined
@@ -126,4 +49,4 @@
    {
       return annotation;
    }
-}
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTMethod.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTMethod.java	2008-03-11 04:27:49 UTC (rev 70720)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/pointcut/ast/ASTMethod.java	2008-03-11 04:36:50 UTC (rev 70721)
@@ -21,9 +21,8 @@
  */
 package org.jboss.aop.pointcut.ast;
 
-import java.util.ArrayList;
 
-public class ASTMethod extends SimpleNode
+public class ASTMethod extends ASTBehaviour
 {
    public ASTMethod(int id)
    {
@@ -35,47 +34,12 @@
       super(p, id);
    }
 
-
-   /** Accept the visitor. **/
-   public Object jjtAccept(PointcutExpressionParserVisitor visitor, Object data)
-   {
-      return visitor.visit(this, data);
-   }
-   /** Accept the visitor. **/
-   public Object jjtAccept(TypeExpressionParserVisitor visitor, Object data)
-   {
-      return visitor.visit(this, data);
-   }
-
-
    String returnTypeExpr;
    ClassExpression returnType;
-   String classExpr;
-   ClassExpression clazz;
    String methodExpr;
    IdentifierExpression methodIdentifier;
-   boolean anyParameters = false;
-   boolean hasAnyZeroOrMoreParameters = false;
-   ArrayList<ASTParameter> parameters = new ArrayList<ASTParameter>();
-   ArrayList<ASTAttribute> attributes = new ArrayList<ASTAttribute>();
-   ArrayList<ASTException> exceptions = new ArrayList<ASTException>();
+   
 
-   public void jjtAddChild(Node n, int i)
-   {
-      if (n instanceof ASTAttribute) attributes.add((ASTAttribute) n);
-      else if (n instanceof ASTException) exceptions.add((ASTException) n);
-      else if (n instanceof ASTAllParameter) anyParameters = true;
-      else if (n instanceof ASTParameter && !anyParameters)
-      {
-         ASTParameter param = (ASTParameter) n;
-         parameters.add(0, param);
-         if (!hasAnyZeroOrMoreParameters && param.isAnyZeroOrMoreParameters())
-         {
-            hasAnyZeroOrMoreParameters = true;
-         }
-      }
-      else super.jjtAddChild(n, i);
-   }
    public void setMethodExpression(String expression)
    {
       methodExpr = expression;
@@ -88,65 +52,23 @@
       returnType = new ClassExpression(exp);
    }
 
-   public void setClassExpression(String exp)
-   {
-      classExpr = exp;
-      clazz = new ClassExpression(exp);
-   }
-
    public String getReturnTypeExpression()
    {
       return returnTypeExpr;
    }
 
-   public String getClassExpr()
-   {
-      return classExpr;
-   }
-
    public String getMethodExpr()
    {
       return methodExpr;
    }
 
-   public boolean isAnyParameters()
-   {
-      return anyParameters;
-   }
-
-   public boolean hasAnyZeroOrMoreParameters()
-   {
-      return hasAnyZeroOrMoreParameters;
-   }
-   
-   public ArrayList<ASTParameter> getParameters()
-   {
-      return parameters;
-   }
-
-   public ArrayList<ASTException> getExceptions()
-   {
-      return exceptions;
-   }
-
-   public ArrayList<ASTAttribute> getAttributes()
-   {
-      return attributes;
-   }
-
    public ClassExpression getReturnType()
    {
       return returnType;
    }
 
-   public ClassExpression getClazz()
-   {
-      return clazz;
-   }
-
    public IdentifierExpression getMethodIdentifier()
    {
       return methodIdentifier;
    }
-
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list