1
import java.lang.annotation.*;
3
@Retention(RetentionPolicy.RUNTIME)
4
@interface Colored { String color();}
6
public class WithinCodeBinding1 {
8
@Colored(color="red") void mRed() {System.out.println("red"); }
10
@Colored(color="blue") void mBlue() {System.out.println("blue");}
12
@Colored(color="green") void mGreen() {System.out.println("green");}
14
@Colored(color="yellow") WithinCodeBinding1() {
15
System.out.println("yellow");
18
public static void main(String[]argv) {
19
WithinCodeBinding1 instance = new WithinCodeBinding1();
29
// Expected color order
30
static String exp[] = new String[]{"yellow","red","blue","green"};
32
static int i = 0; // Count of advice executions
34
before(Colored c): @withincode(c) && call(* println(..)) {
35
System.err.println(thisJoinPoint+" color="+c.color());
36
if (!c.color().equals(exp[i])) throw new RuntimeException("not "+exp[i]+"? "+c.color());
40
public static void verifyRun() {
41
if (X.i != exp.length)
42
throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);