aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs/EnsureOverriding.java
blob: 5ac22d21d6a627cdd447f0c952e73a563158905a (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
// from Bug#:  28703  

class Base {
     /** extend when overriding - must call Base.lockResource() */
      public void lockResource(boolean dummy) { /* ... */ }
}

class Derived extends Base {
      boolean isLocked;

      public void lockResource(boolean callSuper) {
      	  if (callSuper) super.lockResource(true);
          isLocked = true;
      }
}
 
public aspect EnsureOverriding pertarget(mustExtend()) {
    boolean calledSuper = false;
    pointcut mustExtend() : 
        execution(void Base+.lockResource(..)) && !within(Base);
 
    after () returning: mustExtend() {
//        assert(calledSuper);
        if (!calledSuper) { throw new RuntimeException("need super call"); }
    }
 
    after(Base a, Base b) returning: 
            cflow(mustExtend() && target(a)) && execution(void Base.lockResource(..)) && target(b) 
    {
        if (a == b) {
                //System.err.println("made call");
            calledSuper = true;
        }
    }
 
     public static void main(String args[]) {
         (new Derived()).lockResource(true);
         try {
         	(new Derived()).lockResource(false);
         	throw new Error("shouldn't get here");
         } catch (RuntimeException re) {
         	if (!re.getMessage().equals("need super call")) throw re;
         }	
     }
}