summaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-10-03 16:17:15 +0000
committeracolyer <acolyer>2005-10-03 16:17:15 +0000
commit0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade (patch)
tree85dda17da70b10b31b422853d1323421a82b3a21 /tests/java5/ataspectj
parentc86fa6de889e521ebe8224d1a7579269c53ac357 (diff)
downloadaspectj-0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade.tar.gz
aspectj-0fae66242efd3fd91dc7ace349cdcf7e5ebc2ade.zip
completes all of the MAP bar ITDs
Diffstat (limited to 'tests/java5/ataspectj')
-rw-r--r--tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj77
-rw-r--r--tests/java5/ataspectj/annotationGen/DeclareParentsTest.aj56
-rw-r--r--tests/java5/ataspectj/annotationGen/DeclareParentsTestAdvanced.aj39
-rw-r--r--tests/java5/ataspectj/annotationGen/DeclarePrecedenceTest.aj35
-rw-r--r--tests/java5/ataspectj/annotationGen/DeclareSoftTest.aj22
5 files changed, 229 insertions, 0 deletions
diff --git a/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj b/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj
new file mode 100644
index 000000000..0c3e4608d
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj
@@ -0,0 +1,77 @@
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.*;
+import java.lang.annotation.*;
+
+public aspect DeclareAnnotationTest {
+
+ declare @type : a.b.c..* : @MyAnnotation("ady 1");
+
+ declare @method : * *(String) : @MyAnnotation("ady 2");
+
+ declare @field : java.io.Serializable+ * : @MyClassRetentionAnnotation("ady 3");
+
+ declare @constructor : new(String,..) : @MyAnnotation;
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ AjType<DeclareAnnotationTest> myType = AjTypeSystem.getAjType(DeclareAnnotationTest.class);
+ DeclareAnnotation[] decAs = myType.getDeclareAnnotations();
+ if (decAs.length != 4) throw new RuntimeException("Expecting 4 members, got " + decAs.length);
+ // should be in declaration order...
+ checkAtType(decAs[0]);
+ checkAtMethod(decAs[1]);
+ checkAtField(decAs[2]);
+ checkAtConstructor(decAs[3]);
+ }
+
+
+ private static void checkAtType(DeclareAnnotation da) {
+ if (da.getKind() != DeclareAnnotation.Kind.Type) throw new RuntimeException("expecting @type");
+ if (da.getSignaturePattern() != null) throw new RuntimeException("not expecting a signature pattern");
+ if (!da.getTypePattern().asString().equals("a.b.c..*")) throw new RuntimeException("expecting 'a.b.c..*' but got '" + da.getTypePattern().asString() + "'");
+ if (da.getDeclaringType().getJavaClass() != DeclareAnnotationTest.class) throw new RuntimeException("bad declaring type: " + da.getDeclaringType());
+ MyAnnotation ma = (MyAnnotation) da.getAnnotation();
+ if (!ma.value().equals("ady 1")) throw new RuntimeException("bad value: " + ma.value());
+ if (!da.getAnnotationAsText().equals("@MyAnnotation(\"ady 1\")")) throw new RuntimeException("bad annotation text: " + da.getAnnotationAsText());
+ }
+
+ private static void checkAtMethod(DeclareAnnotation da) {
+ if (da.getKind() != DeclareAnnotation.Kind.Method) throw new RuntimeException("expecting @method");
+ if (da.getTypePattern() != null) throw new RuntimeException("not expecting a type pattern");
+ if (!da.getSignaturePattern().asString().equals("* *(java.lang.String)")) throw new RuntimeException("expecting '* *(java.lang.String)' but got '" + da.getSignaturePattern().asString() + "'");
+ if (da.getDeclaringType().getJavaClass() != DeclareAnnotationTest.class) throw new RuntimeException("bad declaring type: " + da.getDeclaringType());
+ MyAnnotation ma = (MyAnnotation) da.getAnnotation();
+ if (!ma.value().equals("ady 2")) throw new RuntimeException("bad value: " + ma.value());
+ if (!da.getAnnotationAsText().equals("@MyAnnotation(\"ady 2\")")) throw new RuntimeException("bad annotation text: " + da.getAnnotationAsText());
+ }
+
+ private static void checkAtField(DeclareAnnotation da) {
+ if (da.getKind() != DeclareAnnotation.Kind.Field) throw new RuntimeException("expecting @field");
+ if (da.getTypePattern() != null) throw new RuntimeException("not expecting a type pattern");
+ if (!da.getSignaturePattern().asString().equals("java.io.Serializable+ *")) throw new RuntimeException("expecting 'java.io.Serializable+ *' but got '" + da.getSignaturePattern().asString() + "'");
+ if (da.getDeclaringType().getJavaClass() != DeclareAnnotationTest.class) throw new RuntimeException("bad declaring type: " + da.getDeclaringType());
+ if (da.getAnnotation() != null) throw new RuntimeException("expecting null annotation, but got " + da.getAnnotation());
+ if (!da.getAnnotationAsText().equals("@MyClassRetentionAnnotation(\"ady 3\")")) throw new RuntimeException("bad annotation text: " + da.getAnnotationAsText());
+ }
+
+ private static void checkAtConstructor(DeclareAnnotation da) {
+ if (da.getKind() != DeclareAnnotation.Kind.Constructor) throw new RuntimeException("expecting @constructor");
+ if (da.getTypePattern() != null) throw new RuntimeException("not expecting a type pattern");
+ if (!da.getSignaturePattern().asString().equals("new(java.lang.String, ..)")) throw new RuntimeException("expecting 'new(java.lang.String,..)' but got '" + da.getSignaturePattern().asString() + "'");
+ if (da.getDeclaringType().getJavaClass() != DeclareAnnotationTest.class) throw new RuntimeException("bad declaring type: " + da.getDeclaringType());
+ MyAnnotation ma = (MyAnnotation) da.getAnnotation();
+ if (!ma.value().equals("some value")) throw new RuntimeException("bad value: " + ma.value());
+ if (!da.getAnnotationAsText().equals("@MyAnnotation")) throw new RuntimeException("bad annotation text: " + da.getAnnotationAsText());
+ }
+
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface MyAnnotation {
+
+ String value() default "some value";
+
+}
+
+@interface MyClassRetentionAnnotation {
+ String value();
+}
diff --git a/tests/java5/ataspectj/annotationGen/DeclareParentsTest.aj b/tests/java5/ataspectj/annotationGen/DeclareParentsTest.aj
new file mode 100644
index 000000000..0a0da6769
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/DeclareParentsTest.aj
@@ -0,0 +1,56 @@
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.*;
+
+public aspect DeclareParentsTest {
+
+ declare parents : B || C extends A;
+
+ declare parents : A implements I,J;
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ AjType<DeclareParentsTest> myType = AjTypeSystem.getAjType(DeclareParentsTest.class);
+ DeclareParents[] decPs = myType.getDeclareParents();
+ if (decPs.length != 2) throw new RuntimeException("Expecting 2 members, got " + decPs.length);
+ if (decPs[0].isExtends()) {
+ checkExtends(decPs[0]);
+ checkImplements(decPs[1]);
+ } else {
+ checkExtends(decPs[1]);
+ checkImplements(decPs[0]);
+ }
+ }
+
+ private static void checkExtends(DeclareParents extendsDecP) throws ClassNotFoundException {
+ if (!extendsDecP.isExtends()) throw new RuntimeException("Should be extends");
+ AjType declaring = extendsDecP.getDeclaringType();
+ if (declaring.getJavaClass() != DeclareParentsTest.class) throw new RuntimeException("wrong declaring type");
+ TypePattern tp = extendsDecP.getTargetTypesPattern();
+ if (!tp.asString().equals("(B || C)")) throw new RuntimeException("expecting (B || C) but got '" + tp.asString() + "'");
+ Type[] parentTypes = extendsDecP.getParentTypes();
+ if (parentTypes.length != 1) throw new RuntimeException("expecting 1 parent type");
+ if (((AjType<?>)parentTypes[0]).getJavaClass() != A.class) throw new RuntimeException("expecting parent to be A but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");
+ }
+
+ private static void checkImplements(DeclareParents implementsDecP) throws ClassNotFoundException {
+ if (!implementsDecP.isImplements()) throw new RuntimeException("Should be implements");
+ AjType declaring = implementsDecP.getDeclaringType();
+ if (declaring.getJavaClass() != DeclareParentsTest.class) throw new RuntimeException("wrong declaring type");
+ TypePattern tp = implementsDecP.getTargetTypesPattern();
+ if (!tp.asString().equals("A")) throw new RuntimeException("expecting A but got '" + tp.asString() + "'");
+ Type[] parentTypes = implementsDecP.getParentTypes();
+ if (parentTypes.length != 2) throw new RuntimeException("expecting 2 parent types");
+ if (((AjType<?>)parentTypes[0]).getJavaClass() != I.class) throw new RuntimeException("expecting parent to be I but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");
+ if (((AjType<?>)parentTypes[1]).getJavaClass() != J.class) throw new RuntimeException("expecting parent to be J but was '" + ((AjType<?>)parentTypes[0]).getName() + "'");
+ }
+}
+
+
+class A {}
+
+class B {}
+
+class C {}
+
+interface I {}
+
+interface J {} \ No newline at end of file
diff --git a/tests/java5/ataspectj/annotationGen/DeclareParentsTestAdvanced.aj b/tests/java5/ataspectj/annotationGen/DeclareParentsTestAdvanced.aj
new file mode 100644
index 000000000..12d516e94
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/DeclareParentsTestAdvanced.aj
@@ -0,0 +1,39 @@
+package a.b.c;
+
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.*;
+
+public class DeclareParentsTestAdvanced {
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ AjType<ConcreteAspect> aType = AjTypeSystem.getAjType(ConcreteAspect.class);
+ DeclareParents[] decPs = aType.getDeclareParents();
+ if (decPs.length != 1) throw new RuntimeException("should see decp from super");
+ DeclareParents dp = decPs[0];
+ if (!dp.isImplements()) throw new RuntimeException("Expecting implements");
+ if (dp.getDeclaringType().getJavaClass() != AbstractAspect.class) {
+ throw new RuntimeException("Expecting declaring class to be AbstractAspect");
+ }
+ TypePattern tp = dp.getTargetTypesPattern();
+ if (!tp.asString().equals("a.b.c.A")) {
+ throw new RuntimeException("expecting 'a.b.c.A' but was '" + tp.asString() + "'");
+ }
+ Type[] parents = dp.getParentTypes();
+ if (parents.length != 1) throw new RuntimeException("expecting 1 parent");
+ if (((AjType)parents[0]).getJavaClass() != B.class) {
+ throw new RuntimeException("expecting 'B' but was '" + parents[0].toString() + "'");
+ }
+ }
+}
+
+abstract aspect AbstractAspect {
+
+ declare parents : A implements B;
+
+}
+
+aspect ConcreteAspect extends AbstractAspect {}
+
+class A {}
+
+class B {} \ No newline at end of file
diff --git a/tests/java5/ataspectj/annotationGen/DeclarePrecedenceTest.aj b/tests/java5/ataspectj/annotationGen/DeclarePrecedenceTest.aj
new file mode 100644
index 000000000..d8cda81a1
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/DeclarePrecedenceTest.aj
@@ -0,0 +1,35 @@
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.*;
+
+@org.aspectj.lang.annotation.DeclarePrecedence("DeclarePrecedenceTest,*")
+public aspect DeclarePrecedenceTest {
+
+ declare precedence : org.xyz..*, org.abc..*;
+
+ declare precedence : org.abc..*, org.def..*;
+
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ AjType<DeclarePrecedenceTest> myType = AjTypeSystem.getAjType(DeclarePrecedenceTest.class);
+ DeclarePrecedence[] decPs = myType.getDeclarePrecedence();
+ if (decPs.length != 3) throw new RuntimeException("Expecting 3 members, got " + decPs.length);
+ for(int i = 0; i < decPs.length; i++) {
+ validateDecP(decPs[i]);
+ }
+ }
+
+ private static void validateDecP(DeclarePrecedence dp) {
+ TypePattern[] tps = dp.getPrecedenceOrder();
+ if (tps.length != 2) throw new RuntimeException("Expecting 2 type patterns, got " + tps.length);
+ if (tps[0].asString().equals("DeclarePrecedenceTest")) {
+ if (!tps[1].asString().equals("*")) throw new RuntimeException("Excepting '*', got '" + tps[1].asString() + "'");
+ } else if (tps[0].asString().equals("org.xyz..*")) {
+ if (!tps[1].asString().equals("org.abc..*")) throw new RuntimeException("Excepting 'org.abc..*', got '" + tps[1].asString() + "'");
+ } else if (tps[0].asString().equals("org.abc..*")) {
+ if (!tps[1].asString().equals("org.def..*")) throw new RuntimeException("Excepting 'org.def..*', got '" + tps[1].asString() + "'");
+ } else {
+ throw new RuntimeException("Unexpected type pattern: " + tps[0].asString());
+ }
+ }
+
+}
diff --git a/tests/java5/ataspectj/annotationGen/DeclareSoftTest.aj b/tests/java5/ataspectj/annotationGen/DeclareSoftTest.aj
new file mode 100644
index 000000000..0dd4c1f6f
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/DeclareSoftTest.aj
@@ -0,0 +1,22 @@
+import org.aspectj.lang.reflect.*;
+import java.lang.reflect.*;
+
+public aspect DeclareSoftTest {
+
+ declare soft : ClassNotFoundException : call(* Class.forName(..));
+
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ AjType<DeclareSoftTest> myType = AjTypeSystem.getAjType(DeclareSoftTest.class);
+ DeclareSoft[] decSs = myType.getDeclareSofts();
+ if (decSs.length != 1) throw new RuntimeException("Expecting 1 members, got " + decSs.length);
+ if (decSs[0].getDeclaringType() != myType) throw new RuntimeException("Bad declaring type: " + decSs[0].getDeclaringType());
+ String pc = decSs[0].getPointcutExpression().asString();
+ if (!pc.equals("call(* java.lang.Class.forName(..))")) throw new RuntimeException("Bad pcut: " + pc);
+ AjType exType = decSs[0].getSoftenedExceptionType();
+ if (exType != AjTypeSystem.getAjType(ClassNotFoundException.class)) {
+ throw new RuntimeException("Bad ex type: " + exType);
+ }
+ }
+
+}