~ubuntu-branches/ubuntu/natty/aspectj/natty

« back to all changes in this revision

Viewing changes to org.aspectj/modules/tests/java5/annotations/binding/WithinCodeBinding1.aj

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-10-04 16:37:23 UTC
  • mfrom: (1.1.3 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091004163723-ck4y7j7fhjxskkie
Tags: 1.6.6+dfsg-1
* New upstream release.
  - Update 02_use_gjdoc.diff patch
* Update my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import java.lang.annotation.*;
2
 
 
3
 
@Retention(RetentionPolicy.RUNTIME)
4
 
@interface Colored { String color();}
5
 
 
6
 
public class WithinCodeBinding1 {
7
 
 
8
 
  @Colored(color="red") void mRed() {System.out.println("red"); }
9
 
 
10
 
  @Colored(color="blue") void mBlue() {System.out.println("blue");}
11
 
 
12
 
  @Colored(color="green") void mGreen() {System.out.println("green");}
13
 
 
14
 
  @Colored(color="yellow") WithinCodeBinding1() {
15
 
        System.out.println("yellow");
16
 
  }
17
 
 
18
 
  public static void main(String[]argv) {
19
 
    WithinCodeBinding1 instance = new WithinCodeBinding1();
20
 
    instance.mRed();
21
 
    instance.mBlue();
22
 
    instance.mGreen();
23
 
    X.verifyRun();
24
 
  }
25
 
}
26
 
 
27
 
aspect X {
28
 
 
29
 
    // Expected color order
30
 
    static String exp[] = new String[]{"yellow","red","blue","green"};
31
 
    
32
 
    static int i = 0; // Count of advice executions
33
 
    
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());
37
 
        i++;
38
 
    }
39
 
    
40
 
    public static void verifyRun() {
41
 
        if (X.i != exp.length)
42
 
                throw new RuntimeException("Expected "+exp.length+" advice runs but did "+X.i);
43
 
    }
44
 
}