Announcement Announcement Module
Collapse
No announcement yet.
is this ok? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • is this ok?

    Shouldn't this pass?

    Code:
    public class PointcutTest extends TestCase {
    	
    	public void testPointcut() throws Exception {
    		AspectJExpressionPointcut p = new AspectJExpressionPointcut();
    		p.setExpression("execution(* *.service.*(..))");
    		assertFalse(p.matches(java.lang.Long.class));
    	}
    
    }

  • #2
    I'm forced to use this construction. Is this the intended behavior or it is a bug?

    Code:
    	
    	public void testPointcutWithWithin() throws Exception {
    		AspectJExpressionPointcut p = new AspectJExpressionPointcut();
    		p.setExpression("within(com.xyz..AccountService) && execution(* com.xyz..AccountService.*(..))");
    		assertFalse(p.matches(java.lang.Long.class));
    	}

    Comment


    • #3
      First of all your first pointcut is wrong.

      Code:
      execution(* *.service.*(..))
      The wildcard in AspectJ expression language is '..' not a '*' the '*' is for 1 level the otherone is for 0 or more levels. Next to that you specify an execution pointcut but aren't trying to execute anything. Also your pointcut is off on that because you either aren't defining a method to call or aren't defining a class to intercept.

      Code:
      execution(* *..service.*.*(..))
      Is the actuall expression to use.

      Next to that you should check if a method call would match the pointcut.

      Code:
      public void testPointcut() throws Exception {
      	AspectJExpressionPointcut p = new AspectJExpressionPointcut();
      	p.setExpression("execution(* *..service.*.*(..))");
      	Method m = ClassUtils.getMethodIfAvailable(Long.class, "valueOf", new Class[] {String.class});
      	assertFalse(p.matches(m, java.lang.Long.class, new Object[] {"12"}));
      }
      However one question I have is WHY are you doing this?!
      Last edited by Marten Deinum; Mar 7th, 2008, 07:16 AM. Reason: Copy/Paste error.

      Comment


      • #4
        Thank you for the response. Please excuse me for the first post. It was a copy/paste error. The second one contains the correct AspectJ expression.
        The reason for doing this is a sequence of code in AopUtils.canApply(..) method
        Code:
        if (!pc.getClassFilter().matches(targetClass)) {
        			return false;
        }
        I was in debug and expected that this returned false but it didn't. I thought that this is the normal execution path because the expression includes a pattern for matching the actual class. When using within(...) expression the code works. Can you please explain what is the purpose of this? Thank you.

        Comment


        • #5
          You are comparing apples and oranges here. The matches here is the matches of the ClassFilter NOT the matches of the Pointcut!

          Hmm not entirely true I check the implementation you use and getClassFilter() returns this so p.matches and p.getClassFilter().matches do the same....

          Comment


          • #6
            I don't think I understand when this sequence returns false. The AspectJPointcut.getClassFilter() returns this as the class filter. My test result is the same when using p.getClassFilter(). Maybe I didn't understand correctly what is the purpose of the ClassFilter? Thank you.

            Comment

            Working...
            X