Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Question about precedence between boolean operators


Hi, all.

I was wondering how ajc handles the precedence order of boolean operators in pointcut expressions. Do "AND" (&&) and "OR" (||) operators have the same precedence? In the example below, extracted from Laddad's AspectJ in Action book, the original _expression_ compiles with no errors, while the modified version results in "multiple bindings" errors (the full aspect code is attached). That means "AND" and "OR" have the same precedence, right?

Original pointcut _expression_:

    pointcut accountActivity(Account account, float amount)    :
   ( (execution(void Account.credit(float)) || execution(void Account.debit(float))) && this(account) && args(amount) )
   ||
   ( execution(void CheckClearanceSystem.*(Account, float)) && args(account, amount) );


Modified pointcut _expression_:

  pointcut accountActivity (Account account, float amount) :
   (execution(void Account.credit(float)) || execution(void Account.debit(float))) && this(account) && args(amount)
   ||
   execution(void CheckClearanceSystem.*(Account, float)) && args(account, amount);


Cheers,

  Fabiano Ferrari.
//Listing 12.14 An aspect that logs account activities

package banking;

import logging.*;

public aspect LogAccountActivities extends IndentedLogging {

	declare precedence : LogAccountActivities, *;

	pointcut accountActivity(Account account, float amount)	: 
		( (execution(void Account.credit(float))
		  || execution(void Account.debit(float))
		  )
		  && this(account)
		  && args(amount))
		|| (execution(void CheckClearanceSystem.*(Account, float))
		  && args(account, amount));

	protected pointcut loggedOperations() : accountActivity(Account, float);

	void around(Account account, float amount) : accountActivity(account, amount) {
		try {
			System.out.println("[" +
				thisJoinPointStaticPart.getSignature().toShortString()
				+ "] " + account + " " + amount);
			System.out.println("Before: " + account.getBalance());
			proceed(account, amount);
		} finally {
			System.out.println("After: " + account.getBalance());
		}
	}
}

Back to the top