@@ -0,0 +1,7 @@ | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
@Retention(RetentionPolicy.RUNTIME) | |||
public @interface MyAnnotation { | |||
MyEnum[] value(); | |||
} |
@@ -0,0 +1,21 @@ | |||
import java.util.Arrays; | |||
privileged public aspect MyAspect { | |||
Object around(MyClass o, MyAnnotation a) : | |||
execution(@MyAnnotation * *(..)) && | |||
target(o) && | |||
@annotation(a) { | |||
if (!isOneOf(o.getValue(), a.value())) | |||
throw new IllegalStateException( | |||
o.getValue() + | |||
" is not one of " + | |||
Arrays.toString(a.value())); | |||
return proceed(o, a); | |||
} | |||
private static final <T> boolean isOneOf(T obj, T[] arr) { | |||
for (T el : arr) if (obj == el) return true; | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
public class MyClass { | |||
public MyEnum getValue() { | |||
return MyEnum.ONE; | |||
} | |||
@MyAnnotation({ MyEnum.ONE, MyEnum.TWO }) | |||
public void test() { | |||
} | |||
public static void main(String[] args) { | |||
new MyClass().test(); | |||
} | |||
} |
@@ -0,0 +1,3 @@ | |||
public enum MyEnum { | |||
ONE, TWO, THREE, FOUR, FIVE | |||
} |
@@ -112,6 +112,11 @@ | |||
<ajc-test dir="bugs152/pr148537" title="classcast annotation value"> | |||
<compile files="MyClass.java,MyAspect.java" options="-1.5"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs152/pr148545" title="nosuchmethoderror for privileged aspect"> | |||
<compile files="MyClass.java,MyAspect.java,MyAnnotation.java,MyEnum.java" options="-1.5"/> | |||
<run class="MyClass"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs152/pr145391" title="itd calling generic method - 2"> | |||
<compile files="GenericType2.java" options="-1.5"/> |