private BcelWorld world;
private AnnotationTypePattern fooTP,simpleAnnotationTP;
+ private static boolean is13VMOrGreater = true;
+ private static boolean is14VMOrGreater = true;
+ private static boolean is15VMOrGreater = false;
+
+ static {
+ String vm = System.getProperty("java.vm.version");
+ if (vm.startsWith("1.3")) {
+ is14VMOrGreater = false;
+ } else if (vm.startsWith("1.5")) {
+ is15VMOrGreater = true;
+ }
+ }
+
private ResolvedTypeX loadType(String name) {
if (world == null) {
world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar");
public void testAnnotationPatternMatchingOnTypes() {
-
+ if (is15VMOrGreater) {
ResolvedTypeX rtx = loadType("AnnotatedClass");
initAnnotationTypePatterns();
fooTP.matches(rtx).alwaysFalse());
assertTrue("@SimpleAnnotation should match on the AnnotatedClass",
simpleAnnotationTP.matches(rtx).alwaysTrue());
+ }
}
}
public void testAnnotationPatternMatchingOnMethods() {
-
+ if (is15VMOrGreater) {
ResolvedTypeX rtx = loadType("AnnotatedClass");
ResolvedMember aMethod = rtx.getDeclaredMethods()[1];
fooTP.matches(aMethod).alwaysFalse());
assertTrue("@SimpleAnnotation should match on the AnnotatedClass.m1() method",
simpleAnnotationTP.matches(aMethod).alwaysTrue());
-
+ }
}
public void testAnnotationPatternMatchingOnFields() {
-
+ if (is15VMOrGreater) {
ResolvedTypeX rtx = loadType("AnnotatedClass");
ResolvedMember aField = rtx.getDeclaredFields()[0];
fooTP.matches(aField).alwaysFalse());
assertTrue("@SimpleAnnotation should match on the AnnotatedClass.i field",
simpleAnnotationTP.matches(aField).alwaysTrue());
+ }
}
import junit.framework.TestCase;
public class AnnotationPatternTestCase extends TestCase {
-
+
+ private static boolean is13VMOrGreater = true;
+ private static boolean is14VMOrGreater = true;
+ private static boolean is15VMOrGreater = false;
+
+ static {
+ String vm = System.getProperty("java.vm.version");
+ if (vm.startsWith("1.3")) {
+ is14VMOrGreater = false;
+ } else if (vm.startsWith("1.5")) {
+ is15VMOrGreater = true;
+ }
+ }
+
public void testParseSimpleAnnotationPattern() {
PatternParser p = new PatternParser("@Foo");
AnnotationTypePattern foo = p.maybeParseAnnotationPattern();
}
public void testExactAnnotationPatternMatching() {
+ if (is15VMOrGreater) {
PatternParser p = new PatternParser("@Foo");
AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);
assertTrue("matches element with Foo",ap.matches(ae).alwaysTrue());
AnnotatedElementImpl ae2 = new AnnotatedElementImpl(new String[]{"Boo"});
assertTrue("does not match element with Boo",ap.matches(ae2).alwaysFalse());
+ }
}
public void testBindingAnnotationPatternMatching() {
+ if (is15VMOrGreater) {
PatternParser p = new PatternParser("foo");
AnnotationTypePattern ap = p.parseAnnotationNameOrVarTypePattern();
try {
// assertTrue("matches element with Foo",ap.matches(ae).alwaysTrue());
// AnnotatedElementImpl ae2 = new AnnotatedElementImpl(new String[]{"Boo"});
// assertTrue("does not match element with Boo",ap.matches(ae2).alwaysFalse());
+ }
}
public void testAndAnnotationPatternMatching() {
+ if (is15VMOrGreater) {
PatternParser p = new PatternParser("@Foo @Boo");
AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);
ae = new AnnotatedElementImpl(new String[] {"Boo"});
assertTrue("does not match boo",ap.matches(ae).alwaysFalse());
ae = new AnnotatedElementImpl(new String[] {"Goo"});
- assertTrue("does not match goo",ap.matches(ae).alwaysFalse());
+ assertTrue("does not match goo",ap.matches(ae).alwaysFalse());
+ }
}
//
// public void testOrAnnotationPatternMatching() {
// }
//
public void testNotAnnotationPatternMatching() {
+ if (is15VMOrGreater) {
PatternParser p = new PatternParser("!@Foo");
AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);
AnnotatedElementImpl ae = new AnnotatedElementImpl(new String[] {"Foo","Boo"});
assertTrue("does not match foo and boo",ap.matches(ae).alwaysFalse());
ae = new AnnotatedElementImpl(new String[] {"Boo"});
- assertTrue("matches boo",ap.matches(ae).alwaysTrue());
+ assertTrue("matches boo",ap.matches(ae).alwaysTrue());
+ }
}
public void testAnyAnnotationPatternMatching() {