aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/IntroOnIntro.java
blob: ca8d0a96beb61426870858ea915aab740bd329c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import org.aspectj.testing.*;

public class IntroOnIntro {
  public static void main(String[] args) {
    Class1 c1 = new Class1();

    try {
      c1.getName();
    } catch (NoSuchMethodError nsme) {
      Tester.check(false, "getName was not found in Class1");
    }

    try {
      c1.m = "potato";
    } catch (NoSuchFieldError nsfe) {
      Tester.check(false, "m was not introduced into Class1");
    }
  }
}

class Class1 {
  String name = "";  //public String getName() { return name; }
}

aspect Aspect1 /**of eachobject (instanceof(Class1))*/ {
    public String Class1.getName() { return this.name; } 
  
  void f() {}
  before(): call(* getName(..)) && this(Class1) {
    f();
  }  
}

aspect AComposer /**of eachobject(instanceof(Class1 || Aspect1))*/ {
	interface HasManager {}
    private String HasManager.my_manager;
    String HasManager.m;
    public void HasManager.setManager(String manager) { 
      this.my_manager = manager; 
    }
    declare parents: Class1 || Aspect1 implements HasManager;
  
  before(Aspect1 a1): call(void f()) && this(a1) {
    
    try {
      a1.setManager("potato");
    } catch (NoSuchMethodError nsme) {
      Tester.check(false, "getName not found in Aspect1");
    }
    
    try {
      a1.m = "potato";
    } catch (NoSuchFieldError nsfe) {
      Tester.check(false, "m was not introduced into Class1");
    }    
  }
}