aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs152/pr136026/CflowOrderOriginal.java
blob: bd3dea68f9a473c6f8dd21c7084da69208de29fa (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package bugs;

import java.io.PrintStream;
import java.lang.annotation.*;

import org.aspectj.lang.JoinPoint;

public class CflowOrderOriginal {

    public static void main(String[] args) {
        Log.print("Starting CflowOrder.main(..)");
        A.main(null);
        Log.print("Ending CflowOrder.main(..)");
    }

    @Retention(value = RetentionPolicy.RUNTIME)
    @interface Annotation {
        String value();
    }

    static class A {
        @Annotation("A.foo")
        void foo() {
            new B().foo();
            Log.print("A.foo()");
        }

        public static void main(String[] args) {
            new A().foo();
            Log.print("A.main(..)");
        }
    }

    static class B {
        @Annotation("B.foo")
        void foo() {
            Log.print("B.foo()");
        }
    }

    static class Log implements IAspect {
        static final PrintStream out = System.err;

        static void print(String label) {
            out.println(label);
        }

        static void print(String label, JoinPoint tjp, JoinPoint.StaticPart sp,
                Object a) {
            out.println(label);
//            out.println(" Join point: " + tjp);
//            out.println(" Enclosing join point: " + sp);
//            out.println(" Annotation: " + a);
        }
    }
    static aspect Logger implements IAspect {

        //declare error: execution(* *(..)) && !within(Log) : "er";

//        before() : cflow(execution(void CflowOrder.main(String[]))) 
//            && !call(* IAspect+.*(..)) && ! within(IAspect+) {
//            Log.print("cflow(..main(..))", thisJoinPoint,
//                    thisEnclosingJoinPointStaticPart, null);
//        }
    }

    interface IAspect {}
    static aspect MyAspect  implements IAspect {

        pointcut annotated(Annotation a) :
            call(@Annotation * *(..)) && @annotation(a);

        pointcut belowAnnotated() :
            cflowbelow(annotated(Annotation));
      pointcut topAnnotated(Annotation a) : annotated(a) 
            && !belowAnnotated();

      pointcut notTopAnnotated(Annotation a, Annotation aTop) : annotated(a) 
      && cflowbelow(annotated(aTop));
//        pointcut topAnnotated(Annotation a) : annotated(a) 
//            && !cflowbelow(annotated(Annotation));
//
//        pointcut notTopAnnotated(Annotation a, Annotation aTop) : annotated(a) 
//            &&  cflowbelow(topAnnotated(aTop));

        // if this first, then no nonTopAnnotated advice
        before(Annotation a) : topAnnotated(a) {
            Log.print("topAnnotated", thisJoinPoint,
                    thisEnclosingJoinPointStaticPart, a);
        }
        // if topAnnotated is first, this does not run
        before(Annotation a, Annotation aTop) : notTopAnnotated(a, aTop) {
            Log.print("nonTopAnnotated", thisJoinPoint,
                    thisEnclosingJoinPointStaticPart, a);
        }
    }
}