[jboss-cvs] JBossAS SVN: r70755 - projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 11 22:30:37 EDT 2008
Author: flavia.rainone at jboss.com
Date: 2008-03-11 22:30:36 -0400 (Tue, 11 Mar 2008)
New Revision: 70755
Added:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviorSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorFilter.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeFilter.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcherFactory.java
Removed:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviourSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AnnotationRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourFilter.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNodeSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasBlockRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasFieldRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/InstanceOfRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestriction.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestrictionFactory.java
Modified:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CallSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConstructionSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ExecutionSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldFilter.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ParsedSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyParser.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Searcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SubtypeSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefParser.java
Log:
[JBAOP-508] Some refactoring and javadoc.
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviorSearcher.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviourSearcher.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviorSearcher.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviorSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,60 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.util.Collection;
+
+import org.jboss.aop.JoinPointInfo;
+
+/**
+ * Performs a search on {@link BehaviorNode}, returning all joinpoints contained
+ * in the node (execution, construction and calls).
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AllBehaviorSearcher implements Searcher<BehaviorNode>
+{
+ private static AllBehaviorSearcher INSTANCE = new AllBehaviorSearcher();
+
+ /**
+ * Returns the singleton instance.
+ */
+ public static AllBehaviorSearcher getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private AllBehaviorSearcher() {}
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
+ {
+ if (node.hasConstruction())
+ {
+ searchResult.add(node.getConstruction());
+ }
+ if (node.hasExecution())
+ {
+ searchResult.add(node.getExecution());
+ }
+ node.searchCallers("*", searchResult);
+ }
+}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviourSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviourSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllBehaviourSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,55 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.util.Collection;
-
-import org.jboss.aop.JoinPointInfo;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-class AllBehaviourSearcher implements Searcher<BehaviourNode>
-{
- private static AllBehaviourSearcher INSTANCE = new AllBehaviourSearcher();
-
- public static AllBehaviourSearcher getInstance()
- {
- return INSTANCE;
- }
-
- private AllBehaviourSearcher() {}
-
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
- {
- if (node.hasConstruction())
- {
- searchResult.add(node.getConstruction());
- }
- if (node.hasExecution())
- {
- searchResult.add(node.getExecution());
- }
- node.searchCallers("*", searchResult);
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AllSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,3 +1,24 @@
+/*
+ * 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.joinpoint.graph;
import java.util.Collection;
@@ -4,26 +25,37 @@
import org.jboss.aop.JoinPointInfo;
-
-class AllSearcher implements ClassNodeSearcher
+/**
+ * Performs a search for all field-related joinpoints and method executions on a
+ * class node.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AllSearcher implements Searcher<ClassNode>
{
private static AllSearcher INSTANCE = new AllSearcher();
+ /**
+ * Returns the singleton instance.
+ */
public static AllSearcher getInstance()
{
return INSTANCE;
}
- private BehaviourSearcher allMethodExecutions;
+ private BehaviorSearcher allMethodExecutions;
private FieldSearcher allFieldAccesses;
+ /**
+ * Default constructor.
+ */
public AllSearcher()
{
- this.allMethodExecutions = new BehaviourSearcher("* *(*)",
+ this.allMethodExecutions = new BehaviorSearcher("* *(*)",
SearchKeyParser.EMPTY_ATTRIBUTES, SearchKeyParser.EMPTY_EXCEPTIONS, null, true);
- this.allMethodExecutions.setSearchType(BehaviourSearcher.SearchType.EXECUTION);
+ this.allMethodExecutions.setSearchType(BehaviorSearcher.SearchType.EXECUTION);
this.allFieldAccesses = new FieldSearcher("*", SearchKeyParser.EMPTY_ATTRIBUTES, null);
- this.allFieldAccesses.setAccessType(FieldSearcher.SearchType.ALL);
+ this.allFieldAccesses.setSearchType(FieldSearcher.SearchType.ALL);
}
public void search(ClassNode node, Collection<JoinPointInfo> searchResult)
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AnnotationRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AnnotationRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AnnotationRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,56 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.annotation.AnnotationElement;
-import org.jboss.aop.pointcut.ast.ClassExpression;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-public class AnnotationRestriction implements TypeRestriction
-{
- private String annotation;
- public AnnotationRestriction(ClassExpression classExpression)
- {
- this.annotation = classExpression.getOriginal().substring(1);
-
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- try
- {
- return AnnotationElement.isAnyAnnotationPresent(target, annotation);
- }
- catch (Exception e)
- {
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException) e;
- }
- throw new RuntimeException(e);
- }
- }
-}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorFilter.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourFilter.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorFilter.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorFilter.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,339 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTBehavior;
+import org.jboss.aop.pointcut.ast.ASTConstructor;
+import org.jboss.aop.pointcut.ast.ASTMethod;
+import org.jboss.aop.pointcut.ast.ClassExpression;
+import org.jboss.aop.pointcut.ast.IdentifierExpression;
+
+/**
+ * A filter for behaviors.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+interface BehaviorFilter
+{
+ /**
+ * Tests whether or not {@code method} is accepted or rejected by this filter.
+ *
+ * @param method the method to be tested
+ * @return {@code true} if this filter accepts {@code method}
+ */
+ public boolean accept(Method method);
+
+ /**
+ * Tests whether or not {@code constructor} is accepted or rejected by this filter.
+ *
+ * @param constructor the constructor to be tested
+ * @return {@code true} if this filter accepts {@code constructor}
+ */
+ public boolean accept(Constructor constructor);
+}
+
+/**
+ * Checks if a behavior is accepted by two filters.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class ConjunctiveBehaviorFilter implements BehaviorFilter
+{
+ private BehaviorFilter filter1;
+ private BehaviorFilter filter2;
+
+ /**
+ * Creates a disjunctive filter that will apply the restrictions represented by
+ * both {@code filter1} and {@code filter2}.
+ * Always pick as filter1 the most likely one to fail for acception.
+ */
+ public ConjunctiveBehaviorFilter(BehaviorFilter filter1, BehaviorFilter filter2)
+ {
+ this.filter1 = filter1;
+ this.filter2 = filter2;
+ }
+
+ public boolean accept(Method method)
+ {
+ return filter1.accept(method) && filter2.accept(method);
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ return filter1.accept(constructor) && filter2.accept(constructor);
+ }
+}
+
+/**
+ * Checks if the return type of a method follow a type restriction.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class ReturnTypeFilter implements BehaviorFilter
+{
+ private ClassExpression classExpression;
+
+ /**
+ * Creates a filter that will accept only methods whose return type matches
+ * {@code classExpression}.
+ *
+ * @param classExpression an complex type expression (a call to its
+ * {@code isSimple()} method would return {@code false}).
+ */
+ public ReturnTypeFilter(ClassExpression classExpression)
+ {
+ this.classExpression = classExpression;
+ }
+
+ public boolean accept(Method method)
+ {
+ return Util.matchesClassExpr(classExpression, method.getReturnType());
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ throw new RuntimeException ("Should never be called");
+ }
+}
+
+/**
+ * Checks if the target type of a behavior follow a type restriction.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class TargetTypeFilter implements BehaviorFilter
+{
+ private ClassExpression classExpression;
+
+ /**
+ * Creates a filter that will accept only behaviors whose target type matches
+ * {@code classExpression}.
+ *
+ * @param classExpression an complex type expression (a call to its
+ * {@code isSimple()} method would return {@code false}).
+ */
+ public TargetTypeFilter(ClassExpression classExpression)
+ {
+ this.classExpression = classExpression;
+ }
+
+ public boolean accept(Method method)
+ {
+ return Util.matchesClassExpr(classExpression, method.getDeclaringClass());
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ return Util.matchesClassExpr(classExpression, constructor.getDeclaringClass());
+ }
+}
+
+/**
+ * Checks if a method overrides a method in a superclass, or is the implementation of
+ * an abstract method defined in a superclass or interface.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class OverridenMethodFilter implements BehaviorFilter
+{
+ boolean exactSuper;
+ ClassExpression expression;
+
+ /**
+ * Creates a filter that will accept only methods that override a method in a
+ * superclass, or that are the implementation of an abstract method defined in a
+ * superclass or implemented interface.
+ *
+ * @param identifierExpression the parsed exception that contains the $implements
+ * or $implementing declaration.
+ */
+ public OverridenMethodFilter(IdentifierExpression identifierExpression)
+ {
+ this.exactSuper = (identifierExpression.getType() == (IdentifierExpression.Type.IMPLEMENTS));
+ this.expression = identifierExpression.getImplementsExpression();
+ }
+
+ public boolean accept(Method method)
+ {
+ try
+ {
+ return Util.methodExistsInSuperClassOrInterface(method, expression,
+ exactSuper, null);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException) e;
+ }
+ throw new RuntimeException(e);
+ }
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ throw new RuntimeException("This method should not be called");
+ }
+}
+
+/**
+ * Checks if all the parameters of a behavior follow a list of type restrictions.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class FullParameterFilter implements BehaviorFilter
+{
+ private ASTBehavior astBehavior;
+
+ /**
+ * Creates a filter that will accept only the behavior whose parameters follow
+ * fully the parameter restrictions contained in {@code astBehavior}.
+ *
+ * @param astBehavior the parsed behavior expression
+ */
+ public FullParameterFilter(ASTBehavior astBehavior)
+ {
+ this.astBehavior = astBehavior;
+ }
+
+ public boolean accept(Method method)
+ {
+ return Util.matchesParameters(null, (ASTMethod) astBehavior, method);
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ return Util.matchesParameters(null, (ASTConstructor) astBehavior, constructor);
+ }
+}
+
+/**
+ * Checks if some of the parameters of a behavior follow a list of type restrictions.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class PartialParameterFilter implements BehaviorFilter
+{
+ protected ClassExpression[] classExpressions;
+
+ /**
+ * Creates a filter that accepts only the behaviors whose parameters follow a list
+ * of type restrictions.
+ *
+ * @param parameterLength the maximum length of the parameter type restrictions to
+ * be checked
+ */
+ public PartialParameterFilter(int parameterLength)
+ {
+ classExpressions = new ClassExpression[parameterLength];
+ }
+
+ /**
+ * Adds a parameter restriction to be checked by this filter.
+ *
+ * @param expression an complex type expression (a call to its {@code isSimple()}
+ * method would return {@code false}). This expression contains
+ * the parsed type restriction to be applied to a parameter.
+ * @param index the index where this restriction was found (this index
+ * represents the position of the type restriction in a list
+ * that may contain wildcards "..")
+ */
+ public void addParameterRestriction(ClassExpression expression, int index)
+ {
+ classExpressions[index] = expression;
+ }
+
+ public boolean accept(Method method)
+ {
+ return checkParameters(method.getParameterTypes());
+ }
+
+ public boolean accept(Constructor constructor)
+ {
+ return checkParameters(constructor.getParameterTypes());
+ }
+
+ abstract protected boolean checkParameters(Class[] parameters);
+}
+
+/**
+ * An implementation of the {@code PartialParameterFilter}, that applies the type
+ * restrictions to the behavior parameters in ascending order.
+ * This filter contains only restrictions that were not found after a wildcard in the
+ * parameter expression list.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AscendingPartialParameterFilter extends PartialParameterFilter
+{
+ public AscendingPartialParameterFilter(int parameterLength)
+ {
+ super(parameterLength);
+ }
+
+ protected boolean checkParameters(Class[] parameters)
+ {
+ for (int i = 0; i < classExpressions.length; i++)
+ {
+ if (classExpressions[i] != null &&
+ !Util.matchesClassExpr(classExpressions[i], parameters[i], null))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
+/**
+ * An implementation of the {@code PartialParameterFilter}, that applies the type
+ * restrictions to the behavior parameters in descending order.
+ * This filter contains only restrictions that were not found before a wildcard in
+ * the parameter expression list.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class DescendingPartialParameterFilter extends PartialParameterFilter
+{
+ public DescendingPartialParameterFilter(int parameterLength)
+ {
+ super(parameterLength);
+ }
+
+ protected boolean checkParameters(Class[] parameters)
+ {
+ int paramIndex = parameters.length - 1;
+ for (int i = classExpressions.length; i >= 0 ; i--,paramIndex--)
+ {
+ if (classExpressions[i] != null &&
+ !Util.matchesClassExpr(classExpressions[i], parameters[paramIndex], null))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourNode.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,229 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class BehaviorNode implements Node
+{
+ private ClassNode classNode;
+ private BehaviourType behaviourType;
+ private Member member;
+ private JoinPointInfo execution;
+ private ConstructionInfo construction;
+ private Tree<JoinPointInfo> calls;
+
+ public BehaviorNode(ClassNode classNode, Method member)
+ {
+ this.classNode = classNode;
+ this.member = member;
+ this.behaviourType = BehaviourType.METHOD;
+ }
+
+ public BehaviorNode(ClassNode classNode, Constructor member)
+ {
+ this.classNode = classNode;
+ this.member = member;
+ this.behaviourType = BehaviourType.CONSTRUCTOR;
+ }
+
+ // TODO Flavia
+ public ClassNode getClassNode()
+ {
+ return this.classNode;
+ }
+
+ public static final String getDefaultKey(Method member)
+ {
+ return getDefaultKey(member, BehaviourType.METHOD);
+ }
+
+ public static final String getDefaultKey(Constructor member)
+ {
+ return getDefaultKey(member, BehaviourType.CONSTRUCTOR);
+ }
+
+ private static final String getDefaultKey(Member member, BehaviourType type)
+ {
+ return type.getName(member) + getParameterList(member, type);
+ }
+
+ private static final String getParameterList(Member member, BehaviourType type)
+ {
+ Class[] parameterTypes = type.getParameterTypes(member);
+ if (parameterTypes.length == 0)
+ {
+ return "()";
+ }
+ StringBuffer paramList = new StringBuffer(type.getName(member));
+ paramList.append('(');
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ paramList.append(parameterTypes[i].getName()).append(' ');
+ }
+ paramList.append(')');
+ return paramList.toString();
+ }
+
+ public String getDefaultKey()
+ {
+ return getDefaultKey(this.member, this.behaviourType);
+ }
+
+ public void loadMetaDataKeys(Collection<String> keys)
+ {
+ String commonPrefix = behaviourType.getReturnType(member) + "@";
+ String commonSuffix = getParameterList(member, behaviourType);
+ Collection<String> metaDataTags =
+ behaviourType.getMetaDataTags(classNode.getAdvisor(), member);
+ for (String metaDataTag: metaDataTags)
+ {
+ keys.add(commonPrefix + metaDataTag + commonSuffix);
+ }
+ }
+
+ public Member getMember()
+ {
+ return this.member;
+ }
+
+ public Class[] getExceptionTypes()
+ {
+ return this.behaviourType.getExceptionTypes(member);
+ }
+
+ public boolean hasExecution()
+ {
+ return this.execution != null;
+ }
+
+ public JoinPointInfo getExecution()
+ {
+ return this.execution;
+ }
+
+ public void setExecution(JoinPointInfo execution)
+ {
+ this.execution = execution;
+ }
+
+ public boolean hasConstruction()
+ {
+ return this.construction != null;
+ }
+
+ public ConstructionInfo getConstruction()
+ {
+ return this.construction;
+ }
+
+ public void setConstruction(ConstructionInfo construction)
+ {
+ this.construction = construction;
+ }
+
+ public void insertCaller(String callerName, JoinPointInfo callNode)
+ {
+ calls.insert(callerName, callNode);
+ }
+
+ public void searchCallers(String callerExpression, Collection<JoinPointInfo> result)
+ {
+ calls.search(callerExpression, result);
+ }
+
+ private enum BehaviourType
+ {
+ CONSTRUCTOR
+ {
+ public String getName(Member member)
+ {
+ return "new";
+ }
+
+ public String getReturnType(Member member)
+ {
+ return "";
+ }
+
+ public Class[] getParameterTypes(Member member)
+ {
+ return ((Constructor) member).getParameterTypes();
+ }
+
+ public Class[] getExceptionTypes(Member member)
+ {
+ return ((Constructor) member).getExceptionTypes();
+ }
+
+ public Collection<String> getMetaDataTags(Advisor advisor, Member member)
+ {
+ return advisor.getMetaDataTags((Constructor) member);
+ }
+ },
+ METHOD
+ {
+ public String getName(Member member)
+ {
+ return ((Method) member).getReturnType().getName() + " " + member.getName();
+ }
+
+ public String getReturnType(Member member)
+ {
+ return ((Method) member).getReturnType().getName() + " ";
+ }
+
+ public Class[] getParameterTypes(Member member)
+ {
+ return ((Method) member).getParameterTypes();
+ }
+
+ public Class[] getExceptionTypes(Member member)
+ {
+ return ((Method) member).getExceptionTypes();
+ }
+
+ public Collection<String> getMetaDataTags(Advisor advisor, Member member)
+ {
+ return advisor.getMetaDataTags((Method) member);
+ }
+ };
+
+ public abstract String getName(Member member);
+ public abstract Class[] getExceptionTypes(Member member);
+ public abstract Class[] getParameterTypes(Member member);
+ public abstract Collection<String> getMetaDataTags(Advisor advisor, Member member);
+ public abstract String getReturnType(Member member);
+ };
+}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourSearcher.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,192 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTAttribute;
+import org.jboss.aop.pointcut.ast.ASTException;
+
+/**
+ * Performs a search for behavior-related joinpoints on a class node. Those
+ * joinpoints can be of the type execution, construction, and call.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class BehaviorSearcher implements Searcher<ClassNode>
+{
+ /**
+ * Indicates the type of joinpoint that this searcher should look for.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+ public enum SearchType {
+ /**
+ * Indicates this searcher must retrieve only joinpoints of the type execution.
+ */
+ EXECUTION
+ {
+ public Searcher<BehaviorNode> getSearcher()
+ {
+ return ExecutionSearcher.getInstance();
+ }
+ },
+ /**
+ * Indicates this searcher must retrieve only joinpoints of the type
+ * construction.
+ */
+ CONSTRUCTION
+ {
+ public Searcher<BehaviorNode> getSearcher()
+ {
+ return ConstructionSearcher.getInstance();
+ }
+ },
+ /**
+ * Indicates this searcher must retrieve only joinpoints of the type call.
+ */
+ CALL
+ {
+ public Searcher<BehaviorNode> getSearcher()
+ {
+ return new CallSearcher();
+ }
+ },
+ /**
+ * Indicates this searcher must retrieve joinpoints of all the three types:
+ * execution, construction, and call.
+ */
+ ALL
+ {
+ public Searcher<BehaviorNode> getSearcher()
+ {
+ return AllBehaviorSearcher.getInstance();
+ }
+ };
+
+ /**
+ * Returns a searcher that performs the joinpoint search on a BehaviorNode
+ * accordingly to the type of search to be performed.
+ *
+ * @return a searcher whose target type is {@code BehaviorNode}
+ */
+ public abstract Searcher<BehaviorNode> getSearcher();
+ }
+
+ private String behaviorExpression;
+ private Collection<ASTAttribute> attributes;
+ private Collection<ASTException> exceptions;
+ private BehaviorFilter behaviorFilter;
+ private boolean isMethod;
+ private Searcher<BehaviorNode> internalSearcher;
+
+ /**
+ * Creates an instance of this searcher.
+ *
+ * @param behaviorExpression the expression that will be used to identify a
+ * behavior in a {@code ClassNode}
+ * @param attributes the attribute restrictions that the searched
+ * behavior must follow
+ * @param exceptions the type of the exceptions that the searched
+ * behavior must declare to throw
+ * @param behaviorFilter a filter for extra checks on the searched behavior.
+ * This filter should be {@code null} if there are no
+ * extra checks to be performed on the searched
+ * behavior.
+ * @param isMethod indicates whether {@code behaviorExpression} selects
+ * only methods or constructor. If {@code
+ * behaviorFilter} is {@code null}, the value of this
+ * parameter is not relevant.
+ */
+ public BehaviorSearcher(String behaviorExpression,
+ Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
+ BehaviorFilter behaviorFilter, boolean isMethod)
+ {
+
+ this.behaviorExpression = behaviorExpression;
+ this.attributes = attributes;
+ this.exceptions = exceptions;
+ this.behaviorFilter = behaviorFilter;
+ this.isMethod = isMethod;
+ }
+
+ /**
+ * Sets the type of search that this searcher should perform.
+ * <p>
+ * This method must be called before this object performs a search.
+ *
+ * @param searchType indicates the type of joinpoint that this class searches for
+ */
+ public void setSearchType(SearchType searchType)
+ {
+ this.internalSearcher = searchType.getSearcher();
+ }
+
+ /**
+ * Returns the internal searcher, used by this object to perform the search
+ * on a {@code BehaviorNode} instance.
+ */
+ Searcher<BehaviorNode> getInternalSearcher()
+ {
+ return this.internalSearcher;
+ }
+
+ /**
+ * Before this method is executed, the search type to be performed must have
+ * been set.
+ *
+ * @see #setSearchType(org.jboss.aop.joinpoint.graph.BehaviorSearcher.SearchType)}
+ */
+ public void search(ClassNode node, Collection<JoinPointInfo> result)
+ {
+ Collection<BehaviorNode> behaviors = node.searchBehaviours(behaviorExpression);
+ if (isMethod)
+ {
+ for (BehaviorNode behaviorNode: behaviors)
+ {
+ if (Util.matchModifiers(attributes, behaviorNode.getMember().getModifiers())
+ && Util.matchExceptions(exceptions, behaviorNode.getExceptionTypes())
+ && (behaviorFilter == null || behaviorFilter.accept((Method) behaviorNode.getMember())))
+ {
+ this.internalSearcher.search(behaviorNode, result);
+ }
+ }
+ }
+ else
+ {
+ for (BehaviorNode behaviorNode: behaviors)
+ {
+ if (Util.matchModifiers(attributes, behaviorNode.getMember().getModifiers())
+ && Util.matchExceptions(exceptions, behaviorNode.getExceptionTypes())
+ && (behaviorFilter == null || behaviorFilter.accept((Constructor) behaviorNode.getMember())))
+ {
+ this.internalSearcher.search(behaviorNode, result);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourFilter.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourFilter.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourFilter.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,241 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ASTBehaviour;
-import org.jboss.aop.pointcut.ast.ASTConstructor;
-import org.jboss.aop.pointcut.ast.ASTMethod;
-import org.jboss.aop.pointcut.ast.ClassExpression;
-import org.jboss.aop.pointcut.ast.IdentifierExpression;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-interface BehaviourFilter
-{
- public boolean accept(Method method);
- public boolean accept(Constructor constructor);
-}
-
-class CompositeFilter implements BehaviourFilter
-{
- private BehaviourFilter filter1;
- private BehaviourFilter filter2;
-
- // always use filter1 as the more likely to fail for acception
- public CompositeFilter(BehaviourFilter filter1, BehaviourFilter filter2)
- {
- this.filter1 = filter1;
- this.filter2 = filter2;
- }
-
- public boolean accept(Method method)
- {
- return filter1.accept(method) && filter2.accept(method);
- }
-
- public boolean accept(Constructor constructor)
- {
- return filter1.accept(constructor) && filter2.accept(constructor);
- }
-}
-
-class ReturnTypeFilter implements BehaviourFilter
-{
- ClassExpression classExpression;
-
- public ReturnTypeFilter(ClassExpression classExpression)
- {
- this.classExpression = classExpression;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.BehaviourFilter#accept(java.lang.reflect.Method)
- */
- public boolean accept(Method method)
- {
- return Util.matchesClassExpr(classExpression, method.getReturnType());
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.BehaviourFilter#accept(java.lang.reflect.Constructor)
- */
- public boolean accept(Constructor constructor)
- {
- throw new RuntimeException ("Should never be called");
- }
-}
-
-class TargetTypeFilter implements BehaviourFilter
-{
- ClassExpression classExpression;
-
- public TargetTypeFilter(ClassExpression classExpression)
- {
- this.classExpression = classExpression;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.BehaviourFilter#accept(java.lang.reflect.Method)
- */
- public boolean accept(Method method)
- {
- return Util.matchesClassExpr(classExpression, method.getDeclaringClass());
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.BehaviourFilter#accept(java.lang.reflect.Constructor)
- */
- public boolean accept(Constructor constructor)
- {
- return Util.matchesClassExpr(classExpression, constructor.getDeclaringClass());
- }
-}
-
-class OverridenMethodFilter implements BehaviourFilter
-{
- boolean exactSuper;
- ClassExpression expression;
-
- public OverridenMethodFilter(IdentifierExpression identifierExpression)
- {
- this.exactSuper = (identifierExpression.getType() == (IdentifierExpression.Type.IMPLEMENTS));
- this.expression = identifierExpression.getImplementsExpression();
- }
-
- public boolean accept(Method method)
- {
- try
- {
- return Util.methodExistsInSuperClassOrInterface(method, expression, exactSuper, null);
- }
- catch (Exception e)
- {
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException) e;
- }
- throw new RuntimeException(e);
- }
- }
-
- public boolean accept(Constructor constructor)
- {
- throw new RuntimeException("This method should not be called");
- }
-}
-
-// filters everything
-class FullParameterFilter implements BehaviourFilter
-{
- private ASTBehaviour astBehaviour;
-
- public FullParameterFilter(ASTBehaviour astBehaviour)
- {
- this.astBehaviour = astBehaviour;
- }
-
- public boolean accept(Method method)
- {
- return Util.matchesParameters(null, (ASTMethod) astBehaviour, method);
- }
-
- public boolean accept(Constructor constructor)
- {
- return Util.matchesParameters(null, (ASTConstructor) astBehaviour, constructor);
- }
-}
-
-
-abstract class PartialParameterFilter implements BehaviourFilter
-{
- protected ClassExpression[] classExpressions;
- public PartialParameterFilter(int parameterLength)
- {
- classExpressions = new ClassExpression[parameterLength];
- }
-
- public void addExpression(ClassExpression expression, int index)
- {
- classExpressions[index] = expression;
- }
-
- public boolean accept(Method method)
- {
- return checkParameters(method.getParameterTypes());
- }
-
- public boolean accept(Constructor constructor)
- {
- return checkParameters(constructor.getParameterTypes());
- }
-
- abstract protected boolean checkParameters(Class[] parameters);
-}
-
-class CrescentPartialParameterFilter extends PartialParameterFilter
-{
- public CrescentPartialParameterFilter(int parameterLength)
- {
- super(parameterLength);
- }
-
- protected boolean checkParameters(Class[] parameters)
- {
- for (int i = 0; i < classExpressions.length; i++)
- {
- if (classExpressions[i] != null &&
- !Util.matchesClassExpr(classExpressions[i], parameters[i], null))
- {
- return false;
- }
- }
- return true;
- }
-}
-
-class DecrescentPartialParameterFilter extends PartialParameterFilter
-{
- public DecrescentPartialParameterFilter(int parameterLength)
- {
- super(parameterLength);
- }
-
- protected boolean checkParameters(Class[] parameters)
- {
- int paramIndex = parameters.length - 1;
- for (int i = classExpressions.length; i >= 0 ; i--,paramIndex--)
- {
- if (classExpressions[i] != null &&
- !Util.matchesClassExpr(classExpressions[i], parameters[paramIndex], null))
- {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourNode.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourNode.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,229 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.Collection;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.ConstructionInfo;
-import org.jboss.aop.JoinPointInfo;
-import org.jboss.aop.joinpoint.graph.tree.Tree;
-
-/**
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- */
-class BehaviourNode implements Node
-{
- private ClassNode classNode;
- private BehaviourType behaviourType;
- private Member member;
- private JoinPointInfo execution;
- private ConstructionInfo construction;
- private Tree<JoinPointInfo> calls;
-
- public BehaviourNode(ClassNode classNode, Method member)
- {
- this.classNode = classNode;
- this.member = member;
- this.behaviourType = BehaviourType.METHOD;
- }
-
- public BehaviourNode(ClassNode classNode, Constructor member)
- {
- this.classNode = classNode;
- this.member = member;
- this.behaviourType = BehaviourType.CONSTRUCTOR;
- }
-
- // TODO Flavia
- public ClassNode getClassNode()
- {
- return this.classNode;
- }
-
- public static final String getDefaultKey(Method member)
- {
- return getDefaultKey(member, BehaviourType.METHOD);
- }
-
- public static final String getDefaultKey(Constructor member)
- {
- return getDefaultKey(member, BehaviourType.CONSTRUCTOR);
- }
-
- private static final String getDefaultKey(Member member, BehaviourType type)
- {
- return type.getName(member) + getParameterList(member, type);
- }
-
- private static final String getParameterList(Member member, BehaviourType type)
- {
- Class[] parameterTypes = type.getParameterTypes(member);
- if (parameterTypes.length == 0)
- {
- return "()";
- }
- StringBuffer paramList = new StringBuffer(type.getName(member));
- paramList.append('(');
- for (int i = 0; i < parameterTypes.length; i++)
- {
- paramList.append(parameterTypes[i].getName()).append(' ');
- }
- paramList.append(')');
- return paramList.toString();
- }
-
- public String getDefaultKey()
- {
- return getDefaultKey(this.member, this.behaviourType);
- }
-
- public void loadMetaDataKeys(Collection<String> keys)
- {
- String commonPrefix = behaviourType.getReturnType(member) + "@";
- String commonSuffix = getParameterList(member, behaviourType);
- Collection<String> metaDataTags =
- behaviourType.getMetaDataTags(classNode.getAdvisor(), member);
- for (String metaDataTag: metaDataTags)
- {
- keys.add(commonPrefix + metaDataTag + commonSuffix);
- }
- }
-
- public Member getMember()
- {
- return this.member;
- }
-
- public Class[] getExceptionTypes()
- {
- return this.behaviourType.getExceptionTypes(member);
- }
-
- public boolean hasExecution()
- {
- return this.execution != null;
- }
-
- public JoinPointInfo getExecution()
- {
- return this.execution;
- }
-
- public void setExecution(JoinPointInfo execution)
- {
- this.execution = execution;
- }
-
- public boolean hasConstruction()
- {
- return this.construction != null;
- }
-
- public ConstructionInfo getConstruction()
- {
- return this.construction;
- }
-
- public void setConstruction(ConstructionInfo construction)
- {
- this.construction = construction;
- }
-
- public void insertCaller(String callerName, JoinPointInfo callNode)
- {
- calls.insert(callerName, callNode);
- }
-
- public void searchCallers(String callerExpression, Collection<JoinPointInfo> result)
- {
- calls.search(callerExpression, result);
- }
-
- private enum BehaviourType
- {
- CONSTRUCTOR
- {
- public String getName(Member member)
- {
- return "new";
- }
-
- public String getReturnType(Member member)
- {
- return "";
- }
-
- public Class[] getParameterTypes(Member member)
- {
- return ((Constructor) member).getParameterTypes();
- }
-
- public Class[] getExceptionTypes(Member member)
- {
- return ((Constructor) member).getExceptionTypes();
- }
-
- public Collection<String> getMetaDataTags(Advisor advisor, Member member)
- {
- return advisor.getMetaDataTags((Constructor) member);
- }
- },
- METHOD
- {
- public String getName(Member member)
- {
- return ((Method) member).getReturnType().getName() + " " + member.getName();
- }
-
- public String getReturnType(Member member)
- {
- return ((Method) member).getReturnType().getName() + " ";
- }
-
- public Class[] getParameterTypes(Member member)
- {
- return ((Method) member).getParameterTypes();
- }
-
- public Class[] getExceptionTypes(Member member)
- {
- return ((Method) member).getExceptionTypes();
- }
-
- public Collection<String> getMetaDataTags(Advisor advisor, Member member)
- {
- return advisor.getMetaDataTags((Method) member);
- }
- };
-
- public abstract String getName(Member member);
- public abstract Class[] getExceptionTypes(Member member);
- public abstract Class[] getParameterTypes(Member member);
- public abstract Collection<String> getMetaDataTags(Advisor advisor, Member member);
- public abstract String getReturnType(Member member);
- };
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviourSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,131 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.jboss.aop.JoinPointInfo;
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ASTAttribute;
-import org.jboss.aop.pointcut.ast.ASTException;
-
-/**
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- */
-class BehaviourSearcher implements ClassNodeSearcher
-{
-
-
- public enum SearchType {
- EXECUTION
- {
- public Searcher<BehaviourNode> getSearcher()
- {
- return ExecutionSearcher.getInstance();
- }
- },
- CONSTRUCTION
- {
- public Searcher<BehaviourNode> getSearcher()
- {
- return ConstructionSearcher.getInstance();
- }
- },
- CALL
- {
- public Searcher<BehaviourNode> getSearcher()
- {
- return new CallSearcher();
- }
- },
- ALL
- {
- public Searcher<BehaviourNode> getSearcher()
- {
- return AllBehaviourSearcher.getInstance();
- }
- };
-
- public abstract Searcher<BehaviourNode> getSearcher();
- }
- private String behaviourExpression;
- private Collection<ASTAttribute> attributes;
- private Collection<ASTException> exceptions;
- private BehaviourFilter behaviourFilter;
- private boolean isMethod;
- private Searcher<BehaviourNode> internalSearcher;
-
- public BehaviourSearcher(String behaviourExpression,
- Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
- BehaviourFilter behaviourFilter, boolean isMethod)
- {
-
- this.behaviourExpression = behaviourExpression;
- this.attributes = attributes;
- this.exceptions = exceptions;
- this.behaviourFilter = behaviourFilter;
- this.isMethod = isMethod;
- }
-
- public void setSearchType(SearchType searchType)
- {
- this.internalSearcher = searchType.getSearcher();
- }
-
- Searcher<BehaviourNode> getInternalSearcher()
- {
- return this.internalSearcher;
- }
-
- public void search(ClassNode node, Collection<JoinPointInfo> result)
- {
- Collection<BehaviourNode> behaviours = node.searchBehaviours(behaviourExpression);
- if (isMethod)
- {
- for (BehaviourNode behaviourNode: behaviours)
- {
- if (Util.matchModifiers(attributes, behaviourNode.getMember().getModifiers())
- && Util.matchExceptions(exceptions, behaviourNode.getExceptionTypes())
- && (behaviourFilter == null || behaviourFilter.accept((Method) behaviourNode.getMember())))
- {
- this.internalSearcher.search(behaviourNode, result);
- }
- }
- }
- else
- {
- for (BehaviourNode behaviourNode: behaviours)
- {
- if (Util.matchModifiers(attributes, behaviourNode.getMember().getModifiers())
- && Util.matchExceptions(exceptions, behaviourNode.getExceptionTypes())
- && (behaviourFilter == null || behaviourFilter.accept((Constructor) behaviourNode.getMember())))
- {
- this.internalSearcher.search(behaviourNode, result);
- }
- }
- }
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CallSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CallSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CallSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -25,19 +25,26 @@
import org.jboss.aop.JoinPointInfo;
-class CallSearcher implements Searcher<BehaviourNode>
+/**
+ * Searches for the call joinpoints on a {@code BehaviorNode}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class CallSearcher implements Searcher<BehaviorNode>
{
- private Collection<WithinRestriction> withinRestrictionList;
+ private Collection<WithinSearcher> withinRestrictionList;
- void setWithinRestrictionList(Collection<WithinRestriction> withinRestrictionList)
+ /**
+ * Sets the l
+ * @param withinRestrictionList
+ */
+ public void setWithinRestrictionList(Collection<WithinSearcher> withinRestrictionList)
{
this.withinRestrictionList = withinRestrictionList;
}
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.Searcher#search(java.lang.Object, java.util.Collection)
- */
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
{
if (withinRestrictionList.isEmpty())
{
@@ -45,7 +52,7 @@
}
else
{
- for (WithinRestriction withinRestriction: withinRestrictionList)
+ for (WithinSearcher withinRestriction: withinRestrictionList)
{
withinRestriction.search(node, searchResult);
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -157,7 +157,7 @@
* such node does not exist, it is created and inserted in the
* behaviour subtree.
*/
- public BehaviourNode getBehaviour(Constructor constructor)
+ public BehaviorNode getBehaviour(Constructor constructor)
{
return advisedData.getBehaviour(constructor);
}
@@ -172,7 +172,7 @@
* node does not exist, it is created and inserted in the
* behaviour subtree.
*/
- public BehaviourNode getBehaviour(Method method)
+ public BehaviorNode getBehaviour(Method method)
{
return advisedData.getBehaviour(method);
}
@@ -186,7 +186,7 @@
* @return a collection containing all the behaviour nodes
* whose keys match {@code behaviourExpression}.
*/
- public Collection<BehaviourNode> searchBehaviours(String behaviourExpression)
+ public Collection<BehaviorNode> searchBehaviours(String behaviourExpression)
{
return advisedData.searchBehaviours(behaviourExpression);
}
@@ -227,14 +227,14 @@
{
private Advisor advisor;
private Tree<FieldNode> fields;
- private Tree<BehaviourNode> behaviours;
+ private Tree<BehaviorNode> behaviours;
public AdvisedClassData(Advisor advisor)
{
this.advisor = advisor;
this.fields = new Tree<FieldNode>();
- this.behaviours = new Tree<BehaviourNode>();
+ this.behaviours = new Tree<BehaviorNode>();
}
public Advisor getAdvisor()
@@ -242,31 +242,31 @@
return this.advisor;
}
- public BehaviourNode getBehaviour(Constructor constructor)
+ public BehaviorNode getBehaviour(Constructor constructor)
{
- String behaviourKey = BehaviourNode.getDefaultKey(constructor);
- BehaviourNode behaviourNode = behaviours.searchValue(behaviourKey);
+ String behaviourKey = BehaviorNode.getDefaultKey(constructor);
+ BehaviorNode behaviourNode = behaviours.searchValue(behaviourKey);
if (behaviourNode == null)
{
- behaviourNode = new BehaviourNode(ClassNode.this, constructor);
+ behaviourNode = new BehaviorNode(ClassNode.this, constructor);
TreeInsertionUtil.insertNode(behaviourNode, behaviourKey, behaviours);
}
return behaviourNode;
}
- public BehaviourNode getBehaviour(Method method)
+ public BehaviorNode getBehaviour(Method method)
{
- String behaviourKey = BehaviourNode.getDefaultKey(method);
- BehaviourNode behaviourNode = behaviours.searchValue(behaviourKey);
+ String behaviourKey = BehaviorNode.getDefaultKey(method);
+ BehaviorNode behaviourNode = behaviours.searchValue(behaviourKey);
if (behaviourNode == null)
{
- behaviourNode = new BehaviourNode(ClassNode.this, method);
+ behaviourNode = new BehaviorNode(ClassNode.this, method);
TreeInsertionUtil.insertNode(behaviourNode, behaviourKey, behaviours);
}
return behaviourNode;
}
- public Collection<BehaviourNode> searchBehaviours(String behaviourExpression)
+ public Collection<BehaviorNode> searchBehaviours(String behaviourExpression)
{
return behaviours.search(behaviourExpression);
}
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNodeSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNodeSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNodeSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,31 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-/**
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-public interface ClassNodeSearcher extends Searcher<ClassNode>
-{
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -43,12 +43,12 @@
this.searchKey2 = searchKey2;
}
- public void addTypeRestriction(TypeRestriction typeRestriction)
+ public void addTypeRestriction(TypeFilter typeRestriction)
{
searchKey2.addTypeRestriction(typeRestriction);
}
- public void addWithinRestriction(WithinRestriction withinRestriction)
+ public void addWithinRestriction(WithinSearcher withinRestriction)
{
searchKey2.addWithinRestriction(withinRestriction);
}
@@ -63,7 +63,7 @@
searchKey2.setClassExpression(className, instanceOf);
}
- public void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher)
+ public void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher)
{
searchKey2.setClassNodeSearcher(classNodeSearcher);
}
@@ -94,12 +94,12 @@
this.searchKey2.replaceNegativeSearchKey(searchKey);
}
- public void replaceTypeRestriction(TypeRestriction restriction)
+ public void replaceTypeRestriction(TypeFilter restriction)
{
this.searchKey2.replaceTypeRestriction(restriction);
}
- public void replaceWithinRestriction(WithinRestriction restriction)
+ public void replaceWithinRestriction(WithinSearcher restriction)
{
this.searchKey2.replaceWithinRestriction(restriction);
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConstructionSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConstructionSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConstructionSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,3 +1,24 @@
+/*
+ * 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.joinpoint.graph;
import java.util.Collection;
@@ -4,10 +25,18 @@
import org.jboss.aop.JoinPointInfo;
-class ConstructionSearcher implements Searcher<BehaviourNode>
+/**
+ * Searcher that retrieves the construction joinpoint of a BehaviorNode, if present.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class ConstructionSearcher implements Searcher<BehaviorNode>
{
private static final ConstructionSearcher INSTANCE = new ConstructionSearcher();
+ /**
+ * Returns the singleton instance.
+ */
public static ConstructionSearcher getInstance()
{
return INSTANCE;
@@ -15,7 +44,7 @@
private ConstructionSearcher() {}
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
{
if (node.hasConstruction())
{
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -41,12 +41,12 @@
this.searchKey2 = searchKey2;
}
- public void addTypeRestriction(TypeRestriction typeRestriction)
+ public void addTypeRestriction(TypeFilter typeRestriction)
{
searchKey2.addTypeRestriction(typeRestriction);
}
- public void addWithinRestriction(WithinRestriction withinRestriction)
+ public void addWithinRestriction(WithinSearcher withinRestriction)
{
searchKey2.addWithinRestriction(withinRestriction);
}
@@ -61,7 +61,7 @@
searchKey2.setClassExpression(className, instanceOf);
}
- public void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher)
+ public void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher)
{
searchKey2.setClassNodeSearcher(classNodeSearcher);
}
@@ -92,12 +92,12 @@
this.searchKey2.replaceNegativeSearchKey(searchKey);
}
- public void replaceTypeRestriction(TypeRestriction restriction)
+ public void replaceTypeRestriction(TypeFilter restriction)
{
this.searchKey2.replaceTypeRestriction(restriction);
}
- public void replaceWithinRestriction(WithinRestriction restriction)
+ public void replaceWithinRestriction(WithinSearcher restriction)
{
this.searchKey2.replaceWithinRestriction(restriction);
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -36,14 +36,14 @@
{
}
- public void addTypeRestriction(TypeRestriction typeRestriction)
+ public void addTypeRestriction(TypeFilter typeRestriction)
{
}
/* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#addWithinRestriction(org.jboss.aop.joinpoint.graph.WithinRestriction)
+ * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#addWithinRestriction(org.jboss.aop.joinpoint.graph.WithinSearcher)
*/
- public void addWithinRestriction(WithinRestriction withinRestriction)
+ public void addWithinRestriction(WithinSearcher withinRestriction)
{
// TODO Auto-generated method stub
@@ -86,18 +86,18 @@
}
/* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#replaceTypeRestriction(org.jboss.aop.joinpoint.graph.TypeRestriction)
+ * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#replaceTypeRestriction(org.jboss.aop.joinpoint.graph.TypeFilter)
*/
- public void replaceTypeRestriction(TypeRestriction restriction)
+ public void replaceTypeRestriction(TypeFilter restriction)
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#replaceWithinRestriction(org.jboss.aop.joinpoint.graph.WithinRestriction)
+ * @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#replaceWithinRestriction(org.jboss.aop.joinpoint.graph.WithinSearcher)
*/
- public void replaceWithinRestriction(WithinRestriction restriction)
+ public void replaceWithinRestriction(WithinSearcher restriction)
{
// TODO Auto-generated method stub
@@ -115,7 +115,7 @@
/* (non-Javadoc)
* @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#setClassNodeSearcher(org.jboss.aop.joinpoint.graph.ClassNodeSearcher)
*/
- public void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher)
+ public void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher)
{
// TODO Auto-generated method stub
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ExecutionSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ExecutionSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ExecutionSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -25,10 +25,18 @@
import org.jboss.aop.JoinPointInfo;
-public class ExecutionSearcher implements Searcher<BehaviourNode>
+/**
+ * Searcher that retrieves the execution joinpoint of a BehaviorNode, if present.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class ExecutionSearcher implements Searcher<BehaviorNode>
{
private static final ExecutionSearcher INSTANCE = new ExecutionSearcher();
+ /**
+ * Returns the singleton instance.
+ */
public static ExecutionSearcher getInstance()
{
return INSTANCE;
@@ -36,7 +44,7 @@
private ExecutionSearcher() {}
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
{
if (node.hasExecution())
{
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldFilter.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldFilter.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldFilter.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -27,29 +27,44 @@
import org.jboss.aop.pointcut.ast.ClassExpression;
/**
+ * A filter for fields.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
*/
interface FieldFilter
{
+ /**
+ * Tests whether or not {@code field} is accepted or rejected by this filter.
+ *
+ * @param field the field to be tested
+ * @return {@code boolean} if this filter accepts {@code field}
+ */
public boolean accept(Field field);
}
+/**
+ * Checks if the type of a field follow a type restriction.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
class FieldTypeFilter implements FieldFilter
{
private ClassExpression classExpression;
+ /**
+ * Creates a filter that will accept only fields whose type matches
+ * {@code classExpression}.
+ *
+ * @param classExpression an complex type expression (a call to its
+ * {@code isSimple()} method would return {@code false}).
+ */
public FieldTypeFilter(ClassExpression classExpression)
{
this.classExpression = classExpression;
}
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.FieldFilter#accept(java.lang.reflect.Field)
- */
public boolean accept(Field field)
{
return Util.matchesClassExpr(classExpression, field.getType());
- }
-
+ }
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -29,13 +29,21 @@
import org.jboss.aop.pointcut.ast.ASTAttribute;
/**
+ * Performs a search for field-related joinpoints on a class node. Those
+ * joinpoints can be of the type read, write, and all.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
*/
-class FieldSearcher implements ClassNodeSearcher
+class FieldSearcher implements Searcher<ClassNode>
{
+ /**
+ * Indicates the type of joinpoint that this searcher should look for.
+ */
public enum SearchType implements Searcher<FieldNode>
{
+ /**
+ * Indicates this searcher must retrieve only joinpoints of the type read.
+ */
READ
{
public void search(FieldNode node, Collection<JoinPointInfo> searchResult)
@@ -46,6 +54,9 @@
}
}
},
+ /**
+ * Indicates this searcher must retrieve only joinpoints of the type write.
+ */
WRITE
{
public void search(FieldNode node, Collection<JoinPointInfo> searchResult)
@@ -57,6 +68,10 @@
}
},
+ /**
+ * Indicates this searcher must retrieve joinpoints of both the types read and
+ * write.
+ */
ALL
{
public void search(FieldNode node, Collection<JoinPointInfo> searchResult)
@@ -73,24 +88,48 @@
}
}
- private SearchType accessType;
+ private Searcher<FieldNode> internalSearcher;
private String fieldExpression;
+ private Collection<ASTAttribute> attributes;
private FieldFilter fieldFilter;
- private Collection<ASTAttribute> attributes;
-
- public FieldSearcher(String fieldExpression, Collection<ASTAttribute> attributes, FieldFilter fieldFilter)
+ /**
+ * Creates an instance of this searcher.
+ *
+ * @param fieldExpression the expression that will be used to identify a field in
+ * a {@code ClassNode}
+ * @param attributes the attribute restrictions that the searched field must
+ * follow
+ * @param fieldFilter a filter for extra checks on the searched field. This
+ * filter should be {@code null} if there are no extra
+ * checks to be performed on the searched field.
+ */
+ public FieldSearcher(String fieldExpression, Collection<ASTAttribute> attributes,
+ FieldFilter fieldFilter)
{
this.fieldExpression = fieldExpression;
this.attributes = attributes;
this.fieldFilter = fieldFilter;
}
- public void setAccessType(SearchType accessType)
+ /**
+ * Sets the type of search that this searcher should perform.
+ * <p>
+ * This method must be called before this object performs a search.
+ *
+ * @param internalSearcher indicates the type of joinpoint that this class searches for
+ */
+ public void setSearchType(SearchType searchType)
{
- this.accessType = accessType;
+ this.internalSearcher = searchType;
}
+ /**
+ * Before this method is executed, the search type to be performed must have
+ * been set.
+ *
+ * @see #setSearchType(org.jboss.aop.joinpoint.graph.FieldSearcher.SearchType)
+ */
public void search(ClassNode node, Collection<JoinPointInfo> searchResult)
{
Collection<FieldNode> fieldNodes = node.searchFields(fieldExpression);
@@ -100,7 +139,7 @@
if (Util.matchModifiers(attributes, field.getModifiers()) &&
(fieldFilter == null || fieldFilter.accept(field)))
{
- accessType.search(fieldNode, searchResult);
+ internalSearcher.search(fieldNode, searchResult);
}
}
}
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasBlockRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasBlockRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasBlockRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,48 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ASTConstructor;
-import org.jboss.aop.pointcut.ast.ASTMethod;
-import org.jboss.aop.pointcut.ast.SimpleNode;
-
-
-class HasBlockRestriction implements TypeRestriction {
-
- private SimpleNode behaviourASTNode;
-
- public HasBlockRestriction(SimpleNode behaviourASTNode)
- {
- this.behaviourASTNode = behaviourASTNode;
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- if (behaviourASTNode instanceof ASTConstructor)
- {
- return Util.has(target, (ASTConstructor) behaviourASTNode, advisor);
- }
- return Util.has(target, (ASTMethod) behaviourASTNode, advisor);
- }
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasFieldRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasFieldRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/HasFieldRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,41 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ASTField;
-
-class HasFieldRestriction implements TypeRestriction
-{
- private ASTField fieldASTNode;
-
- public HasFieldRestriction(ASTField fieldASTNode)
- {
- this.fieldASTNode = fieldASTNode;
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- return Util.has(target, fieldASTNode, advisor);
- }
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/InstanceOfRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/InstanceOfRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/InstanceOfRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,45 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ClassExpression;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-public class InstanceOfRestriction implements TypeRestriction
-{
- private ClassExpression classExpression;
-
- public InstanceOfRestriction(ClassExpression classExpression)
- {
- this.classExpression = classExpression;
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- return Util.subtypeOf(target, classExpression, advisor);
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -100,33 +100,33 @@
public synchronized void register(ConByConInfo info)
{
- BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ BehaviorNode behaviour = getBehaviour(info.getAdvisor(),
info.getCalledClass(), info.getConstructor());
- String callName = BehaviourNode.getDefaultKey(info.getCallingConstructor());
+ String callName = BehaviorNode.getDefaultKey(info.getCallingConstructor());
behaviour.insertCaller(callName, info);
}
public synchronized void register(ConByMethodInfo info)
{
- BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ BehaviorNode behaviour = getBehaviour(info.getAdvisor(),
info.getCalledClass(), info.getConstructor());
- String callName = BehaviourNode.getDefaultKey(info.getCallingMethod());
+ String callName = BehaviorNode.getDefaultKey(info.getCallingMethod());
behaviour.insertCaller(callName, info);
}
public synchronized void register(MethodByMethodInfo info)
{
- BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ BehaviorNode behaviour = getBehaviour(info.getAdvisor(),
info.getCalledClass(), info.getMethod());
- String callerName = BehaviourNode.getDefaultKey(info.getCallingMethod());
+ String callerName = BehaviorNode.getDefaultKey(info.getCallingMethod());
behaviour.insertCaller(callerName, info);
}
public synchronized void register(MethodByConInfo info)
{
- BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ BehaviorNode behaviour = getBehaviour(info.getAdvisor(),
info.getCalledClass(), info.getMethod());
- String callerName = BehaviourNode.getDefaultKey(info.getCallingConstructor());
+ String callerName = BehaviorNode.getDefaultKey(info.getCallingConstructor());
behaviour.insertCaller(callerName, info);
}
@@ -135,7 +135,7 @@
* @param constructor
* @return
*/
- private BehaviourNode getBehaviour(Advisor advisor, Class clazz, Constructor constructor)
+ private BehaviorNode getBehaviour(Advisor advisor, Class clazz, Constructor constructor)
{
ClassNode classNode = getClassNode(clazz, advisor);
return classNode.getBehaviour(constructor);
@@ -146,7 +146,7 @@
* @param method
* @return
*/
- private BehaviourNode getBehaviour(Advisor advisor, Class clazz, Method method)
+ private BehaviorNode getBehaviour(Advisor advisor, Class clazz, Method method)
{
ClassNode classNode = getClassNode(clazz, advisor);
return classNode.getBehaviour(method);
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ParsedSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ParsedSearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ParsedSearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -11,13 +11,13 @@
abstract String getClassExpression();
abstract void setClassExpression(String className, boolean instanceOf);
- abstract void addTypeRestriction(TypeRestriction typeRestriction);
- abstract void addWithinRestriction(WithinRestriction withinRestriction);
- abstract void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher);
+ abstract void addTypeRestriction(TypeFilter typeRestriction);
+ abstract void addWithinRestriction(WithinSearcher withinRestriction);
+ abstract void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher);
abstract void addNegativeSearchKey(ParsedSearchKey searchKey);
abstract Object getLastAddedElement();
- abstract void replaceTypeRestriction(TypeRestriction restriction);
- abstract void replaceWithinRestriction(WithinRestriction restriction);
+ abstract void replaceTypeRestriction(TypeFilter restriction);
+ abstract void replaceWithinRestriction(WithinSearcher restriction);
abstract void replaceNegativeSearchKey(ParsedSearchKey searchKey);
abstract void merge(SimpleSearchKey simpleSearchKey);
abstract ParsedSearchKey finishParsing();
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -78,7 +78,7 @@
* @see org.jboss.aop.joinpoint.graph.ParsedSearchKey#setClassNodeSearcher(org.jboss.aop.joinpoint.graph.ClassNodeSearcher)
*/
@Override
- void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher)
+ void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher)
{
// TODO Auto-generated method stub
@@ -93,8 +93,8 @@
Collection<ClassNode> allClasses = classTree.search("*");
for (ClassNode classNode: allClasses)
{
- Collection<BehaviourNode> behaviourNodes = classNode.searchBehaviours("*");
- for (BehaviourNode behaviourNode: behaviourNodes)
+ Collection<BehaviorNode> behaviourNodes = classNode.searchBehaviours("*");
+ for (BehaviorNode behaviourNode: behaviourNodes)
{
if (behaviourNode.hasConstruction() &&
pointcut.matchesConstruction(
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -21,9 +21,7 @@
*/
package org.jboss.aop.joinpoint.graph;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import org.jboss.aop.JoinPointInfo;
@@ -36,32 +34,18 @@
class SearchKeyImpl extends SimpleSearchKey
{
private String classExpression;
- private ClassNodeSearcher classNodeSearcher;
- private boolean instanceOf;
+ private Searcher<ClassNode> classNodeSearcher;
public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
{
Collection<ClassNode> classes = new LinkedList<ClassNode>();
classTree.search(classExpression, classes);
- if (isInstanceOf())
- {
- Collection<ClassNode> superClasses = classes;
- classes = new ArrayList<ClassNode>(superClasses.size() * 2);
- for (Iterator<ClassNode> iterator = superClasses.iterator(); iterator.hasNext(); )
- {
- ClassNode superClassNode = iterator.next();
- classes.add(superClassNode);
- iterator.remove();
- classes.addAll(superClassNode.getDirectSubtypes());
- superClasses.addAll(superClassNode.getDirectSubtypes());
- }
- }
outer: for (ClassNode classNode: classes)
{
- for (TypeRestriction restriction: typeRestrictions)
+ for (TypeFilter restriction: typeRestrictions)
{
- if (!restriction.satisfies(classNode.getRepresentedClass(), classNode.getAdvisor()))
+ if (!restriction.accept(classNode.getRepresentedClass(), classNode.getAdvisor()))
{
continue outer;
}
@@ -75,23 +59,18 @@
return this.classExpression;
}
- boolean isInstanceOf()
- {
- return this.instanceOf;
- }
public void setClassExpression(String className, boolean instanceOf)
{
- this.classExpression = className;
- this.instanceOf = instanceOf;
+ this.classExpression = instanceOf? className + "+": className;
}
- ClassNodeSearcher getClassNodeSearcher()
+ Searcher<ClassNode> getClassNodeSearcher()
{
return classNodeSearcher;
}
- public void setClassNodeSearcher(ClassNodeSearcher classNodeSearcher)
+ public void setClassNodeSearcher(Searcher<ClassNode> classNodeSearcher)
{
this.classNodeSearcher = classNodeSearcher;
}
@@ -103,20 +82,20 @@
if (this.classExpression == null)
{
this.classExpression = "*";
- BehaviourSearcher behaviourSearcher =
- new BehaviourSearcher("*", SearchKeyParser.EMPTY_ATTRIBUTES,
+ BehaviorSearcher behaviourSearcher =
+ new BehaviorSearcher("*", SearchKeyParser.EMPTY_ATTRIBUTES,
SearchKeyParser.EMPTY_EXCEPTIONS, null, true);
- behaviourSearcher.setSearchType(BehaviourSearcher.SearchType.CALL);
+ behaviourSearcher.setSearchType(BehaviorSearcher.SearchType.CALL);
((CallSearcher) behaviourSearcher.getInternalSearcher()).
setWithinRestrictionList(this.withinRestrictions);
this.classNodeSearcher = behaviourSearcher;
return this;
}
- if (this.classNodeSearcher instanceof BehaviourSearcher &&
- ((BehaviourSearcher) this.classNodeSearcher).getInternalSearcher()
+ if (this.classNodeSearcher instanceof BehaviorSearcher &&
+ ((BehaviorSearcher) this.classNodeSearcher).getInternalSearcher()
instanceof CallSearcher)
{
- CallSearcher callSearcher = (CallSearcher) ((BehaviourSearcher)
+ CallSearcher callSearcher = (CallSearcher) ((BehaviorSearcher)
this.classNodeSearcher).getInternalSearcher();
callSearcher.setWithinRestrictionList(this.withinRestrictions);
return this;
@@ -126,21 +105,27 @@
if (this.classExpression == null)
{
this.classExpression = "*";
- BehaviourSearcher behaviourSearcher =
- new BehaviourSearcher("*", SearchKeyParser.EMPTY_ATTRIBUTES,
+ BehaviorSearcher behaviourSearcher =
+ new BehaviorSearcher("*", SearchKeyParser.EMPTY_ATTRIBUTES,
SearchKeyParser.EMPTY_EXCEPTIONS, null, true);
- behaviourSearcher.setSearchType(BehaviourSearcher.SearchType.ALL);
+ behaviourSearcher.setSearchType(BehaviorSearcher.SearchType.ALL);
this.classNodeSearcher = behaviourSearcher;
SearchKeyImpl fieldSearchKey = new SearchKeyImpl();
fieldSearchKey.classExpression = "*";
FieldSearcher fieldSearcher = new FieldSearcher("*",
SearchKeyParser.EMPTY_ATTRIBUTES, null);
- fieldSearcher.setAccessType(FieldSearcher.SearchType.ALL);
+ fieldSearcher.setSearchType(FieldSearcher.SearchType.ALL);
fieldSearchKey.classNodeSearcher = fieldSearcher;
fieldSearchKey.typeRestrictions = this.typeRestrictions;
fieldSearchKey.negativeSearchKeys = this.negativeSearchKeys;
return new DisjunctiveSearchKey(this, fieldSearchKey);
}
+ if (this.classExpression.endsWith("+"))
+ {
+ this.classExpression = this.classExpression.substring(0,
+ classExpression.length() - 1);
+ this.classNodeSearcher = new SubtypeSearcher(this.classNodeSearcher);
+ }
return this;
}
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyParser.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyParser.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyParser.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -34,7 +34,7 @@
import org.jboss.aop.pointcut.ast.ASTAnd;
import org.jboss.aop.pointcut.ast.ASTAndCFlow;
import org.jboss.aop.pointcut.ast.ASTAttribute;
-import org.jboss.aop.pointcut.ast.ASTBehaviour;
+import org.jboss.aop.pointcut.ast.ASTBehavior;
import org.jboss.aop.pointcut.ast.ASTBoolean;
import org.jboss.aop.pointcut.ast.ASTCFlow;
import org.jboss.aop.pointcut.ast.ASTCFlowBoolean;
@@ -115,13 +115,13 @@
Object result = node.jjtGetChild(0).jjtAccept(this, negativeSearchKey);
if (result!= null)
{
- if (result instanceof TypeRestriction)
+ if (result instanceof TypeFilter)
{
- return new NegativeTypeRestriction((TypeRestriction) result);
+ return new NegativeTypeFilter((TypeFilter) result);
}
- else if (result instanceof WithinRestriction)
+ else if (result instanceof WithinSearcher)
{
- return new NegativeWithinRestriction((WithinRestriction) result);
+ return new NegativeWithinSearcher((WithinSearcher) result);
}
searchKey.addNegativeSearchKey(negativeSearchKey.finishParsing());
}
@@ -154,13 +154,13 @@
Object result = node.jjtGetChild(0).jjtAccept(this, searchKey);
if (result!= null)
{
- if (result instanceof TypeRestriction)
+ if (result instanceof TypeFilter)
{
- searchKey.addTypeRestriction((TypeRestriction) result);
+ searchKey.addTypeRestriction((TypeFilter) result);
}
- else if (result instanceof WithinRestriction)
+ else if (result instanceof WithinSearcher)
{
- searchKey.addWithinRestriction((WithinRestriction) result);
+ searchKey.addWithinRestriction((WithinSearcher) result);
}
else // result intanceof ParsedSearchKey
{
@@ -177,22 +177,22 @@
Object result = node.jjtGetChild(0).jjtAccept(this, newSearchKey);
if (result!= null)
{
- if (result instanceof TypeRestriction &&
+ if (result instanceof TypeFilter &&
searchKey.getLastAddedElement() != null &&
- searchKey.getLastAddedElement() instanceof TypeRestriction)
+ searchKey.getLastAddedElement() instanceof TypeFilter)
{
- searchKey.replaceTypeRestriction(new DisjunctiveTypeRestriction(
- (TypeRestriction) searchKey.getLastAddedElement(),
- (TypeRestriction) result));
+ searchKey.replaceTypeRestriction(new DisjunctiveTypeFilter(
+ (TypeFilter) searchKey.getLastAddedElement(),
+ (TypeFilter) result));
return searchKey;
}
- else if (result instanceof WithinRestriction &&
+ else if (result instanceof WithinSearcher &&
searchKey.getLastAddedElement() != null &&
- searchKey.getLastAddedElement() instanceof WithinRestriction)
+ searchKey.getLastAddedElement() instanceof WithinSearcher)
{
- searchKey.replaceWithinRestriction(new DisjunctiveWithinRestriction(
- (WithinRestriction) searchKey.getLastAddedElement(),
- (WithinRestriction) result));
+ searchKey.replaceWithinRestriction(new DisjunctiveWithinSearcher(
+ (WithinSearcher) searchKey.getLastAddedElement(),
+ (WithinSearcher) result));
return searchKey;
}
else if(result instanceof ParsedSearchKey)
@@ -202,13 +202,13 @@
}
else // partially filled ParsedSearchKey
{
- if (result instanceof TypeRestriction)
+ if (result instanceof TypeFilter)
{
- newSearchKey.addTypeRestriction((TypeRestriction) result);
+ newSearchKey.addTypeRestriction((TypeFilter) result);
}
else
{
- newSearchKey.addWithinRestriction((WithinRestriction) result);
+ newSearchKey.addWithinRestriction((WithinSearcher) result);
}
return new DisjunctiveSearchKey(searchKey.finishParsing(), newSearchKey);
}
@@ -246,7 +246,7 @@
}
FieldSearcher searcher = (FieldSearcher) node.jjtGetChild(0).jjtAccept(this,
key);
- searcher.setAccessType(FieldSearcher.SearchType.READ);
+ searcher.setSearchType(FieldSearcher.SearchType.READ);
key.setClassNodeSearcher(searcher);
return returnValue;
}
@@ -261,7 +261,7 @@
}
FieldSearcher searcher = (FieldSearcher) node.jjtGetChild(0).jjtAccept(this,
key);
- searcher.setAccessType(FieldSearcher.SearchType.WRITE);
+ searcher.setSearchType(FieldSearcher.SearchType.WRITE);
key.setClassNodeSearcher(searcher);
return returnValue;
}
@@ -276,7 +276,7 @@
}
FieldSearcher searcher = (FieldSearcher) node.jjtGetChild(0).jjtAccept(this,
key);
- searcher.setAccessType(FieldSearcher.SearchType.ALL);
+ searcher.setSearchType(FieldSearcher.SearchType.ALL);
key.setClassNodeSearcher(searcher);
return returnValue;
}
@@ -292,9 +292,9 @@
{
returnValue = key = new SearchKeyImpl();
}
- BehaviourSearcher searcher = (BehaviourSearcher) node.jjtGetChild(0)
+ BehaviorSearcher searcher = (BehaviorSearcher) node.jjtGetChild(0)
.jjtAccept(this, key);
- searcher.setSearchType(BehaviourSearcher.SearchType.CONSTRUCTION);
+ searcher.setSearchType(BehaviorSearcher.SearchType.CONSTRUCTION);
key.setClassNodeSearcher(searcher);
return returnValue;
}
@@ -310,9 +310,9 @@
{
returnValue = key = new SearchKeyImpl();
}
- BehaviourSearcher searcher = (BehaviourSearcher) node.jjtGetChild(0)
+ BehaviorSearcher searcher = (BehaviorSearcher) node.jjtGetChild(0)
.jjtAccept(this, key);
- searcher.setSearchType(BehaviourSearcher.SearchType.EXECUTION);
+ searcher.setSearchType(BehaviorSearcher.SearchType.EXECUTION);
key.setClassNodeSearcher(searcher);
return returnValue;
}
@@ -328,9 +328,9 @@
{
returnValue = key = new SearchKeyImpl();
}
- BehaviourSearcher searcher = (BehaviourSearcher) node.jjtGetChild(0)
+ BehaviorSearcher searcher = (BehaviorSearcher) node.jjtGetChild(0)
.jjtAccept(this, key);
- searcher.setSearchType(BehaviourSearcher.SearchType.CALL);
+ searcher.setSearchType(BehaviorSearcher.SearchType.CALL);
key.setClassNodeSearcher(searcher);
return returnValue;
@@ -347,11 +347,11 @@
callerExpression.append(".(*)");
if (restriction != null)
{
- return WithinRestrictionFactory.create(callerExpression.toString(),
+ return WithinSearcherFactory.create(callerExpression.toString(),
EMPTY_ATTRIBUTES, EMPTY_EXCEPTIONS,
new TargetTypeFilter(restriction));
}
- return WithinRestrictionFactory.create(callerExpression.toString());
+ return WithinSearcherFactory.create(callerExpression.toString());
}
public Object visit(ASTWithincode node, Object data)
@@ -363,7 +363,7 @@
{
SimpleNode n = (SimpleNode) node.jjtGetChild(0);
ParsedSearchKey searchKey = (ParsedSearchKey) data;
- searchKey.addTypeRestriction(new HasBlockRestriction(n));
+ searchKey.addTypeRestriction(new HasBehaviorFilter(n));
return null;
}
@@ -371,7 +371,7 @@
{
ASTField astField = (ASTField) node.jjtGetChild(0);
ParsedSearchKey searchKey = (ParsedSearchKey) data;
- searchKey.addTypeRestriction(new HasFieldRestriction(astField));
+ searchKey.addTypeRestriction(new HasFieldFilter(astField));
return null;
}
@@ -409,42 +409,42 @@
public Object visit(ASTConstructor node, Object data)
{
StringBuffer expression = new StringBuffer();
- BehaviourFilter behaviourFilter = visit(node, expression, (ParsedSearchKey) data);
+ BehaviorFilter behaviourFilter = visit(node, expression, (ParsedSearchKey) data);
if (data == null)
{
if (behaviourFilter == null)
{
- return WithinRestrictionFactory.create(expression.toString(),
+ return WithinSearcherFactory.create(expression.toString(),
node.getAttributes(), node.getExceptions());
}
else
{
- return WithinRestrictionFactory.create(expression.toString(),
+ return WithinSearcherFactory.create(expression.toString(),
node.getAttributes(), node.getExceptions(), behaviourFilter);
}
}
- return new BehaviourSearcher(expression.toString(), node.getAttributes(), node
+ return new BehaviorSearcher(expression.toString(), node.getAttributes(), node
.getExceptions(), behaviourFilter, false);
}
public Object visit(ASTMethod node, Object data)
{
StringBuffer expression = new StringBuffer();
- BehaviourFilter behaviourFilter = visit(node, expression, ((ParsedSearchKey) data));
+ BehaviorFilter behaviourFilter = visit(node, expression, ((ParsedSearchKey) data));
if (data == null)
{
if (behaviourFilter != null)
{
- return WithinRestrictionFactory.create(expression.toString(),
+ return WithinSearcherFactory.create(expression.toString(),
node.getAttributes(), node.getExceptions(), behaviourFilter);
}
else
{
- return WithinRestrictionFactory.create(expression.toString(),
+ return WithinSearcherFactory.create(expression.toString(),
node.getAttributes(), node.getExceptions());
}
}
- return new BehaviourSearcher(expression.toString(), node.getAttributes(), node
+ return new BehaviorSearcher(expression.toString(), node.getAttributes(), node
.getExceptions(), behaviourFilter, true);
}
@@ -485,10 +485,10 @@
/* HELPER METHODS ***************************************************************/
- public BehaviourFilter visit(ASTConstructor node, StringBuffer expression, ParsedSearchKey searchKey)
+ public BehaviorFilter visit(ASTConstructor node, StringBuffer expression, ParsedSearchKey searchKey)
{
// behaviour filter
- BehaviourFilter behaviourFilter = null;
+ BehaviorFilter behaviourFilter = null;
// check target type
if (searchKey == null)
@@ -516,7 +516,7 @@
expression.append(annotationExp.getOriginal());
}
- BehaviourFilter parameterFilter = printParameters(expression, node);
+ BehaviorFilter parameterFilter = printParameters(expression, node);
if (parameterFilter != null)
{
if (behaviourFilter == null)
@@ -525,16 +525,16 @@
}
else
{
- behaviourFilter = new CompositeFilter(behaviourFilter, parameterFilter);
+ behaviourFilter = new ConjunctiveBehaviorFilter(behaviourFilter, parameterFilter);
}
}
return behaviourFilter;
}
- private BehaviourFilter visit(ASTMethod node, StringBuffer expression, ParsedSearchKey searchKey)
+ private BehaviorFilter visit(ASTMethod node, StringBuffer expression, ParsedSearchKey searchKey)
{
// behaviour filter
- BehaviourFilter behaviourFilter = null;
+ BehaviorFilter behaviourFilter = null;
// check return type
ClassExpression returnFilter = appendType(node.getReturnType(), expression);
@@ -556,7 +556,7 @@
}
else
{
- behaviourFilter = new CompositeFilter(behaviourFilter, new TargetTypeFilter(typeFilter));
+ behaviourFilter = new ConjunctiveBehaviorFilter(behaviourFilter, new TargetTypeFilter(typeFilter));
}
}
expression.append('.');
@@ -580,7 +580,7 @@
expression.append('*');
if (behaviourFilter != null)
{
- behaviourFilter = new CompositeFilter(behaviourFilter, new OverridenMethodFilter(identifier));
+ behaviourFilter = new ConjunctiveBehaviorFilter(behaviourFilter, new OverridenMethodFilter(identifier));
}
else
{
@@ -589,12 +589,12 @@
}
// check parameters
- BehaviourFilter parameterFilter = printParameters(expression, node);
+ BehaviorFilter parameterFilter = printParameters(expression, node);
if (parameterFilter != null)
{
if (behaviourFilter != null)
{
- behaviourFilter = new CompositeFilter(behaviourFilter, parameterFilter);
+ behaviourFilter = new ConjunctiveBehaviorFilter(behaviourFilter, parameterFilter);
}
else
{
@@ -648,11 +648,11 @@
Typedef typedef = TypedefParser.getTypedef(classExpression);
String expression = TypedefParser.parse(typedef);
searchKey.setClassExpression(expression, false);
- searchKey.addTypeRestriction(new TypedefRestriction(typedef));
+ searchKey.addTypeRestriction(new TypedefFilter(typedef));
}
- private BehaviourFilter printParameters(StringBuffer expression,
- ASTBehaviour behaviour)
+ private BehaviorFilter printParameters(StringBuffer expression,
+ ASTBehavior behaviour)
{
Collection<ASTParameter> parameters = behaviour.getParameters();
expression.append('(');
@@ -660,7 +660,7 @@
boolean wildcardFound = false;
int currentIndex = 0;
PartialParameterFilter filter = null;
- BehaviourFilter beforeWildcardFilter = null;
+ BehaviorFilter beforeWildcardFilter = null;
Iterator<ASTParameter> iterator = parameters.iterator();
for (ASTParameter parameter = iterator.next(); iterator.hasNext(); parameter = iterator
@@ -700,12 +700,12 @@
if (filter == null)
{
// initialize filter accordingly to wildcardFound value
- filter = wildcardFound ? new DecrescentPartialParameterFilter(
- parameters.size()) : new CrescentPartialParameterFilter(
+ filter = wildcardFound ? new DescendingPartialParameterFilter(
+ parameters.size()) : new AscendingPartialParameterFilter(
parameters.size());
}
// add the restriction to the filter
- filter.addExpression(classExpression, currentIndex);
+ filter.addParameterRestriction(classExpression, currentIndex);
}
}
}
@@ -718,7 +718,7 @@
if (filter != null)
{
// use composite filter
- return new CompositeFilter(beforeWildcardFilter, filter);
+ return new ConjunctiveBehaviorFilter(beforeWildcardFilter, filter);
}
// otherwise, use the beforeWildcardFilter
return beforeWildcardFilter;
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Searcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Searcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Searcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -25,7 +25,21 @@
import org.jboss.aop.JoinPointInfo;
-interface Searcher<N>
+/**
+ * Interface to be implemented by a joinpoint searcher.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ * @param <N> the target of the searcher
+ */
+interface Searcher<N extends Node>
{
+ /**
+ * Performs a search on {@code node}, adding the search result to
+ * {@code searchResult}.
+ *
+ * @param node a node in the graph
+ * @param searchResult collection to where the search result will be added.
+ */
public void search(N node, Collection<JoinPointInfo> searchResult);
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleSearchKey.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleSearchKey.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -30,37 +30,37 @@
*/
abstract class SimpleSearchKey extends ParsedSearchKey
{
- protected ArrayList<TypeRestriction> typeRestrictions;
- protected ArrayList<WithinRestriction> withinRestrictions;
+ protected ArrayList<TypeFilter> typeRestrictions;
+ protected ArrayList<WithinSearcher> withinRestrictions;
protected ArrayList<ParsedSearchKey> negativeSearchKeys;
private Object lastElementAdded = null;
- public void addTypeRestriction(TypeRestriction typeRestriction)
+ public void addTypeRestriction(TypeFilter typeRestriction)
{
if (typeRestrictions == null)
{
- typeRestrictions = new ArrayList<TypeRestriction>(1);
+ typeRestrictions = new ArrayList<TypeFilter>(1);
}
typeRestrictions.add(typeRestriction);
lastElementAdded = typeRestriction;
}
- public Collection<TypeRestriction> getTypeRestrictions()
+ public Collection<TypeFilter> getTypeRestrictions()
{
return this.typeRestrictions;
}
- public void addWithinRestriction(WithinRestriction withinRestriction)
+ public void addWithinRestriction(WithinSearcher withinRestriction)
{
if (withinRestrictions == null)
{
- withinRestrictions = new ArrayList<WithinRestriction>(1);
+ withinRestrictions = new ArrayList<WithinSearcher>(1);
}
withinRestrictions.add(withinRestriction);
lastElementAdded = withinRestriction;
}
- Collection<WithinRestriction> getWithinRestrictions()
+ Collection<WithinSearcher> getWithinRestrictions()
{
return this.withinRestrictions;
}
@@ -80,12 +80,12 @@
return this.lastElementAdded;
}
- public void replaceTypeRestriction(TypeRestriction restriction)
+ public void replaceTypeRestriction(TypeFilter restriction)
{
this.typeRestrictions.set(typeRestrictions.size() -1, restriction);
}
- public void replaceWithinRestriction(WithinRestriction restriction)
+ public void replaceWithinRestriction(WithinSearcher restriction)
{
this.withinRestrictions.set(withinRestrictions.size() -1, restriction);
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SubtypeSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SubtypeSearcher.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SubtypeSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -26,20 +26,32 @@
import org.jboss.aop.JoinPointInfo;
/**
+ * When requested to perform a search on a class node, this searcher performs a
+ * search on the requested class node and on all of its subtypes.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
*/
-public class SubtypeSearcher implements ClassNodeSearcher
+class SubtypeSearcher implements Searcher<ClassNode>
{
- ClassNodeSearcher internalSearcher;
+ Searcher<ClassNode> internalSearcher;
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.Searcher#search(java.lang.Object, java.util.Collection)
+ /**
+ * Creates a subtype searcher that applies a search on all the subtypes of a
+ * {@code ClassNode}.
+ *
+ * @param searcher performs the search that will be applied to the subtypes of
+ * a {@code ClassNode}.
*/
+ public SubtypeSearcher(Searcher<ClassNode> searcher)
+ {
+ this.internalSearcher = searcher;
+ }
+
public void search(ClassNode node, Collection<JoinPointInfo> searchResult)
{
for (ClassNode classNode: node.getDirectSubtypes())
{
+ this.search(classNode, searchResult);
internalSearcher.search(classNode, searchResult);
}
}
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeFilter.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeRestriction.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeFilter.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeFilter.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,185 @@
+/*
+ * 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.joinpoint.graph;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.pointcut.Typedef;
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTConstructor;
+import org.jboss.aop.pointcut.ast.ASTField;
+import org.jboss.aop.pointcut.ast.ASTMethod;
+import org.jboss.aop.pointcut.ast.SimpleNode;
+
+/**
+ * A filter for types.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+interface TypeFilter {
+
+ /**
+ * Tests whether or not {@code type} is accepted or rejected by this filter.
+ *
+ * @param type the type to be tested
+ * @return {@code true} if this filter accepts {@code type}
+ */
+ public boolean accept(Class type, Advisor advisor);
+}
+
+
+/**
+ * Checks if a type is accepted by one of two filters.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class DisjunctiveTypeFilter implements TypeFilter
+{
+ private TypeFilter typeRestriction1;
+ private TypeFilter typeRestriction2;
+
+ /**
+ * Creates a disjunctive filter that will apply the restrictions represented by
+ * both {@code filter1} or {@code filter2}.
+ * Always pick as filter1 the most likely one to suceed for acception.
+ */
+ public DisjunctiveTypeFilter(TypeFilter typeRestriction1,
+ TypeFilter typeRestriction2)
+ {
+ this.typeRestriction1 = typeRestriction1;
+ this.typeRestriction2 = typeRestriction2;
+ }
+
+ public boolean accept(Class target, Advisor advisor)
+ {
+ return typeRestriction1.accept(target, advisor) ||
+ typeRestriction2.accept(target, advisor);
+ }
+}
+
+
+/**
+ * Checks if a type is not accepted by a {@code TypeFilter}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class NegativeTypeFilter implements TypeFilter
+{
+ private TypeFilter typeFilter;
+
+ /**
+ * Creates a type filter that will accept only the type that are not accepted by
+ * {@code typeFilter}.
+ *
+ * @param typeFilter represents a type restriction that must be negated
+ */
+ public NegativeTypeFilter(TypeFilter typeFilter)
+ {
+ this.typeFilter = typeFilter;
+ }
+
+ public boolean accept(Class type, Advisor advisor)
+ {
+ return !typeFilter.accept(type, advisor);
+ }
+}
+
+/**
+ * Checks if a type contain a specific behavior.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class HasBehaviorFilter implements TypeFilter {
+
+ private SimpleNode astBehavior;
+
+ /**
+ * Creates a filter that accepts a type only if it contains a behavior that
+ * matches {@code astBehavior}.
+ *
+ * @param astBehavior a behavior parsed expression
+ */
+ public HasBehaviorFilter(SimpleNode astBehavior)
+ {
+ this.astBehavior = astBehavior;
+ }
+
+ public boolean accept(Class target, Advisor advisor)
+ {
+ if (astBehavior instanceof ASTConstructor)
+ {
+ return Util.has(target, (ASTConstructor) astBehavior, advisor);
+ }
+ return Util.has(target, (ASTMethod) astBehavior, advisor);
+ }
+}
+
+
+/**
+ * Checks if a type contain a specific field.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class HasFieldFilter implements TypeFilter
+{
+ private ASTField astField;
+
+ /**
+ * Creates a filter that accepts a type only if it contains a filter that matches
+ * {@code astFilter}.
+ *
+ * @param astFilter a field parsed expression
+ */
+ public HasFieldFilter(ASTField astField)
+ {
+ this.astField = astField;
+ }
+
+ public boolean accept(Class target, Advisor advisor)
+ {
+ return Util.has(target, astField, advisor);
+ }
+}
+
+/**
+ * Checks if a type matches a typedef.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class TypedefFilter implements TypeFilter
+{
+ private Typedef typedef;
+
+ /**
+ * Creates a filter that accepts only the types that match {@code typedef}.
+ *
+ * @param typedef a typedef expression.
+ */
+ public TypedefFilter(Typedef typedef)
+ {
+ this.typedef = typedef;
+ }
+
+ public boolean accept(Class target, Advisor advisor)
+ {
+ return typedef.matches(advisor, target);
+ }
+}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypeRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,61 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-
-interface TypeRestriction {
-
- public boolean satisfies(Class target, Advisor advisor);
-}
-
-class NegativeTypeRestriction implements TypeRestriction
-{
- private TypeRestriction typeRestriction;
- public NegativeTypeRestriction(TypeRestriction typeRestriction)
- {
- this.typeRestriction = typeRestriction;
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- return !typeRestriction.satisfies(target, advisor);
- }
-}
-
-class DisjunctiveTypeRestriction implements TypeRestriction
-{
- private TypeRestriction typeRestriction1;
- private TypeRestriction typeRestriction2;
- public DisjunctiveTypeRestriction(TypeRestriction typeRestriction1,
- TypeRestriction typeRestriction2)
- {
- this.typeRestriction1 = typeRestriction1;
- this.typeRestriction2 = typeRestriction2;
- }
-
- public boolean satisfies(Class target, Advisor advisor)
- {
- return typeRestriction1.satisfies(target, advisor) ||
- typeRestriction2.satisfies(target, advisor);
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefParser.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefParser.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefParser.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -49,11 +49,14 @@
import org.jboss.aop.pointcut.ast.TypeExpressionParserVisitor;
/**
- *
+ * Parses a {@link Typedef} returning a type search expression.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
class TypedefParser implements TypeExpressionParserVisitor
{
- private static ThreadLocal<TypedefParser> INSTANCE = new ThreadLocal<TypedefParser>() {
+ private static ThreadLocal<TypedefParser> INSTANCE =
+ new ThreadLocal<TypedefParser>() {
protected synchronized TypedefParser initialValue() {
return new TypedefParser();
}
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TypedefRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,47 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.pointcut.Typedef;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-public class TypedefRestriction implements TypeRestriction
-{
- private Typedef typedef;
-
- public TypedefRestriction(Typedef typedef)
- {
- this.typedef = typedef;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.TypeRestriction#satisfies(java.lang.Class, org.jboss.aop.Advisor)
- */
- public boolean satisfies(Class target, Advisor advisor)
- {
- return typedef.matches(advisor, target);
- }
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestriction.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestriction.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestriction.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,240 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.aop.ConByConInfo;
-import org.jboss.aop.ConByMethodInfo;
-import org.jboss.aop.JoinPointInfo;
-import org.jboss.aop.MethodByConInfo;
-import org.jboss.aop.MethodByMethodInfo;
-import org.jboss.aop.pointcut.Util;
-import org.jboss.aop.pointcut.ast.ASTAttribute;
-import org.jboss.aop.pointcut.ast.ASTException;
-
-
-abstract class WithinRestriction
-{
- String searchExpression;
-
- public WithinRestriction(String searchExpression)
- {
- this.searchExpression = searchExpression;
- }
-
- abstract void search(BehaviourNode node, Collection<JoinPointInfo> searchResult);
-}
-
-class OptimizedWithinRestriction extends WithinRestriction
-{
- public OptimizedWithinRestriction(String searchExpression)
- {
- super(searchExpression);
- }
-
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
- {
- node.searchCallers(searchExpression, searchResult);
- }
-}
-
-abstract class NonOptimizedWithinRestriction extends WithinRestriction
-{
- private static ThreadLocal<Collection<JoinPointInfo>> TEMP = new ThreadLocal<Collection<JoinPointInfo>>()
- {
- protected synchronized Collection<JoinPointInfo> initialValue()
- {
- return new ArrayList<JoinPointInfo>(2);
- }
- };
-
- public NonOptimizedWithinRestriction(String searchExpression)
- {
- super(searchExpression);
- }
-
- public void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
- {
- Collection<JoinPointInfo> temp = TEMP.get();
- node.searchCallers(searchExpression, temp);
- for (JoinPointInfo joinPointInfo: temp)
- {
- if (joinPointInfo instanceof ConByConInfo)
- {
- if (this.accept(((ConByConInfo) joinPointInfo).getCallingConstructor()))
- {
- searchResult.add(joinPointInfo);
- }
- }
- else if (joinPointInfo instanceof ConByMethodInfo)
- {
- if (this.accept(((ConByMethodInfo) joinPointInfo).getCallingMethod()))
- {
- searchResult.add(joinPointInfo);
- }
- }
- if (joinPointInfo instanceof MethodByConInfo)
- {
- if (this.accept(((MethodByConInfo) joinPointInfo).getCallingConstructor()))
- {
- searchResult.add(joinPointInfo);
- }
- }
- else if (joinPointInfo instanceof MethodByMethodInfo)
- {
- if (this.accept(((MethodByMethodInfo) joinPointInfo).getCallingMethod()))
- {
- searchResult.add(joinPointInfo);
- }
- }
- }
- temp.clear();
- }
-
- protected abstract boolean accept(Method method);
- protected abstract boolean accept(Constructor constructor);
-
-}
-
-class AttExcWithinRestriction extends NonOptimizedWithinRestriction
-{
- private Collection<ASTAttribute> attributes;
- private Collection<ASTException> exceptions;
- public AttExcWithinRestriction(String searchExpression, Collection<ASTAttribute> attributes, Collection<ASTException> exceptions)
- {
- super(searchExpression);
- this.attributes = attributes;
- this.exceptions = exceptions;
- }
-
- protected boolean accept(Method method)
- {
- return Util.matchModifiers(attributes, method.getModifiers()) &&
- Util.matchExceptions(exceptions, method.getExceptionTypes());
- }
-
- protected boolean accept(Constructor constructor)
- {
- return Util.matchModifiers(attributes, constructor.getModifiers()) &&
- Util.matchExceptions(exceptions, constructor.getExceptionTypes());
- }
-}
-
-class FilteredWithinRestriction extends NonOptimizedWithinRestriction
-{
- private BehaviourFilter behaviourFilter;
-
- public FilteredWithinRestriction(String searchExpression, BehaviourFilter filter)
- {
- super(searchExpression);
- this.behaviourFilter = filter;
- }
-
- protected boolean accept(Method method)
- {
- return behaviourFilter.accept(method);
- }
-
- protected boolean accept(Constructor constructor)
- {
- return behaviourFilter.accept(constructor);
- }
-}
-
-class AttExcFilteredWithinRestriction extends NonOptimizedWithinRestriction
-{
- private Collection<ASTAttribute> attributes;
- private Collection<ASTException> exceptions;
- private BehaviourFilter behaviourFilter;
-
- public AttExcFilteredWithinRestriction(String searchExpression,
- Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
- BehaviourFilter behaviourFilter)
- {
- super(searchExpression);
- this.attributes = attributes;
- this.exceptions = exceptions;
- this.behaviourFilter = behaviourFilter;
- }
-
- protected boolean accept(Method method)
- {
- return Util.matchModifiers(attributes, method.getModifiers()) &&
- Util.matchExceptions(exceptions, method.getExceptionTypes()) &&
- behaviourFilter.accept(method);
- }
-
- protected boolean accept(Constructor constructor)
- {
- return Util.matchModifiers(attributes, constructor.getModifiers()) &&
- Util.matchExceptions(exceptions, constructor.getExceptionTypes()) &&
- behaviourFilter.accept(constructor);
- }
-}
-
-class NegativeWithinRestriction extends WithinRestriction
-{
- private WithinRestriction withinRestriction;
-
- public NegativeWithinRestriction(WithinRestriction withinRestriction)
- {
- super(null);
- this.withinRestriction = withinRestriction;
- }
-
- void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
- {
- Set<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
- node.searchCallers("*", temp);
- Collection<JoinPointInfo> toRemove = new ArrayList<JoinPointInfo>();
- withinRestriction.search(node, toRemove);
- temp.removeAll(toRemove);
- searchResult.addAll(temp);
- }
-}
-
-class DisjunctiveWithinRestriction extends WithinRestriction
-{
- private WithinRestriction withinRestriction1;
- private WithinRestriction withinRestriction2;
-
- public DisjunctiveWithinRestriction(WithinRestriction withinRestriction1, WithinRestriction withinRestriction2)
- {
- super(null);
- this.withinRestriction1 = withinRestriction1;
- this.withinRestriction2 = withinRestriction2;
- }
-
- void search(BehaviourNode node, Collection<JoinPointInfo> searchResult)
- {
- Set<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
- withinRestriction1.search(node, temp);
- withinRestriction2.search(node, temp);
- searchResult.addAll(temp);
- }
-}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestrictionFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestrictionFactory.java 2008-03-12 01:28:31 UTC (rev 70754)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestrictionFactory.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -1,68 +0,0 @@
-/*
- * 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.joinpoint.graph;
-
-import java.util.Collection;
-
-import org.jboss.aop.pointcut.ast.ASTAttribute;
-import org.jboss.aop.pointcut.ast.ASTException;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-class WithinRestrictionFactory
-{
-
- public static WithinRestriction create(String withinExpression)
- {
- return new OptimizedWithinRestriction(withinExpression);
- }
-
- public static WithinRestriction create(String withinExpression,
- Collection<ASTAttribute> attributes, Collection<ASTException> exceptions)
- {
- if (attributes.isEmpty() && exceptions.isEmpty())
- {
- return new OptimizedWithinRestriction(withinExpression);
- }
- else
- {
- return new AttExcWithinRestriction(withinExpression, attributes, exceptions);
- }
- }
-
- public static WithinRestriction create(String withinExpression,
- Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
- BehaviourFilter behaviourFilter)
- {
- if (attributes.isEmpty() && exceptions.isEmpty())
- {
- return new FilteredWithinRestriction(withinExpression, behaviourFilter);
- }
- else
- {
- return new AttExcFilteredWithinRestriction(withinExpression, attributes,
- exceptions, behaviourFilter);
- }
- }
-}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcher.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestriction.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcher.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcher.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,292 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.aop.ConByConInfo;
+import org.jboss.aop.ConByMethodInfo;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTAttribute;
+import org.jboss.aop.pointcut.ast.ASTException;
+
+/**
+ * Searcher for call joinpoints whose context matches a within expression.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class WithinSearcher implements Searcher<BehaviorNode>
+{
+ String withinExpression;
+
+ /**
+ * Creates a searcher that searches for all calls whose context match
+ * {@code withinExpression}.
+ *
+ * @param withinExpression search expression to be used on a search for callers.
+ */
+ public WithinSearcher(String withinExpression)
+ {
+ this.withinExpression = withinExpression;
+ }
+}
+
+/**
+ * Searcher that does not apply any extra check to the caller of the searched call
+ * joinpoints.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class OptimizedWithinSearcher extends WithinSearcher
+{
+ public OptimizedWithinSearcher(String withinExpression)
+ {
+ super(withinExpression);
+ }
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
+ {
+ node.searchCallers(withinExpression, searchResult);
+ }
+}
+
+/**
+ * Searcher that applies an extra check on callers during search.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class NonOptimizedWithinSearcher extends WithinSearcher
+{
+ private static ThreadLocal<Collection<JoinPointInfo>> TEMP =
+ new ThreadLocal<Collection<JoinPointInfo>>()
+ {
+ protected synchronized Collection<JoinPointInfo> initialValue()
+ {
+ return new ArrayList<JoinPointInfo>(2);
+ }
+ };
+
+ public NonOptimizedWithinSearcher(String withinExpression)
+ {
+ super(withinExpression);
+ }
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
+ {
+ Collection<JoinPointInfo> temp = TEMP.get();
+ node.searchCallers(withinExpression, temp);
+ for (JoinPointInfo joinPointInfo: temp)
+ {
+ if (joinPointInfo instanceof ConByConInfo)
+ {
+ if (this.accept(((ConByConInfo) joinPointInfo).getCallingConstructor()))
+ {
+ searchResult.add(joinPointInfo);
+ }
+ }
+ else if (joinPointInfo instanceof ConByMethodInfo)
+ {
+ if (this.accept(((ConByMethodInfo) joinPointInfo).getCallingMethod()))
+ {
+ searchResult.add(joinPointInfo);
+ }
+ }
+ if (joinPointInfo instanceof MethodByConInfo)
+ {
+ if (this.accept(((MethodByConInfo) joinPointInfo).getCallingConstructor()))
+ {
+ searchResult.add(joinPointInfo);
+ }
+ }
+ else if (joinPointInfo instanceof MethodByMethodInfo)
+ {
+ if (this.accept(((MethodByMethodInfo) joinPointInfo).getCallingMethod()))
+ {
+ searchResult.add(joinPointInfo);
+ }
+ }
+ }
+ temp.clear();
+ }
+
+ protected abstract boolean accept(Method method);
+ protected abstract boolean accept(Constructor constructor);
+}
+
+
+/**
+ * Searcher that checks the attributes of a caller and the exceptions it declares to
+ * throw during search.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AttExcWithinSearcher extends NonOptimizedWithinSearcher
+{
+ private Collection<ASTAttribute> attributes;
+ private Collection<ASTException> exceptions;
+
+ public AttExcWithinSearcher(String searchExpression,
+ Collection<ASTAttribute> attributes, Collection<ASTException> exceptions)
+ {
+ super(searchExpression);
+ this.attributes = attributes;
+ this.exceptions = exceptions;
+ }
+
+ protected boolean accept(Method method)
+ {
+ return Util.matchModifiers(attributes, method.getModifiers()) &&
+ Util.matchExceptions(exceptions, method.getExceptionTypes());
+ }
+
+ protected boolean accept(Constructor constructor)
+ {
+ return Util.matchModifiers(attributes, constructor.getModifiers()) &&
+ Util.matchExceptions(exceptions, constructor.getExceptionTypes());
+ }
+}
+
+/**
+ * Searcher that applies a {@link BehaviorFilter} to a caller during search.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class FilteredWithinRestriction extends NonOptimizedWithinSearcher
+{
+ private BehaviorFilter behaviourFilter;
+
+ public FilteredWithinRestriction(String searchExpression, BehaviorFilter filter)
+ {
+ super(searchExpression);
+ this.behaviourFilter = filter;
+ }
+
+ protected boolean accept(Method method)
+ {
+ return behaviourFilter.accept(method);
+ }
+
+ protected boolean accept(Constructor constructor)
+ {
+ return behaviourFilter.accept(constructor);
+ }
+}
+
+/**
+ * Searcher that checks the attributes of a caller, the exceptions it declares,
+ * and applies a {@link BehaviorFilter} as well, during search.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class AttExcFilteredWithinRestriction extends NonOptimizedWithinSearcher
+{
+ private Collection<ASTAttribute> attributes;
+ private Collection<ASTException> exceptions;
+ private BehaviorFilter behaviourFilter;
+
+ public AttExcFilteredWithinRestriction(String searchExpression,
+ Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
+ BehaviorFilter behaviourFilter)
+ {
+ super(searchExpression);
+ this.attributes = attributes;
+ this.exceptions = exceptions;
+ this.behaviourFilter = behaviourFilter;
+ }
+
+ protected boolean accept(Method method)
+ {
+ return Util.matchModifiers(attributes, method.getModifiers()) &&
+ Util.matchExceptions(exceptions, method.getExceptionTypes()) &&
+ behaviourFilter.accept(method);
+ }
+
+ protected boolean accept(Constructor constructor)
+ {
+ return Util.matchModifiers(attributes, constructor.getModifiers()) &&
+ Util.matchExceptions(exceptions, constructor.getExceptionTypes()) &&
+ behaviourFilter.accept(constructor);
+ }
+}
+
+/**
+ * Searcher that selects all the call joinpoints whose context does not matche a
+ * within expression.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class NegativeWithinSearcher extends WithinSearcher
+{
+ private WithinSearcher withinRestriction;
+
+ public NegativeWithinSearcher(WithinSearcher withinRestriction)
+ {
+ super(null);
+ this.withinRestriction = withinRestriction;
+ }
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
+ {
+ Set<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
+ node.searchCallers("*", temp);
+ Collection<JoinPointInfo> toRemove = new ArrayList<JoinPointInfo>();
+ withinRestriction.search(node, toRemove);
+ temp.removeAll(toRemove);
+ searchResult.addAll(temp);
+ }
+}
+
+/**
+ * Searcher that selectes all the call joinpoints whose context match one of two
+ * within expressions.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class DisjunctiveWithinSearcher extends WithinSearcher
+{
+ private WithinSearcher withinSearcher1;
+ private WithinSearcher withinSearcher2;
+
+ public DisjunctiveWithinSearcher(WithinSearcher withinRestriction1,
+ WithinSearcher withinRestriction2)
+ {
+ super(null);
+ this.withinSearcher1 = withinRestriction1;
+ this.withinSearcher2 = withinRestriction2;
+ }
+
+ public void search(BehaviorNode node, Collection<JoinPointInfo> searchResult)
+ {
+ Set<JoinPointInfo> temp = new HashSet<JoinPointInfo>();
+ withinSearcher1.search(node, temp);
+ withinSearcher2.search(node, temp);
+ searchResult.addAll(temp);
+ }
+}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcherFactory.java (from rev 70750, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinRestrictionFactory.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcherFactory.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/WithinSearcherFactory.java 2008-03-12 02:30:36 UTC (rev 70755)
@@ -0,0 +1,110 @@
+/*
+ * 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.joinpoint.graph;
+
+import java.util.Collection;
+
+import org.jboss.aop.pointcut.ast.ASTAttribute;
+import org.jboss.aop.pointcut.ast.ASTException;
+
+/**
+ * Creates {@link WithinSearcher} instances accordingly to within expressions.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class WithinSearcherFactory
+{
+ /**
+ * Creates a {@code WithinSearcher} that searches for all call joinpoints that
+ * match {@code withinExpression}.
+ *
+ * @param withinExpression the within expression
+ * @return a {@code WithinSearcher} that searches for all call
+ * joinpoints that match {@code withinExpression}
+ */
+ public static WithinSearcher create(String withinExpression)
+ {
+ return new OptimizedWithinSearcher(withinExpression);
+ }
+
+ /**
+ * Creates a {@code WithinSearcher} that searches for all call joinpoints that
+ * match {@code withinExpression}, and whose contexts satisfy the attribute and
+ * exception restrictions.
+ *
+ * @param withinExpression the within expression
+ * @param attributes a list of attribute restrictions the caller must follow.
+ * May be empty.
+ * @param exceptions a list of exceptions the caller must declare to throw.
+ * May be empty.
+ * @return a {@code WithinSearcher} that searches for all call
+ * joinpoints that match {@code withinExpression}, and
+ * whose contexts satisfy the attribute and exception
+ * restrictions
+ */
+ public static WithinSearcher create(String withinExpression,
+ Collection<ASTAttribute> attributes, Collection<ASTException> exceptions)
+ {
+ if (attributes.isEmpty() && exceptions.isEmpty())
+ {
+ return new OptimizedWithinSearcher(withinExpression);
+ }
+ else
+ {
+ return new AttExcWithinSearcher(withinExpression, attributes, exceptions);
+ }
+ }
+
+ /**
+ * Creates a {@code WithinSearcher} that searches for all call joinpoints that
+ * match {@code withinExpression}, and whose contexts satisfy the attribute and
+ * exception restrictions. Besides, the call joinpoint context must be accepted
+ * by {@code behaviorFilter}.
+ *
+ * @param withinExpression the within expression
+ * @param attributes a list of attribute restrictions the caller must follow.
+ * May be empty.
+ * @param exceptions a list of exceptions the caller must declare to throw.
+ * May be empty.
+ * @param behaviorFilter a filter that must be applied to each call joinpoint
+ * context during search
+ * @return a {@code WithinSearcher} that searches for all call
+ * joinpoints that match {@code withinExpression}, and
+ * whose contexts satisfy the attribute and exception
+ * restrictions, besides being accepted by
+ * {@code behaviorFilter}
+ */
+ public static WithinSearcher create(String withinExpression,
+ Collection<ASTAttribute> attributes, Collection<ASTException> exceptions,
+ BehaviorFilter behaviorFilter)
+ {
+ if (attributes.isEmpty() && exceptions.isEmpty())
+ {
+ return new FilteredWithinRestriction(withinExpression, behaviorFilter);
+ }
+ else
+ {
+ return new AttExcFilteredWithinRestriction(withinExpression, attributes,
+ exceptions, behaviorFilter);
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list