aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs163/pr128664/Bug.java
blob: 92eb248e5afeebfb7356dbd291ca709d2e58c5ee (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
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class Bug {
	public static void main(String[] args) {		
        MonitorMyAnnotationExecution.aspectOf().executionCount = 0;
        new ClassImplementingInterfaceWithInheritedAnnotation();
        if (MonitorMyAnnotationExecution.aspectOf().executionCount!=1) {
        	throw new RuntimeException();
        }

        MonitorMyAnnotationExecution.aspectOf().executionCount = 0;
        new ClassExtendingClassWithInheritedAnnotation();
	// Expecting 2, one for derived and one for base class ctor execution
	if (MonitorMyAnnotationExecution.aspectOf().executionCount!=2) {
		throw new RuntimeException();
	}
    }
}

@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface InheritedAnnotation { }

@InheritedAnnotation
interface InterfaceWithInheritedAnnotation { }

@InheritedAnnotation class ClassWithInheritedAnnotation { }

class ClassImplementingInterfaceWithInheritedAnnotation implements InterfaceWithInheritedAnnotation { }

class ClassExtendingClassWithInheritedAnnotation extends ClassWithInheritedAnnotation { }

aspect MonitorMyAnnotationExecution {
        int executionCount;

        before() : execution((@InheritedAnnotation *)+.new(..)) && !within(Monitor*) && !within(Bug) {
                executionCount++;
        }
}