summaryrefslogtreecommitdiffstats
path: root/aspectj5rt/java5-testsrc/org
diff options
context:
space:
mode:
authorwisberg <wisberg>2005-05-11 09:18:33 +0000
committerwisberg <wisberg>2005-05-11 09:18:33 +0000
commita2545d0e25640e03d2e97a6229ffe9f031617f9f (patch)
treebd673df3ca2a7fad3639af32adce81c9d09e123c /aspectj5rt/java5-testsrc/org
parentc479b60b4987b55a9ba84bd472dc0e1119942ae4 (diff)
downloadaspectj-a2545d0e25640e03d2e97a6229ffe9f031617f9f.tar.gz
aspectj-a2545d0e25640e03d2e97a6229ffe9f031617f9f.zip
testsrc -> java5-testsrc, placeholders for pre-1.5 build
Diffstat (limited to 'aspectj5rt/java5-testsrc/org')
-rw-r--r--aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTests.java317
-rw-r--r--aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java420
2 files changed, 737 insertions, 0 deletions
diff --git a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTests.java b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTests.java
new file mode 100644
index 000000000..dde2f4fba
--- /dev/null
+++ b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTests.java
@@ -0,0 +1,317 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer initial implementation
+ * ******************************************************************/
+package org.aspectj.internal.lang.reflect;
+
+import java.io.Serializable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+
+import junit.framework.TestCase;
+
+import org.aspectj.lang.reflect.AjType;
+import org.aspectj.lang.reflect.AjTypeSystem;
+
+public class AjTypeTests extends TestCase {
+
+ private AjType stringType;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ stringType = AjTypeSystem.getAjType(String.class);
+ }
+
+ public void testCreateAjType() {
+ assertNotNull("should find type",stringType);
+ }
+
+ public void testGetName() {
+ assertEquals(String.class.getName(),stringType.getName());
+ }
+
+ public void testGetPackage() {
+ assertEquals(String.class.getPackage(),stringType.getPackage());
+ }
+
+ public void testGetInterfaces() {
+ Class[] i1 = String.class.getInterfaces();
+ Class[] i2 = stringType.getInterfaces();
+ assertEquals(i1.length,i2.length);
+ for (int i = 0; i < i1.length; i++)
+ assertEquals(i1[i],i2[i]);
+ }
+
+ public void testGetModifiers() {
+ assertEquals(String.class.getModifiers(),stringType.getModifiers());
+ }
+
+ public void testGetSupertype() {
+ Class stringSuper = String.class.getSuperclass();
+ AjType ajSuper = stringType.getSupertype();
+ assertEquals(AjTypeSystem.getAjType(stringSuper),ajSuper);
+ }
+
+ public void testGetGenericSupertype() {
+ Type t = AjTypeSystem.getAjType(Goo.class).getGenericSupertype();
+ assertEquals(Foo.class,t);
+ }
+
+ public void testGetEnclosingMethod() {
+ new Goo().foo();
+ }
+
+ public void testGetEnclosingConstructor() {
+ new Goo();
+ }
+
+ public void testGetEnclosingType() {
+ AjType t = AjTypeSystem.getAjType(Foo.Z.class);
+ assertEquals("org.aspectj.internal.lang.reflect.Foo",t.getEnclosingType().getName());
+ }
+
+ public void testGetDeclaringType() {
+ AjType t = AjTypeSystem.getAjType(Foo.Z.class);
+ assertEquals("org.aspectj.internal.lang.reflect.Foo",t.getDeclaringType().getName());
+ }
+
+ public void testIsAnnotationPresent() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ assertTrue(foo.isAnnotationPresent(SomeAnn.class));
+ assertFalse(goo.isAnnotationPresent(SomeAnn.class));
+ }
+
+ public void testGetAnnotation() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ assertNotNull(foo.getAnnotation(SomeAnn.class));
+ assertNull(goo.getAnnotation(SomeAnn.class));
+ }
+
+ public void testGetAnnotations() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ assertEquals(1,foo.getAnnotations().length);
+ assertEquals(0,goo.getAnnotations().length);
+ }
+
+ public void testGetDeclaredAnnotations() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ assertEquals(0,goo.getDeclaredAnnotations().length);
+ assertEquals(1,foo.getDeclaredAnnotations().length);
+ }
+
+ public void testGetAjTypes() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType[] fooTypes = foo.getAjTypes();
+ assertEquals(1,fooTypes.length);
+ assertEquals("org.aspectj.internal.lang.reflect.Foo$Z",fooTypes[0].getName());
+ }
+
+ public void testGetDeclaredAjTypes() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ AjType[] fooTypes = foo.getDeclaredAjTypes();
+ assertEquals(2,fooTypes.length);
+ // Alex -> Adrian: looks like you can not make assumption on the ordering
+ String s = " " + fooTypes[0].getName() + " " + fooTypes[1].getName();
+ assertTrue(s.indexOf(" org.aspectj.internal.lang.reflect.Foo$Z") >= 0);
+ assertTrue(s.indexOf(" org.aspectj.internal.lang.reflect.Foo$XX") >= 0);
+ }
+
+ public void testGetConstructor() throws Exception {
+ Constructor c1 = String.class.getConstructor(String.class);
+ Constructor c2 = stringType.getConstructor(String.class);
+ assertEquals(c1,c2);
+ }
+
+ public void testGetConstructors() {
+ Constructor[] c1 = String.class.getConstructors();
+ Constructor[] c2 = stringType.getConstructors();
+ assertEquals(c1.length,c2.length);
+ for (int i = 0; i < c1.length; i++)
+ assertEquals(c1[i],c2[i]);
+ }
+
+ public void testGetDeclaredConstructor() throws Exception {
+ Constructor c1 = String.class.getDeclaredConstructor(String.class);
+ Constructor c2 = stringType.getDeclaredConstructor(String.class);
+ assertEquals(c1,c2);
+ }
+
+ public void testGetDeclaredConstructors() {
+ Constructor[] c1 = String.class.getDeclaredConstructors();
+ Constructor[] c2 = stringType.getDeclaredConstructors();
+ assertEquals(c1.length,c2.length);
+ for (int i = 0; i < c1.length; i++)
+ assertEquals(c1[i],c2[i]);
+ }
+
+ public void testGetDeclaredField() throws Exception {
+ Field f1 = String.class.getDeclaredField("value");
+ Field f2 = stringType.getDeclaredField("value");
+ assertEquals(f1,f2);
+ }
+
+ public void testGetDeclaredFields() {
+ Field[] f1 = String.class.getDeclaredFields();
+ Field[] f2 = stringType.getDeclaredFields();
+ assertEquals(f1.length,f2.length);
+ for (int i = 0; i < f1.length; i++)
+ assertEquals(f1[i],f2[i]);
+ }
+
+ public void testGetField() throws Exception {
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ assertEquals("g",goo.getField("g").getName());
+ }
+
+ public void testGetFields() {
+ AjType<Goo> goo = AjTypeSystem.getAjType(Goo.class);
+ Field[] fields = goo.getFields();
+ assertEquals(1,fields.length);
+ assertEquals("g",fields[0].getName());
+
+ }
+
+ public void testGetDeclaredMethod() throws Exception {
+ Method m1 = String.class.getDeclaredMethod("toUpperCase");
+ Method m2 = stringType.getDeclaredMethod("toUpperCase");
+ assertEquals(m1,m2);
+ }
+
+ public void testGetMethod() throws Exception {
+ Method m1 = String.class.getMethod("toUpperCase");
+ Method m2 = stringType.getMethod("toUpperCase");
+ assertEquals(m1,m2);
+ }
+
+ public void testGetDeclaredMethods() {
+ Method[] m1 = String.class.getDeclaredMethods();
+ Method[] m2 = stringType.getDeclaredMethods();
+ assertEquals(m1.length,m2.length);
+ for (int i = 0; i < m1.length; i++)
+ assertEquals(m1[i],m2[i]);
+ }
+
+ public void testGetMethods() {
+ Method[] m1 = String.class.getMethods();
+ Method[] m2 = stringType.getMethods();
+ assertEquals(m1.length,m2.length);
+ for (int i = 0; i < m1.length; i++)
+ assertEquals(m1[i],m2[i]);
+ }
+
+ public void testGetEnumConstants() {
+ AjType e = AjTypeSystem.getAjType(E.class);
+ Object[] consts = e.getEnumConstants();
+ assertEquals(3,consts.length);
+ }
+
+ public void testGetTypeParameters() {
+ AjType<Foo> foo = AjTypeSystem.getAjType(Foo.class);
+ TypeVariable<Class<Foo>>[] tvs = foo.getTypeParameters();
+ assertEquals(1,tvs.length);
+ assertEquals("T",tvs[0].getName());
+ }
+
+ public void testIsEnum() {
+ assertFalse(stringType.isEnum());
+ }
+
+ public void testIsInstance() {
+ assertTrue(stringType.isInstance("I am"));
+ }
+
+ public void testIsInterface() {
+ assertFalse(stringType.isInterface());
+ assertTrue(AjTypeSystem.getAjType(Serializable.class).isInterface());
+ }
+
+ public void testIsLocalClass() {
+ assertFalse(stringType.isLocalClass());
+ }
+
+ public void testIsArray() {
+ assertFalse(stringType.isArray());
+ assertTrue(AjTypeSystem.getAjType(Integer[].class).isArray());
+ }
+
+ public void testIsPrimitive() {
+ assertFalse(stringType.isPrimitive());
+ assertTrue(AjTypeSystem.getAjType(boolean.class).isPrimitive());
+ }
+
+ public void testIsAspect() {
+ assertFalse(stringType.isAspect());
+ }
+
+ public void testIsMemberAspect() {
+ assertFalse(stringType.isMemberAspect());
+ }
+
+ public void testIsPrivileged() {
+ assertFalse(stringType.isPrivileged());
+ }
+
+ public void testEquals() {
+ AjType stringTypeTwo = AjTypeSystem.getAjType(String.class);
+ assertTrue(stringType.equals(stringTypeTwo));
+ }
+
+ public void testHashCode() {
+ AjType stringTypeTwo = AjTypeSystem.getAjType(String.class);
+ assertEquals(stringType.hashCode(),stringTypeTwo.hashCode());
+ }
+
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface SomeAnn {}
+
+@SomeAnn
+class Foo<T> {
+
+ public Foo() {
+ class Y { int y; }
+ AjType t = AjTypeSystem.getAjType(Y.class);
+ Constructor c = t.getEnclosingConstructor();
+ if (!c.getName().equals("org.aspectj.internal.lang.reflect.Foo")) throw new RuntimeException("should have been Foo");
+ }
+ public void foo() {
+ class X { int x; }
+ AjType t = AjTypeSystem.getAjType(X.class);
+ Method m = t.getEnclosingMethod();
+ if (!m.getName().equals("foo")) throw new RuntimeException("should have been foo");
+ }
+ public class Z { int z; }
+ class XX { int xx; }
+}
+
+class Goo extends Foo {
+ @interface IX {}
+
+ public Goo() {
+ super();
+ }
+
+ public int g;
+ int g2;
+
+}
+
+enum E { A,B,C; }
diff --git a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java
new file mode 100644
index 000000000..1ecd34516
--- /dev/null
+++ b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java
@@ -0,0 +1,420 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer initial implementation
+ * ******************************************************************/
+package org.aspectj.internal.lang.reflect;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import junit.framework.TestCase;
+
+import org.aspectj.internal.lang.annotation.ajcDeclareEoW;
+import org.aspectj.internal.lang.annotation.ajcPrivileged;
+import org.aspectj.lang.annotation.AdviceName;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.AfterThrowing;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.DeclareError;
+import org.aspectj.lang.annotation.DeclareWarning;
+import org.aspectj.lang.reflect.Advice;
+import org.aspectj.lang.reflect.AdviceType;
+import org.aspectj.lang.reflect.AjType;
+import org.aspectj.lang.reflect.AjTypeSystem;
+import org.aspectj.lang.reflect.DeclareErrorOrWarning;
+import org.aspectj.lang.reflect.NoSuchAdviceException;
+import org.aspectj.lang.reflect.NoSuchPointcutException;
+import org.aspectj.lang.reflect.PerClause;
+import org.aspectj.lang.reflect.PerClauseKind;
+import org.aspectj.lang.reflect.Pointcut;
+
+public class AjTypeTestsWithAspects extends TestCase {
+
+ private AjType sa;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ sa = AjTypeSystem.getAjType(SimpleAspect.class);
+ }
+
+ public void testGetPerClause() {
+ AjType perThisA = AjTypeSystem.getAjType(PerThisAspect.class);
+ AjType perTargetA = AjTypeSystem.getAjType(PerTargetAspect.class);
+ AjType perCflowA = AjTypeSystem.getAjType(PerCflowAspect.class);
+ AjType perCflowbelowA = AjTypeSystem.getAjType(PerCflowbelowAspect.class);
+ AjType perTypeWithinA = AjTypeSystem.getAjType(PerTypeWithin.class);
+
+ PerClause pc = perThisA.getPerClause();
+ assertEquals(PerClauseKind.PERTHIS,pc.getKind());
+ assertEquals("pc()",pc.getPointcutExpression());
+
+ pc= perTargetA.getPerClause();
+ assertEquals(PerClauseKind.PERTARGET,pc.getKind());
+ assertEquals("pc()",pc.getPointcutExpression());
+
+ pc= perCflowA.getPerClause();
+ assertEquals(PerClauseKind.PERCFLOW,pc.getKind());
+ assertEquals("pc()",pc.getPointcutExpression());
+
+ pc= perCflowbelowA.getPerClause();
+ assertEquals(PerClauseKind.PERCFLOWBELOW,pc.getKind());
+ assertEquals("pc()",pc.getPointcutExpression());
+
+ pc= perTypeWithinA.getPerClause();
+ assertEquals(PerClauseKind.PERTYPEWITHIN,pc.getKind());
+ assertEquals("org.aspectj..*",pc.getPointcutExpression());
+
+ }
+
+ public void testGetDeclaredField() throws Exception{
+ Field f = sa.getDeclaredField("s");
+ try {
+ Field f2 = sa.getDeclaredField("ajc$xyz$s");
+ fail("Expecting NoSuchFieldException");
+ } catch (NoSuchFieldException nsf) {}
+ }
+
+ public void testGetField() throws Exception {
+ Field f = sa.getField("s");
+ try {
+ Field f2 = sa.getField("ajc$xyz$s");
+ fail("Expecting NoSuchFieldException");
+ } catch (NoSuchFieldException nsf) {}
+ }
+
+ public void testGetDeclaredFields() {
+ Field[] fields = sa.getDeclaredFields();
+ assertEquals(1,fields.length);
+ assertEquals("s",fields[0].getName());
+ }
+
+ public void testGetFields() {
+ Field[] fields = sa.getFields();
+ assertEquals(1,fields.length);
+ assertEquals("s",fields[0].getName());
+ }
+
+ public void testGetDeclaredMethod() throws Exception {
+ Method m = sa.getDeclaredMethod("aMethod");
+ try {
+ Method m2 = sa.getDeclaredMethod("logEntry");
+ fail("Expecting NoSuchMethodException");
+ } catch(NoSuchMethodException ex) {}
+ try {
+ Method m3 = sa.getDeclaredMethod("ajc$before$123");
+ fail("Expecting NoSuchMethodException");
+ } catch(NoSuchMethodException ex) {}
+ }
+
+ public void testGetMethod() throws Exception {
+ Method m = sa.getMethod("aMethod");
+ try {
+ Method m2 = sa.getMethod("logEntry");
+ fail("Expecting NoSuchMethodException");
+ } catch(NoSuchMethodException ex) {}
+ try {
+ Method m3 = sa.getMethod("ajc$before$123");
+ fail("Expecting NoSuchMethodException");
+ } catch(NoSuchMethodException ex) {}
+ }
+
+ public void testGetDeclaredMethods() {
+ Method[] ms = sa.getDeclaredMethods();
+ assertEquals(1,ms.length);
+ assertEquals("aMethod",ms[0].getName());
+ }
+
+ public void testGetMethods() {
+ Method[] ms = sa.getMethods();
+ assertEquals(10,ms.length);
+ assertEquals("aMethod",ms[0].getName());
+ }
+
+ public void testGetDeclaredPointcut() throws Exception {
+ Pointcut p1 = sa.getDeclaredPointcut("simpleAspectMethodExecution");
+ assertEquals("simpleAspectMethodExecution",p1.getName());
+ assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression());
+ assertEquals(sa,p1.getDeclaringType());
+ assertEquals(0,p1.getParameterTypes().length);
+ assertTrue(Modifier.isPublic(p1.getModifiers()));
+ Pointcut p2 = sa.getDeclaredPointcut("simpleAspectCall");
+ assertEquals("simpleAspectCall",p2.getName());
+ assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression());
+ assertEquals(sa,p2.getDeclaringType());
+ assertEquals(1,p2.getParameterTypes().length);
+ assertTrue(Modifier.isPrivate(p2.getModifiers()));
+ try {
+ Pointcut p3 = sa.getDeclaredPointcut("sausages");
+ fail("Expecting NoSuchPointcutExcetpion");
+ } catch (NoSuchPointcutException ex) {
+ assertEquals("sausages",ex.getName());
+ }
+ }
+
+ public void testGetPointcut() throws Exception {
+ Pointcut p1 = sa.getPointcut("simpleAspectMethodExecution");
+ assertEquals("simpleAspectMethodExecution",p1.getName());
+ assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression());
+ assertEquals(sa,p1.getDeclaringType());
+ assertEquals(0,p1.getParameterTypes().length);
+ assertTrue(Modifier.isPublic(p1.getModifiers()));
+ Pointcut p2 = sa.getPointcut("simpleAspectCall");
+ assertEquals("simpleAspectCall",p2.getName());
+ assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression());
+ assertEquals(sa,p2.getDeclaringType());
+ assertEquals(1,p2.getParameterTypes().length);
+ assertTrue(Modifier.isPrivate(p2.getModifiers()));
+ try {
+ Pointcut p3 = sa.getPointcut("sausages");
+ fail("Expecting NoSuchPointcutExcetpion");
+ } catch (NoSuchPointcutException ex) {
+ assertEquals("sausages",ex.getName());
+ }
+ }
+
+ public void testGetDeclaredPointcuts() {
+ Pointcut[] pcs = sa.getDeclaredPointcuts();
+ assertEquals(2,pcs.length);
+ assertEquals("simpleAspectMethodExecution",pcs[0].getName());
+ assertEquals("simpleAspectCall",pcs[1].getName());
+ }
+
+ public void testGetPointcuts() {
+ Pointcut[] pcs = sa.getPointcuts();
+ assertEquals(1,pcs.length);
+ assertEquals("simpleAspectMethodExecution",pcs[0].getName());
+ }
+
+ public void testGetDeclaredAdvice() {
+ Advice[] advice = sa.getDeclaredAdvice();
+ assertEquals(10,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.BEFORE);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER_RETURNING);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER_THROWING);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AROUND);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.BEFORE,AdviceType.AFTER);
+ assertEquals(4,advice.length);
+
+ advice = sa.getDeclaredAdvice(AdviceType.BEFORE);
+ assertEquals("execution(* SimpleAspect.*(..))",advice[0].getPointcutExpression());
+ assertEquals("logEntry",advice[0].getName());
+ assertEquals(AdviceType.BEFORE,advice[0].getKind());
+ assertEquals("execution(* SimpleAspect.*(..))",advice[1].getPointcutExpression());
+ assertEquals("",advice[1].getName());
+ }
+
+ public void testGetAdvice() {
+ Advice[] advice = sa.getDeclaredAdvice();
+ assertEquals(10,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.BEFORE);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER_RETURNING);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AFTER_THROWING);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.AROUND);
+ assertEquals(2,advice.length);
+ advice = sa.getDeclaredAdvice(AdviceType.BEFORE,AdviceType.AFTER);
+ assertEquals(4,advice.length);
+ }
+
+ public void testGetNamedAdvice() throws Exception {
+ Advice a = sa.getAdvice("logItAll");
+ assertEquals("logItAll",a.getName());
+ assertEquals(AdviceType.AROUND,a.getKind());
+ a = sa.getAdvice("whatGoesAround");
+ assertEquals("whatGoesAround",a.getName());
+ assertEquals(AdviceType.AROUND,a.getKind());
+ try {
+ a = sa.getAdvice("ajc$after$123");
+ fail("Expecting NoSuchAdviceException");
+ } catch (NoSuchAdviceException ex) {
+ assertEquals("ajc$after$123",ex.getName());
+ }
+ try {
+ a = sa.getAdvice("");
+ fail("Expecting IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ ;
+ }
+ }
+
+ public void testGetNamedDeclaredAdvice() throws Exception {
+ Advice a = sa.getDeclaredAdvice("logItAll");
+ assertEquals("logItAll",a.getName());
+ assertEquals(AdviceType.AROUND,a.getKind());
+ a = sa.getDeclaredAdvice("whatGoesAround");
+ assertEquals("whatGoesAround",a.getName());
+ assertEquals(AdviceType.AROUND,a.getKind());
+ try {
+ a = sa.getDeclaredAdvice("ajc$after$123");
+ fail("Expecting NoSuchAdviceException");
+ } catch (NoSuchAdviceException ex) {
+ assertEquals("ajc$after$123",ex.getName());
+ }
+ try {
+ a = sa.getDeclaredAdvice("");
+ fail("Expecting IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ ;
+ }
+ }
+
+ public void testIsPrivileged() {
+ assertFalse(sa.isPrivileged());
+ assertTrue(AjTypeSystem.getAjType(SimplePrivilegedAspect.class).isPrivileged());
+ }
+
+ public void testIsAspect() {
+ assertTrue(sa.isAspect());
+ }
+
+ public void testIsMemberAspect() {
+ assertFalse(AjTypeSystem.getAjType(SimplePrivilegedAspect.class).isMemberAspect());
+ assertTrue(AjTypeSystem.getAjType(SimplePrivilegedAspect.MemberAspect.class).isMemberAspect());
+
+ }
+
+ public void testGetDeclareEoWarnings() {
+ DeclareErrorOrWarning[] deows = sa.getDeclareErrorOrWarnings();
+ assertEquals(4,deows.length);
+ boolean foundCodeWarning = false;
+ boolean foundCodeError = false;
+ boolean foundAnnWarning = false;
+ boolean foundAnnError = false;
+ for (DeclareErrorOrWarning deow : deows) {
+ if (deow.isError()) {
+ if (deow.getMessage().equals("dont call this method code")) foundCodeError = true;
+ if (deow.getMessage().equals("dont call this method ann")) foundAnnError = true;
+ assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression());
+ } else {
+ if (deow.getMessage().equals("dont call this method code")) foundCodeWarning = true;
+ if (deow.getMessage().equals("dont call this method ann")) foundAnnWarning = true;
+ assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression());
+ }
+ }
+ assertTrue(foundCodeWarning && foundAnnWarning && foundCodeError && foundAnnError);
+ }
+
+}
+
+
+@Aspect
+class SimpleAspect {
+
+ // regular field
+ public String s;
+
+ // synthetic field
+ public String ajc$xyz$s;
+
+ // regular method
+ public void aMethod() {}
+
+ // advice method, annotation style
+ @Before("execution(* SimpleAspect.*(..))")
+ public void logEntry() {}
+
+ // advice method, code style
+ @Before("execution(* SimpleAspect.*(..))")
+ public void ajc$before$123() {}
+
+ // advice method, annotation style
+ @After("execution(* SimpleAspect.*(..))")
+ public void logFinally() {}
+
+ // advice method, code style
+ @After("execution(* SimpleAspect.*(..))")
+ public void ajc$after$123() {}
+
+ // advice method, annotation style
+ @AfterReturning("execution(* SimpleAspect.*(..))")
+ public void logExit() {}
+
+ // advice method, code style
+ @AfterReturning("execution(* SimpleAspect.*(..))")
+ public void ajc$afterReturning$123() {}
+
+ // advice method, annotation style
+ @AfterThrowing("execution(* SimpleAspect.*(..))")
+ public void logException() {}
+
+ // advice method, code style
+ @AfterThrowing("execution(* SimpleAspect.*(..))")
+ public void ajc$afterThrowing$123() {}
+
+ // advice method, annotation style
+ @Around("execution(* SimpleAspect.*(..))")
+ public void logItAll() {}
+
+ // advice method, code style
+ @Around("execution(* SimpleAspect.*(..))")
+ @AdviceName("whatGoesAround")
+ public void ajc$around$123() {}
+
+ // pointcut, annotation style
+ @org.aspectj.lang.annotation.Pointcut("execution(* SimpleAspect.*(..))")
+ public void simpleAspectMethodExecution() {};
+
+ // pointcut, code style
+ @org.aspectj.lang.annotation.Pointcut("call(* SimpleAspect.*(..))")
+ private void ajc$pointcut$$simpleAspectCall$123(SimpleAspect target) {};
+
+ // decw, ann style
+ @DeclareWarning("call(* DontDoIt.*(..))")
+ public static final String dontDoIt = "dont call this method ann";
+
+ // decw, code style
+ @ajcDeclareEoW(pointcut="call(* DontDoIt.*(..))",message="dont call this method code",isError=false)
+ private void ajc$declare_eow$123() {}
+
+ // dec., ann style
+ @DeclareError("call(* DontDoIt.*(..))")
+ public static final String dontDoItISaid = "dont call this method ann";
+
+ // decw, code style
+ @ajcDeclareEoW(pointcut="call(* DontDoIt.*(..))",message="dont call this method code",isError=true)
+ private void ajc$declare_eow$124() {}
+}
+
+@Aspect
+@ajcPrivileged
+class SimplePrivilegedAspect {
+
+ @Aspect
+ static class MemberAspect {}
+
+}
+
+@Aspect("perthis(pc())")
+class PerThisAspect {}
+
+@Aspect("pertarget(pc())")
+class PerTargetAspect {}
+
+@Aspect("percflow(pc())")
+class PerCflowAspect {}
+
+@Aspect("percflowbelow(pc())")
+class PerCflowbelowAspect {}
+
+@Aspect("pertypewithin(org.aspectj..*)")
+class PerTypeWithin {}