Sergej Chodarev
Sergej Chodarev
public class Factorial {
public long factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n – 1);
}
}
pointcut factorial(int n)
: call(long Factorial.factorial(int)) && args(n);
before(int n)
: factorial(n) && !cflowbelow(factorial(int)) {
System.out.println("Calculating factorial for " + n);
}
public aspect NoIOAspect {
Object around() :
call(* java.io..*(..)) &&
cflow(execution(@NoIO * *(..))) {
return null;
}
}
this(Typ) && !within(Typ)
public aspect PrintRecAspect {
pointcut printTest() : call(* println(..));
before() : printTest() {
System.out.println("In Advice ...");
}
}
public aspect PrintRecAspect {
pointcut printTest() : call(* println(..))
&& !within(PrintRecAspect);
before() : printTest() {
System.out.println("In Advice ...");
}
}
public aspect PrintRecAspect {
pointcut printTest() : call(* println(..))
&& !cflow(adviceexecution());
before() : printTest() {
System.out.println("In Advice ...");
}
}
@Aspect
public class LoggingAspect {
private Logger logger;
public LoggingAspect() { logger = new Logger(); }
@Pointcut(
"execution(* Product.setPrice(..)) &&" +
"this(product) && args(price)")
public void priceChange(Product product, BigDecimal price) {
}
@Before("priceChange(product, price)")
public void log(Product product, BigDecimal price) {
logger.writeLog("Changed " + product.getPrice() +
" to " + price);
}
}
public String Customer.name;
public interface Nameable {
public void setName(String name);
public String getName();
static aspect Impl {
private String Nameable.name;
public void Nameable.setName(String name) {
this.name = name;
}
public String Nameable.getName() {
return this.name;
}
}
}
public interface NameableMixin extends Nameable {
static aspect Impl {
private String NameableMixin.name;
... implementácia
}
}
aspect «NázovAspektu» issingleton() { … }
perthis(«bodový prierez»)
pertarget(«bodový prierez»)
percflow(«bodový prierez»)
percflowbelow(«bodový prierez»)
pertypewithin(«vzor typov»)
aspectOf()
hasAspect()
Aspects
@EnableAspectJAutoProxy
<aop:aspectj-autoproxy/>
@Configurable
@EnableSpringConfigured
<context:spring-configured/>
public abstract aspect AbstractTracing {
public abstract pointcut traced();
public abstract Logger getLogger();
before() : traced() {
getLogger().log(Level.INFO, "Before: " + thisJoinPoint);
}
}
public aspect BankingTracing extends AbstractTracing {
public pointcut traced() : execution(* banking..*.*(..));
public Logger getLogger() {
return Logger.getLogger("banking");
}
}
K. Ostermann, P. Giarrusso, C. Kästner, and T. Rendel, “Revisiting Information Hiding: Reflections on Classical and Nonclassical Modularity,” in ECOOP 2011, doi: 10.1007/978-3-642-22655-7_8
Ďalší zaujímavý článok F. Steimann, “The Paradoxical Success of Aspect-oriented Programming,” OOPSLA '06, doi: 10.1145/1167473.1167514