diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/new | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/new')
537 files changed, 26981 insertions, 0 deletions
diff --git a/tests/new/.cvsignore b/tests/new/.cvsignore new file mode 100644 index 000000000..168aa3113 --- /dev/null +++ b/tests/new/.cvsignore @@ -0,0 +1 @@ +ajworkingdir diff --git a/tests/new/AJDBClass.java b/tests/new/AJDBClass.java new file mode 100644 index 000000000..7dd1b3e24 --- /dev/null +++ b/tests/new/AJDBClass.java @@ -0,0 +1,110 @@ +public class AJDBClass { + + public int publicInt = 0; + protected int protectedInt = 1; + private int privateInt = 2; + /*package*/ int packageInt = 3; + + public AJDBClass() {} + /*package*/ AJDBClass(int i) {} + protected AJDBClass(byte b) {} + private AJDBClass(String s) {} + + { + publicInt = 13; + } + + public static void main(String[] args) { + System.out.println("Starting..."); + new AJDBClass().go(); + System.out.println("Done."); + } + + void go() { + int j = 1; + String string = "string"; + byte b = (byte)9; + long l = 123123123; + double d = 123.123; + short s = (short)4; + char c = 'c'; + Object o = null; + Integer integer = new Integer(13); + a(); + b(); + c(); + d(); + } + + public void a() { + System.out.println("a"); + } + + protected void b() { + System.out.println("b"); + } + + private void c() { + System.out.println("c"); + } + + void d() { + System.out.println("d"); + } +} + +aspect Aspect { + pointcut ours(): instanceof(AJDBClass); + pointcut allReceptions(): receptions(void *(..)) && ours(); + pointcut allExecutions(): executions(void *(..)) && within(AJDBClass); + pointcut allCalls(): calls(void AJDBClass.*(..)); + pointcut allCallsTo(): callsto(receptions(void *(..)) && instanceof(AJDBClass)); + + static before(): allReceptions() { + System.out.println("before receptions: " + thisJoinPoint); + } + static after(): allReceptions() { + System.out.println("after receptions: " + thisJoinPoint); + } + static around() returns void: allReceptions() { + System.out.println("around before receptions: " + thisJoinPoint); + proceed(); + System.out.println("around after receptions: " + thisJoinPoint); + } + + static before(): allExecutions() { + System.out.println("before executions: " + thisJoinPoint); + } + static after(): allExecutions() { + System.out.println("after executions: " + thisJoinPoint); + } + static around() returns void: allExecutions() { + System.out.println("around before executions: " + thisJoinPoint); + proceed(); + System.out.println("around after executions: " + thisJoinPoint); + } + + static before(): allCalls() { + System.out.println("before calls: " + thisJoinPoint); + } + static after(): allCalls() { + System.out.println("after calls: " + thisJoinPoint); + } + static around() returns void: allCalls() { + System.out.println("around before calls: " + thisJoinPoint); + proceed(); + System.out.println("around after calls: " + thisJoinPoint); + } + + static before(): allCallsTo() { + System.out.println("before callsTo: " + thisJoinPoint); + } + static after(): allCallsTo() { + System.out.println("after callsTo: " + thisJoinPoint); + } + static around() returns void: allCallsTo() { + System.out.println("around before callsTo: " + thisJoinPoint); + proceed(); + System.out.println("around after callsTo: " + thisJoinPoint); + } +} diff --git a/tests/new/AJDBTest.java b/tests/new/AJDBTest.java new file mode 100644 index 000000000..197539fe1 --- /dev/null +++ b/tests/new/AJDBTest.java @@ -0,0 +1,188 @@ +import org.aspectj.tools.ajdb.Main; +import org.aspectj.debugger.tty.CommandLineDebugger; +import org.aspectj.debugger.base.*; +import com.sun.jdi.*; +import com.sun.jdi.event.*; +import java.io.*; +import java.util.*; +import org.aspectj.testing.Tester; + +public class AJDBTest implements StopListener, VMListener { + + String classpath; + { + classpath = "\"" + Tester.outputDir(); + String javaClasspath = System.getProperty("java.class.path"); + if (javaClasspath != null) { + classpath += ";" + javaClasspath; + } + classpath += "\""; + } + + protected String[] stringCommands() { + return new String[] { + "workingdir " + Tester.workingDir(), + "use " + "./new", + "stop on AJDBClass.java:24", + "run -classpath " + classpath + " AJDBClass", + }; + } + protected String getSourceName() { + return "AJDBClass.java"; + } + + // Methods for VMListener + protected void death(VMDeathEvent e) { + System.out.println("*** Death: " + e); + } + protected void disconnect(VMDisconnectEvent e) { + System.out.println("*** Disconnect: " + e); + } + protected void start(VMStartEvent e) { + System.out.println("*** Start: " + e); + } + + // Methods for StopListener + protected void access(AccessWatchpointEvent e) { + } + protected void breakpoint(BreakpointEvent e) { + checkLines((List) ex("where"), "next"); + } + protected void exception(ExceptionEvent e) { + } + protected void modification(ModificationWatchpointEvent e) { + } + protected void step(StepEvent e) { + List lines = (List) ex("where"); + checkLines(lines); + try { + StackFrame frame = (StackFrame) lines.get(0); + Location loc = frame.location(); + if (loc.sourceName().equals("Thread.java") && + loc.method().name().equals("exit")) { + isRunning = false; + } + } catch (Throwable t) {} + ex("next"); + + } + + public void checkLines(Collection lines, Object then) { + checkLines(lines); + if (then != null) ex(then); + } + + public void checkLines(Collection lines) { + Iterator iter = lines.iterator(); + while (iter.hasNext()) { + StackFrame frame = (StackFrame) iter.next(); + String source = "no.source"; + try { + source = debugger.sourceName(frame.location()); + } catch (Throwable t) {} + int line = debugger.lineNumber(frame.location()); + if (source.equals(getSourceName())) { + Tester.check(line>0, "non-mapping line for " + frame); + } + } + } + + // VMListener + public void vmDeathEvent(VMDeathEvent e) { + death(e); + } + public void vmDisconnectEvent(VMDisconnectEvent e) { + disconnect(e); + } + public void vmStartEvent(VMStartEvent e) { + start(e); + } + + // StopListener + public final void accessWatchpointEvent(AccessWatchpointEvent e) { + access(e); + } + public final void breakpointEvent(BreakpointEvent e) { + breakpoint(e); + } + public final void exceptionEvent(ExceptionEvent e) { + exception(e); + } + public final void modificationWatchpointEvent(ModificationWatchpointEvent e) { + modification(e); + } + public final void stepEvent(StepEvent e) { + step(e); + } + + AJDebugger debugger; + CommandLineDebugger ajdb; + + public void realMain(String[] args) { + String fileName = null; + String[] newArgs = args; + if (args.length > 0) { + fileName = args[0]; + newArgs = new String[args.length-1]; + System.arraycopy(args, 1, newArgs, 0, newArgs.length); + } + realMain(fileName, newArgs); + } + + private void realMain(String fileName, String[] args) { + debugger = (ajdb = new Main().debug(args)).getDebugger(); + debugger.addStopListener(this); + debugger.addVMListener(this); + ex(fileName == null ? commands() : commands(fileName)); + while (isRunning) { + //System.out.println(">>>>>>>> " + debugger.isRunning()); + } + } + private boolean isRunning = true; + + public final Collection commands() { + Collection list = new Vector(); + String[] commands = stringCommands(); + for (int i = 0; i < commands.length; i++) { + list.add(commands[i]); + } + return list; + } + + Object ex(Object command) { + return ajdb.executeCommand(command+""); + } + + void ex(Collection list) { + Iterator iter = list.iterator(); + while (iter.hasNext()) { + ex(iter.next()); + } + } + + final static String COMMENT = "#"; + final static String FILENAME = "script.txt"; + Collection commands(String fileName) { + Collection list = new Vector(); + try { + BufferedReader in = new BufferedReader(new FileReader(fileName)); + String line; + while ((line = in.readLine()) != null) { + line = line.trim(); + if (line.startsWith(COMMENT)) { + continue; + } + list.add(line); + } + in.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + System.exit(-1); + } + return list; + } + + public static void main(String[] args) { + new AJDBTest().realMain(args); + } +} diff --git a/tests/new/AbstractAspectsExtendingAbstractAspectsGeneratesMethodsWithTheSameName_PR464.java b/tests/new/AbstractAspectsExtendingAbstractAspectsGeneratesMethodsWithTheSameName_PR464.java new file mode 100644 index 000000000..a16c1e86b --- /dev/null +++ b/tests/new/AbstractAspectsExtendingAbstractAspectsGeneratesMethodsWithTheSameName_PR464.java @@ -0,0 +1,52 @@ +import org.aspectj.testing.Tester; +public class AbstractAspectsExtendingAbstractAspectsGeneratesMethodsWithTheSameName_PR464 { + public static void main(String[] args) { + new AbstractAspectsExtendingAbstractAspectsGeneratesMethodsWithTheSameName_PR464().realMain(args); + } + public void realMain(String[] args) { + new C().c(); + // No tests to actually run. The point is that all advice is abstract! + //Tester.checkAllEvents(); + } + static { + //Tester.expectEventsInString("AspectA.star,AspectA.c"); + //Tester.expectEventsInString("AspectB.star,AspectB.c"); + //Tester.expectEventsInString("AspectC.star,AspectC.c"); + } +} + +class C { + public void c() {} +} + +abstract aspect AspectA { + before() : execution(* *(..)) { + Tester.event("AspectA.star"); + } + + before() : execution(* c(..)) { + Tester.event("AspectA.c"); + } +} + +abstract aspect AspectB extends AspectA { + + before() : execution(* *(..)) { + Tester.event("AspectB.star"); + } + + before() : execution(* c(..)) { + Tester.event("AspectB.c"); + } +} + +abstract aspect AspectC extends AspectB { + before() : execution(* *(..)) { + Tester.event("AspectC.star"); + } + + before() : execution(* c(..)) { + Tester.event("AspectC.c"); + } +} + diff --git a/tests/new/AbstractCflows.java b/tests/new/AbstractCflows.java new file mode 100644 index 000000000..25d21a9be --- /dev/null +++ b/tests/new/AbstractCflows.java @@ -0,0 +1,90 @@ +import org.aspectj.testing.Tester; + +public class AbstractCflows { + public static void main(String[] args) { + C c = new C(); + c.enter(1, 2); + c.enter1(3); + Tester.checkEvents(expected); + } + private static final String[] expected = { + "enter(1, 2)", + "CflowX: call(void C.body()); i = 1", + "CflowY: call(void C.body()); i = 2", + "PerCflowX: call(void C.body())", + "PerCflowY: call(void C.body())", + "BODY", + "CflowX: call(void C.body()); i = 1", + "CflowY: call(void C.body()); i = 2", + "PerCflowX: call(void C.body())", + "PerCflowY: call(void C.body())", + "BODY", + "enter1(3)", + "Cflow3: call(void C.body()); i = 3", + "PerCflow3: call(void C.body())", + "BODY", + }; +} + +class C { + public void enter(int x, int y) { + Tester.event("enter(" + x + ", " + y + ")"); + body(); + body(); + } + + public void enter1(int i) { + Tester.event("enter1(" + i + ")"); + body(); + } + + public void body() { + Tester.event("BODY"); + } +} + +abstract aspect CflowBase { + abstract pointcut entry(int i); + pointcut flow(int x): cflow(entry(x)); + + pointcut body(): call(* body()); + + before(int i): body() && flow(i) { + Tester.event(this.getClass().getName() + ": " + thisJoinPoint + "; i = " + i); + } +} + +aspect CflowY extends CflowBase { + pointcut entry(int y): args(*, y) && call(void enter(int, int)); +} + +aspect CflowX extends CflowBase { + pointcut entry(int x): args(x, *) && call(void enter(int, int)); +} + +aspect Cflow3 extends CflowBase { + pointcut entry(int i): args(i) && call(void enter1(int)); +} + +abstract aspect PerCflowBase percflow(entry(int)) { + abstract pointcut entry(int i); + + pointcut body(): call(* body()); + + before(): body() { + Tester.event(this.getClass().getName() + ": " + thisJoinPoint); + } +} + +aspect PerCflowY extends PerCflowBase { + pointcut entry(int y): args(*, y) && call(void enter(int, int)); +} + +aspect PerCflowX extends PerCflowBase { + pointcut entry(int x): args(x, *) && call(void enter(int, int)); +} + +aspect PerCflow3 extends PerCflowBase { + pointcut entry(int i): args(i) && call(void enter1(int)); +} + diff --git a/tests/new/AbstractDeclare.java b/tests/new/AbstractDeclare.java new file mode 100644 index 000000000..6f3859913 --- /dev/null +++ b/tests/new/AbstractDeclare.java @@ -0,0 +1,31 @@ +public class AbstractDeclare { + public static void main(String[] args) { + new C().m(); + int y = new C().x; + } +} + +class C { + int x; + + void m() {} +} + + +abstract aspect BaseErr { + abstract pointcut acid(); + abstract pointcut base(); + + declare error: acid() && base(): + "acid's and base's don't mix"; +} + +aspect CallErr extends BaseErr { + pointcut acid(): within(AbstractDeclare); + pointcut base(): call(* C.*()); +} + +aspect GetErr extends BaseErr { + pointcut acid(): within(AbstractDeclare); + pointcut base(): get(* C.*); +} diff --git a/tests/new/AbstractMethodCall.java b/tests/new/AbstractMethodCall.java new file mode 100644 index 000000000..8803faba0 --- /dev/null +++ b/tests/new/AbstractMethodCall.java @@ -0,0 +1,18 @@ + + +abstract class AbstractClass { + public abstract void abstractMethod (); +} + +public class AbstractMethodCall extends AbstractClass { + /** @testcase PR591 PUREJAVA compiler error expected when directly calling unimplemented abstract method using super */ + public void abstractMethodCall () { + super.abstractMethod (); // expecting compiler error: cannot access directly + } + public void abstractMethod() {} + public static void main(String[] args) { + new AbstractMethodCall().abstractMethodCall(); + } +} + + diff --git a/tests/new/AbstractPointcutAccess.java b/tests/new/AbstractPointcutAccess.java new file mode 100644 index 000000000..83846dfea --- /dev/null +++ b/tests/new/AbstractPointcutAccess.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#619 direct use outside aspect of defined abstract pointcut */ +public abstract aspect AbstractPointcutAccess { + public static void main (String[] args) { + Tester.event("main"); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("main"); + Tester.expectEvent("used"); + } + + abstract pointcut abstractPointcut(); +} +aspect ConcretePointcutAccess extends AbstractPointcutAccess { + pointcut abstractPointcut() : execution(void main(..)); +} + +aspect AbstractPointcutUser { + before () : ConcretePointcutAccess.abstractPointcut() { + Tester.event("used"); + } +} + diff --git a/tests/new/AbstractPointcutAccessCE.java b/tests/new/AbstractPointcutAccessCE.java new file mode 100644 index 000000000..fe032a9d0 --- /dev/null +++ b/tests/new/AbstractPointcutAccessCE.java @@ -0,0 +1,11 @@ + +/** @testcase PR#619 direct use outside aspect of undefined abstract pointcut */ +abstract aspect AbstractPointcutAccessCE { + abstract pointcut abstractPointcut(); +} + +aspect AbstractPointcutUser { + before () + : AbstractPointcutAccessCE.abstractPointcut() { } // CE +} + diff --git a/tests/new/AbstractPointcutIndirectCE.java b/tests/new/AbstractPointcutIndirectCE.java new file mode 100644 index 000000000..3f3b5df76 --- /dev/null +++ b/tests/new/AbstractPointcutIndirectCE.java @@ -0,0 +1,12 @@ + +/** @testcase PR#619 indirect use outside aspect of undefined abstract pointcut */ +abstract aspect AbstractPointcutIndirectCE { + abstract pointcut abstractPointcut(); + pointcut pc() : abstractPointcut(); +} + +aspect AbstractPointcutUser { + before () + : AbstractPointcutIndirectCE.pc() { } // CE +} + diff --git a/tests/new/AddObjectMethodProblem.java b/tests/new/AddObjectMethodProblem.java new file mode 100644 index 000000000..d218f77af --- /dev/null +++ b/tests/new/AddObjectMethodProblem.java @@ -0,0 +1,48 @@ +import org.aspectj.testing.Tester; + +public class AddObjectMethodProblem { + + // Uncommenting this and changing addObject -> doAddObject in the advice + // works around the bug 0.5beta1 + //public void doAddObject(Class1 o) { + // addObject(o); + //} + + public static void main(String[] args) { test(); } + + crosscut ccut(Class1 c1): c1 && void process(); + + advice(Class1 c1): ccut(c1) { + before { + if (c1.getElement() != null) addObject(c1.getElement()); + c1.setProcessedAndAdvised(true); + } + } + + public static void test() { + AddObjectMethodProblem a = new AddObjectMethodProblem(); + Class1 c1 = new Class1(); + Class1 c2 = new Class1(); + c1.element = c2; + a.addObject(c1); + c1.process(); + Tester.check(c1.processedAndAdvised, "advice on top"); + Tester.check(c2.processedAndAdvised, "advice on element"); + } +} + +class Class1 { + public Class1 element; + public boolean processedAndAdvised = false; + + public Class1 getElement() { return element; } + + public void setProcessedAndAdvised( boolean val ) { + processedAndAdvised = val; + } + + public void process() { + if (element != null) element.process(); + } +} + diff --git a/tests/new/AddObjectOnAbstract.java b/tests/new/AddObjectOnAbstract.java new file mode 100644 index 000000000..1aff55215 --- /dev/null +++ b/tests/new/AddObjectOnAbstract.java @@ -0,0 +1,36 @@ + +import org.aspectj.testing.Tester; + +public class AddObjectOnAbstract { + + advice (I1 i1): i1 && String process() { + before { + i1.addA(); + } + } + + public static void main(String[] args) { test(); } + + public static void test() { + AddObjectOnAbstract a = new AddObjectOnAbstract(); + ConcreteC1 c1 = new ConcreteC1(); + a.addObject(c1); + Tester.checkEqual(c1.process(), "ab", ""); + } +} + +abstract class I1 { + public String s = ""; + public abstract void addA(); + public abstract String process(); +} + +class ConcreteC1 extends I1 { + public void addA() { + s += "a"; + } + public String process() { + s += "b"; + return s; + } +}
\ No newline at end of file diff --git a/tests/new/AdviceFormalsCf.java b/tests/new/AdviceFormalsCf.java new file mode 100644 index 000000000..f68540582 --- /dev/null +++ b/tests/new/AdviceFormalsCf.java @@ -0,0 +1,44 @@ +import org.aspectj.testing.Tester; + +/** + * PR#544 the formals passed to advice should behave just like + * any other method formal + */ + +public class AdviceFormalsCf { + public static void main(String[] args) { + Tester.checkEqual(new C().m("bye"), "foo"); + Tester.checkEqual(new C().mi(2.), 1); + } +} + +class C { + public String m(Object p) { + return "foo"; + } + + public int mi(double p) { + return 1; + } +} + + +aspect A { + after(final Object p) returning(final Object o): call(* C.m*(*)) && args(p) { + p = Boolean.TRUE; //ERR: p is final + o = Boolean.TRUE; //ERR: o is final + Tester.checkEqual(p, Boolean.TRUE); + Tester.checkEqual(o, Boolean.TRUE); + } + + Object around(final Object p, final Object o): call(* C.m*(*)) && args(p) && target(o) { + Object ret = proceed(p, o); + p = Boolean.TRUE; //ERR: p is final + o = Boolean.TRUE; //ERR: o is final + Tester.checkEqual(p, Boolean.TRUE); + Tester.checkEqual(o, Boolean.TRUE); + return ret; + } + + +} diff --git a/tests/new/AdviceFormalsCp.java b/tests/new/AdviceFormalsCp.java new file mode 100644 index 000000000..245d7d500 --- /dev/null +++ b/tests/new/AdviceFormalsCp.java @@ -0,0 +1,44 @@ +import org.aspectj.testing.Tester; + +/** + * PR#544 the formals passed to advice should behave just like + * any other method formal + */ + +public class AdviceFormalsCp { + public static void main(String[] args) { + Tester.checkEqual(new C().m("bye"), "foo"); + Tester.checkEqual(new C().mi(2.), 1); + } +} + +class C { + public String m(Object p) { + return "foo"; + } + + public int mi(double p) { + return 1; + } +} + + +aspect A { + after(Object p) returning(Object o): call(* C.m*(*)) && args(p) { + p = Boolean.TRUE; + o = Boolean.TRUE; + Tester.checkEqual(p, Boolean.TRUE); + Tester.checkEqual(o, Boolean.TRUE); + } + + Object around(Object p, Object o): call(* C.m*(*)) && args(p) && target(o) { + Object ret = proceed(p, o); + p = Boolean.TRUE; + o = Boolean.TRUE; + Tester.checkEqual(p, Boolean.TRUE); + Tester.checkEqual(o, Boolean.TRUE); + return ret; + } + + +} diff --git a/tests/new/AdviceOnAdvice.java b/tests/new/AdviceOnAdvice.java new file mode 100644 index 000000000..174e489e3 --- /dev/null +++ b/tests/new/AdviceOnAdvice.java @@ -0,0 +1,42 @@ + +/* + * To test some stuff + */ + +import org.aspectj.testing.*; + +public class AdviceOnAdvice { + public static void main(String[] args) { + new Class1().a(); + Tester.check(Class1.calledB, "Aspect2 did not get advice"); + } +} + +class Class1 { + public void a() { } + public void b() { } + public static boolean calledA = false; + public static boolean calledB = false; +} + + +aspect Aspect1 { + pointcut a(Class1 c1) : + target(c1) && call(public void a()); + + void around(Class1 c1) : a(c1) { + proceed(c1); + c1.b(); + } +} + + +aspect Aspect2b { + + pointcut b() : + call(public void Class1.b()) && within(Aspect1); + + after () : b() { + Class1.calledB = true; + } +} diff --git a/tests/new/AdviceOnAdviceRecursion.java b/tests/new/AdviceOnAdviceRecursion.java new file mode 100644 index 000000000..fe0752d20 --- /dev/null +++ b/tests/new/AdviceOnAdviceRecursion.java @@ -0,0 +1,32 @@ + +import org.aspectj.testing.*; + +/** PR#745 stack overflow expected when advice recurses into itself */ +public class AdviceOnAdviceRecursion { // XXX n-aspect variant? + public static void main (String[] args) { + boolean passed = false; + Throwable ex = null; + try { + C.m(); + } catch (StackOverflowError e) { + passed = true; + } catch (Throwable e) { + ex = e; + } + Tester.check(passed, "expected StackOverflowError, got " + ex); + } +} + +class C { + static void m() { ; } +} + +aspect A { + before() : within(C) || within(B) { + C.m(); + } +} + +aspect B { + before() : call(void m()) { } +} diff --git a/tests/new/AdviceOnEmptyConstructor.java b/tests/new/AdviceOnEmptyConstructor.java new file mode 100644 index 000000000..04b2ed99f --- /dev/null +++ b/tests/new/AdviceOnEmptyConstructor.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; + +public aspect AdviceOnEmptyConstructor { + public static void main(String[] args) { test(); } + + public static void test() { + // C has an implied empty constructor so should be advised + Tester.checkEqual(new C().value, "afterInit:foo", "new C"); + + // C1 has no implied empty constructor (make sure we aren't cheating) + Tester.checkEqual(new C1(0).value, "foo", "new C1"); + } + + /*static*/ after() returning (C c): + //this(c) && + call(C.new()) { + c.value = "afterInit:" + c.value; + } + /*static*/ after() returning(C1 c1): + //this(c1) && + call(C1.new()) { + c1.value = "afterInit:" + c1.value; + } +} + +class C { + public String value = "foo"; +} + +class C1 { + public String value = "foo"; + public C1(int dummy) {} +} diff --git a/tests/new/AdviceOnInheritedMethod.java b/tests/new/AdviceOnInheritedMethod.java new file mode 100644 index 000000000..2733250a3 --- /dev/null +++ b/tests/new/AdviceOnInheritedMethod.java @@ -0,0 +1,64 @@ + +import org.aspectj.testing.Tester; + +import org.aspectj.lang.*; + +public aspect AdviceOnInheritedMethod { + public static void main(String[] args) { test(); } + + public static void test() { + SuperC sc = new SubC(); + Tester.checkEqual(sc.doIt(":foo"), + ":foo:beforeDoIt:inSubC:foo:beforeDoIt1:inSubC:doIt1", + "SubC.doIt"); + Tester.checkEqual(new SuperC().doIt(":foo"), + ":foo:beforeDoIt1:inSuperC:doIt1", + "SuperC.doIt"); + Tester.checkEqual(new SubC().packageDoIt(":foo"), + ":foo:beforePackageDoIt:inSubC:foo", + "SubC.packageDoIt"); + } + + String getTargetName(JoinPoint thisJoinPoint) { + return thisJoinPoint.getTarget().getClass().getName(); + } + + String around(String a): + target(*) && call(String packageDoIt(String)) && args(a) + { + return a+ + ":beforePackageDoIt:in"+getTargetName(thisJoinPoint) + + proceed(a); + } + String around(String a): + target(SubC) && call(String doIt(String)) && args(a) { + return a+ + ":beforeDoIt:in"+getTargetName(thisJoinPoint) + + proceed(a); + } + String around(String a): + target(SuperC) && call(String doIt1(String)) && args(a) { + return a+ + ":beforeDoIt1:in"+getTargetName(thisJoinPoint) + + proceed(a); + } +} + +class SuperC { + public String doIt(String arg) { + return doIt1(arg); + } + protected String doIt1(String arg) { + return ":doIt1"; + } + String packageDoIt(String arg) { + return arg; + } +} + +class SubC extends SuperC { + public String doIt(String arg) { + return super.doIt(arg); + } +} + diff --git a/tests/new/AdviceOnIntroduced.java b/tests/new/AdviceOnIntroduced.java new file mode 100644 index 000000000..4da93f0ca --- /dev/null +++ b/tests/new/AdviceOnIntroduced.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.Tester; + +public aspect AdviceOnIntroduced { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new Foo(10).foo(5), 6, "foo"); + } + + int Foo.foo(int n) { return n; } + Foo.new(int w) {} + + int around(int n): + within(AdviceOnIntroduced) && + (args(n) && execution(int foo(int))) { + int result = proceed(n); + return result+1; + } + + before(): within(Foo) && execution(new(..)) { + //System.out.println("before new"); + } +} + +class Foo { +} diff --git a/tests/new/AdviceOnPrivileged.java b/tests/new/AdviceOnPrivileged.java new file mode 100644 index 000000000..1aa66dc85 --- /dev/null +++ b/tests/new/AdviceOnPrivileged.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; + +public class AdviceOnPrivileged { + public static void main(String[] args) { + C c1 = new C(); + c1.getX(); + + Tester.check(!c1.gotXOutsideC, "normal field access"); + + C c2 = new C(); + ExposeC.getX(c2); + + Tester.check(c2.gotXOutsideC, "privileged field access"); + } +} + +class C { + public boolean gotXOutsideC = false; + + private int x=1; + public int getX() { return x; } +} + +aspect WatchGets { + before(C c): get(int C.x) && target(c) && !within(C) { + System.out.println("got C.x"); + c.gotXOutsideC = true; + } +} + +privileged aspect ExposeC { + public static int getX(C c) { return c.x; } +} diff --git a/tests/new/AdviceOrdering.java b/tests/new/AdviceOrdering.java new file mode 100644 index 000000000..a67dc57c6 --- /dev/null +++ b/tests/new/AdviceOrdering.java @@ -0,0 +1,125 @@ +import org.aspectj.testing.*; + +public class AdviceOrdering { + public static void main(String[] args) { test(); } + + public static void test() { + new C().m(); + T.checkAndReset("before:aroundStart:m:aroundEnd:after:afterReturning"); + + new C().recur(2); + T.checkAndReset("P&&!cflowbelow(P):P:recur-2:P:recur-1:P:recur-0"); + + new C().a(); + T.checkAndReset("C1:C2:C3:C4:A3:A4:A1:A2:B1:a"); + } +} + + +class T { + private static StringBuffer order = new StringBuffer(); + public static void add(String s) { + if (order.length() > 0) { order.append(':'); } + order.append(s); + } + public static void reset() { order = new StringBuffer(); } + + public static void checkAndReset(String expectedValue) { + Tester.checkEqual(order.toString(), expectedValue); + order.setLength(0); + } +} + +class C { + public void m() { T.add("m"); } + public void a() { T.add("a"); } + public void b() { T.add("b"); } + public void c() { T.add("c"); } + + public void recur(int n) { + T.add("recur-"+n); + if (n > 0) recur(n-1); + } +} + +aspect A { + pointcut cut() : target(C) && call(void m()); + + before(): cut() { T.add("before"); } + void around(): cut() { + T.add("aroundStart"); + proceed(); + T.add("aroundEnd"); + } + + after(): cut() { T.add("after"); } + after() returning(): cut() { T.add("afterReturning"); } + +} + +//check that P && !cflow(P) never matches anything regardless of ordering issues +aspect FlowCheck { + pointcut cut() : target(C) && call(void recur(int)); + + before(): cut() && !cflow(cut()) { + // should never run + T.add("P&&!cflow(P)"); + } + before(): cut() && !cflowbelow(cut()) { + // should run once + T.add("P&&!cflowbelow(P)"); + } + + before(): cut() && cflow(cut() && !cflow(cut())) { + // should never run + T.add("cflow(P&&!cflow(P))"); + } + + before(): cut() { + T.add("P"); + } +} + + + +// This cluster of aspects checks that the partial order rules work +//aspect A1 dominates A2, B1 { +aspect A1 { declare dominates: A1, A2 || B1; + pointcut cut() : target(C) && call(void a()); + + before(): A1.cut() { T.add("A1"); } +} + +aspect A2 { declare dominates: A2, B1; + before(): A1.cut() { T.add("A2"); } +} + +aspect A3 { declare dominates: A3, A4, A1; + before(): A1.cut() { T.add("A3"); } +} + +aspect A4 { declare dominates: A4, A1; + before(): A1.cut() { T.add("A4"); } +} + +aspect B1 { + before(): A1.cut() { T.add("B1"); } +} + + + +//aspect C1 dominates C2, C3 { +aspect C1 { declare dominates: C1, C2 || C3; + before(): A1.cut() { T.add("C1"); } +} +aspect C2 { declare dominates: C2, C3; + before(): A1.cut() { T.add("C2"); } +} +aspect C3 { declare dominates: C3, C4; + before(): A1.cut() { T.add("C3"); } +} +//aspect C4 dominates A1, A2, A3, A4, B1 { +aspect C4 { declare dominates: C4, (A1 || A2 || A3 || A4 || B1); + before(): A1.cut() { T.add("C4"); } +} + diff --git a/tests/new/AdviceThrowsCf.java b/tests/new/AdviceThrowsCf.java new file mode 100644 index 000000000..f8564d979 --- /dev/null +++ b/tests/new/AdviceThrowsCf.java @@ -0,0 +1,80 @@ +import org.aspectj.testing.Tester; +import java.io.IOException; + +public class AdviceThrowsCf { + public static void main(String[] args) { + try { + new C().m1(); + Tester.checkFailed("m1"); + } catch (CheckedExc ce) { + Tester.checkEqual("b1", ce.getMessage(), "m1"); + } + try { + new C().m2(); + Tester.checkFailed("m2"); + } catch (UncheckedExc ce) { + Tester.checkEqual("b3", ce.getMessage(), "m2"); + } + try { + new C().m3(); + Tester.checkFailed("m3"); + } catch (CheckedExc ce) { + Tester.checkEqual("b1", ce.getMessage(), "m3"); + } catch (Exception e) { + Tester.checkFailed("IOException"); + System.out.println("m3: " + e); + } + try { + new C().m4(); + Tester.checkFailed("m4"); + } catch (UncheckedExc ce) { + Tester.checkEqual("b3", ce.getMessage(), "m4"); + } + } + + +} + +class CheckedExc extends Exception { + CheckedExc(String m) { super(m); } +} + +class UncheckedExc extends RuntimeException { + UncheckedExc(String m) { super(m); } +} + + +class C { + int x=0; + public void m1() throws CheckedExc { + x += 1; + } + + public void m2() throws UncheckedExc { + } + + public void m3() throws IOException, CheckedExc { + } + + public void m4() { + } +} + +aspect A { + pointcut canThrowChecked(): call(* C.m1()) || call(* C.m3()); + pointcut canThrowChecked1(): call(* C.m*() throws CheckedExc); + + pointcut canThrowUnchecked(): call(* C.m*()); + + + before() throws CheckedExc: canThrowUnchecked() { // ERR: m2 and m4 + throw new CheckedExc("b1"); + } + + before() throws CheckedExc: get(int C.x) { //ERR: all gets + } + before() throws CheckedExc: set(int C.x) { //ERR: all sets + } + before() throws CheckedExc: staticinitialization(C) { //ERR: can't throw + } +} diff --git a/tests/new/AdviceThrowsCp.java b/tests/new/AdviceThrowsCp.java new file mode 100644 index 000000000..40e33f046 --- /dev/null +++ b/tests/new/AdviceThrowsCp.java @@ -0,0 +1,97 @@ +import org.aspectj.testing.Tester; +import java.io.IOException; + +public class AdviceThrowsCp { + public static void main(String[] args) { + try { + new C().m1(); + Tester.checkFailed("m1"); + } catch (CheckedExc ce) { + Tester.checkEqual("b1", ce.getMessage(), "m1"); + } + try { + new C().m2(); + Tester.checkFailed("m2"); + } catch (UncheckedExc ce) { + Tester.checkEqual("b3", ce.getMessage(), "m2"); + } + try { + new C().m3(); + Tester.checkFailed("m3"); + } catch (CheckedExc ce) { + Tester.checkEqual("b1", ce.getMessage(), "m3"); + } catch (Exception e) { + Tester.checkFailed("IOException"); + System.out.println("m3: " + e); + } + try { + new C().m4(); + Tester.checkFailed("m4"); + } catch (UncheckedExc ce) { + Tester.checkEqual("b3", ce.getMessage(), "m4"); + } + } + + +} + +class CheckedExc extends Exception { + CheckedExc(String m) { super(m); } +} + +class UncheckedExc extends RuntimeException { + UncheckedExc(String m) { super(m); } +} + + +class C { + public void m1() throws CheckedExc { + } + + public void m2() throws UncheckedExc { + } + + public void m3() throws IOException, CheckedExc { + } + + public void m4() { + } +} + +aspect A { + pointcut canThrowChecked(): call(* C.m1()) || call(* C.m3()); + pointcut canThrowChecked1(): call(* C.m*() throws CheckedExc); + + pointcut canThrowUnchecked(): call(* C.m*()); + + + before() throws CheckedExc: canThrowChecked() { + throw new CheckedExc("b1"); + } + before() throws CheckedExc: canThrowChecked1() { + throw new CheckedExc("b2"); + } + + before() throws UncheckedExc: canThrowUnchecked() { + throw new UncheckedExc("b3"); + } + + before(): canThrowUnchecked() { + throw new UncheckedExc("b4"); + } + + void around() throws CheckedExc: canThrowChecked() { + throw new CheckedExc("a1"); + } + void around() throws CheckedExc: canThrowChecked1() { + throw new CheckedExc("a2"); + } + + void around() throws UncheckedExc: canThrowUnchecked() { + throw new UncheckedExc("a3"); + } + + void around(): canThrowUnchecked() { + throw new UncheckedExc("a4"); + } +} diff --git a/tests/new/AfterAdviceOnConstructorsOnTheWrongType.java b/tests/new/AfterAdviceOnConstructorsOnTheWrongType.java new file mode 100644 index 000000000..e29ee974a --- /dev/null +++ b/tests/new/AfterAdviceOnConstructorsOnTheWrongType.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; +public class AfterAdviceOnConstructorsOnTheWrongType { + public static void main(String[] args) { + new AfterAdviceOnConstructorsOnTheWrongType().realMain(args); + } + public void realMain(String[] args) { + new C().c(); + new D().d(); + Tester.checkAllEvents(); + } + static { + Tester.clearEvents(); + // new(..) for both class and interface + Tester.expectEventsInString("after-c,after-c,c,after-d,after-d,d"); + } +} + +interface I {} +class C implements I { public void c() { Tester.event("c"); } } +class D implements I { public void d() { Tester.event("d"); } } + +aspect A { + after(C c): target(c) && execution(new(..)) { + Tester.event("after-c"); + } + after(D d): target(d) && execution(new(..)) { + Tester.event("after-d"); + } +} diff --git a/tests/new/AfterConstructorCalls.java b/tests/new/AfterConstructorCalls.java new file mode 100644 index 000000000..80f5dcb62 --- /dev/null +++ b/tests/new/AfterConstructorCalls.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +public class AfterConstructorCalls { + public static void main(String[] args) { + new Foo().bar(); + } +} + +class Foo { + int bar() { return 0; } +} + +aspect A { + pointcut nimboCut() : + call(Foo.new(..)); + + /*static*/ after() returning (Object o): nimboCut() { + Tester.check(o != null && o instanceof Foo, o + " !instanceof Foo"); + } + + /*static*/ after() returning (int i): call(int Foo.*(..)) { + Tester.checkEqual(i, 0); + } +} diff --git a/tests/new/AfterFinally.java b/tests/new/AfterFinally.java new file mode 100644 index 000000000..aec60fbe8 --- /dev/null +++ b/tests/new/AfterFinally.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; + +import java.util.*; + +public class AfterFinally { + public static void main(String[] args) { + new AfterFinally().m("hi"); + } + + private String getX() { return "X"; } + + public Collection m(String key) { + String x = null; + ArrayList y = new ArrayList(); + Iterator i = null; + try { + x = this.getX(); + Collection personList = new ArrayList(); + + y.add("foo"); + //prepStmt.setString(1, name); + i = y.iterator(); + + while (i.hasNext()) { + personList.add(new String(i.next() + " foo")); + } + return personList; + } catch (Exception e) { + throw new RuntimeException("bad:" + e); + } finally { + x.toString(); + y.toString(); + i.toString(); + } + } +} + + +aspect A { + before(): execution(* *(..)) && within(AfterFinally) { + System.out.println(thisJoinPoint); + } + after(): execution(* *(..)) && within(AfterFinally) { + System.out.println(thisJoinPoint); + } +} diff --git a/tests/new/AfterReturningConstructor.java b/tests/new/AfterReturningConstructor.java new file mode 100644 index 000000000..8e70b0eca --- /dev/null +++ b/tests/new/AfterReturningConstructor.java @@ -0,0 +1,60 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#827 after returning advice on interface and implementation constructor */ +public class AfterReturningConstructor { + public static void main(String[] args) { + U.ee(U.before + U.ijp); + U.ee(U.afterReturning + U.ijp); + U.ee(U.before + U.cjp); + U.ee(U.c); + U.ee(U.afterReturning + U.cjp); + U.ee("done"); + new C(); + U.e("done"); + Tester.checkAllEvents(); + } +} + +class C implements I { + C() { U.e("C()"); } + public void run() { } +} + +interface I { + void run(); +} + +class U { + static final String before = "before(): "; + static final String after = "after(): "; + static final String afterReturning = "after() returning(): "; + static final String afterThrowing = "after() throwing(): "; + static final String c = "C()"; + static final String i = "I()"; + static final String cjp = "execution(" + c + ")"; + static final String ijp = "execution(" + i + ")"; + + static void e(String event) { + //System.err.println("act event: " + event); // XXX + Tester.event(event); + } + static void ee(String event) { + //System.err.println("exp event: " + event); // XXX + Tester.expectEvent(event); + } +} + +aspect A { + /** must pick out both interface and implementor constructor execution */ + pointcut pc(): execution(new(..)); + + before(): pc() { + U.e(U.before + thisJoinPoint); + } + + after() returning(): pc() { + U.e(U.afterReturning + thisJoinPoint); + } +} + diff --git a/tests/new/AfterReturningHandler.java b/tests/new/AfterReturningHandler.java new file mode 100644 index 000000000..d6ba60bdc --- /dev/null +++ b/tests/new/AfterReturningHandler.java @@ -0,0 +1,60 @@ +import org.aspectj.testing.Tester; + +public class AfterReturningHandler { + public static void main(String[] args) { + + AfterReturningHandler p = new AfterReturningHandler(); + p.mIntThrowing(); + Tester.checkAndClearEvents(new String[] {"returned null" }); // will probably say "returned null" for all below + p.mVoidThrowing(); + Tester.checkAndClearEvents(new String[] { }); + p.mIntThrowingReturning(); + Tester.checkAndClearEvents(new String[] { }); + p.mVoidThrowingReturning(); + Tester.checkAndClearEvents(new String[] { }); + + + + } + + public void mVoidThrowing() { + try { throw new RuntimeException(); } + catch (RuntimeException e) { + } + } + + public int mIntThrowing() { + try { throw new RuntimeException(); } + catch (RuntimeException e) { + } + return 3; + } + public void mVoidThrowingReturning() { + try { throw new RuntimeException(); } + catch (RuntimeException e) { + return; + } + } + + public int mIntThrowingReturning() { + try { if (true) throw new RuntimeException(); } + catch (RuntimeException e) { + return 3; + } + return 999999; + } + + AfterReturningHandler() { + } +} + + +aspect A { + private void callEvent(String s, Object o) { + Tester.event(s + " " + o); + } + + after() returning (Object o) : handler(RuntimeException) { + callEvent("returned ", o); + } +} diff --git a/tests/new/AfterReturningInterfaceConstructor.java b/tests/new/AfterReturningInterfaceConstructor.java new file mode 100644 index 000000000..71e851867 --- /dev/null +++ b/tests/new/AfterReturningInterfaceConstructor.java @@ -0,0 +1,30 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#889 after returning advice on interface constructor */ +public class AfterReturningInterfaceConstructor { + public static void main (String[] args) { + Tester.expectEvent("constructor"); + Tester.expectEvent("advice"); + new C(); + Tester.checkAllEvents(); + } +} + +interface I {} + +class C implements I { + C() { + Tester.event("constructor"); + } +} + +aspect A { + int I.i; + I.new() { + i = 2; + } + after() returning: execution(I.new()) { + Tester.event("advice"); + } +} diff --git a/tests/new/AfterReturningParam.java b/tests/new/AfterReturningParam.java new file mode 100644 index 000000000..4010bf058 --- /dev/null +++ b/tests/new/AfterReturningParam.java @@ -0,0 +1,68 @@ +import org.aspectj.testing.Tester; + +public class AfterReturningParam { + public static void main(String[] args) { + + AfterReturningParam p = new AfterReturningParam(); + Tester.checkAndClearEvents(new String[] { "constr exec as Object null" }); + + p.mInt(); + Tester.checkAndClearEvents(new String[] { "int as Object 2" }); + + p.mObject(); + Tester.checkAndClearEvents(new String[] { "Object as Object ning", + "Object (that is String) as String ning" }); + + p.mVoid(); + Tester.checkAndClearEvents(new String[] { "void as Object null" }); + + } + + public int mInt() { return 2; } + public Object mObject() { return "ning"; } + public void mVoid() { return; } + + AfterReturningParam() { + } +} + + +aspect A { + private void callEvent(String s, Object o) { + Tester.event(s + " " + o); + } + + after() returning (AfterReturningParam o) : execution(AfterReturningParam.new()) { // CW 35 in 1.0.4, no match + callEvent("constr exec as constd object", o); + } + after() returning (Object o) : execution(AfterReturningParam.new()) { // CW 38 in 1.0.4, does match + callEvent("constr exec as Object", o); + } + after() returning (String o) : execution(AfterReturningParam.new()) { // CW 41 in 1.0.4, no match + callEvent("constr exec as String", o); + } + + after() returning (Object o) : execution(int AfterReturningParam.mInt()) { // match + callEvent("int as Object", o); + } + after() returning (String o) : execution(int AfterReturningParam.mInt()) { // no match + callEvent("int as String", o); + } + after() returning (Integer o) : execution(int AfterReturningParam.mInt()) { // no match + callEvent("int as Integer", o); + } + + after() returning (Object o) : execution(Object AfterReturningParam.mObject()) { // match + callEvent("Object as Object", o); + } + after() returning (String o) : execution(Object AfterReturningParam.mObject()) { // match (interesting, matching by instanceof) + callEvent("Object (that is String) as String", o); + } + + after() returning (Object o) : execution(void AfterReturningParam.mVoid()) { // match + callEvent("void as Object", o); + } + after() returning (String o) : execution(void AfterReturningParam.mVoid()) { // CW 65 warning in 1.0.4 no match + callEvent("void as String", o); + } +} diff --git a/tests/new/AfterReturningResult.java b/tests/new/AfterReturningResult.java new file mode 100644 index 000000000..6d963cd64 --- /dev/null +++ b/tests/new/AfterReturningResult.java @@ -0,0 +1,32 @@ +public class AfterReturningResult { + public static void main (String[] args) { + new CFCommandProcessor().run(); + } +} + +class CFCommand { + void handleResponse() {} + void updateCache() { System.err.println("updating cache");} } + +class CFCommandProcessor { + public void run() { + new CFCommand().handleResponse(); + } +} + +aspect A { + pointcut response(CFCommand cmd) : within(CFCommandProcessor) && + target(cmd) && + call(void CFCommand.handleResponse (..)); + + after(CFCommand cmd) returning: response(cmd) { + cmd.updateCache(); + } +} + + +aspect B { + Object around(): execution(void run()) { + return proceed(); + } +} diff --git a/tests/new/AfterThrowing.java b/tests/new/AfterThrowing.java new file mode 100644 index 000000000..69e5306a7 --- /dev/null +++ b/tests/new/AfterThrowing.java @@ -0,0 +1,92 @@ +import org.aspectj.testing.Tester; + +import java.util.*; + +public class AfterThrowing { + public static void main(String[] args) { test(); } + + public static void test() { + throwException(true); + Tester.check("Throwable:throwException"); + Tester.check("Exception:throwException"); + + throwRuntimeException(true); + Tester.check("Throwable:throwRuntimeException"); + Tester.check("RuntimeException:throwRuntimeException"); + + throwError(true); + Tester.check("Throwable:throwError"); + + throwMyException(true); + Tester.check("Throwable:throwMyException"); + Tester.check("Exception:throwMyException"); + Tester.check("MyException:throwMyException"); + } + + static void throwNothing(boolean b) { } + + static void throwException(boolean b) throws Exception { + if (b) throw new Exception(); + throwError(false); + } + + static void throwRuntimeException(boolean b) { + if (b) throw new RuntimeException(); + } + + static String throwError(boolean b) { + int[] i = new int[10]; + // this line is to make sure ajc doesn't think it needs to worry about a + // CloneNotSupportedException when arrays are cloned + i = (int[])i.clone(); + + if (b) throw new Error(); + return "foo"; + } + + static Object throwMyException(boolean b) throws MyException { + if (b) throw new MyException(); + return new Integer(10); + } + + public static class MyException extends Exception { } +} + + +aspect A { + pointcut throwerCut(): within(AfterThrowing) && execution(* *(boolean)); + + + after () throwing (Throwable t): throwerCut() { + Tester.note("Throwable:" + thisJoinPointStaticPart.getSignature().getName()); + } + + after () throwing (Exception t): throwerCut() { + Tester.note("Exception:" + thisJoinPoint.getSignature().getName()); + } + + after () throwing (RuntimeException t): throwerCut() { + Tester.note("RuntimeException:" + thisJoinPointStaticPart.getSignature().getName()); + } + + after () throwing (AfterThrowing.MyException t): throwerCut() { + Tester.note("MyException:" + thisJoinPoint.getSignature().getName()); + } + + pointcut catchThrowsFrom(): + within(AfterThrowing) && call(* AfterThrowing.*(boolean)); + + + declare soft: Throwable: catchThrowsFrom(); + + Object around(): catchThrowsFrom() { + try { + return proceed(); + } catch (Throwable t) { + //System.out.println("caught " + t); + return null; + } + } +} + + diff --git a/tests/new/AfterThrowingNonThrowable.java b/tests/new/AfterThrowingNonThrowable.java new file mode 100644 index 000000000..108d2cd7a --- /dev/null +++ b/tests/new/AfterThrowingNonThrowable.java @@ -0,0 +1,44 @@ + +import org.aspectj.testing.Tester; +import java.util.*; + +/** @testcase PR#832 after throwing advice with non-throwable formal */ +public class AfterThrowingNonThrowable { + + public static void main(String[] args) { + U.ee("after() throwing (Object o) : call(void C.run())"); + U.ee("run()"); + C c = new C(); + boolean gotError = false; + try { + c.run(); + } catch (Error e) { + gotError = true; + } + Tester.check(gotError, "failed to get error"); + Tester.checkAllEvents(); + } +} + +class C { + public void run() { + U.e("run()"); + throw new Error(""); + } +} + +class U { + static void e(String event) { + //System.err.println(event); + Tester.event(event); + } + static void ee(String event) { + Tester.expectEvent(event); + } +} + +aspect A { + after() throwing (Object o) : call(void C.run()) { + U.e("after() throwing (Object o) : call(void C.run())"); + } +} diff --git a/tests/new/AfterThrowingNotWoven.java b/tests/new/AfterThrowingNotWoven.java new file mode 100644 index 000000000..4b583e890 --- /dev/null +++ b/tests/new/AfterThrowingNotWoven.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.*; + +public class AfterThrowingNotWoven { + public static void main(String[] args) { + try { + new Server().doSomething(); + } catch (FaultException fe) { + Tester.event("caught-in-main"); + } + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("caught"); + Tester.expectEvent("caught-in-main"); + } +} + +class Server { + public void doSomething() { + System.out.println("Doing something."); + throw new FaultException(); + } +} + +class DisabledException extends RuntimeException {} +class FaultException extends RuntimeException {} + +aspect FaultHandler { + + private boolean Server.disabled = false; + + private void reportFault() { + System.out.println("Failure! Please fix it."); + } + + public static void fixServer(Server s) { + s.disabled = false; + } + + pointcut service(Server s): target(s) && call(public * *(..)); + + before(Server s): service(s) { + if (s.disabled) throw new DisabledException(); + } + + after(Server s) throwing (FaultException e): service(s) { + s.disabled = true; + Tester.event("caught"); + } +} diff --git a/tests/new/AmbiguousClassReference.java b/tests/new/AmbiguousClassReference.java new file mode 100644 index 000000000..5b34f57fe --- /dev/null +++ b/tests/new/AmbiguousClassReference.java @@ -0,0 +1,15 @@ +import java.sql.*; +import java.lang.reflect.*; + +/** support mail from Dave Trombley */ +public class AmbiguousClassReference { + + /** @testcase PR#631 PUREJAVA expecting CE for ambiguous reference */ + public static void main(String[] args) { + int[] gh; + gh = new int[5]; + Array.getLength(gh); + throw new Error("Expecting compiler error, not compile/run"); + } +} + diff --git a/tests/new/AmbiguousClassReference2CE.java b/tests/new/AmbiguousClassReference2CE.java new file mode 100644 index 000000000..5c1884226 --- /dev/null +++ b/tests/new/AmbiguousClassReference2CE.java @@ -0,0 +1,14 @@ +import java.sql.Array; +import java.lang.reflect.Array; // ERR: importing same name different types + +public class AmbiguousClassReference2CE { + + /** @testcase PR#701 PUREJAVA CE for ambiguous type reference (imports) + * see also testcase PR#631 */ + public static void main(String[] args) { + int[] gh = new int[5]; + Array.getLength(gh); // bug: expect ~ambiguous~ not "no method getLength..." + throw new Error("Expecting compiler error, not compile/run"); + } +} + diff --git a/tests/new/AmbiguousClassReference3CE.java b/tests/new/AmbiguousClassReference3CE.java new file mode 100644 index 000000000..35c5f95ff --- /dev/null +++ b/tests/new/AmbiguousClassReference3CE.java @@ -0,0 +1,14 @@ +public class AmbiguousClassReference3CE { + + /** @testcase PR#701 PUREJAVA CE for ambiguous type reference (two type declarations) + * see also testcase PR#631 */ + public static void main(String[] args) { + throw new Error("Expecting compiler error, not compile/run"); + } +} +class Foo {} // expect: "duplicate type name" +interface Foo {} // expect: "duplicate type name" +class Bar { + Foo f; +} + diff --git a/tests/new/AmbiguousClassReference4CE.java b/tests/new/AmbiguousClassReference4CE.java new file mode 100644 index 000000000..f37f5155d --- /dev/null +++ b/tests/new/AmbiguousClassReference4CE.java @@ -0,0 +1,12 @@ + +public class AmbiguousClassReference4CE { + + /** @testcase PR#701 PUREJAVA CE for ambiguous type reference (two inner types) + * see also testcase PR#631 */ + public static void main(String[] args) { + throw new Error("Expecting compiler error, not compile/run"); + } + static class Foo {} // CE: "duplicate type name" + static interface Foo {} // CE: "duplicate type name" +} + diff --git a/tests/new/AnonymousClassName.java b/tests/new/AnonymousClassName.java new file mode 100644 index 000000000..e3a894876 --- /dev/null +++ b/tests/new/AnonymousClassName.java @@ -0,0 +1,79 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +/** @testcase declaring type in signature of anonymous class */ +public class AnonymousClassName { + public static void main(String[] args) { + Tester.expectEvent("run()"); + new Runnable(){ + public void run() { + Tester.event("run()"); + } + }.run(); + Tester.checkAllEvents(); + } +} + +aspect A { + static { + Tester.expectEvent("before constructRunnable"); + Tester.expectEvent("before callRun"); + Tester.expectEvent("before executeRun"); + Tester.expectEvent("before initRunnable"); + Tester.expectEvent("around constructRunnable"); + Tester.expectEvent("around callRun"); + Tester.expectEvent("around executeRun"); + Tester.expectEvent("around initRunnable"); + Tester.expectEvent("after constructRunnable"); + Tester.expectEvent("after callRun"); + Tester.expectEvent("after executeRun"); + Tester.expectEvent("after initRunnable"); + } + static final int Runnable+.provokeStaticInit = 1; + + pointcut constructRunnable () : call(Runnable+.new()); + pointcut initRunnable () : staticinitialization(Runnable+); + pointcut callRun () : target(Runnable) && call(void run()); + pointcut executeRun () : target(Runnable) && execution(void run()); + before () : constructRunnable() { check("before constructRunnable", thisJoinPoint); } + before () : callRun() { check("before callRun", thisJoinPoint); } + before () : executeRun() { check("before executeRun", thisJoinPoint); } + before () : initRunnable() { check("before initRunnable", thisJoinPoint); } + Object around () : constructRunnable() { + check("around constructRunnable", thisJoinPoint); + return proceed(); + } + Object around () : callRun() { + check("around callRun", thisJoinPoint); + return proceed(); + } + Object around () : executeRun() { + check("around executeRun", thisJoinPoint); + return proceed(); + } + Object around () : initRunnable() { + check("around initRunnable", thisJoinPoint); + return proceed(); + } + + after () : constructRunnable() { check("after constructRunnable", thisJoinPoint); } + after () : callRun() { check("after callRun", thisJoinPoint); } + after () : executeRun() { check("after executeRun", thisJoinPoint); } + after () : initRunnable() { check("after initRunnable", thisJoinPoint); } + + void check(String event, JoinPoint jp) { + Tester.event(event); + //System.err.println(event + ": " + jp.toLongString()); + Signature sig = jp.getSignature(); + Class c = sig.getDeclaringType(); + Tester.check(null != c, event + " null class"); + Tester.check(ClassNotFoundException.class != c, + event + " got: " + c); + String name = "" + sig; + Tester.check(-1 != name.indexOf("AnonymousClassName"), + event + " expecting AnonymousClassName..: " + name); + } +} + diff --git a/tests/new/AnonymousSelfReference.java b/tests/new/AnonymousSelfReference.java new file mode 100644 index 000000000..5a910622f --- /dev/null +++ b/tests/new/AnonymousSelfReference.java @@ -0,0 +1,23 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#774 interface self-reference by anonymous instance */ +public class AnonymousSelfReference { + public static void main (String[] args) { + Tester.expectEvent("run"); + Tester.expectEvent("im"); + I it = new I() { public void im() { Tester.event("im");} }; + it.runnable.run(); + Tester.checkAllEvents(); + } +} + +interface I { public void im(); } + +aspect A { + Runnable I.runnable = new Runnable() { + public void run() { + im(); // comment out to avoid VerifyError + Tester.event("run"); + } + }; +} diff --git a/tests/new/ArgsAlone.java b/tests/new/ArgsAlone.java new file mode 100644 index 000000000..89b3736d6 --- /dev/null +++ b/tests/new/ArgsAlone.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.Tester; + +public class ArgsAlone { + public static void main(String[] args) { + Tester.expectEvent("within 2 method-call"); + Tester.expectEvent("within 2 method-execution"); + new TargetClass().callInt(2); + Tester.checkAllEvents(); + } +} + +class TargetClass { + void callInt(int i) { + while (i > 0) { --i; } + } + +} + +aspect Aspect { + pointcut pc () + : (call(void TargetClass.callInt(int)) + || execution(void TargetClass.callInt(int))); + + before(int i) + : !target(Aspect) && args(i) + //&& pc() // uncomment to avoid InternalCompilerError + { + Tester.event("within " + i + + " " + thisJoinPointStaticPart.getKind()); + } +} diff --git a/tests/new/ArgsInCflow.java b/tests/new/ArgsInCflow.java new file mode 100644 index 000000000..2ee5c7e3a --- /dev/null +++ b/tests/new/ArgsInCflow.java @@ -0,0 +1,35 @@ + +import org.aspectj.testing.*; + +/** PR#659 name binding in around cflow containing cflowbelow */ +public class ArgsInCflow { + public static void main(String[] args) { + Tester.check(6==fact(3), "6==fact(3)"); + Tester.checkAllEvents(); + } + + static int fact(int x) { + if (x<0) x = -x; + if (x==0) return 1; + else return x*fact(x-1); + } + static { + Tester.expectEvent("3-2"); + Tester.expectEvent("3-1"); + Tester.expectEvent("3-0"); + } +} + +aspect Test { + + // picks any calls to fact. + pointcut factCall(int n) : call(int fact(int)) && args(n); + + // picks parameter to the first and current fact calls + before(int n, int firstN, int dummy) : + factCall(n) + && cflow(factCall(firstN) + && !cflowbelow(factCall(dummy))) { + Tester.event(firstN + "-" + n); + } +} diff --git a/tests/new/ArgsInCflow2.java b/tests/new/ArgsInCflow2.java new file mode 100644 index 000000000..a2ddf1eb8 --- /dev/null +++ b/tests/new/ArgsInCflow2.java @@ -0,0 +1,25 @@ + +import org.aspectj.testing.*; + +/** PR#660 name binding in around cflow */ +public class ArgsInCflow2 { + public static void main(String[] args) { + Tester.check(3==foo(1), "3==foo(1)"); + Tester.checkAllEvents(); + } + static int foo(int x) {return bar(x+1);} + static int bar(int x) {return x+1;} + + static { + Tester.expectEvent("1-2"); + } +} + +aspect Test { + int around(final int x, final int y) : + cflow(call(int foo(int)) && args(x)) + && call(int bar(int)) && args(y) { + Tester.event(x + "-" + y); + return proceed(x,y); + } +} diff --git a/tests/new/ArgsInCflowCf.java b/tests/new/ArgsInCflowCf.java new file mode 100644 index 000000000..21ec256b6 --- /dev/null +++ b/tests/new/ArgsInCflowCf.java @@ -0,0 +1,37 @@ + +import org.aspectj.testing.*; + +/** PR#660 name binding in around cflow */ +public class ArgsInCflowCf { + public static void main(String[] args) { + Tester.check(3==foo(1), "3==foo(1)"); + Tester.checkAllEvents(); + } + static int foo(int x) {return bar(x+1);} + static int bar(int x) {return x+1;} + + static { + Tester.expectEvent("1-2"); + } +} + +aspect Test { + int around(int x, int y) : // ERR not final + cflow(call(int foo(int)) && args(x)) + && call(int bar(int)) && args(y) { + Tester.event(x + "-" + y); + return proceed(x,y); + } + int around(final int x, int y) : + cflow(call(int foo(int)) && args(x)) + && call(int bar(int)) && args(y) { + Tester.event(x + "-" + y); + return proceed(y,y); // ERR simple refs + } + int around(final int x, int y) : + cflow(call(int foo(int)) && args(x)) + && call(int bar(int)) && args(y) { + Tester.event(x + "-" + y); + return proceed(x+1,y+1); // ERR simple refs + } +} diff --git a/tests/new/AroundAdvice.java b/tests/new/AroundAdvice.java new file mode 100644 index 000000000..bc6778326 --- /dev/null +++ b/tests/new/AroundAdvice.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.Tester; + +public aspect AroundAdvice { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new Foo().foo(5), 1+2+3+4+5, "sum"); + Tester.checkEqual(new Foo().bar(), "overridden", "bar()"); + } + + pointcut fooCut(int n): target(Foo) && call(int foo(int)) && args(n); + + int around(int n): fooCut(n) { + int N = n; + int sum = 0; + for(int i=0; i<N; i++) { + n = i; + int ret = proceed(n); + sum += ret; + } + return sum; + } + + String around(): within(AroundAdvice) && call(String bar()) { + return "overridden"; + } +} + +class Foo { + public int foo(int x) { + //System.out.println("foo("+x+")"); + return x+1; + } + public String bar() { + return "bar()"; + } +} diff --git a/tests/new/AroundAdviceOnMethodsCalledInAroundAdvice.java b/tests/new/AroundAdviceOnMethodsCalledInAroundAdvice.java new file mode 100644 index 000000000..1068d9159 --- /dev/null +++ b/tests/new/AroundAdviceOnMethodsCalledInAroundAdvice.java @@ -0,0 +1,150 @@ +import org.aspectj.testing.Tester; + +public class AroundAdviceOnMethodsCalledInAroundAdvice { + public static void main(String[] args) { + new AroundAdviceOnMethodsCalledInAroundAdvice().realMain(args); + } + public void realMain(String[] args) { + Expect.expect(); + new C().g(); + new C().f("AroundMetaJoinpoints.realMain"); + new C("C.package.constructor"); + new C(123); + new D().g(); + new D("D.package.constructor"); + new D(123); + Tester.checkAllEvents(); + } +} + + + +aspect A { + + Object around(): call(public Object f(String)) { + jp(thisJoinPoint); + return proceed(); + } + + private void jp (Object join) {} + + void around(): call(* jp(..)) { + proceed(); + } + +} + +class D { + Object o = new C().f("D.o"); + public D() { new C().f("D.public.constructor"); } + D(String f) { new C().f(f); } + protected D(int i) { new C().f("D.protected.constructor"); } + private D(Integer i) { new C().f("D.private.constructor"); } + { new C().f("D.init"); } + static { + new D(new Integer(123)); + new C().f("D.static"); + } + public void g() { + Tester.event("D.g"); + new C().f("D.g"); + } +} + +class C { + public C() { f("C.public.constructor"); } + C(String f) { f(f); } + protected C(int i) { f("C.protected.constructor"); } + private C(Integer i) { f("C.private.constructor"); } + Object o = f("C.o"); + static { new C(new Integer(123)).f("C.static"); } + { f("C.init"); } + public void g() { + Tester.event("C.g"); + f("C.g"); + } + public Object f(String f) { + Tester.event("C.f-"+f); + return null; + } +} +class Expect { + static void expect() { + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.private.constructor"); + Tester.expectEvent("C.f-C.static"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.g"); + Tester.expectEvent("C.f-C.g"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-AroundMetaJoinpoints.realMain"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.package.constructor"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.protected.constructor"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.o"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.init"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.private.constructor"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.static"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.o"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.init"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.public.constructor"); + Tester.expectEvent("D.g"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.g"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.o"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.init"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.package.constructor"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.o"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.init"); + Tester.expectEvent("C.f-C.o"); + Tester.expectEvent("C.f-C.init"); + Tester.expectEvent("C.f-C.public.constructor"); + Tester.expectEvent("C.f-D.protected.constructor"); + } +} diff --git a/tests/new/AroundAll.java b/tests/new/AroundAll.java new file mode 100644 index 000000000..48d1263c8 --- /dev/null +++ b/tests/new/AroundAll.java @@ -0,0 +1,165 @@ +import java.util.*; +import org.aspectj.testing.Tester; + +public class AroundAll { + public static void main(String[] args) { + new C(); + new C("9"); + //A.printLog(); + A.checkLog(); + } +} + +class C extends SuperC { + static final int i; + final int x; + + int y = 42; + + static { + i = 23; + } + + C(String s) { + this(Integer.valueOf(s).intValue()); + A.log("C(" + s + ")"); + A.log("y = " + y); + } + + C(int i) { + super(i); + x = i; + i = i+1; + //System.out.println(i + 1); + A.log("x = " + x); + } + + C() { + this("2"); + A.log("C()"); + } +} + +class SuperC { + SuperC(int x) { + A.log("SuperC(" + x + ")"); + } +} + +aspect A { + static String[] expectedSteps = new String[] { + "enter staticinitialization(AroundAll.<clinit>)", + "exit staticinitialization(AroundAll.<clinit>)", + "enter execution(void AroundAll.main(String[]))", + "enter call(C())", + "enter staticinitialization(SuperC.<clinit>)", + "exit staticinitialization(SuperC.<clinit>)", + "enter staticinitialization(C.<clinit>)", + "enter set(int C.i)", + "exit set(int C.i)", + "exit staticinitialization(C.<clinit>)", + "enter call(Integer java.lang.Integer.valueOf(String))", + "exit call(Integer java.lang.Integer.valueOf(String))", + "enter call(int java.lang.Integer.intValue())", + "exit call(int java.lang.Integer.intValue())", + "enter initialization(SuperC(int))", + "enter execution(SuperC.<init>)", + "exit execution(SuperC.<init>)", + "enter execution(SuperC(int))", + "SuperC(2)", + "exit execution(SuperC(int))", + "exit initialization(SuperC(int))", + "enter initialization(C())", + "enter execution(C.<init>)", + "enter set(int C.y)", + "exit set(int C.y)", + "exit execution(C.<init>)", + "enter execution(C(int))", + "enter set(int C.x)", + "exit set(int C.x)", + "enter get(int C.x)", + "exit get(int C.x)", + "x = 2", + "exit execution(C(int))", + "enter execution(C(String))", + "C(2)", + "enter get(int C.y)", + "exit get(int C.y)", + "y = 42", + "exit execution(C(String))", + "exit initialization(C())", + "enter execution(C())", + "C()", + "exit execution(C())", + "exit call(C())", + "enter call(C(String))", + "enter call(Integer java.lang.Integer.valueOf(String))", + "exit call(Integer java.lang.Integer.valueOf(String))", + "enter call(int java.lang.Integer.intValue())", + "exit call(int java.lang.Integer.intValue())", + "enter initialization(SuperC(int))", + "enter execution(SuperC.<init>)", + "exit execution(SuperC.<init>)", + "enter execution(SuperC(int))", + "SuperC(9)", + "exit execution(SuperC(int))", + "exit initialization(SuperC(int))", + "C.new(9)", + "enter initialization(C(String))", + "enter execution(C.<init>)", + "enter set(int C.y)", + "exit set(int C.y)", + "exit execution(C.<init>)", + "enter execution(C(int))", + "enter set(int C.x)", + "exit set(int C.x)", + "enter get(int C.x)", + "exit get(int C.x)", + "x = 9", + "exit execution(C(int))", + "enter execution(C(String))", + "C(91)", + "enter get(int C.y)", + "exit get(int C.y)", + "y = 42", + "exit execution(C(String))", + "exit initialization(C(String))", + "exit call(C(String))", + }; + + static List logList = new ArrayList(); + + static void printLog() { + for (Iterator i = logList.iterator(); i.hasNext(); ) { + System.out.println(" \"" + i.next() + "\", "); + } + } + + static void checkLog() { + Tester.checkEqual(expectedSteps, A.logList.toArray(), "steps"); + Tester.checkEqual(A.logList, expectedSteps, "steps"); + } + + static void log(String s) { + logList.add(s); + } + + static boolean test() { return true; } + + //before(): initialization(C.new(String)) { } + + void around(String s): initialization(C.new(String)) && args(s) && if(s.equals("9")) { + log("C.new(9)"); + proceed(s+"1"); + } + + Object around(): //initialization(C.new(String)) { + if(test()) && !within(A) && !call(* A.*(..)) { + A.log("enter " + thisJoinPoint); + Object ret = proceed(); + A.log("exit " + thisJoinPoint); + //proceed(); + //System.err.println("run twice"); + return ret; + } +} diff --git a/tests/new/AroundAndCalls.java b/tests/new/AroundAndCalls.java new file mode 100644 index 000000000..2b77e8e4c --- /dev/null +++ b/tests/new/AroundAndCalls.java @@ -0,0 +1,30 @@ +import org.aspectj.testing.Tester; + +public class AroundAndCalls { + public static void main(String[] args) { + Tester.checkEqual(new CL().go(), "basic-advised"); + } +} + +aspect MustAspect /*of eachobject(instanceof(CL))*/ { + + pointcut parseCalls(CP cp, String cmd): + (args(cmd) && target(cp) && call(String CP.parse(String))) && + within(CL); + + String around(CP cp, String cmd): parseCalls(cp, cmd) { + return proceed(cp, cmd + "-advised"); + } +} + +class CL { + String go() { + return new CP().parse("basic"); + } +} + +class CP { + String parse(String cmd) { + return cmd; + } +} diff --git a/tests/new/AroundCall.java b/tests/new/AroundCall.java new file mode 100644 index 000000000..1a6905493 --- /dev/null +++ b/tests/new/AroundCall.java @@ -0,0 +1,28 @@ +import org.aspectj.testing.*; + +public class AroundCall { + void a(int nullm) { b(); } + void b() { + Tester.check(false, "around failed"); + } + + public static void main(String[] args) { + AroundCall t = new AroundCall(); + t.a(42); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("around"); + } +} + +aspect TestAspect { + /** @testcase PR#666 name binding in around cflow */ + void around(final int n) : // no bug if before advice + cflow(execution(void AroundCall.a(int)) && args(n)) // no bug if no args + && target(AroundCall) + { + Tester.event("around"); + if (n > 100) proceed(n); // some bugs hidden without call to proceed + } +} diff --git a/tests/new/AroundCalls.java b/tests/new/AroundCalls.java new file mode 100644 index 000000000..0dd2960e1 --- /dev/null +++ b/tests/new/AroundCalls.java @@ -0,0 +1,42 @@ +import org.aspectj.testing.Tester; + +public class AroundCalls { + public static void main(String[] args) { test(); } + + public static void test() { + //Tester.checkEqual(new C().m(), "abc:2", "many arounds"); + Tester.checkEqual(new C().m(), "acb:2", "many arounds"); + } +} + +class C { + public String m() { + return new D().m1("a", 0); + } +} + +class D { + public String m1(String s, int x) { return s + ":" + x; } +} + +aspect A { + String around(D d, String as, int ax): + call(String D.m1(String,int)) && + args(as,ax) && + target(d) + //receptions(String d.m1(as, ax)) + + { + //System.out.println(as + " : " + d + " : " + ax); + return proceed(d, as + "c", ax + 1); + } + + String around(String as/*, C c1*/, D d1, int ax): + within(C) && + target(d1) && call(String m1(String,int)) && args(as,ax) + //instanceof(c1) && callsto(instanceof(d1) && receptions(String m1(as, ax))) + { + //System.out.println(as + " : " + c1 + " : " + d1 + " : " + ax); + return proceed(as + "b", /*c1,*/ d1, ax + 1); + } +} diff --git a/tests/new/AroundCallsArgs.java b/tests/new/AroundCallsArgs.java new file mode 100644 index 000000000..6056a59ac --- /dev/null +++ b/tests/new/AroundCallsArgs.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; + +public class AroundCallsArgs { + public static void main(String[] args) { + new CL().go(); + //Tester.checkEqual(A.data, "CL:CP(hello)"); + Tester.checkEqual(A.data, "CP(hello)"); + } +} + +aspect A /*of eachobject(instanceof(CL))*/ { + public static String data = ""; + + //pointcut parseCalls(CL cl, CP cp, String cmd): + pointcut parseCalls(CP cp, String cmd): + //calls(void cp1.parse(cmd1)) && within(cl1); + (target(cp) && args(cmd) && call(void CP.parse(String))) && + within(CL); + + //void around(CL cl, CP cp, String cmd): + void around(CP cp, String cmd): + //parseCalls(cl, cp, cmd) { + parseCalls(cp, cmd) { + //data = cl.getClass().getName()+":"+cp.getClass().getName()+"("+cmd+")"; + data = cp.getClass().getName()+"("+cmd+")"; + //proceed(cl, cp, cmd); + proceed(cp, cmd); + } +} + +class CL { + void go() { + new CP().parse("hello"); + } +} + +class CP { + void parse(String cmd) { + } +} diff --git a/tests/new/AroundCasting.java b/tests/new/AroundCasting.java new file mode 100644 index 000000000..8fbc98bf6 --- /dev/null +++ b/tests/new/AroundCasting.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +public class AroundCasting { + public static void main(String[] args) { + Tester.checkEqual(x = 3, 1003); + Tester.checkEqual(x, 3); + Tester.checkEvents(new String[] { "enter main" }); + } + static int x; +} + + +aspect A { + static boolean test() { return true; } + + int around(): if (test()) && set(int AroundCasting.x) { + return proceed() + 1000; + } + + void around(): execution(void AroundCasting.main(String[])) { + Tester.event("enter main"); + proceed(); + } +} diff --git a/tests/new/AroundChangeThis.java b/tests/new/AroundChangeThis.java new file mode 100644 index 000000000..bf96cdd9b --- /dev/null +++ b/tests/new/AroundChangeThis.java @@ -0,0 +1,61 @@ +import org.aspectj.testing.Tester; + +public class AroundChangeThis { + public static void main(String[] args) { + C c1 = new C("c1"); + C c2 = new C("c2"); + SubC sc = new SubC("sc"); + + c1.m(c2); + Tester.checkAndClearEvents(new String[] { "c1.m(c2)", "c2.m(c1)" }); + + c1.m(sc); + Tester.checkAndClearEvents(new String[] { "c1.m(sc)", "sc.m(c1)" }); + + sc.m(c1); + Tester.checkAndClearEvents(new String[] { "sc.m(c1)", "c1.m(sc)" }); + + try { + sc.m1(c1); + } catch (ClassCastException e) { + Tester.event("ClassCastException"); + } + Tester.checkAndClearEvents(new String[] { "ClassCastException" }); + + Tester.printEvents(); + } +} + +class C { + private String name; + + public C(String name) { this.name = name; } + + public String toString() { return name; } + + public void m(Object other) { + Tester.event(this + ".m(" + other + ")"); + } +} + +class SubC extends C { + public SubC(String name) { super(name); } + + public void m1(Object other) { + Tester.event(this + ".m1(" + other + ")"); + } +} + + +aspect A { + /* Swaps this with arg for calls of C.m(C) */ + void around(C thisC, C argC): execution(void m*(*)) && this(thisC) && args(argC) { + proceed(argC, thisC); + proceed(thisC, argC); + } + + + void around(C thisC, C argC): call(void m*(*)) && target(thisC) && args(argC) { + proceed(argC, thisC); + } +} diff --git a/tests/new/AroundDoubleAssignment.java b/tests/new/AroundDoubleAssignment.java new file mode 100644 index 000000000..b8ef0d27c --- /dev/null +++ b/tests/new/AroundDoubleAssignment.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.*; + +/** + * with -usejavac: cannot resolve symbol + * without -usejavac: VerifyError + */ +public aspect AroundDoubleAssignment { + public static void main( String[] args ){ + Tester.expectEvent("test"); + Tester.expectEvent("proceed"); + StaticSet.test(); + Tester.checkAllEvents(); + } + Object around() : execution( * StaticSet.*() ) { + Tester.event("proceed"); + return proceed(); + } +} + +class StaticSet { + /** @testcase PR#687 around all execution with double assignment in initializer (simple) */ + public static void test(){ + String s = s = "test"; + Tester.event("test"); + } +} diff --git a/tests/new/AroundDoubleAssignmentC.java b/tests/new/AroundDoubleAssignmentC.java new file mode 100644 index 000000000..f1b13d630 --- /dev/null +++ b/tests/new/AroundDoubleAssignmentC.java @@ -0,0 +1,117 @@ +import org.aspectj.testing.*; + +/** + * with -usejavac: cannot resolve symbol + * without -usejavac: VerifyError + */ +public aspect AroundDoubleAssignmentC { + public static void main( String[] args ){ + //---------- passing tests + // field init + Tester.expectEvent("proceed-fieldinit"); + new FieldInit(); + + // field set + Tester.expectEvent("fieldset"); + Tester.expectEvent("proceed-fieldset"); + new FieldSet().test(); + + + //---------- failing tests + // static method, field set + Tester.expectEvent("staticfieldset-test"); + Tester.expectEvent("proceed-staticset"); + StaticSet.staticTest(); + + // static initializer + Tester.expectEvent("staticinit"); + Tester.expectEvent("proceed-staticinit"); + Class c2 = StaticInit.class.getClass(); + Tester.check("test".equals(StaticInit.string), + "\"test\".equals(StaticInit.string)"); + + // instance initializer + Tester.expectEvent("init"); + Tester.expectEvent("proceed-init"); + String s = new Init().string; + Tester.check("test".equals(s), + "\"test\".equals(new Init().string)"); + Tester.checkAllEvents(); + } // main + + Object around() : within(FieldInit) && execution( * *() ) { + Tester.event("proceed-fieldinit"); + return proceed(); + } + + Object around() : execution( * FieldSet.*() ) { + Tester.event("proceed-fieldset"); + return proceed(); + } + + // static method + Object around() : execution( * StaticSet.*() ) { + Tester.event("proceed-staticset"); + return proceed(); + } + + // static initializer + Object around() : staticinitialization(StaticInit) { + Tester.event("proceed-staticinit"); + return proceed(); + } + + // instance initializer + Object around() : initialization(Init.new(..)) { + Tester.event("proceed-init"); + return proceed(); + } +} + +class FieldInit { + /** @testcase PR#687 around all execution with double assignment in initializer (fieldinit) */ + String s = s = getString(); + String getString() { return "test".toString(); } +} + +class FieldSet { + + /** @testcase PR#687 around all execution with double assignment in initializer (fieldset) */ + String s; + public void test(){ + s = s = "test"; // not initializer, so... + Tester.event("fieldset"); + } +} + +class StaticSet { + /** @testcase PR#687 around all execution with double assignment in initializer (staticfieldset) */ + static String string; + public static void staticTest(){ + String s = s = "test"; + string = s; + Tester.event("staticfieldset-" + string); + } +} + +/** @testcase PR#687 around all execution with double assignment in initializer (staticinitialization) */ +class StaticInit { + static String string; + static { + String s = s = getString(); + Tester.event("staticinit"); + string = s; + } + static String getString() { return "test"; } +} + +/** @testcase PR#687 around all execution with double assignment in initializer (instance initialization) */ +class Init { + String string; + Init() { + String s = s = "test"; + Tester.event("init"); + string = s; + } +} + diff --git a/tests/new/AroundExceptions.java b/tests/new/AroundExceptions.java new file mode 100644 index 000000000..81bb1e445 --- /dev/null +++ b/tests/new/AroundExceptions.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; +import java.io.IOException; + +public class AroundExceptions { + public static void main(String[] args) { + new SubC().m(); + Tester.checkAndClear("around-reception caught-IOException", "subc.m"); + + new C().m(); + Tester.checkAndClear("around-reception", "c.m"); + } +} + +class C { + public void m() throws IOException { + } +} + +class SubC extends C { + public void m() throws IOException { + throw new IOException(); + } +} + + + +aspect A { + void around (): call(void C.m()) { + Tester.note("around-reception"); + proceed(); + } + + void around(): call(void C+.m()) { + try { + proceed(); + } catch (IOException ioe) { + Tester.note("caught-IOException"); + } + } +} diff --git a/tests/new/AroundHandler.java b/tests/new/AroundHandler.java new file mode 100644 index 000000000..ac9e9e2e1 --- /dev/null +++ b/tests/new/AroundHandler.java @@ -0,0 +1,192 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +/* + These test advice on handlers: + 1) can use before advice to skip handler by throwing Error + 2) can use after advice after running handler and throw Error + 3) can use around advice [skip | run] X [ throw Error or complete normally ] + a) skip without throwing error + b) skip with throwing error + c) run without throwing error + d) run with throwing error + + Rather than overload advice at join points, + there is one method and one advice for each of the 6 test cases. + */ +/** @testcase VerifyError after around advice falls off end of tryCatch */ +public class AroundHandler { + /** if true, then run the around test cases */ + public static final boolean TEST_AROUND = true ; + public static void main(String[] args) { + Target target = new Target(); + /** @testcase before advice skips handler by throwing Error */ + Tester.check(target.skipBeforeErrorHandler(), "target.skipBeforeErrorHandler()"); + /** @testcase after advice runs handler, throws Error */ + Tester.check(target.runAfterErrorHandler(), "target.runAfterErrorHandler()"); + if (TEST_AROUND) { + /** @testcase around advice skips handler, no Error thrown */ + Tester.check(target.skipErrorHandler(), "target.skipErrorHandler()"); + /** @testcase around advice runs handler, no Error thrown */ + Tester.check(target.runErrorHandler(), "target.runErrorHandler()"); + /** @testcase around advice skips handler, throws exception from around advice */ + Tester.expectEvent("skipErrorHandlerGotError"); + try { + target.skipErrorHandlerThrowError(); + Tester.check(false, "expecting Error thrown by around"); + } catch (Error e) { + Target.isERR(e); + Tester.event("skipErrorHandlerGotError"); + } + /** @testcase around advice runs handler, throws exception from around advice */ + Tester.expectEvent("runErrorHandlerThrowError"); + Tester.expectEvent("runErrorHandlerGotError"); + try { + target.runErrorHandlerThrowError(); + Tester.check(false, "expecting Error thrown by around"); + } catch (Error e) { + Target.isERR(e); + Tester.event("runErrorHandlerGotError"); + } + } // TEST_AROUND + } +} +class OuterError extends Error { + public OuterError(String s) { super(s); } +} +class Target { + public static String ERR = "goto Error"; + public static void isERR(Throwable throwable) { + String message = (null == throwable ? "" : throwable.getMessage()); + Tester.check(Target.ERR.equals(message), + "\"" + ERR + "\".equals(\"" + message + "\")"); + } + + /** advised by before */ + public boolean skipBeforeErrorHandler() { + boolean ranHandler = false; + boolean ranOuterHandler = false; + try { + try { throw new Error(ERR); } + catch (Error t) { ranHandler = true; } + } catch (OuterError t) { ranOuterHandler = true; } + Tester.check(!ranHandler, "!ranHandler"); + Tester.check(ranOuterHandler, "ranOuterHandler"); + return (!ranHandler && ranOuterHandler); + } + + /** advised by after */ + public boolean runAfterErrorHandler() { + boolean ranHandler = false; + boolean ranOuterHandler = false; + try { + try { throw new Error(ERR); } + catch (Error t) { ranHandler = true; } + } catch (OuterError t) { ranOuterHandler = true; } + Tester.check(ranHandler, "!ranHandler"); + Tester.check(ranOuterHandler, "ranOuterHandler"); + return (ranHandler && ranOuterHandler); + } + + //---------------- remainder all advised using around + public boolean skipErrorHandler() { + boolean ranHandler = false; + try { throw new Error(ERR); } + catch (Error t) { ranHandler = true; } + Tester.check(!ranHandler, "!ranHandler"); + return !ranHandler; + } + + public boolean runErrorHandler() { + boolean ranHandler = false; + try { throw new Error(ERR); } + catch (Error t) { ranHandler = true; } + Tester.check(ranHandler, "ranHandler"); + return ranHandler; + } + + public boolean skipErrorHandlerThrowError() { + try { throw new Error(ERR); } + catch (Error t) { + Tester.check(false, "skipErrorHandlerThrowError ran handler"); + } + return false; // should never get here - Error thrown + } + + public boolean runErrorHandlerThrowError() { + try { throw new Error(ERR); } + catch (Error t) { + Tester.event("runErrorHandlerThrowError"); + } + return false; // should never get here - Error thrown + } +} + +aspect A { + /** @testcase use before to skip handler by throwing Error from advice */ + before(Error error) + : withincode(boolean Target.skipBeforeErrorHandler()) + && handler(Error) && args(error) + { + Target.isERR(error); + throw new OuterError(Target.ERR); + } + + /** @testcase use after to run handler but throw Error from advice */ + after(Error error) + : withincode(boolean Target.runAfterErrorHandler()) + && handler(Error) && args(error) + { + Target.isERR(error); + throw new OuterError(Target.ERR); + } + + // -------------------- around advice + + /** @testcase use around, run handler */ + Object around(Error error) + : withincode(boolean Target.runErrorHandler()) + && handler(Error) && args(error) + && if(AroundHandler.TEST_AROUND) + { + Target.isERR(error); + return proceed(error); + } + + /** @testcase use around to skip handler, throw no Error from around */ + Object around(Error error) + : withincode(boolean Target.skipErrorHandler()) + && handler(Error) && args(error) + && if(AroundHandler.TEST_AROUND) + { + Target.isERR(error); + //Object ignore = proceed(error); + //throw new Error(Target.ERR); + return null; + } + + /** @testcase use around to skip handler, but throw Error from around */ + Object around(Error error) + : withincode(boolean Target.skipErrorHandlerThrowError()) + && handler(Error) && args(error) + && if(AroundHandler.TEST_AROUND) + { + Target.isERR(error); + //Object ignore = proceed(error); + throw new OuterError(Target.ERR); + //return null; + } + + /** @testcase use around, run handler, but throw Error from around */ + Object around(Error error) + : withincode(boolean Target.runErrorHandlerThrowError()) + && handler(Error) && args(error) + && if(AroundHandler.TEST_AROUND) + { + Target.isERR(error); + Object result = proceed(error); + throw new OuterError(Target.ERR); + // return result; + } +} diff --git a/tests/new/AroundInnerCalls.java b/tests/new/AroundInnerCalls.java new file mode 100644 index 000000000..6cdd966a1 --- /dev/null +++ b/tests/new/AroundInnerCalls.java @@ -0,0 +1,56 @@ +import org.aspectj.testing.Tester; + +public class AroundInnerCalls { + public static void main(String[] args) { + new Outer().foo(); + + Tester.check("Outer.foo() calls Outer.Inner.mi()"); + Tester.check("Outer.foo() calls Outer.InnerRandom.nextHook(..)"); + Tester.check("Outer.InnerRandom.nextHook(..) calls Random.next(..)"); + Tester.check("Outer.Inner.mi() calls PrintStream.println(..)"); + + Tester.check("X.toString()"); + Tester.check("Outer.foo() calls Random.nextInt(..)"); + } +} + +class Outer { + private class Inner extends Object { + public void mi() { + System.out.println("."); + } + } + + public void foo() { + new Inner().mi(); + new InnerRandom().nextHook(2); + + new java.util.Random() { public String toString() { Tester.note("X.toString()"); return "X"; } }.nextInt(2); + } + + private class InnerRandom extends java.util.Random { + public int nextHook(int bits) { + return next(bits); + } + } +} + +aspect A { + Object around(): call(* *(..)) && !within(A) { + //System.out.println + Tester.note + (thisEnclosingJoinPointStaticPart.getSignature().toShortString() + + " calls " + thisJoinPointStaticPart.getSignature().toShortString()); + return proceed(); + } + + before(Object caller, Object callee): + this(caller) && target(callee) && call(* *(..)) && !within(A) + { + System.out.println(thisEnclosingJoinPointStaticPart.getSignature().toShortString() + + " calls " + thisJoinPointStaticPart.getSignature().toShortString()); + System.out.println + (caller + "." + thisEnclosingJoinPointStaticPart.getSignature().getName() + + " calls " + callee + "." + thisJoinPoint.getSignature().getName()); + } +} diff --git a/tests/new/AroundNumericCastCE.java b/tests/new/AroundNumericCastCE.java new file mode 100644 index 000000000..4e357ebd3 --- /dev/null +++ b/tests/new/AroundNumericCastCE.java @@ -0,0 +1,26 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#838 checking around join point for advice return type - numeric */ +public class AroundNumericCastCE { + + public static double doubleMethod(int total){ + return (double) total; + } + + public static int intMethod(int total){ + return total; + } + + public static aspect Selector{ + // expect CE "illegal return value" from execution(int intMethod(int)) + double around(int i) : execution(* *Method(int)) && args(i) { // CE 17 + return proceed(i); + } + } + public static void main(String[] args){ + double result = doubleMethod(1000); + Tester.check(result != 0, "calculatePayment(1000)"); + } +} + diff --git a/tests/new/AroundVoid.java b/tests/new/AroundVoid.java new file mode 100644 index 000000000..8d4393c9d --- /dev/null +++ b/tests/new/AroundVoid.java @@ -0,0 +1,66 @@ +import org.aspectj.testing.Tester; + +public class AroundVoid { + public static void main(String[] args) { + C c = new C(); + try { + c.m1(); + } catch (RuntimeException exc) { + Tester.event("caught RuntimeException"); + } + c.m2(); + c.m3(true); + c.m4(true); + try { + c.m5(); + } catch (ArithmeticException exc) { + Tester.event("caught ArithmeticException"); + } + c.m6(); + + //Tester.printEvents(); + Tester.checkEventsFromFile("AroundVoid.out"); + } +} + +class C { + void m1() { + throw new RuntimeException("m1"); + } + + void m2() { + Tester.event("m2"); + } + + void m3(boolean test) { + if (test) { + return; + } else { + return; + } + } + + void m4(boolean test) { + if (test) { + return; + } else { + Tester.event("false"); + } + } + + void m5() { + while (true) { + int x = 0; + int y = 2/x; + } + } + + void m6() {} +} + +aspect A { + Object around(): execution(void C.m*(..)) { + Tester.event(thisJoinPoint.toShortString()); + return proceed(); + } +} diff --git a/tests/new/AroundVoid.out b/tests/new/AroundVoid.out new file mode 100644 index 000000000..729a36cc3 --- /dev/null +++ b/tests/new/AroundVoid.out @@ -0,0 +1,9 @@ +execution(C.m1())
+caught RuntimeException
+execution(C.m2())
+m2
+execution(C.m3(..))
+execution(C.m4(..))
+execution(C.m5())
+caught ArithmeticException
+execution(C.m6())
diff --git a/tests/new/ArrayCasts.java b/tests/new/ArrayCasts.java new file mode 100644 index 000000000..b92dd5dbf --- /dev/null +++ b/tests/new/ArrayCasts.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; + +public class ArrayCasts { + public static void main(String[] args) { + new ArrayCasts().realMain(args); + } + + int[] ints = new int[1]; + int[][] intss = new int[2][]; + int[][][] intsss = new int[3][][]; + + Integer[] integers = new Integer[4]; + Integer[][] integerss = new Integer[5][]; + Integer[][][] integersss = new Integer[6][][]; + + public void realMain(String[] args) { + + ints = (int[]) new ArrayCasts().ints.clone(); + intss = (int[][]) new ArrayCasts().intss.clone(); + intsss = (int[][][])new ArrayCasts().intsss.clone(); + + integers = (Integer[]) new ArrayCasts().integers.clone(); + integerss = (Integer[][]) new ArrayCasts().integerss.clone(); + integersss = (Integer[][][])new ArrayCasts().integersss.clone(); + + Tester.checkEqual(ints.length, 1); + Tester.checkEqual(intss.length, 2); + Tester.checkEqual(intsss.length, 3); + + Tester.checkEqual(integers.length, 4); + Tester.checkEqual(integerss.length, 5); + Tester.checkEqual(integersss.length, 6); + } +} + +aspect A { + //pointcut callstoSets(): callsto(receptions(void set*(..)) && instanceof(ArrayCasts)); + pointcut callstoSets(): call(void set*(..)) && target(ArrayCasts); + before() : callstoSets() {} +} diff --git a/tests/new/ArrayFieldDeclaration.java b/tests/new/ArrayFieldDeclaration.java new file mode 100644 index 000000000..fec447fb1 --- /dev/null +++ b/tests/new/ArrayFieldDeclaration.java @@ -0,0 +1,18 @@ + +import org.aspectj.testing.Tester; +import java.util.*; + +/** @testcase PR#829 declare array field using postfix */ +public class ArrayFieldDeclaration { + + public static void main(String[] args) { + Tester.check(null != new C().f[0], "null != new C().f[0]"); + } +} + +class C { +} + +aspect A { + Object C.f[] = new Object[] { "hello" }; +} diff --git a/tests/new/ArrayFieldDeclarationCE.java b/tests/new/ArrayFieldDeclarationCE.java new file mode 100644 index 000000000..e49ba740f --- /dev/null +++ b/tests/new/ArrayFieldDeclarationCE.java @@ -0,0 +1,15 @@ + + +/** @testcase PR#829 CE expected when declaring fields on arrays */ +public class ArrayFieldDeclarationCE { + + public static void main(String[] args) { + throw new Error("should not run"); + } +} + +class C { } + +aspect A { + public int C[].foo; // CE 14 cannot declare fields on arrays +} diff --git a/tests/new/ArrayInc.java b/tests/new/ArrayInc.java new file mode 100644 index 000000000..b54de4e84 --- /dev/null +++ b/tests/new/ArrayInc.java @@ -0,0 +1,53 @@ + + +import org.aspectj.testing.Tester; +/** + * @testcase PR#715 PUREJAVA incrementing array + */ +public class ArrayInc { + private static void testCheck(boolean b, String s) { + Tester.check(b,s); + //if (!b) System.err.println("error: " + s); + } + + private static int[] IRA=new int[]{0,1,2}; + static int[] getIRA() { return IRA; } + static int[] throwError() { throw new Error(""); } + + public static void main(String[] args) { + ArrayInc me = new ArrayInc(); + me.testArrayExpressionOrdering(); + me.testArrayExpression(); + } + + public void testArrayExpression() { + IRA = new int[]{0}; + String[] sra = new String[] {""}; + sra[0] += "1"; + sra[0] += "string concat"; + testCheck(0==getIRA()[0], + "0==getIRA()[0]: " + IRA[0]); + testCheck(0==IRA[0]++, "0==IRA[0]++: " + IRA[0]); + testCheck(1==IRA[0], "1==IRA[0]: " + IRA[0]); + testCheck(2==++getIRA()[0], + "2==++getIRA()[0]: " + IRA[0]);; + testCheck(2==IRA[0], "2==IRA[0]: " + IRA[0]); + } + + public void testArrayExpressionOrdering() { + boolean gotError = false; + int i = 0; + try { int k = throwError()[++i]; } + catch (Error e) { gotError = true; } + testCheck(i==0, "i=" + i); + testCheck(gotError, "no error"); + + i = 0; + gotError = false; + try { int k = throwError()[i++]; } + catch (Error e) { gotError = true; } + testCheck(i==0, "i++ !=0: " + i); + testCheck(gotError, "no error"); + } +} + diff --git a/tests/new/ArrayInc1CE.java b/tests/new/ArrayInc1CE.java new file mode 100644 index 000000000..5ebd86112 --- /dev/null +++ b/tests/new/ArrayInc1CE.java @@ -0,0 +1,29 @@ + +/** + * @testcase PR#715 PUREJAVA incrementing objects, arrays + */ +public class ArrayIncCE { + private static int[] IRA = new int[]{0,1,2}; + private static Object OBJECT = new Object(); + static int[] getIRA() { return IRA; } + static Object getObject() { return null; } + + public void testObjectIncrementingCE() { + int i = 0; + Object object = new Object(); + String[] sra = new String[]{""}; + //++getIRA(); // CE prefix ++ not applied to int[] + //++getObject(); // CE prefix ++ not applied to Object + //getIRA()++; // CE postfix ++ not applied to int[] + //getObject()++; // CE postfix ++ not applied to Object + IRA += 1; // CE + not applied to int[], int + //getIRA() += 1; // CE + not applied to int[], int + object += 1; // CE + not applied to Object, int + //getObject() += 1; // CE + not applied to Object, int + i = +IRA; // CE unary + not applied to int[] + i = +getIRA(); // CE unary + not applied to int[] + sra += "bad concat"; // CE string + not applied to String[], String + //"1" += sra[0]; // CE no literal on lhs + } +} + diff --git a/tests/new/ArrayInc2CE.java b/tests/new/ArrayInc2CE.java new file mode 100644 index 000000000..ce31617e7 --- /dev/null +++ b/tests/new/ArrayInc2CE.java @@ -0,0 +1,18 @@ + +/** + * @testcase PR#715 PUREJAVA incrementing objects, arrays + */ +public class ArrayInc2CE { + + public void testObjectIncrementingCE() { + boolean b; + int i = 0; + Object object = new Object(); + int[] ra = new int[]{}; + ++ra; // CE prefix ++ cannot be applied to int[] + ++object; // CE prefix ++ cannot be applied to Object + ra++; // CE postfix ++ cannot be applied to int[] + object++; // CE postfix ++ cannot be applied to Object + } +} + diff --git a/tests/new/ArrayInc3CE.java b/tests/new/ArrayInc3CE.java new file mode 100644 index 000000000..17f7fa9e0 --- /dev/null +++ b/tests/new/ArrayInc3CE.java @@ -0,0 +1,22 @@ + +/** + * @testcase PR#715 PUREJAVA incrementing objects, arrays + */ +public class ArrayInc3CE { + private static int[] IRA = new int[]{0,1,2}; + private static Object OBJECT = new Object(); + static int[] getIRA() { return IRA; } + static Object getObject() { return null; } + + public void testObjectIncrementingCE() { + int i = 0; + Object object = new Object(); + String[] sra = new String[]{""}; + IRA += 1; // CE + not applied to int[], int + object += 1; // CE + not applied to Object, int + i = +IRA; // CE unary + not applied to int[] + i = +getIRA(); // CE unary + not applied to int[] + sra += "bad concat"; // CE string + not applied to String[], String + } +} + diff --git a/tests/new/ArrayIncCE.java b/tests/new/ArrayIncCE.java new file mode 100644 index 000000000..0f809a0dc --- /dev/null +++ b/tests/new/ArrayIncCE.java @@ -0,0 +1,24 @@ + +/** + * @testcase PR#715 PUREJAVA incrementing objects, arrays + */ +public class ArrayIncCE { + private static int[] IRA = new int[]{0,1,2}; + private static Object OBJECT = new Object(); + static int[] getIRA() { return IRA; } + static Object getObject() { return null; } + + public void testObjectIncrementingCE() { + int i = 0; + Object object = new Object(); + String[] sra = new String[]{""}; + ++getIRA(); // CE prefix ++ not applied to int[] + ++getObject(); // CE prefix ++ not applied to Object + getIRA()++; // CE postfix ++ not applied to int[] + getObject()++; // CE postfix ++ not applied to Object + getIRA() += 1; // CE + not applied to int[], int + getObject() += 1; // CE + not applied to Object, int + "1" += sra[0]; // CE no literal on lhs + } +} + diff --git a/tests/new/ArrayMethod.java b/tests/new/ArrayMethod.java new file mode 100644 index 000000000..5018e992d --- /dev/null +++ b/tests/new/ArrayMethod.java @@ -0,0 +1,27 @@ +import org.aspectj.testing.*; + +public class ArrayMethod { + public static void main(String[] args) { + new ArrayMethod().go(); + Tester.check(true, "compiled"); + } + + void go() { + try { + int[] array1 = array1(); + int[] array2 = array2(); + for (int i = 0; i < array1.length; i++) { + Tester.checkEqual(array1[i],i); + Tester.checkEqual(array2[i],i); + } + } catch (Exception e) { + } + } + + int array1()[] throws Exception { + return new int[] {0,1,2}; + } + int[] array2() throws Exception { + return new int[] {0,1,2}; + } +} diff --git a/tests/new/Aspect.java b/tests/new/Aspect.java new file mode 100644 index 000000000..16257d4fd --- /dev/null +++ b/tests/new/Aspect.java @@ -0,0 +1,3 @@ +aspect Aspect of eachobject(instanceof(Clazz)) { + +} diff --git a/tests/new/AspectInInterfaceCF.java b/tests/new/AspectInInterfaceCF.java new file mode 100644 index 000000000..dbba0473a --- /dev/null +++ b/tests/new/AspectInInterfaceCF.java @@ -0,0 +1,17 @@ + +import org.aspectj.testing.Tester; +public class AspectInInterfaceCF { + public static void main(String[] args) { + Tester.checkEvents("before"); + } +} + +interface HasPrivateAspect { + /** @testcase PR#534 static aspect in interface causes CE if - usejavac */ + private static aspect Inner { + before(): execution(* main(..)) { Tester.event("before"); } + } + protected static aspect Inner1 { + before(): execution(* main(..)) { Tester.event("before"); } + } +} diff --git a/tests/new/AspectInInterfaceCP.java b/tests/new/AspectInInterfaceCP.java new file mode 100644 index 000000000..520fc2381 --- /dev/null +++ b/tests/new/AspectInInterfaceCP.java @@ -0,0 +1,14 @@ + +import org.aspectj.testing.Tester; +public class AspectInInterfaceCP { + public static void main(String[] args) { + Tester.checkEvents("before"); + } +} + +interface HasPrivateAspect { + /** @testcase PR#534 static aspect in interface causes CE if - usejavac */ + static aspect Inner { + before(): execution(* main(..)) { Tester.event("before"); } + } +} diff --git a/tests/new/AspectInheritance.java b/tests/new/AspectInheritance.java new file mode 100644 index 000000000..92289a5e9 --- /dev/null +++ b/tests/new/AspectInheritance.java @@ -0,0 +1,57 @@ +import org.aspectj.testing.Tester; +import java.util.*; + +public class AspectInheritance { + public static void main(String[] args) { + new C().m(2); + + Tester.checkEqual(Base.aspectNames, "FullConcrete ConcreteFlow", "names"); + } +} + + +abstract aspect Base { + public static Set aspectNames = new HashSet(); + + abstract pointcut targets(int i, C c); + + after(int i, C c): targets(i, c) { + Base.aspectNames.add(this.getClass().getName()); + } +} + +aspect EmptyConcrete extends Base { + pointcut targets(int i, C c); +} + +aspect FullConcrete extends Base { + pointcut targets(int i, C c): target(c) && call(void C.m(int)) && args(i); +} + +abstract aspect Flow percflow(entries()) { + abstract pointcut entries(); + + { + Base.aspectNames.add(this.getClass().getName()); + } +} + +abstract aspect MainFlow extends Flow { + pointcut entries(): execution(void C.m(..)); +} + +aspect ConcreteFlow extends MainFlow { } + + + +abstract aspect AbstractWorld { + before(): execution(void C.m(..)) { + System.out.println("before C.m"); + } +} + + + +class C { + public void m(int i) { } +} diff --git a/tests/new/AspectOf.java b/tests/new/AspectOf.java new file mode 100644 index 000000000..fe0b1b798 --- /dev/null +++ b/tests/new/AspectOf.java @@ -0,0 +1,76 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class AspectOf { + public static void main(String[] args) { + Tester.expectEvent("IsSingleton before AspectOf.run()"); + Tester.expectEvent("PerCFlow before AspectOf.run()"); + Tester.expectEvent("PerTarget before AspectOf.run()"); + Tester.expectEvent("PerThis before AspectOf.run()"); + Tester.expectEvent("PerCFlowBelow before AspectOf.subrun()"); + Tester.expectEvent("run()"); + Tester.expectEvent("subrun()"); + new AspectOf().run(); + Tester.checkAllEvents(); + } + public void subrun() { + Object aspect = PerCFlowBelow.aspectOf(); + Tester.check(null != aspect, "PerCFlowBelow.aspectOf()"); + Tester.event("subrun()"); + } + public void run() { + Object aspect = null; + + aspect = IsSingleton.aspectOf(); + Tester.check(null != aspect, "IsSingleton.aspectOf()"); + aspect = PerThis.aspectOf(this); + Tester.check(null != aspect, "PerThis.aspectOf(this)"); + aspect = PerTarget.aspectOf(this); + Tester.check(null != aspect, "PerTarget.aspectOf(this)"); + aspect = PerCFlow.aspectOf(); + Tester.check(null != aspect, "PerCFlow.aspectOf()"); + Tester.event("run()"); + subrun(); + } + public static void log(String s) { + Tester.event(s); + //System.out.println(s); + } +} + +aspect IsSingleton { + before() : execution(void AspectOf.run()) { + AspectOf.log("IsSingleton before AspectOf.run()"); + } +} + +aspect PerThis perthis(pc()) { + pointcut pc() : execution(void AspectOf.run()) ; + before() : pc() { + AspectOf.log("PerThis before AspectOf.run()"); + } +} +aspect PerTarget pertarget(pc()) { + pointcut pc() : execution(void AspectOf.run()) ; + before() : pc() { + AspectOf.log("PerTarget before AspectOf.run()"); + } +} + +aspect PerCFlow percflow(pc()) { + pointcut pc() : execution(void AspectOf.run()); + before() : pc() { + AspectOf.log("PerCFlow before AspectOf.run()"); + } +} + +aspect PerCFlowBelow percflowbelow(pc()) { + pointcut pc() : execution(void AspectOf.run()); + before() : execution(void AspectOf.subrun()) { + AspectOf.log("PerCFlowBelow before AspectOf.subrun()"); + } +} + + + diff --git a/tests/new/AspectOfInterface.java b/tests/new/AspectOfInterface.java new file mode 100644 index 000000000..82c7ae38e --- /dev/null +++ b/tests/new/AspectOfInterface.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +public class AspectOfInterface { + public static void main(String[] args) { test(); } + + public static boolean ranAdvice = false; + public static void test() { + new C().foo(); + Tester.check(ranAdvice, "advice on interface"); + } +} + +interface I { + public void foo(); +} + +class C implements I { + public void foo() { } //System.out.println("foo"); } +} + +aspect A /*of eachobject(instanceof(I))*/ { + before(): call(* *(..)) { + AspectOfInterface.ranAdvice = true; //System.out.println("before"); + } +} diff --git a/tests/new/AspectOnInterface.java b/tests/new/AspectOnInterface.java new file mode 100644 index 000000000..7e4bdf358 --- /dev/null +++ b/tests/new/AspectOnInterface.java @@ -0,0 +1,27 @@ +import org.aspectj.testing.Tester; + +public aspect AspectOnInterface /*of eachobject(instanceof(I1))*/ { + before (I1 i1): target(i1) && call(String process()) { + i1.addToS("-advised"); + } + + public static void main(String[] args) { test(); } + + public static void test() { + ConcreteC1 c1 = new ConcreteC1(); + Tester.checkEqual(c1.process(), "foo-advised-processed", ""); + } +} + +interface I1 { + public void addToS(String newS); + public String process(); +} + +class ConcreteC1 implements I1 { + String s = "foo"; + public void addToS(String newS) { s += newS; } + public String process() { + return s + "-processed"; + } +} diff --git a/tests/new/AspectRedefinesParam.java b/tests/new/AspectRedefinesParam.java new file mode 100644 index 000000000..11de62a0a --- /dev/null +++ b/tests/new/AspectRedefinesParam.java @@ -0,0 +1,28 @@ + +import org.aspectj.testing.Tester; + +/** + * Test for: PR #65 + */ + +public aspect AspectRedefinesParam { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new Foo().b("a"), "a", "b('a')"); + } + + pointcut ccut(String s): this(Foo) && call(String b(String)) && args(s); + + before(String methodString): ccut(methodString) { + String s; + s = "b"; + methodString += s; + } +} + +class Foo { + String b( String s ) { + return s; + } +} diff --git a/tests/new/AspectStaticInit.java b/tests/new/AspectStaticInit.java new file mode 100644 index 000000000..2a7e2a87b --- /dev/null +++ b/tests/new/AspectStaticInit.java @@ -0,0 +1,16 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#804 aspect static initializers should run before instance constructed */ +public class AspectStaticInit { + public static void main(String[] args) { + Tester.check(A.i == 1, "1 != A.i=" + A.i); + } +} +// XXX need tests for other instantiations besides issingleton +aspect A { + static int i = 1; + A() { + Tester.check(i == 1, "1 != i=" + i); + } +} diff --git a/tests/new/AssertInAdvice.java b/tests/new/AssertInAdvice.java new file mode 100644 index 000000000..8dc6fcc55 --- /dev/null +++ b/tests/new/AssertInAdvice.java @@ -0,0 +1,90 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#657 PUREJAVA assert statement in advice coverage [requires 1.4] */ +public class AssertInAdvice { + public static void main(String[] args) { + AssertInAdvice.class.getClassLoader().setClassAssertionStatus("Test", true); + AssertInAdvice.class.getClassLoader().setClassAssertionStatus("AssertInAdvice", false); + + boolean expectAssert = false; + boolean gotit = false; + do { + Test.throwAssert = expectAssert; + gotit = false; + // 6 cases - separate join point for advice below + // call + try { call1(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call1"+expectAssert); gotit = false; + try { call2(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call2"+expectAssert); gotit = false; + try { call3(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call3"+expectAssert); gotit = false; + try { call4(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call4"+expectAssert); gotit = false; + try { call5(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call5"+expectAssert); gotit = false; + try { call6(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "call6"+expectAssert); gotit = false; + // execution + try { execution1(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution1"+expectAssert); gotit = false; + try { execution2(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution2"+expectAssert); gotit = false; + try { execution3(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution3"+expectAssert); gotit = false; + try { execution4(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution4"+expectAssert); gotit = false; + try { execution5(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution5"+expectAssert); gotit = false; + try { execution6(); } catch (AssertionError e) { gotit = true; } + Tester.check(gotit == expectAssert, "execution6"+expectAssert); + + // run for false, true + if (expectAssert) break; + expectAssert = true; + } while (true); + } + public static void call1() {} + public static void call2() {} + public static void call3() {} + public static void call4() {} + public static void call5() {} + public static void call6() {} + public static void execution1() {} + public static void execution2() {} + public static void execution3() {} + public static void execution4() {} + public static void execution5() {} + public static void execution6() {} +} + +aspect Test { + // todo: convert to 1.3 test? + public static boolean throwAssert; + public static boolean throwAssert() { return throwAssert; } + public static final AssertionError EXPECTED = new AssertionError("expected"); + public static void testAssert() { + //if (throwAssert) throw EXPECTED; + assert !throwAssert() ; + } + // call + after() returning : call(void AssertInAdvice.call1() ) { + assert !throwAssert(); + } + after() : call(void AssertInAdvice.call2() ) { + assert !throwAssert(); + } + before() : call(void AssertInAdvice.call3() ) { testAssert(); } + void around() : call(void AssertInAdvice.call4() ) { testAssert(); } + void around() : call(void AssertInAdvice.call5() ) { proceed(); testAssert(); } + void around() : call(void AssertInAdvice.call6() ) { testAssert(); proceed(); } + + // execution + after() returning : execution(void AssertInAdvice.execution1() ) { testAssert(); } + after() : execution(void AssertInAdvice.execution2() ) { testAssert(); } + before() : execution(void AssertInAdvice.execution3() ) { testAssert(); } + void around() : execution(void AssertInAdvice.execution4() ) { testAssert(); } + void around() : execution(void AssertInAdvice.execution5() ) { proceed(); testAssert(); } + void around() : execution(void AssertInAdvice.execution6() ) { testAssert(); proceed(); } +} diff --git a/tests/new/AssertInAdviceBug.java b/tests/new/AssertInAdviceBug.java new file mode 100644 index 000000000..e74ffe9e5 --- /dev/null +++ b/tests/new/AssertInAdviceBug.java @@ -0,0 +1,78 @@ +import org.aspectj.testing.Tester; + +aspect Test { + public static boolean invariant() { return true ; } + after() returning : call(static void AssertInAdviceBug.call() ) { + assert !invariant() ; + } + + void around(): call(static void call1()) { + assert !invariant(); + } + + static void AssertInAdviceBug.call2() { + assert !invariant(); + } +} + + +/** @testcase PR#657 PUREJAVA assert statement in advice [requires 1.4] */ +public class AssertInAdviceBug { + private static boolean useJavacMode = false; + + public static void main(String[] args) { + AssertInAdviceBug.class.getClassLoader().setClassAssertionStatus("Test", true); + AssertInAdviceBug.class.getClassLoader().setClassAssertionStatus("AssertInAdviceBug", false); + boolean gotAssert = false; + try { + call(); + } catch (AssertionError e) { + gotAssert = true; + StackTraceElement[] stack = e.getStackTrace(); + + // this test should only run when we're not in -usejavac mode + if (stack[0].getFileName().endsWith("AssertInAdviceBug.java")) { + Tester.checkEqual(stack[0].getLineNumber(), 6, "bad line for assert"); + } else { + useJavacMode = true; + System.err.println("!!!!!!!!!!!!!!!!!!!!!!!IN JAVAC MODE!!!!!!!!!!!!!!!!!!!!1"); + } + } + Tester.check(gotAssert, "no assert"); + + gotAssert = false; + try { + call1(); + } catch (AssertionError e) { + gotAssert = true; + StackTraceElement[] stack = e.getStackTrace(); + + // this test should only run when we're not in -usejavac mode + if (!useJavacMode) { + Tester.checkEqual(stack[0].getLineNumber(), 10, "bad line for assert"); + } + } + Tester.check(gotAssert, "no assert on call1"); + + gotAssert = false; + try { + call2(); + } catch (AssertionError e) { + gotAssert = true; + StackTraceElement[] stack = e.getStackTrace(); + //e.printStackTrace(); + + // this test should only run when we're not in -usejavac mode + if (!useJavacMode) { + Tester.checkEqual(stack[0].getLineNumber(), 14, "bad line for assert"); + } + } + Tester.check(gotAssert, "no assert on call1"); + } + + + public static void call() {} + + public static void call1() {} +} + diff --git a/tests/new/AssertInInnerIntro.java b/tests/new/AssertInInnerIntro.java new file mode 100644 index 000000000..aaf13ccf8 --- /dev/null +++ b/tests/new/AssertInInnerIntro.java @@ -0,0 +1,33 @@ +// compile this guy with -usejavac to show warning + +public class AssertInInnerIntro { + + public static void main(String[] args) { + turnOnAssertions(); + runTests(); + } + + static void turnOnAssertions() { + ClassLoader cl = AssertInInnerIntro.class.getClassLoader(); + cl.setClassAssertionStatus("C", false); + cl.setClassAssertionStatus("A", true); + } + + static void runTests() { + // should throw assertion error, will not + C.foo(); + } +} + +class C { +} + +aspect A { + static void C.foo() { + new Runnable() { + public void run() { + assert false; + } + }.run(); + } +} diff --git a/tests/new/AssertInIntro.java b/tests/new/AssertInIntro.java new file mode 100644 index 000000000..395eaa0d4 --- /dev/null +++ b/tests/new/AssertInIntro.java @@ -0,0 +1,45 @@ +import org.aspectj.testing.Tester; + +public class AssertInIntro { + + public static void main(String[] args) { + turnOnAssertions(); + runTests(); + } + + static void turnOnAssertions() { + ClassLoader cl = AssertInIntro.class.getClassLoader(); + cl.setClassAssertionStatus("C", false); + cl.setClassAssertionStatus("A", true); + } + + static void runTests() { + boolean failed = false; + try { + C.foo(); + } catch (AssertionError e) { + failed = true; + } + Tester.check(failed, "introduced assertions improperly off"); + + failed = false; + try { + C.goo(); + } catch (AssertionError e) { + failed = true; + } + Tester.check(!failed, "non-introduced assertions improperly on"); + } +} + +class C { + static void goo() { + assert false; + } +} + +aspect A { + static void C.foo() { + assert false; + } +} diff --git a/tests/new/AssignOps.java b/tests/new/AssignOps.java new file mode 100644 index 000000000..f33d1dd05 --- /dev/null +++ b/tests/new/AssignOps.java @@ -0,0 +1,152 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +aspect A { + static boolean start = false; + static int bset; + static int bget; + static int siset; + static int siget; + static int iset; + static int iget; + static void start() { + siset = siget = iset = iget = 0; + start = true; + } + static String p() { + return + " siset=" + siset + + " siget=" + siget + + " iset=" + iset + + " iget=" + iget ; + } + before() : get(int AssignOps.staticInt) { + signal(AssignOps.sigetStr+ siget++); + check(siget == (1+siset), "siget == (1+siset)" + p()); + } + before() : set(int AssignOps.staticInt) { + signal(AssignOps.sisetStr + siset++); + check(siget == siset, "siget == siset" + p()); + } + before() : get(int AssignOps.instanceInt) { + signal(AssignOps.igetStr + iget++); + check(iget == (1+iset), "iget == (1+iset)" + p()); + } + before() : set(int AssignOps.instanceInt) { + signal(AssignOps.isetStr + iset++); + check(iget == iset, "iget == iset" + p()); + } + before() : get(boolean AssignOps.bool) { + signal(AssignOps.bgetStr + bget++); + check(bget == (1+bset), "bget == (1+bset)" + p()); + } + before() : set(boolean AssignOps.bool) { + signal(AssignOps.bsetStr + bset++); + check(bget == bset, "bget == bset" + p()); + } + static void check(boolean b, String s) { + if (start) Tester.check(b, s); + } + static void signal(String s) { + if (start) Tester.event(s); + } +} + +/** @testcase operators ++ += etc. result in a get and set join point */ +public class AssignOps { + static int staticInt; + int instanceInt; + boolean bool; + static final String sisetStr = "before() : set(int AssignOps.staticInt)"; + static final String sigetStr = "before() : get(int AssignOps.staticInt)"; + static final String isetStr = "before() : set(int AssignOps.instanceInt)"; + static final String igetStr = "before() : get(int AssignOps.instanceInt)"; + static final String bsetStr = "before() : set(boolean AssignOps.bool)"; + static final String bgetStr = "before() : get(boolean AssignOps.bool)"; + public static void main(String[] args) { + new AssignOps(3).run(); + Tester.checkAllEvents(); + } + static void t(String s) { Tester.expectEvent(s); } + AssignOps(int i) { instanceInt = i; } + void run() { + A.start(); + t(igetStr + "0"); + t(isetStr + "0"); + instanceInt++; + t(sigetStr + "0"); + t(sisetStr + "0"); + staticInt++; + t(igetStr + "1"); + t(isetStr + "1"); + instanceInt += 2; + t(sigetStr + "1"); + t(sisetStr + "1"); + staticInt += 2; + + t(igetStr + "2"); + t(isetStr + "2"); + instanceInt--; + t(sigetStr + "2"); + t(sisetStr + "2"); + staticInt--; + t(igetStr + "3"); + t(isetStr + "3"); + instanceInt -= 2; + t(sigetStr + "3"); + t(sisetStr + "3"); + staticInt -= 2; + + t(igetStr + "4"); + t(isetStr + "4"); + instanceInt *= 2; + t(sigetStr + "4"); + t(sisetStr + "4"); + staticInt *= 2; + + t(igetStr + "5"); + t(isetStr + "5"); + instanceInt /= 2; + t(sigetStr + "5"); + t(sisetStr + "5"); + staticInt /= 2; + + t(igetStr + "6"); + t(isetStr + "6"); + instanceInt %= 2; + t(sigetStr + "6"); + t(sisetStr + "6"); + staticInt %= 2; + + t(igetStr + "7"); + t(isetStr + "7"); + instanceInt >>= 2; + t(sigetStr + "7"); + t(sisetStr + "7"); + staticInt >>= 2; + + t(igetStr + "8"); + t(isetStr + "8"); + instanceInt <<= 2; + t(sigetStr + "8"); + t(sisetStr + "8"); + staticInt <<= 2; + + t(igetStr + "9"); + t(isetStr + "9"); + instanceInt >>>= 2; + t(sigetStr + "9"); + t(sisetStr + "9"); + staticInt >>>= 2; + + t(bgetStr + "0"); + t(bsetStr + "0"); + bool &= true; + t(bgetStr + "1"); + t(bsetStr + "1"); + bool |= false; + t(bgetStr + "2"); + t(bsetStr + "2"); + bool ^= false; + } +} diff --git a/tests/new/BackdoorMethods.java b/tests/new/BackdoorMethods.java new file mode 100644 index 000000000..64f5ec450 --- /dev/null +++ b/tests/new/BackdoorMethods.java @@ -0,0 +1,62 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; +public class BackdoorMethods { + public static void main(String[] args) { + new BackdoorMethods().realMain(args); + } + public void realMain(String[] args) { + new _A().a(); + new _B().a(); + new _C().a(); + new _D().a(); + Tester.checkAllEvents(); + } + static { + for (char c = 'A'; c <= 'D'; c++) { + String n = "_"+c+"."; + Tester.expectEvent(n+"a"); + if (c != 'D') Tester.expectEvent(n+"f"); + Tester.expectEvent(n+"g"); + Tester.expectEvent("before."+n+"a"); + if (c != 'D') Tester.expectEvent("before."+n+"g"); + } + } +} + +class O { + public void a() { Tester.event(n("a")); } + protected String n() { return getClass().getName() + "."; } + protected String n(Object s) { return n() + s; } +} +class A extends O { public void f() { Tester.event(n("f")); } } +class B extends O { void f() { Tester.event(n("f")); } } +class C extends O { protected void f() { Tester.event(n("f")); } } +class D extends O { private void f() { Tester.event(n("f")); } } + +class _A extends O { public void g() { Tester.event(n("g")); } } +class _B extends O { void g() { Tester.event(n("g")); } } +class _C extends O { protected void g() { Tester.event(n("g")); } } +class _D extends O { private void g() { Tester.event(n("g")); } } + +privileged aspect Aspect { + + declare parents: _A extends A; + declare parents: _B extends B; + declare parents: _C extends C; + declare parents: _D extends D; + + before(_A o): target(o) && call(void g()) { o.f(); n(o,"g"); } + before(_B o): target(o) && call(void g()) { o.f(); n(o,"g"); } + before(_C o): target(o) && call(void g()) { o.f(); n(o,"g"); } + + before(_A o): target(o) && call(void a()) { o.g(); n(o,"a"); } + before(_B o): target(o) && call(void a()) { o.g(); n(o,"a"); } + before(_C o): target(o) && call(void a()) { o.g(); n(o,"a"); } + before(_D o): target(o) && call(void a()) { o.g(); n(o,"a"); } + + private static void n(Object o, String m) { + Tester.event("before." + o.getClass().getName() + "." + m); + } +} + + diff --git a/tests/new/BindingArgumentsInWithincode.java b/tests/new/BindingArgumentsInWithincode.java new file mode 100644 index 000000000..ffa696dfa --- /dev/null +++ b/tests/new/BindingArgumentsInWithincode.java @@ -0,0 +1,32 @@ +import java.util.*; + +/** + * PR#479 + * A variant of Hunter Kelly's bug PR#479. This + * doesn't get his desired, but should compile. + */ +public class BindingArgumentsInWithincode { + public static void main(String[] args) { + org.aspectj.testing.Tester.check(true, "compiled"); + } +} + +class C { + public void someMethod(String s) { + new ArrayList().add(s+":"+s); + } +} +aspect A { + + pointcut top(String s): + withincode(void someMethod(String)) && args(s); + + pointcut method(Object o): + call(* java.util.List.add(Object)) && args(o); + + /* + * Won't capture what we're after + * but it should compile + */ + before(String s, Object o): top(s) && method(o) {} +} diff --git a/tests/new/BindingInNotCf.java b/tests/new/BindingInNotCf.java new file mode 100644 index 000000000..5c414fef9 --- /dev/null +++ b/tests/new/BindingInNotCf.java @@ -0,0 +1,14 @@ +/** + * AspectJ should have a rule that binding parameters lexically + * within a ! is always an error. These test some of the most + * obvious forms of that. + */ +public aspect BindingInNotCf { + pointcut pc1(Object o): this(o); + + pointcut pc2(Object o): !this(o); //CE + + pointcut pc3(Object o): !pc2(o); //CE + + pointcut pc4(Object o): !!pc1(o); //CE +} diff --git a/tests/new/BindingInterfaces.java b/tests/new/BindingInterfaces.java new file mode 100644 index 000000000..73d5e3517 --- /dev/null +++ b/tests/new/BindingInterfaces.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; +import java.util.*; +public class BindingInterfaces { + public static void main(String[] args) { + new BindingInterfaces().realMain(args); + } + public void realMain(String[] args) { + + I i0 = new I(){}; Tester.checkEqual(str(i0), "I", "i0"); + I ij = new J(){}; Tester.checkEqual(str(ij), "JI", "ij"); + I ik = new K(){}; Tester.checkEqual(str(ik), "KJI", "ik"); + + J j0 = new J(){}; Tester.checkEqual(str(j0), "JI", "j0"); + J jk = new K(){}; Tester.checkEqual(str(jk), "KJI", "jk"); + + K k0 = new K(){}; Tester.checkEqual(str(k0), "KJI", "k0"); + } + + private String str(Object o) { + return str(o.getClass().getInterfaces()[0]); + } + + private String str(Class c) { + String str = c.getName(); + Class[] is = c.getInterfaces(); + for (int i = 0; i < is.length; i++) { + str += str(is[i]); + } + return str; + } +} + +interface I {} +interface J {} //extends I {} +interface K {} //extends J {} + +aspect Aspect { + declare parents: J implements I; + declare parents: K implements J; +} diff --git a/tests/new/BindingNullPointer.java b/tests/new/BindingNullPointer.java new file mode 100644 index 000000000..06ec48c6d --- /dev/null +++ b/tests/new/BindingNullPointer.java @@ -0,0 +1,17 @@ +import org.aspectj.testing.*; + +public class BindingNullPointer { + boolean ran = false; + final String s1 = new String("s1"); + Runnable r1 = new Runnable() { + public void run() {String = s1; ran = true;} + }; + void go() { + r1.run(); + Tester.check(ran, "r1.run did not run"); + } + + public static void main(String[] args) { + new BindingNullPointer().go(); + } +} diff --git a/tests/new/BindingThisInsteadOfFormal.java b/tests/new/BindingThisInsteadOfFormal.java new file mode 100644 index 000000000..0f7efd4a3 --- /dev/null +++ b/tests/new/BindingThisInsteadOfFormal.java @@ -0,0 +1,57 @@ +import org.aspectj.testing.*; + +public class BindingThisInsteadOfFormal { + public static void main(String[] args) { + Caller c = new Caller(); + c.goo(); + Tester.checkAllEvents(); + } + + static { + Tester.expectEvent("before-string"); + Tester.expectEvent("before-go"); + Tester.expectEvent("before-static"); + Tester.expectEvent("before-c"); + } +} + +class Caller { + void goo() { + go(); + staticGo(); + } + void go() { + String string = new String("string"); + C c = new C(); + } + + static void staticGo() { + } +} + +class C { + +} + +aspect Aspect perthis(this(Caller)) { + pointcut stringCtors(): call(String.new(String)); + before(): stringCtors() { + Tester.event("before-string"); + } + + pointcut cCtors(): call(C.new()); + before(): cCtors() { + Tester.event("before-c"); + } + + pointcut goCalls(Caller caller): call(void go()) && target(caller); + before(Caller caller): goCalls(caller) { + Tester.event("before-go"); + Tester.check(caller != null, "instance method"); + } + + pointcut goStaticCalls(): call(void Caller.staticGo()); + before(): goStaticCalls() { + Tester.event("before-static"); + } +} diff --git a/tests/new/Binkley.java b/tests/new/Binkley.java new file mode 100644 index 000000000..7ab515de5 --- /dev/null +++ b/tests/new/Binkley.java @@ -0,0 +1,16 @@ +import org.aspectj.testing.Tester; + +public class Binkley { + public static void main(String[] args) { + new Binkley().realMain(args); + } + public void realMain(String[] args) { + Tester.check(true, "compiled!"); + } +} + +aspect A percflow(pc()) +{ + pointcut pc() : within(Binkley); + before(): cflow(pc()) && !(call (new())) && !within(A) { } +} diff --git a/tests/new/Binkley2.java b/tests/new/Binkley2.java new file mode 100644 index 000000000..cc2c51323 --- /dev/null +++ b/tests/new/Binkley2.java @@ -0,0 +1,87 @@ +import java.util.*; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; +import org.aspectj.testing.*; + +public class Binkley2 { + public static void main(String[] args) { + // catch the static init early + C c = new C(); + + Art.enable = true; + Ar.enable = false; + new C().foo(); + + Art.enable = false; + Ar.enable = true; + new C().foo(); + Post.checkAll(); + } +} + +class C { + public int x = 0; + public void foo() + { + x = 1; + x = 2; + } + +} + +class Post { + static List haves = new Vector(); + static String[] wants = new String[] { + "initialization(C())-Ar-0", + "execution(C.<init>)-Ar-0", + "set(C.x)-Ar-0", + "execution(C())-Ar-0", + "execution(C.foo())-Ar-0", + "set(C.x)-Ar-0", + "set(C.x)-Ar-0", + + "initialization(C())-Art-0", + "execution(C.<init>)-Art-1", + "set(C.x)-Art-2", + "execution(C())-Art-3", + "execution(C.foo())-Art-0", + "set(C.x)-Art-1", + "set(C.x)-Art-2", + }; + + static void post(JoinPoint jp, String name, int num) { + haves.add(jp.toShortString() + "-" + name + "-" + num); + } + static void checkAll() { + Tester.checkEqual(haves, wants, "haves != wants"); + } +} + +aspect Ar percflow(pc()){ + pointcut pc() : within(C) ; + int count = 0; + static boolean enable = false; + before(): pc() { + if ( enable ) { + Post.post(thisJoinPoint, "Ar", count++); + } + } +} + +/* + * I'm trying to simulate eachcflowrootop. + */ +aspect Art percflow(Art.pc() && !cflowbelow(Art.pc())) +{ + pointcut pc() : within(C) ; + //pointcut pctop(): pc() && !cflow(pc()); (see above) + int count = 0; + static boolean enable = false; + + before(): pc() { + if ( enable ) { + Post.post(thisJoinPoint, "Art", count++); + } + } +} + diff --git a/tests/new/CFlowNoAdvice.java b/tests/new/CFlowNoAdvice.java new file mode 100644 index 000000000..b491866f0 --- /dev/null +++ b/tests/new/CFlowNoAdvice.java @@ -0,0 +1,21 @@ +import org.aspectj.testing.Tester; + +public class CFlowNoAdvice { + public static void main(String[] args) { + new Foo().bar(); + new Foo().bar(); + } +} + +class Foo { + void bar() { + Tester.check(CFlowAspect.aspectOf() != null, "cflow created"); + } +} + + + + +aspect CFlowAspect percflow(CFlowAspect.contexts()) { + pointcut contexts(): target(Foo) && call(void bar()); +} diff --git a/tests/new/CFlowObjects.java b/tests/new/CFlowObjects.java new file mode 100644 index 000000000..598cab2c3 --- /dev/null +++ b/tests/new/CFlowObjects.java @@ -0,0 +1,35 @@ +import org.aspectj.testing.Tester; + +public class CFlowObjects { + public static void main(String[] args){ + new Test().go(); + Tester.checkEqual(Test.cflowObjects, 1, "1st cflow"); + Tester.checkEqual(Test.callsPerCFlow, 1, "1 call for each cflow"); + + new Test().go(); + Tester.checkEqual(Test.cflowObjects, 2, "2nd cflow"); + Tester.checkEqual(Test.callsPerCFlow, 1, "1 call for each cflow"); + } +} + +class Test { + static int cflowObjects = 0; + static int callsPerCFlow = 0; + + void go(){ + foo(); + } + + void foo(){} +} + +aspect A percflow(target(Test) && call(void go())) { + + { Test.cflowObjects++; } + { Test.callsPerCFlow = 0; } + + //before(): instanceof(Test) && calls(void Object.*()){ Test.callsPerCFlow++; } + before(): within(Test) && call(void Object+.*(..)) { + Test.callsPerCFlow++; + } +} diff --git a/tests/new/CFlowPoints.java b/tests/new/CFlowPoints.java new file mode 100644 index 000000000..f81660a39 --- /dev/null +++ b/tests/new/CFlowPoints.java @@ -0,0 +1,62 @@ +import org.aspectj.testing.Tester; + +public class CFlowPoints { + public static void main(String[] args){ + new Test().go(2); + Tester.checkEqual(Test.callsPerCFlow, 2+1, "3 call for each cflow"); + + Test.callsPerCFlow = 0; + + new Test().go(3); + Tester.checkEqual(Test.callsPerCFlow, 3+2+1, "6 call for each cflow"); + + try { + Each.aspectOf(); + Tester.checkFailed("should have thrown exception"); + } catch (org.aspectj.lang.NoAspectBoundException exc) { + // this is what we want + } + } +} + +class Test { + static int cflowObjects = 0; + static int callsPerCFlow = 0; + + Object lastEachCFlow = null; + + void go(int n) { + for (int i=0; i<n; i++) foo("i", "i"); + + if (n >= 0) go(n-1); + + Tester.check(Each.aspectOf() != lastEachCFlow, "unique eachcflows"); + + lastEachCFlow = Each.aspectOf(); + } + + void foo(String s1, String s2){} +} + +aspect A { + pointcut root(int x): target(Test) && call(void go(int)) && args(x); + + pointcut flow(int x): cflow(root(x)); + + before(): root(int) && !cflow(root(int)) { + Tester.checkEqual(Test.callsPerCFlow, 0, "top call"); + } + + before(String s1, int y, String s2): + flow(y) && target(Test) && target(Object) + && call(void *(String,String)) + && args(s1,s2) + { + Test.callsPerCFlow++; + Tester.checkEqual(s1, s2, "extra parameters"); + } +} + +aspect Each percflow(flowCut()) { + pointcut flowCut(): target(Test) && call(void go(int)); +} diff --git a/tests/new/CFlowThreads.java b/tests/new/CFlowThreads.java new file mode 100644 index 000000000..3f6220e0a --- /dev/null +++ b/tests/new/CFlowThreads.java @@ -0,0 +1,106 @@ +class CFlowThreads implements Runnable { + private static final int MAX_VALUE = 100; + + public static void main(String[] argv) { + // Create a lot of threads + int x = 0; + while (x++ < 100) { + new Thread(new CFlowThreads()).start(); + try { + Thread.sleep((long)(Math.random()*100)); + } catch (Exception e) {} + } + } + + public boolean gotOne(int x) { +// System.out.println("Succeeded, x = "+x); + return true; + } + + public boolean methodA(int x) { + if (x % 2 == 0) return methodB(x+3); + else return methodC(x/2); + } + + public boolean methodB(int x) { + if (x % 3 == 0) return methodC(x+4); + else return methodA(x/3); + } + + public boolean methodC(int x) { + if (x > 2) return methodB(x-3); + else return gotOne(x); + } + + public boolean startIt(int x) { + return methodA(x); + } + + public void run() { + startIt((int)(Math.random()*MAX_VALUE)); + } + + static aspect OriginalValue of eachcflow(OriginalValue.entrypoints(int)) { + int recursioncount = 0; + int original; + + pointcut entrypoints(int x): + instanceof(CFlowThreads) && receptions(boolean startIt(x)); + + before(int x): entrypoints(x) { + original = x; + } + + pointcut successes(int x): + instanceof(CFlowThreads) && receptions(boolean gotOne(x)); + + pointcut recursiveCalls(int x): + instanceof(CFlowThreads) && + receptions(boolean *(x)) && !receptions(boolean gotOne(x)); + + after(int x) returning (boolean s): successes(x) { +// System.out.println("Started at "+original+", used "+recursioncount+" hops"); + } + + boolean fail(int x) { +// System.out.println("Never gonna make it from "+original); + return false; + } + + around(int x) returns boolean: recursiveCalls(x) { + if (recursioncount++ > 50) { + return fail(x); + } else { + return(proceed(x)); + } + } + } + static aspect CheckValues { + static int[] hops = new int[MAX_VALUE]; + static after(int x, OriginalValue a) returning (boolean s): + OriginalValue.successes(x) && hasaspect(a) { + synchronized (hops) { + if (hops[a.original] != 0) { + if (hops[a.original] != a.recursioncount) { + System.out.println("Error: "+a.original+" takes "+ + hops[a.original]+", not "+ + a.recursioncount+" hops."); + } + } else { + hops[a.original] = a.recursioncount; + } + } + } + static after(int x, OriginalValue a) returning (boolean s): + instanceof(a) && receptions(boolean fail(x)) { + synchronized (hops) { + if (hops[a.original] != 0 &&&& hops[a.original] != -1) { + System.out.println("Error: "+a.original+" takes "+ + hops[a.original]+" hops, doesn't fail"); + } else { + hops[a.original] = -1; + } + } + } + } +} diff --git a/tests/new/CallNotTarget.java b/tests/new/CallNotTarget.java new file mode 100644 index 000000000..c710e2b60 --- /dev/null +++ b/tests/new/CallNotTarget.java @@ -0,0 +1,53 @@ + +import org.aspectj.testing.*; + +/** @testcase PR#661 !target with second advice on casted call */ +public class CallNotTarget { + public static void main (String args []) { + //new B().go(); // remove cast to avoid bug + ((I) new B()).go(); + Tester.checkAllEvents(); + + doit(new B()); + doit(new A()); + } + static { + Tester.expectEvent("A.before"); + Tester.expectEvent("A.before-not"); + Tester.expectEvent("A*.before-not"); + Tester.expectEvent("go"); + } + + static void doit(I i) { + Tester.check(i != null, "null i"); + //System.out.println(i); + } +} + +interface I { public void go (); } + +class A implements I { + public void go () { Tester.check(false, "A"); } +} +class B implements I { + public void go () { Tester.event("go"); } +} + +aspect Aspect { + + pointcut pc() : call(void I.go()); // same result if pointcut not named + + before () : pc() { // remove this advice to avoid bug + Tester.event("A.before"); + } + before () : pc() && !target (A) { // change to !target(String) to avoid bug + Tester.event("A.before-not"); + } + before () : pc() && !target (A*) { // change to !target(String) to avoid bug + Tester.event("A*.before-not"); + } + +// before(): call(void doit(I)) && !args(A) { +// System.out.println("doit !A"); +// } +} diff --git a/tests/new/CallTypes.java b/tests/new/CallTypes.java new file mode 100644 index 000000000..95ff05602 --- /dev/null +++ b/tests/new/CallTypes.java @@ -0,0 +1,116 @@ +import org.aspectj.testing.Tester; +import java.util.*; + +public class CallTypes { + public static void main(String[] args) { + C1 c1 = new C1(); + + preTest("c1.foo()"); + c1.foo(); + test("static c, static c1, instanceof c, instanceof c1, "); + + C c = c1; + + preTest("(C c = c1).foo()"); + c.foo(); + test("static c, instanceof c, instanceof c1, "); + + c = new C(); + + preTest("new C().foo()"); + c.foo(); + test("static c, instanceof c, "); + + C2 c2 = new C2(); + + preTest("new C2().foo()"); + c2.foo(); + test("static c, static c2, instanceof c, instanceof c2, "); + + preTest("c1.foo1()"); + c1.foo1(); + test("", "static c1, instanceof c, instanceof c1, "); + } + + public static void preTest(String str) { + A.noteAdvice = A.noteAdviceStar = ""; + msg = str; + } + + static String msg; + public static void test(String t1) { + test(t1, t1); + } + + public static void test(String baseString, String starString) { + Tester.checkEqual(sort(A.noteAdvice), sort(baseString), "base: "+msg); + Tester.checkEqual(sort(A.noteAdviceStar), sort(starString), "star: "+msg); + } + private final static Collection sort(String str) { + SortedSet sort = new TreeSet(); + for (StringTokenizer t = new StringTokenizer(str, ",", false); + t.hasMoreTokens();) { + String s = t.nextToken().trim(); + if (s.length() > 0) sort.add(s); + } + return sort; + } +} + +class C { + public void foo() { } +} +class C1 extends C { + public void foo1() { } +} +class C2 extends C { + public void foo() { } +} + +aspect A { + static String noteAdvice = ""; + static String noteAdviceStar = ""; + + before(C c): target(c) && call(void C.foo()) { + noteAdvice += "static c, "; + } + before(C1 c1): target(c1) && call(void C1.foo()) { + noteAdvice += "static c1, "; + } + before(C2 c2): target(c2) && call(void C2.foo()) { + noteAdvice += "static c2, "; + } + + + before(C c): target(c) && call(void foo()) { + noteAdvice += "instanceof c, "; + } + before(C1 c1): target(c1) && call(void foo()) { + noteAdvice += "instanceof c1, "; + } + before(C2 c2): target(c2) && call(void foo()) { + noteAdvice += "instanceof c2, "; + } + + + before(C c): target(c) && call(void C.foo*()) { + noteAdviceStar += "static c, "; + } + before(C1 c1): target(c1) && call(void C1.foo*()) { + noteAdviceStar += "static c1, "; + } + before(C2 c2): target(c2) && call(void C2.foo*()) { + noteAdviceStar += "static c2, "; + } + + + before(C c): target(c) && call(void foo*()) { + noteAdviceStar += "instanceof c, "; + } + before(C1 c1): target(c1) && call(void foo*()) { + noteAdviceStar += "instanceof c1, "; + } + before(C2 c2): target(c2) && call(void foo*()) { + noteAdviceStar += "instanceof c2, "; + } +} diff --git a/tests/new/CallTypesI.java b/tests/new/CallTypesI.java new file mode 100644 index 000000000..7ab225106 --- /dev/null +++ b/tests/new/CallTypesI.java @@ -0,0 +1,100 @@ +import org.aspectj.testing.Tester; +import java.util.*; + +public class CallTypesI { + public static void main(String[] args) { + C1a c1a = new C1a(); + + preTest("c1a.mI()"); + c1a.mI(); + test("static c1a, static i0, static i1a, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, "); + + preTest("c1a.mC()"); + c1a.mC(); + test("static c0, static c1a, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, "); + + C0 c0 = c1a; + + preTest("(C c = c1a).mC()"); + c0.mC(); + test("static c0, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, "); + } + + public static void preTest(String str) { + A.noteAdvice = A.noteAdviceStar = ""; + msg = str; + } + + static String msg; + public static void test(String t1) { + test(t1, t1); + } + + public static void test(String baseString, String starString) { + Tester.checkEqual(sort(A.noteAdvice), sort(baseString), "base: "+msg); + //Tester.checkEqual(sort(A.noteAdviceStar), sort(starString), "star: "+msg); + } + private final static Collection sort(String str) { + SortedSet sort = new TreeSet(); + for (StringTokenizer t = new StringTokenizer(str, ",", false); + t.hasMoreTokens();) { + String s = t.nextToken().trim(); + if (s.length() > 0) sort.add(s); + } + return sort; + } +} + +interface I0 { + public void mI(); +} + +interface I1a extends I0 { } + +interface I1b extends I0 { } + +interface I2 extends I1a, I1b {} + + +class C0 { + public void mC() { } +} + +class C1a extends C0 implements I1a { + public void mI() { } +} +class C1b extends C0 implements I1b { + public void mI() { } +} + +aspect A { + static String noteAdvice = ""; + static String noteAdviceStar = ""; + + before(): call(void C0.mC()) { + noteAdvice += "static c0, "; + } + before(): call(void C1a.mC()) || call(void C1a.mI()) { + noteAdvice += "static c1a, "; + } + before(): call(void C1b.mC()) || call(void C1b.mI()) { + noteAdvice += "static c1b, "; + } + + before(): call(void I0.mI()) { + noteAdvice += "static i0, "; + } + before(): call(void I1a.mI()) { + noteAdvice += "static i1a, "; + } + before(): call(void I1b.mI()) { + noteAdvice += "static i1b, "; + } + + before(): target(C0) && call(* *(..)) { noteAdvice += "instanceof c0, "; } + before(): target(C1a) && call(* *(..)) { noteAdvice += "instanceof c1a, "; } + before(): target(C1b) && call(* *(..)) { noteAdvice += "instanceof c1b, "; } + before(): target(I0) && call(* *(..)) { noteAdvice += "instanceof i0, "; } + before(): target(I1a) && call(* *(..)) { noteAdvice += "instanceof i1a, "; } + before(): target(I1b) && call(* *(..)) { noteAdvice += "instanceof i1b, "; } +} diff --git a/tests/new/CallsAndLocalClasses.java b/tests/new/CallsAndLocalClasses.java new file mode 100644 index 000000000..f807605b1 --- /dev/null +++ b/tests/new/CallsAndLocalClasses.java @@ -0,0 +1,47 @@ +import org.aspectj.testing.Tester; + +public class CallsAndLocalClasses { + public static void main(String[] args) { + Runnable r = new Outer().makeRunnable(); + r.run(); + + Outer o = new Outer(); + o.toString(); + ((Comparable)o).toString(); + + Tester.check("run from Outer"); + Tester.check("m"); + Tester.check("before run"); + Tester.check("before m"); + } +} + + +class Outer implements Comparable { + public int compareTo(Object other) { Tester.note("m"); return 0; } + + public Runnable makeRunnable() { + return new Runnable() { + public void run() { + Tester.note("run from Outer"); + compareTo(this); + } + }; + } +} + +final class Foo { + public String toString() { return "Foo"; } +} + +aspect A { + before(): call(void Runnable.run()) { + Tester.note("before run"); + } + before(): call(int compareTo(Object)) { + Tester.note("before m"); + } + before(): call(String Object.toString()) { + System.out.println("before toString"); + } +} diff --git a/tests/new/CallsParams.java b/tests/new/CallsParams.java new file mode 100644 index 000000000..cf58bbdcb --- /dev/null +++ b/tests/new/CallsParams.java @@ -0,0 +1,44 @@ +import org.aspectj.testing.Tester; +import java.util.*; + +public class CallsParams { + public static void main(String[] args) { + Test t = new Test(); + t.go(); + + //Tester.checkEqual(Test.calls, ", Test.go->Test.foo, Test.foo->java.io.PrintStream.println"); + Tester.checkEqual(Test.calls, ", Test.go->foo, Test.foo->println"); + } +} + + +class Test { + static String calls = ""; + + void go(){ + foo(); + } + + void foo(){ + System.out.println(""); + } +} + +aspect SeqCut percflow(call(* Test.go(..))) { + //before(Object s, Object r) : !instanceof(SeqCut) && instanceof(s) && calls(* r.*(..)) { + before(Object s, Object r) : !this(SeqCut) && this(s) && + //callsto(receptions(* *(..)) && instanceof(r)) { + call(* *(..)) && target(r) { + Test.calls += ", " + s.getClass().getName() + "." + + //thisJoinPoint.getEnclosingExecutionJoinPoint().getSignature().getName() + + thisEnclosingJoinPointStaticPart.getSignature().getName() + + "->" /*+ r.getClass().getName() + "."*/ + thisJoinPoint.getSignature().getName(); + // IBM's VM doesn't have a java.io.PrintStream :) + } + + before(Object s) : !this(SeqCut) && this(s) && call(* *..*.*(..)) { + // no output + //System.out.println(", " + s.getClass().getName() + "." + thisStaticJoinPoint.getSignature().getName()); + } +} + diff --git a/tests/new/CallsReceptionsCallsto.java b/tests/new/CallsReceptionsCallsto.java new file mode 100644 index 000000000..790b8de59 --- /dev/null +++ b/tests/new/CallsReceptionsCallsto.java @@ -0,0 +1,85 @@ +// lifted directly from Mark's email + +import org.aspectj.testing.Tester; + +public class CallsReceptionsCallsto { + + static final String desiredString = + "(calls) (callsto) (receptions) G.foo(A) G.foo(D) (calls) (callsto) (receptions) G.foo(A) G.foo(D) "; + + static StringBuffer buffer; + + public static void main(String[] args) { + buffer = new StringBuffer(); + new C().go(); + String foundString = buffer.toString(); + Tester.checkEqual(foundString, desiredString); + } + + + +} + +class C { + A a = new A(); + D d = new D(); + G g = new G(); + + void go(){ + g.foo(a); + g.foo(d); + bar(g); + bash(g); + } + + void bar(I i){ + i.foo(a); + } + + void bash(J j){ + j.foo(d); + } +} + +aspect Q { + + pointcut pc2(): /*calls*/ within(C) && call(void I.foo(*)); + pointcut pc1(): /*receptions*/ call(void I.foo(*)); + pointcut pc3(): /*callsto*/ call(* I.foo(*)); + + before (): pc2() { + CallsReceptionsCallsto.buffer.append("(calls) "); + } + + before(): pc3(){ + CallsReceptionsCallsto.buffer.append("(callsto) "); + } + + before(): pc1() { + CallsReceptionsCallsto.buffer.append("(receptions) "); + } +} + + +class A {} + + +class D {} + + +interface I { + void foo(A a); +} + +interface J { + void foo(D d); +} + +class G implements I, J { + public void foo(A a){ + CallsReceptionsCallsto.buffer.append("G.foo(A) "); + } + public void foo(D d){ + CallsReceptionsCallsto.buffer.append("G.foo(D) "); + } +} diff --git a/tests/new/CallsTo.java b/tests/new/CallsTo.java new file mode 100644 index 000000000..a4bedb983 --- /dev/null +++ b/tests/new/CallsTo.java @@ -0,0 +1,96 @@ +import org.aspectj.testing.Tester; + +public class CallsTo { + public static void main(String[] args) { + Tester.clearNotes(); + //System.out.println("cleared events"); + //Tester.printEvents(); + C c = new C(); + Tester.checkAndClear + ("ca-newC", + "new C"); + c.m("a"); + Tester.checkAndClear + ("re-all re-C ca-all ca-C ", + "c.m"); + c.m_C("b"); + Tester.checkAndClear + ("re-all re-C ca-all ca-C ", + "c.m_C"); + + c = new SubC(); + Tester.checkAndClear + ("ca-newC", + "new SubC"); + c.m("c"); + Tester.checkAndClear + ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)", + "subc.m"); + c.m_C("d"); + Tester.checkAndClear + ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)", + "subc.m_C"); + + SubC subC = new SubC(); + Tester.checkAndClear + ("ca-newC", + "new SubC"); + subC.m("e"); + Tester.checkAndClear + ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)", + "subc.m"); + subC.m_C("f"); + Tester.checkAndClear + ("re-all re-C re-SubC ca-all ca-C ca-SubC ca-inst(SubC)", + "subc.m_C"); + subC.m_SubC(); + Tester.checkAndClear + ("re-all re-SubC ca-all ca-SubC", + "subc.m_SubC"); + } +} + +class C { + public void m(String s1) {} + public void m_C(String s2) {} +} + +class SubC extends C { + public void m(String s3) {} + public void m_SubC() {} +} + +aspect A { +// pointcut allReceptions(): receptions(void *(..)) && instanceof(C); +// pointcut receptionsInC(String s): receptions(void C.*(s)); +// pointcut receptionsInSubC(): receptions(void SubC.*(..)); + + pointcut allcall(): call(void *(..)) && target(C+); + pointcut callInC(String s): call(void C+.*(String)) && args(s); + pointcut callInSubC(): call(void *(..)) && target(SubC); + + before(): allcall() { note("re-all"); } + before(String s): callInC(s) { note("re-C"); } + before(): callInSubC() { note("re-SubC"); } + + before(): allcall() { note("ca-all"); } + before(String s): callInC(s) { note("ca-C"); } + before(): callInSubC() { note("ca-SubC"); } + + + before(): call(void C.*(..)) && target(SubC) { note("ca-inst(SubC)"); } + + // not implemented +// before(OnSubC o): call(void C.*(..)) && (hasaspect(OnSubC) && target(o)) { +// note("ca-asp(SubC)"); +// } + + before(): call(C+.new(..)) { note("ca-newC"); } + + private final static void note(String msg) { + Tester.note(msg); + } +} + +aspect OnSubC /**of eachobject(instanceof(SubC))*/ { +} diff --git a/tests/new/CallsToArray.java b/tests/new/CallsToArray.java new file mode 100644 index 000000000..dfa8ba019 --- /dev/null +++ b/tests/new/CallsToArray.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; + +public class CallsToArray { + public static void main(String[] args) { + byte[] a = new byte[] {0, 1}; + byte[] b = (byte[])a.clone(); + + Tester.check(a != b, "cloned array is different"); + Tester.check(a[0] == b[0] && a[1] == b[1], "but compares equal"); + + Tester.check(A.returnedClone == b, "advice did right thing"); + } + +} + + +aspect A { + static Object returnedClone; + after () returning(Object cloned): call(Object Object.clone()) { + System.out.println("running advice"); + A.returnedClone = cloned; + } + /* + static after () returning(Object cloned): calls(Object .clone()) { + System.out.println("running advice on byte[]"); + A.returnedClone = cloned; + } + */ +} diff --git a/tests/new/CallsVRec.java b/tests/new/CallsVRec.java new file mode 100644 index 000000000..bb3140cd7 --- /dev/null +++ b/tests/new/CallsVRec.java @@ -0,0 +1,43 @@ +import org.aspectj.compiler.base.ast.*; + +public class CallsVRec { + public static void main(String[] args) { + new CallsVRec().realMain(args); + } + public void realMain(String[] args) { + org.aspectj.testing.Tester.check(true, "Compiled!"); + } + + public CallsVRec() { + } +} + + + + +aspect Wins { + + pointcut showError(ASTObject ast, String msg): + target(ast) + && call(void ASTObject.showError(String)) + && args(msg); + + void around(ASTObject ast, String msg): showError(ast, msg) { + System.out.println("hi"); + proceed(ast, msg); + } +} + +aspect Loses { + + pointcut showError(ASTObject ast, String msg): + target(ast) + && call/*s*/(void ASTObject.showError(String)) + && args(msg); + + void around(ASTObject ast, String msg): showError(ast, msg) { + System.out.println("hi"); + proceed(ast, msg); + } +} + diff --git a/tests/new/CannotReferenceSuper.java b/tests/new/CannotReferenceSuper.java new file mode 100644 index 000000000..3ce4e04d0 --- /dev/null +++ b/tests/new/CannotReferenceSuper.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.*; +public class CannotReferenceSuper { + + public static void main(String[] args) { + new CannotReferenceSuper().go(); + } + + static { + Tester.expectEventsInString("a.go,aa.go,b.go,bb.go"); + } + + void go() { + new A().go(); + new B().go(); + Tester.checkAllEvents(); + } + + class A { + class AA extends A { + void go() { Tester.event("aa.go"); } + } + void go() { Tester.event("a.go"); new AA().go(); } + } + + class B extends A { + class BB extends AA { + void go() { Tester.event("bb.go"); } + } + void go() { Tester.event("b.go"); new BB().go(); } + + } +} + + diff --git a/tests/new/CatchAdvice.java b/tests/new/CatchAdvice.java new file mode 100644 index 000000000..8d0b247f7 --- /dev/null +++ b/tests/new/CatchAdvice.java @@ -0,0 +1,52 @@ +import org.aspectj.testing.Tester; + +import org.aspectj.lang.reflect.*; + +public aspect CatchAdvice { + public static void main(String[] args) { test(); } + + public static void test() { + new C().foo(); + Tester.check(ranAdvice1, "advice on *'s"); + Tester.check(ranAdvice2, "advice on C"); + Tester.check(!ranAdvice3, "advice on C and Error"); + } + + private static boolean ranAdvice1 = false; + before(Throwable t): handler(Throwable+) && args(t){ + //int n = thisJoinPoint.parameters.length; + //System.out.println("caught "+t+" "+n+" params"); + Tester.check(((CatchClauseSignature)thisJoinPoint.getSignature()). + getParameterType() == ArithmeticException.class, + "right catch clause"); + ranAdvice1 = true; + } + after(Throwable t): handler(Throwable+) && args(t) { + //System.out.println("after catch"); + } + + static boolean ranAdvice2 = false; + after(ArithmeticException t): + this(C) && handler(ArithmeticException) && args(t) { + //System.out.println("(in C) caught "+t); + ranAdvice2 = true; + } + + static boolean ranAdvice3 = false; + after(Error e): + within(C) && handler(Error+) && args(e){ + //System.out.println("(in C) caught "+e); + ranAdvice3 = true; + } +} + +class C { + public void foo() { + int x=0; + try { + int y = 1/x; + } catch (ArithmeticException e) { + //System.out.println("caught arithmetic exception"); + } + } +} diff --git a/tests/new/CflowAlone.java b/tests/new/CflowAlone.java new file mode 100644 index 000000000..19cdc035d --- /dev/null +++ b/tests/new/CflowAlone.java @@ -0,0 +1,29 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class CflowAlone { + public static void main(String[] args){ + new testclass1(); + Tester.check(0 < Filteraspect.i, + "0 < Filteraspect.i: " + Filteraspect.i); + } +} +class testclass1 {} +class testclass2 {} +aspect Filteraspect { + static int i; + // all these variants fail + //pointcut goCut(): cflow(this(testclass2)); + //pointcut goCut(): cflow(target(testclass2)); + //pointcut goCut(): cflow(args(testclass2)); + //pointcut goCut(): cflow(!within(FilterAspect)); + //pointcut goCut(): cflow(within(FilterAspect)); + //pointcut goCut(): cflow(within(testclass1)); + pointcut goCut(): !within(Filteraspect) && cflow(within(testclass1)); + // works ok + //pointcut goCut(): within(Filteraspect); + Object around(): goCut() { i++; return proceed(); } + // no bug when using before or after + //after(): goCut() { int i = 1; System.getProperties().put("foo", "bar");} +} diff --git a/tests/new/CflowBelowTest.java b/tests/new/CflowBelowTest.java new file mode 100644 index 000000000..f6c7e07a7 --- /dev/null +++ b/tests/new/CflowBelowTest.java @@ -0,0 +1,44 @@ +import org.aspectj.testing.Tester; + +import java.util.*; + +/** + * Inspired by aspect sandbox and submitted by Chris Dutchyn + */ +public class CflowBelowTest { + static final String[] expectedSteps = new String[] { + "Num.fact(4) within Num.fact(5) within another Num.fact(6)", + "Num.fact(3) within Num.fact(4) within another Num.fact(5)", + "Num.fact(2) within Num.fact(3) within another Num.fact(4)", + "Num.fact(1) within Num.fact(2) within another Num.fact(3)", + }; + + static List steps = new ArrayList(); + + static public void main( String[] args ) { + Tester.checkEqual(new Num().fact(6), 720); + + Tester.checkEqual(steps.toArray(), expectedSteps, "steps"); + } +} + + +class Num { + int fact(int x) { + if (x == 1) + return 1; + return x * fact(x - 1); + } +} + +// check that cflows of nested calls obtain correct parameters +aspect CflowBelow01 { + before (int x1, int x2, int x3) : + call(int Num.fact(int)) && args(x1) + && cflowbelow(call(int Num.fact(int)) && args(x2) + && cflowbelow(call(int Num.fact(int)) && args(x3))) { + CflowBelowTest.steps.add("Num.fact(" + x1 + + ") within Num.fact(" + x2 + + ") within another Num.fact(" + x3 + ")"); + } +} diff --git a/tests/new/CflowBinding.java b/tests/new/CflowBinding.java new file mode 100644 index 000000000..0b4b4478c --- /dev/null +++ b/tests/new/CflowBinding.java @@ -0,0 +1,16 @@ +public class CflowBinding { + public static void main(String[] args) { + } + + public void m1() {} + public void m2() { m1(); } +} + +aspect A { + public static Object foo = null; + + before(final Object t): execution(void m1()) && this(t) && + cflow(execution(void m2()) && if(t == foo)) //CE + { + } +} diff --git a/tests/new/CflowCycles.java b/tests/new/CflowCycles.java new file mode 100644 index 000000000..5b48bf76f --- /dev/null +++ b/tests/new/CflowCycles.java @@ -0,0 +1,39 @@ +import org.aspectj.testing.Tester; + +/** @testcase cflow cycles in advice from different aspects */ +public class CflowCycles { + public static void main( String args[] ) { + Tester.expectEvent("target A1"); + Tester.expectEvent("target A2"); + new Target().run(); + Tester.checkAllEventsIgnoreDups(); + } +} + +class Target { + public void run(){ } +} + +aspect A1 { + pointcut TargetRunFlow () + // ok if no cflow: within(Target) && execution(* *(..)) && !within(A1+); + : !within(A1+) //cflow(within(Target) && execution(* *(..))) && !within(A1+) + ; + Object around () : TargetRunFlow() { + Tester.event("target A1"); + return proceed(); + } + // ok if in the same class +} + +aspect A2 { + pointcut TargetRun () + : within(Target) && execution(* *(..)) && !within(A2+); + ; + Object around () : TargetRun() { + Tester.event("target A2"); + return proceed(); + } +} + + diff --git a/tests/new/CflowInitInAspectVariantsAfter.java b/tests/new/CflowInitInAspectVariantsAfter.java new file mode 100644 index 000000000..51093d86c --- /dev/null +++ b/tests/new/CflowInitInAspectVariantsAfter.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.Tester; + +public class CflowInitInAspectVariantsAfter { + public static void main(String[] args) { + new C().a(); + Tester.checkAllEventsIgnoreDups(); + } + static { + Tester.expectEvent("cflow after pc()"); + Tester.expectEvent("cflow after execution(void C.a())"); + Tester.expectEvent("cflowbelow after pc()"); + Tester.expectEvent("cflowbelow after execution(void C.a())"); + } +} +class C { + void a() {b();} + private void b() {int i = 1;} // avoid later optimizations +} + +aspect A { + + pointcut safety() : !within(A); + pointcut pc() : execution(void C.a()); + after() : safety() && cflow(pc()) { + Tester.event("cflow after pc()"); + } + after() : safety() && cflow(execution(void C.a())) { + Tester.event("cflow after execution(void C.a())"); + } + after() : safety() && cflowbelow(pc()) { + Tester.event("cflowbelow after pc()"); + } + after() : safety() && cflowbelow(execution(void C.a())) { + Tester.event("cflowbelow after execution(void C.a())"); + } +} diff --git a/tests/new/CflowInitInAspectVariantsBefore.java b/tests/new/CflowInitInAspectVariantsBefore.java new file mode 100644 index 000000000..953cfa7d9 --- /dev/null +++ b/tests/new/CflowInitInAspectVariantsBefore.java @@ -0,0 +1,57 @@ +import org.aspectj.testing.Tester; + +public class CflowInitInAspectVariantsBefore { + public static void main(String[] args) { + new C().a(); + Tester.checkAllEventsIgnoreDups(); + } + static { + Tester.expectEvent("cflow before pc()"); + Tester.expectEvent("cflow before execution(void C.a())"); + Tester.expectEvent("cflowbelow before pc()"); + Tester.expectEvent("cflowbelow before execution(void C.a())"); + } +} +class C { + void a() {b();} + private void b() {int i = 1;} // avoid later optimizations +} + +aspect A { + + pointcut pc() : execution(void C.a()); + // ---- works + pointcut safety() : !within(A) ; + // ---- cannot use cflow to exclude itself - reference thereto fails + //pointcut safety() : !(within(A) && cflow(pc())); + // ---- cannot use dynamic calculation, because before call happens first? + //pointcut safety() : !within(A) || (within(A) && if(touched)) ; + static boolean touched = false; + // ---- does not address the before advice methods advising themselves + //pointcut safety() : !(initialization(A.new(..)) || staticinitialization(A)); + // ---- worse way of saying !within(A) + //pointcut safety() : this(C) || this(CflowInitInAspectVariantsBefore) || this(null); + //pointcut safety() : this(C) || this(CflowInitInAspectVariantsBefore) || this(null); + + // no bug if ": within(C) && ..." + // @testTarget cflow.before.namedpc + before() : safety() && cflow(pc()) { + if (!touched) touched = true; + Tester.event("cflow before pc()"); + } + // @testTarget cflow.before.anonpc + before() : safety() && cflow(execution(void C.a())) { + if (!touched) touched = true; + Tester.event("cflow before execution(void C.a())"); + } + // @testTarget cflowbelow.before.namedpc + before() : safety() && cflowbelow(pc()) { + if (!touched) touched = true; + Tester.event("cflowbelow before pc()"); + } + // @testTarget cflowbelow.before.anonpc + before() : safety() && cflowbelow(execution(void C.a())) { + if (!touched) touched = true; + Tester.event("cflowbelow before execution(void C.a())"); + } +} diff --git a/tests/new/CflowOfFieldInitAnonMethods.java b/tests/new/CflowOfFieldInitAnonMethods.java new file mode 100644 index 000000000..1cfe6a2d0 --- /dev/null +++ b/tests/new/CflowOfFieldInitAnonMethods.java @@ -0,0 +1,46 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#755 ajc dies on cflow into field init anon class */ +public class CflowOfFieldInitAnonMethods { + public static void main(String[] args) { + new CflowOfFieldInitAnonMethods().r.run(); // field initializer + // no bug on static field initializers or with non-anonymous class + // or when not calling another method + //XXX test should check, but that's for leter + //Tester.checkAllEvents(); + } + + Runnable r = new Runnable() { + public void run() { calc(1); } + public void calc(int i) {} + }; +} + +aspect ThreadTracer { + pointcut safe(): !within(ThreadTracer); + + before(): safe() && cflow(call(void Runnable.run())) { + Tester.event("before(): cflow(call(void Runnable.run()))"); + } + before(): safe() && cflowbelow(call(void Runnable.run())) { + Tester.event("before(): cflowbelow(call(void Runnable.run()))"); + } + before(): safe() && cflow(execution(void Runnable.run())) { + Tester.event("before(): cflow(execution(void Runnable.run()))"); + } + before(): safe() && cflowbelow(execution(void Runnable.run())) { + Tester.event("before(): cflowbelow(execution(void Runnable.run()))"); + } + before(): execution(void Runnable.run()) { // no bug here + Tester.event("before(): execution(void Runnable.run())"); + } + static { + Tester.expectEvent("before(): cflow(call(void Runnable.run()))"); + Tester.expectEvent("before(): cflowbelow(call(void Runnable.run()))"); + Tester.expectEvent("before(): cflow(execution(void Runnable.run()))"); + Tester.expectEvent("before(): cflowbelow(execution(void Runnable.run()))"); + Tester.expectEvent("before(): execution(void Runnable.run())"); + } +} + diff --git a/tests/new/CircularAdvice.java b/tests/new/CircularAdvice.java new file mode 100644 index 000000000..176d9a001 --- /dev/null +++ b/tests/new/CircularAdvice.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +public class CircularAdvice { + public static void main(String[] args) { + Tester.checkEqual(m(5), 5*4*3*2*1, "factorial with advice"); + } + + public static long m(long l) { + return -1; + } +} + +aspect FactorialViaAround { + // this advice uses recursive calls within its body to compute factorial + // on an otherwise innocent method + long around (long l): call(long m(long)) && args(l) { + if (l == 0) { + return 1; + } else { + return l * CircularAdvice.m(l - 1); + } + } +} + diff --git a/tests/new/ClassAndInterface.java b/tests/new/ClassAndInterface.java new file mode 100644 index 000000000..262be4705 --- /dev/null +++ b/tests/new/ClassAndInterface.java @@ -0,0 +1,8 @@ +import org.aspectj.testing.Tester; +public class ClassAndInterface { + public static void main(String[] args) { + Tester.check(false, "shouldn't have compiled"); + } +} +class I {} +interface I {} diff --git a/tests/new/ClassFieldOnPrimitiveType.java b/tests/new/ClassFieldOnPrimitiveType.java new file mode 100644 index 000000000..81d2a0877 --- /dev/null +++ b/tests/new/ClassFieldOnPrimitiveType.java @@ -0,0 +1,71 @@ + +import org.aspectj.testing.Tester; + +public class ClassFieldOnPrimitiveType +{ + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(checkBoolean(), "boolean", "boolean"); + Tester.checkEqual(checkChar(), "char", "char"); + Tester.checkEqual(checkByte(), "byte", "byte"); + Tester.checkEqual(checkShort(), "short", "short"); + Tester.checkEqual(checkLong(), "long", "long"); + Tester.checkEqual(checkFloat(), "float", "float"); + Tester.checkEqual(checkDouble(), "double", "double"); + Tester.checkEqual(checkIntArray(), "[Z", "boolean[]"); + checkIntArray(); + } + + public static String checkVoid() { + Class c = void.class; + return c.getName(); + } + + public static String checkBoolean() { + Class c = boolean.class; + Tester.check(c.isPrimitive(), "check isPrimitive"); + return c.getName(); + } + + public static String checkChar() { + Class c = char.class; + return c.getName(); + } + + public static String checkByte() { + Class c = byte.class; + return c.getName(); + } + + public static String checkShort() { + Class c = short.class; + return c.getName(); + } + + public static String checkInt() { + Class c = int.class; + Tester.check( c == Integer.TYPE, "check Type field"); + return c.getName(); + } + + public static String checkLong() { + Class c = long.class; + return c.getName(); + } + + public static String checkFloat() { + Class c = float.class; + return c.getName(); + } + + public static String checkDouble() { + Class c = double.class; + return c.getName(); + } + + public static String checkIntArray() { + Class c = boolean[].class; + return c.getName(); + } +} diff --git a/tests/new/ClassImplementsClass.java b/tests/new/ClassImplementsClass.java new file mode 100644 index 000000000..aa49ef3f7 --- /dev/null +++ b/tests/new/ClassImplementsClass.java @@ -0,0 +1,11 @@ + + +/** @testcase PR853 declare class implements class CE */ + +class C {} + +class B {} + +aspect A { + declare C implements B; // CE 10 +}
\ No newline at end of file diff --git a/tests/new/ClassMethods.java b/tests/new/ClassMethods.java new file mode 100644 index 000000000..c614f05ea --- /dev/null +++ b/tests/new/ClassMethods.java @@ -0,0 +1,133 @@ +import org.aspectj.testing.Tester; + +import java.lang.reflect.*; +import java.util.*; + +public class ClassMethods { + public static void main(String[] args) { + new ClassMethods().realMain(args); + } + final static Object[] tuples = new Object[] { + "clone", null, null, + "equals", new Class[]{Object.class}, new Object[]{""}, + "finalize", null, null, + "getClass", null, null, + "hashCode", null, null, + "notify", null, null, + "notifyAll", null, null, + "toString", null, null, + "wait", null, null, + "waitL", new Class[]{long.class}, new Object[]{new Long(3L)}, + "waitLI", new Class[]{long.class, int.class}, new Object[]{new Long(4L), new Integer(5)}, + }; + final List list = new Vector(); + { + for (int i = 0; i < tuples.length; i += 3) { + List tuple = new Vector(); + tuple.add(tuples[i]+ "New"); + tuple.add(tuples[i+1] == null ? new Class[]{} : tuples[i+1]); + tuple.add(tuples[i+2] == null ? new Object[]{} : tuples[i+2]); + list.add(tuple); + } + } + public void realMain(String[] argv) { + Iterator iter = list.iterator(); + while (iter.hasNext()) { + List tuple = (List) iter.next(); + String name = (String) tuple.get(0); + Class[] params = (Class[]) tuple.get(1); + Object[] args = (Object[]) tuple.get(2); + boolean ran = false; + Throwable caught = null; + try { + Object o = new SomeType(); + o.getClass().getMethod(name, params).invoke(o, args); + ran = true; + } catch (Throwable t) { + caught = t; + } finally { + Tester.check(ran, name + " didn't run" + (caught != null ? ":"+caught : "")); + } + } + } +} + +class SomeType { +// public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; } +// public boolean equalsNew(Object o) { return equals(o); } +// public void finalizeNew() { try { finalize(); } catch (Throwable t) {} } +// public Class getClassNew() { return getClass(); } +// public int hashCodeNew() { return hashCode(); } +// public void notifyNew() { try { notify(); } catch (Throwable t) {} } +// public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} } +// public String toStringNew() { return toString(); } +// public void waitNew() { try { wait(); } catch (Throwable t) {} } +// public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} } +// public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} } +} + +aspect AspectToIntroduce_clone { + introduction SomeType { + public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; } + } +} + +aspect AspectToIntroduce_equals { + introduction SomeType { + public boolean equalsNew(Object o) { return equals(o); } + } +} + +aspect AspectToIntroduce_finalize { + introduction SomeType { + public void finalizeNew() { try { finalize(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_getClass { + introduction SomeType { + public Class getClassNew() { return getClass(); } + } +} + +aspect AspectToIntroduce_hashCode { + introduction SomeType { + public int hashCodeNew() { return hashCode(); } + } +} + +aspect AspectToIntroduce_notify { + introduction SomeType { + public void notifyNew() { try { notify(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_notifyAll { + introduction SomeType { + public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_toString { + introduction SomeType { + public String toStringNew() { return toString(); } + } +} + +aspect AspectToIntroduce_wait { + introduction SomeType { + public void waitNew() { try { wait(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_waitL { + introduction SomeType { + public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_waitLI { + introduction SomeType { + public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} } + } +} diff --git a/tests/new/Clazz.java b/tests/new/Clazz.java new file mode 100644 index 000000000..2e2af67a7 --- /dev/null +++ b/tests/new/Clazz.java @@ -0,0 +1,6 @@ +import org.aspectj.testing.*; +class Clazz { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } +} diff --git a/tests/new/Client.java b/tests/new/Client.java new file mode 100644 index 000000000..312520dba --- /dev/null +++ b/tests/new/Client.java @@ -0,0 +1,109 @@ +import org.aspectj.testing.Tester; + +aspect ClientFlow percflow(entries(Client)) { + pointcut entries(Client c): + this(c) && (call(void Server.doService1(Object)) || + call(void Server.doService2())); + + Client client; + before (Client c): entries(c) { client = c; } + + pointcut workPoints(): + (this(ServiceWorker1) && call(void doWorkItemA())) || + (this(ServiceWorker2) && call(void doWorkItemB())) || + (this(ServiceWorker3) && call(void doWorkItemC())) || + (this(ServiceWorker4) && call(void doWorkItemD())); + + Object around(): workPoints() { + //System.out.println("at work: " + thisJoinPoint.methodName); + client.count++; + return proceed(); + //return; + } + + void util(Client c) { + c.count++; + client.count++; + } +} + + +public class Client { + public static void main(String[] args) { test(); } + public static void test() { + Client c = new Client(); + Server s = new Server(); + + c.requestServices(s); + + Tester.checkEqual(c.count, 5, "A+B+C+2*D"); + + Tester.check("WorkA"); + Tester.check("WorkB"); + Tester.check("WorkC"); + Tester.check("WorkD"); + } + + int count; + + public void requestServices(Server s) { + s.doService1("foo"); + s.doService2(); + } +} + +class Server { + + ServiceWorker1 worker1 = new ServiceWorker1(); + ServiceWorker2 worker2 = new ServiceWorker2(); + + public void doService1(Object data) { + worker1.doYourPart(); + } + + public void doService2() { + worker2.doYourPart(); + } +} + +class ServiceWorker1 { + void doYourPart() { + doWorkItemA(); + } + + void doWorkItemA() { Tester.note("WorkA");} +} + +class ServiceWorker2 { + ServiceWorker3 worker3 = new ServiceWorker3(); + ServiceWorker4 worker4 = new ServiceWorker4(); + + void doYourPart() { + worker3.doYourPart(); + worker4.doYourPart(); + doWorkItemB(); + } + + void doWorkItemB() { Tester.note("WorkB");} + +} + +class ServiceWorker3 { + void doYourPart() { + doWorkItemC(); + } + + void doWorkItemC() { Tester.note("WorkC"); } +} + +class ServiceWorker4 { + void doYourPart() { + doWorkItemD(); + } + + void doWorkItemD() { + // charge extra for 'd' "by hand" + ClientFlow.aspectOf().client.count++; + Tester.note("WorkD"); + } +} diff --git a/tests/new/CombinedLogic.java b/tests/new/CombinedLogic.java new file mode 100644 index 000000000..948649280 --- /dev/null +++ b/tests/new/CombinedLogic.java @@ -0,0 +1,21 @@ +import org.aspectj.testing.Tester; + +/** + * Test for: PR #99 + */ + +public class CombinedLogic { + public static void main(String[] args) { test(); } + + public static void test() { + Object foo = null; + int baz = 1; + int foobaz = baz; + + if ((null == foo) && (baz != foobaz)) { + Tester.check(false, "better not"); + } else { + Tester.check(true, "it better be true"); + } + } +} diff --git a/tests/new/CommentAfterClass.java b/tests/new/CommentAfterClass.java new file mode 100644 index 000000000..5bebac797 --- /dev/null +++ b/tests/new/CommentAfterClass.java @@ -0,0 +1,13 @@ +import org.aspectj.testing.Tester; + +/** + * Test for: PR #99 + */ + +public class CommentAfterClass { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.check(true, "it better be true"); + } +}//extra comment
\ No newline at end of file diff --git a/tests/new/Comments.java b/tests/new/Comments.java new file mode 100644 index 000000000..ca76512d0 --- /dev/null +++ b/tests/new/Comments.java @@ -0,0 +1,8 @@ +/**/ +import java.util.Iterator; + +/** + * Javadoc comment for this class + */ +public class MyIterator implements Iterator { +} diff --git a/tests/new/ComputedThrows.java b/tests/new/ComputedThrows.java new file mode 100644 index 000000000..fbaf33888 --- /dev/null +++ b/tests/new/ComputedThrows.java @@ -0,0 +1,28 @@ +import org.aspectj.testing.Tester; + +public class ComputedThrows { + public static void main(String[] args) { test(); } + public static void test() { + new ComputedThrows().bar(); + Tester.check("ran bar"); + Tester.check("caught Exception"); + } + void bar() throws Exception { + Tester.note("ran bar"); + throw new Exception(); + } +} + +aspect Aspect { + pointcut Foo(): within(ComputedThrows) && call(* ComputedThrows.bar(..)); + + declare soft: Exception: Foo(); + + void around(): Foo() { + try { + proceed(); + } catch (Exception e) { + Tester.note("caught Exception"); + } + } +} diff --git a/tests/new/ConstructorExecInit.java b/tests/new/ConstructorExecInit.java new file mode 100644 index 000000000..337fbbda3 --- /dev/null +++ b/tests/new/ConstructorExecInit.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.*; + +/** + * -usejavac mode: no error + * not -usejavac mode: VerifyError + */ +public class ConstructorExecInit { + public static void main(String[] args) { + new ConstructorExecInit(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("execution"); + Tester.expectEvent("initialization"); + } +} + +/** @testcase after returning from initialization and after executing constructor */ +aspect A { + after (Object target) : execution(*.new(..)) && target(target) { + Tester.event("execution"); + } + after () returning (Object target) : initialization(new(..)) { + Tester.event("initialization"); + } +} diff --git a/tests/new/ConstructorNotFound_PR408.java b/tests/new/ConstructorNotFound_PR408.java new file mode 100644 index 000000000..9a673ca75 --- /dev/null +++ b/tests/new/ConstructorNotFound_PR408.java @@ -0,0 +1,11 @@ +import org.aspectj.testing.*; +public class ConstructorNotFound_PR408 { + public static void main(String[] args) { + new ExtendsOuterAbstract_PR408().go(); + new OuterAbstract_PR408() {}.go(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("ExtendsOuterAbstract_PR408.go,InnerAbstract.go,OuterAbstract_PR408.go"); + } +} diff --git a/tests/new/ConstructorSignatures.java b/tests/new/ConstructorSignatures.java new file mode 100644 index 000000000..cfb2a575a --- /dev/null +++ b/tests/new/ConstructorSignatures.java @@ -0,0 +1,39 @@ +// Does annotating 'new' with a type work as desired? + +import org.aspectj.testing.Tester; + +public class ConstructorSignatures { + public static void main(String[] args) { + new A1(); + Tester.checkEqual(A.a0, 2, "A0 advice overcalled"); + Tester.checkEqual(A.a1, 1, "A1 advice overcalled"); + Tester.checkEqual(A.b, 0, "B advice overcalled"); + A.a0 = A.a1 = A.b = 0; + + new B(); + Tester.checkEqual(A.a0, 0, "-A0 advice overcalled"); + Tester.checkEqual(A.a1, 0, "-A1 advice overcalled"); + Tester.checkEqual(A.b, 1, "-B advice overcalled"); + } +} + +class A0 { } + +class A1 extends A0 { } + +class B {} + +aspect A { + static int a0, a1, b; + /*static*/ before(): execution(A0+.new()) { //added + + a0++; + } + + /*static*/ before(): execution(A1.new()) { + a1++; + } + + /*static*/ before(): execution(B.new()) { + b++; + } +} diff --git a/tests/new/Counting1.java b/tests/new/Counting1.java new file mode 100644 index 000000000..d57789612 --- /dev/null +++ b/tests/new/Counting1.java @@ -0,0 +1,156 @@ +import java.util.Vector; +import org.aspectj.testing.*; + +public class Counting1 { + public static void main(String[] args) { + + Point pt1 = new Point(0, 0); + Point pt2 = new Point(4, 4); + Line ln1 = new Line(pt1, pt2); + + System.out.println(MoveTracking.testAndClear()); + ln1.translate(3, 6); + System.out.println(MoveTracking.testAndClear()); + + System.out.println(pt1.getX()); + Mobility.disableMoves(); + ln1.translate(3, 6); + System.out.println(pt1.getX()); + + } + + static class System { + static O out = new O(); + static class O { + public void println(Object o) {} + public void println(int i) {} + public void println(boolean b) {} + } + } +} + +class FigureEditor { + //... +} + +class Figure { + Vector elements = new Vector(); + //... +} + + + +interface FigureElement { + public void translate(int dx, int dy); + //... +} + +class Point implements FigureElement { + private int _x = 0, _y = 0; + + Point(int x, int y) { + _x = x; + _y = y; + } + + public void translate(int dx, int dy) { + setX(getX() + dx); + setY(getY() + dy); + } + + int getX() { return _x; } + int getY() { return _y; } + + void setX(int x) { _x = x; } + void setY(int y) { _y = y; } + + //... +} + +class Line implements FigureElement { + private Point _p1, _p2; + + Line (Point p1, Point p2) { + _p1 = p1; + _p2 = p2; + } + + public void translate(int dx, int dy) { + _p1.translate(dx, dy); + _p2.translate(dx, dy); + } + + Point getP1() { return _p1; } + Point getP2() { return _p2; } + + void setP1(Point p1) { _p1 = p1; } + void setP2(Point p2) { _p2 = p2; } + + //... +} + +aspect JoinPointCounting { + + static int n = 0; + static boolean enable = true; + + pointcut points(): + /* + instanceof(*) && + !(receptions(* *.new(..)) || + executions(* *.new(..))); + */ + + call(* *.*(..)) || + //receptions(* *.*(..)) || + execution(* *.*(..));/* || + gets(* *.*) || + sets(* *.*); + */ + + + before(): points() && !within(JoinPointCounting) { + if ( enable ) { + String s = thisJoinPoint + ""; + Tester.check(s.indexOf("$") == -1, s + " contains a $"); + } + } +} + + +aspect MoveTracking { + + static boolean flag = false; + + static boolean testAndClear() { + boolean result = flag; + flag = false; + return result; + } + + pointcut moves(): + call(void FigureElement.translate(int, int)) || + call(void Line.setP1(Point)) || + call(void Line.setP2(Point)) || + call(void Point.setX(int)) || + call(void Point.setY(int)); + + after(): moves() { + flag = true; + } + } + +aspect Mobility { declare dominates: Mobility, MoveTracking; + private static boolean enableMoves = true; + + static void enableMoves() { enableMoves = true; } + static void disableMoves() { enableMoves = false; } + + void around(): MoveTracking.moves() { + if ( enableMoves ) + proceed(); //!!! in versions prior to 0.7b10 runNext is a + //!!! method on the join point object, so the + //!!! syntax of this call is slightly different + //!!! than in the paper + } +} diff --git a/tests/new/Counting3.java b/tests/new/Counting3.java new file mode 100644 index 000000000..7c3486fea --- /dev/null +++ b/tests/new/Counting3.java @@ -0,0 +1,51 @@ +import java.util.Vector; +import org.aspectj.testing.*; + +public class Counting3 { + public static void main(String[] args) { + Testing.start(); + new Counting3().f(); + Testing.finish(); + } + int j; + void f() { + j = 13; + int i = j; + } +} + +class Testing { + static void start() { + // - e main - - ca f() - - ex f() - - set j --------- - get j --------- + Tester.expectEventsInString("e,egs,cegs,c,cgs,cegs,e,egs,cegs,s,gs,cgs,egs,cegs,g,gs,cgs,egs,cegs"); + // Tester.expectEventsInString("g,s,gs,c,e,cgs,egs,cegs"); // old, incorrect (matching dups) + } + static void finish() { + Tester.checkAllEvents(); + } +} + +aspect JoinPointCounting { + + pointcut g(): get(* *.*) && within(Counting3); + before(): g() { a("g"); } + + pointcut s(): set(* *.*) && within(Counting3); + before(): s() { a("s"); } + + pointcut gs(): g() || s(); + before(): gs() { a("gs"); } + + pointcut c(): call(* *.*(..)) && within(Counting3) && ! call(* Testing.*()); + before(): c() { a("c"); } + pointcut e(): execution(* *.*(..)) && within(Counting3); + before(): e() { a("e"); } + + pointcut cgs(): c() || gs(); before(): cgs() { a("cgs"); } + pointcut egs(): e() || gs(); before(): egs() { a("egs"); } + + pointcut cegs(): c() || e() || gs(); before(): cegs() { a("cegs"); } + + static void a(String s) { Tester.event(s); } + +} diff --git a/tests/new/Cricket.java b/tests/new/Cricket.java new file mode 100644 index 000000000..33c1849e1 --- /dev/null +++ b/tests/new/Cricket.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.Tester; + +public class Cricket { + public static void main(String[] args) { + Lib l = new Lib(); + Tester.event("call stringMethod"); + l.stringMethod(2); + Tester.event("call voidMethod"); + l.voidMethod(2); + Tester.checkEventsFromFile("Cricket.out"); + } +} + + +class Lib { + public void voidMethod(int count) { + if (count == 0) return; + else voidMethod(count - 1); + } + + public String stringMethod(int count) { + if (count == 0) return "0"; + else return count + "-" + stringMethod(count-1); + } +} + + +aspect Trace { + pointcut entry(): target(Lib) && call(* *(..)); + pointcut topEntry(): entry() && !cflowbelow(entry()); + + before(): topEntry() { + Tester.event("->top entry: " + thisJoinPoint); + } + + after(): entry() { + Tester.event("->exit: " + thisJoinPoint); + } + + after() returning (Object o): entry() { + Tester.event("->exit: " + thisJoinPoint + " with " + o); + } + after(): topEntry() { + Tester.event("->top exit: " + thisJoinPoint); + } + + after() returning (Object o): topEntry() { + Tester.event("->top exit: " + thisJoinPoint + " with " + o); + } +} diff --git a/tests/new/Cricket.out b/tests/new/Cricket.out new file mode 100644 index 000000000..30d28a050 --- /dev/null +++ b/tests/new/Cricket.out @@ -0,0 +1,20 @@ +call stringMethod
+->top entry: call(String Lib.stringMethod(int))
+->exit: call(String Lib.stringMethod(int))
+->exit: call(String Lib.stringMethod(int)) with 0
+->exit: call(String Lib.stringMethod(int))
+->exit: call(String Lib.stringMethod(int)) with 1-0
+->exit: call(String Lib.stringMethod(int))
+->exit: call(String Lib.stringMethod(int)) with 2-1-0
+->top exit: call(String Lib.stringMethod(int))
+->top exit: call(String Lib.stringMethod(int)) with 2-1-0
+call voidMethod
+->top entry: call(void Lib.voidMethod(int))
+->exit: call(void Lib.voidMethod(int))
+->exit: call(void Lib.voidMethod(int)) with null
+->exit: call(void Lib.voidMethod(int))
+->exit: call(void Lib.voidMethod(int)) with null
+->exit: call(void Lib.voidMethod(int))
+->exit: call(void Lib.voidMethod(int)) with null
+->top exit: call(void Lib.voidMethod(int))
+->top exit: call(void Lib.voidMethod(int)) with null
\ No newline at end of file diff --git a/tests/new/CyclicClassInheritance.java b/tests/new/CyclicClassInheritance.java new file mode 100644 index 000000000..c5cd0d7c0 --- /dev/null +++ b/tests/new/CyclicClassInheritance.java @@ -0,0 +1,12 @@ + +/** @testcase PR#567 no error for cyclic class inheritance if no classes implement the interfaces */ +public class CyclicClassInheritance { + + public static void main( String args[] ) { + throw new Error("not to be run - error case "); + } +} + + +class A extends B { A(); void a(){} } +class B extends A { B(); void b(){} } diff --git a/tests/new/CyclicInterfaceInheritance.java b/tests/new/CyclicInterfaceInheritance.java new file mode 100644 index 000000000..69e27d99a --- /dev/null +++ b/tests/new/CyclicInterfaceInheritance.java @@ -0,0 +1,15 @@ + +/** @testcase PR#567 no error for cyclic interface inheritance if no classes implement the interfaces */ +public class CyclicInterfaceInheritance { + + public static void main( String args[] ) { + throw new Error("not to be run - error case "); + } +} +// no bug if any class implements the interfaces +class C { + void a() { } + void b() { } +} +interface A extends B { void a(); } //ERR: A <- B <- A +interface B extends A { void b(); } //ERR: B <- A <- B diff --git a/tests/new/CyclicPointcuts.java b/tests/new/CyclicPointcuts.java new file mode 100644 index 000000000..9f5fc41b8 --- /dev/null +++ b/tests/new/CyclicPointcuts.java @@ -0,0 +1,73 @@ + +import org.aspectj.testing.Tester; + + + +/** PR#568 cyclic pointcut definitions */ +public class CyclicPointcuts { + + static aspect A { + /* @testcase pointcut depends on itself */ + pointcut p(): p(); // CE 11 recursion not permitted + + /* @testcase two pointcuts depends on each other */ + pointcut p1(): p2(); // CE 14 recursion not permitted + pointcut p2(): p1(); // line 15 + + /* @testcase three pointcuts depends on each other */ + pointcut pa(): pb(); // CE 18 recursion not permitted + pointcut pb(): pc(); // line 19 + pointcut pc(): pa(); // line 20 + } +} + +/** @testcase three pointcuts in different classes in a cycle */ +aspect One { + pointcut p() : Two.p(); // line 26 +} +aspect Two { + pointcut p() : Three.p(); // line 29 +} +aspect Three { + pointcut p() : One.p(); // CE 32 recursion not permitted +} + +/** @testcase three pointcuts in different classes (sub, super, other) in a cycle */ +abstract aspect Base { + pointcut base() : A.p(); // line 37 +} +aspect A { + pointcut p() : Derived.p(); // line 40 +} +aspect Derived extends Base { + pointcut p() : base(); // CE 43 recursion not permitted +} + +aspect Driver { + // error test, but... + static { + Tester.expectEvent("Derived.p()"); + Tester.expectEvent("Three.p()"); + Tester.expectEvent("CyclicPointcuts.A.p()"); + Tester.expectEvent("CyclicPointcuts.A.p1()"); + Tester.expectEvent("CyclicPointcuts.A.()"); + } + before() : Derived.p() { + Tester.event("Derived.p()"); + } + before() : Three.p() { + Tester.event("Three.p()"); + } + before() : CyclicPointcuts.A.p() { + Tester.event("CyclicPointcuts.A.p()"); + } + before() : CyclicPointcuts.A.p1() { + Tester.event("CyclicPointcuts.A.p1()"); + } + before() : CyclicPointcuts.A.pa() { + Tester.event("CyclicPointcuts.A.pa()"); + } + +} + + diff --git a/tests/new/DeclarationCollisionCE.java b/tests/new/DeclarationCollisionCE.java new file mode 100644 index 000000000..3ad4f4f16 --- /dev/null +++ b/tests/new/DeclarationCollisionCE.java @@ -0,0 +1,31 @@ + +/** @testcase expect CE for declaration collision between subaspects instead of domination order */ +public class DeclarationCollisionCE { + public static void main (String[] args) { + C s = new C(); + System.err.println("title: " + s.title()); + } +} + +class C {} + +// bug: dominates clause prevents collision error +abstract aspect AA dominates B { + // same result if this line is uncommented + //public String C.title() { return "[AA] C.title()"; } +} + +aspect A extends AA { // implicitly dominates AA + // dominates AA's declaration, overriding Super.title + public String C.title() { // CE 21 collision with B declaration + return "[A] C.title()" ; + } +} + +aspect B extends AA { // explicitly dominated by AA ?? --> and hence by A?? + // B fails to dominate AA's declaration, overriding Super.title + public String C.title() { // CE 28 collision with A declaration + return "[B] C.title()" ; + } +} + diff --git a/tests/new/DeclareAccess.java b/tests/new/DeclareAccess.java new file mode 100644 index 000000000..a57363d52 --- /dev/null +++ b/tests/new/DeclareAccess.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.*; + +public class DeclareAccess { + public static void main (String[] args) { + Tester.event("main"); + Target t = new Target(); + Aspect a = Aspect.aspectOf(); + a.tryPI(t); + Tester.checkAllEvents(); + } + + static { + Tester.expectEvent("run"); + Tester.expectEvent("main"); + Tester.expectEvent("value"); + } +} + +class Target { + public String value() { + Tester.event("run"); + return "value"; + } +} + +/** @testcase private inner interface accessible in scope when declared on outer class */ +aspect Aspect { + private interface PI { + public String value(); + } + public void tryPI(Target t) { + PI pi = (PI) t; + Tester.event(pi.value()); + } + /** @testcase private interface declared on Target */ + declare parents: Target implements PI; +} diff --git a/tests/new/DeclareAspectConstructorCE.java b/tests/new/DeclareAspectConstructorCE.java new file mode 100644 index 000000000..864d5f097 --- /dev/null +++ b/tests/new/DeclareAspectConstructorCE.java @@ -0,0 +1,11 @@ + + +/** @testcase PR851 declaring an aspect constructor with argument should be prohibited */ + +aspect A { + A() {} +} + +aspect B { + A.new(int i) {} // CE 10 +} diff --git a/tests/new/DeclareClassExtendsInterface.java b/tests/new/DeclareClassExtendsInterface.java new file mode 100644 index 000000000..8b5454cec --- /dev/null +++ b/tests/new/DeclareClassExtendsInterface.java @@ -0,0 +1,11 @@ + + + + +/** @testcase PR853 declare class extends interface */ + +class C {} + +aspect A { + declare parents: C extends java.io.Serializable; // CE 10 +}
\ No newline at end of file diff --git a/tests/new/DeclareClassImplementsClass.java b/tests/new/DeclareClassImplementsClass.java new file mode 100644 index 000000000..f10c574cb --- /dev/null +++ b/tests/new/DeclareClassImplementsClass.java @@ -0,0 +1,11 @@ + + +/** @testcase PR853 declare class implements class CE */ + +class C {} + +class B {} + +aspect A { + declare parents: C implements B; // CE 10 +}
\ No newline at end of file diff --git a/tests/new/DeclareInterfaceConstructor.java b/tests/new/DeclareInterfaceConstructor.java new file mode 100644 index 000000000..a823faf5d --- /dev/null +++ b/tests/new/DeclareInterfaceConstructor.java @@ -0,0 +1,22 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#884 declare constructor on interface subclasses */ +public class DeclareInterfaceConstructor { + public static void main(String[] args) { + X x = new Z(1); + if (1 != x.i) { + Tester.check(false, "bad constructor initialization"); + } + } +} + +interface X {} + +class Z implements X {} + +aspect Y { + public int X.i; + public X+.new(final int i) {this.i = i;} +} + diff --git a/tests/new/DeclareInterfaceExtendsClass.java b/tests/new/DeclareInterfaceExtendsClass.java new file mode 100644 index 000000000..cb255d26c --- /dev/null +++ b/tests/new/DeclareInterfaceExtendsClass.java @@ -0,0 +1,11 @@ + + +/** @testcase PR853 declare interface extends class CE */ + +interface I {} + +class C {} + +aspect A { + declare parents: I extends C; // CE 10 +}
\ No newline at end of file diff --git a/tests/new/DeclareInterfaceImplementsClass.java b/tests/new/DeclareInterfaceImplementsClass.java new file mode 100644 index 000000000..9e4841624 --- /dev/null +++ b/tests/new/DeclareInterfaceImplementsClass.java @@ -0,0 +1,11 @@ + + +/** @testcase PR853 declare interface implements class CE */ + +interface I {} + +class B {} + +aspect A { + declare parents: I implements B; // CE 10 - XXX error says "extends" - weak +}
\ No newline at end of file diff --git a/tests/new/DeclareInterfaceImplementsInterface.java b/tests/new/DeclareInterfaceImplementsInterface.java new file mode 100644 index 000000000..c8b21ddd8 --- /dev/null +++ b/tests/new/DeclareInterfaceImplementsInterface.java @@ -0,0 +1,11 @@ + + +/** @testcase PR853 declare interface implements interface CE */ + +interface I {} + +interface I2 {} + +aspect A { + declare parents: I implements I2; // CE 10 +}
\ No newline at end of file diff --git a/tests/new/DeclareMethodCE.java b/tests/new/DeclareMethodCE.java new file mode 100644 index 000000000..ded55022f --- /dev/null +++ b/tests/new/DeclareMethodCE.java @@ -0,0 +1,11 @@ + + +/** PR#888 ajc crashes given method in declared method */ +class B {} + +aspect A { + void B.n() { + void n() { // CE 8 method declared in method + } + } +} diff --git a/tests/new/DeclareOnlyAspectConstructorCE.java b/tests/new/DeclareOnlyAspectConstructorCE.java new file mode 100644 index 000000000..11bde660b --- /dev/null +++ b/tests/new/DeclareOnlyAspectConstructorCE.java @@ -0,0 +1,11 @@ + + + +/** @testcase PR851 declaring an aspect constructor with argument should be prohibited - sole constructor */ + +aspect A { +} + +aspect B { + A.new(int i) {} // CE 10 +} diff --git a/tests/new/DeclareParentsNonsenseCE.java b/tests/new/DeclareParentsNonsenseCE.java new file mode 100644 index 000000000..bf567d595 --- /dev/null +++ b/tests/new/DeclareParentsNonsenseCE.java @@ -0,0 +1,8 @@ + +public class DeclareParentsNonsenseCE { } +aspect A { + /** @testcase PR#652 declare parent accepting interface for extension */ + declare parents: DeclareParentsNonsenseCE extends java.io.Serializable; // CE here + /** @testcase PR#652 declare parent accepting class for implementation */ + declare parents: DeclareParentsNonsenseCE implements java.util.Observable; // CE here +} diff --git a/tests/new/DeclareSoft.java b/tests/new/DeclareSoft.java new file mode 100644 index 000000000..095963f5b --- /dev/null +++ b/tests/new/DeclareSoft.java @@ -0,0 +1,84 @@ +import org.aspectj.testing.Tester; +import java.io.*; +import org.aspectj.lang.*; + +public class DeclareSoft { + public static void main(String[] args) { + new C().m1(); + try { + new C().m2(); + } catch (SoftException se) { + Tester.note("m2-soft"); + } + + try { + new C().m3(); + } catch (SoftException se) { + Tester.check(false, "already caught"); + } + + try { + new C().throwIt(); + } catch (SoftException se) { + Tester.note("throwIt-soft"); + } catch (Throwable t) { + Tester.check(false, "should have been softened: " + t); + } + + try { + new C().pretendsToThrow(); + } catch (IOException ioe) { + Tester.check(false, "bad IO"); + } + + Tester.check("m2-soft"); + Tester.check("around-m3"); + } +} + +class C { + public void throwIt() throws Throwable { + throw makeThrowable(); + } + + public void pretendsToThrow() throws IOException, ClassNotFoundException { + + } + + private Throwable makeThrowable() { + return new Exception("make me soft"); + } + + + public void m1() { + } + + public void m2() { + new File("___hi").getCanonicalPath(); + new FileInputStream("___bye"); + } + + public void m3() { + new FileInputStream("___bye"); + new File("___hi").getCanonicalPath(); + } +} + +aspect B { + declare soft: Exception: execution(* C.throwIt()); + + declare soft: ClassNotFoundException: call(* C.pretendsToThrow()); +} + + +aspect A { + declare soft: IOException: execution(* C.*(..)); + + void around(): execution(void C.m3()) { + try { + proceed(); + } catch (IOException ioe) { + Tester.note("around-m3"); + } + } +} diff --git a/tests/new/DeclareSoft2.java b/tests/new/DeclareSoft2.java new file mode 100644 index 000000000..26248898c --- /dev/null +++ b/tests/new/DeclareSoft2.java @@ -0,0 +1,21 @@ +import java.io.IOException; + +class DeclareSoft2 { + public static void main(String[] x) { + foo(); + } + + static void foo() throws IOException { + throw new IOException(); + } + +} + +aspect A { + + void around(): call(void foo()) { + try { proceed(); } + catch (IOException e) {} + } + declare soft: IOException: call(void foo()); +} diff --git a/tests/new/DeclareWarningMain.java b/tests/new/DeclareWarningMain.java new file mode 100644 index 000000000..243a4668b --- /dev/null +++ b/tests/new/DeclareWarningMain.java @@ -0,0 +1,19 @@ +import org.aspectj.testing.*; + +public class DeclareWarningMain { + public static void main (String[] args) { // DW 5 main + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("before"); + } +} + +aspect Warnings { + declare warning : execution(static void main(String[])) : "main"; // for DW 5 main + + // just to show that pointcut is valid - works if warning removed + before() : execution(static void main(String[])) { + Tester.event("before"); + } +} diff --git a/tests/new/DeclaredExcs.java b/tests/new/DeclaredExcs.java new file mode 100644 index 000000000..21b1f1009 --- /dev/null +++ b/tests/new/DeclaredExcs.java @@ -0,0 +1,97 @@ +import org.aspectj.testing.Tester; + +public class DeclaredExcs { + public static void main(String[] args) { test(); } + + public static void test() { + Foo foo = new Foo(); + + Tester.checkEqual(foo.foo(), "success", "foo()"); + try { + foo.bar(false); + } catch (Exception e) { + Tester.check(false, "shouldn't catch"); + } + + try { + Bar bar = new Bar(false); + } catch (MyException e) { + Tester.check(false, "shouldn't catch"); + } + + try { + Bar bar = Bar.getNewBar(true); + Tester.check(false, "shouldn't get here"); + } catch (MyException e) { + Tester.check(true, "should catch"); + } + } +} + +class Foo { + public void bar(boolean throwIt) throws Exception { + if (throwIt) { + throw new MyException("you asked for it"); + } + } + + public String foo() { + try { + bar(false); + } catch (Exception exc) { + Tester.check(false, "shouldn't catch anything"); + } + + try { + bar(true); + } catch (MyException exc) { + return "success"; + } catch (Exception e1) { + return "failure"; + } + + return "failure"; + } +} + +class Bar { + String value; + + public static Bar getNewBar(boolean throwIt) throws MyException { + return new Bar(throwIt); + } + + public Bar(boolean throwIt) throws MyException { + if (throwIt) { + throw new MyException("you asked for it from constructor"); + } + value = "boolean"; + } + + public Bar(String value) { + this.value = value; + } +} + + +class MyException extends Exception { + public MyException(String label) { + super(label); + } +} + +aspect A { + before (): this(*) && execution(* *(..)) || execution(new(..)) { + //System.out.println("entering: "+thisJoinPoint); + } + after (): this(*) && execution(* *(..)) || execution(new(..)) { + //System.out.println("exiting: "+thisJoinPoint); + } + + Object around(): this(*) && call(* *(..)) { + //System.out.println("start around: "+thisJoinPoint); + Object ret = proceed(); + //System.out.println("end around: "+thisJoinPoint); + return ret; + } +} diff --git a/tests/new/DefiniteStatic.java b/tests/new/DefiniteStatic.java new file mode 100644 index 000000000..7f9db6a12 --- /dev/null +++ b/tests/new/DefiniteStatic.java @@ -0,0 +1,11 @@ + +class Type { } + +class bat { + public static final Type SOURCE = new Type(); +} +public class DefiniteStatic { + protected static final Type SINK = bat.SOURCE; + public Type sink = SINK; // incorrect CE: field SINK might not have a value + public static void main(String[] args) { } +} diff --git a/tests/new/DeprecationWarning.java b/tests/new/DeprecationWarning.java new file mode 100644 index 000000000..0748132d1 --- /dev/null +++ b/tests/new/DeprecationWarning.java @@ -0,0 +1,18 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; +import java.rmi.RMISecurityException; // deprecated class + +/** @testcase PR#602 PUREJAVA no deprecation warnings (regardless of -deprecation flag) */ +public class DeprecationWarning { + public static void main(String[] args) { + boolean result = false; + try { + if (!result) throw new RMISecurityException("ok"); // CW 11 deprecated class + } catch (RMISecurityException e) { + result = true; + } + Tester.check(result, "no RMISecurityException"); + } + +} diff --git a/tests/new/Dominates.java b/tests/new/Dominates.java new file mode 100644 index 000000000..c232c4258 --- /dev/null +++ b/tests/new/Dominates.java @@ -0,0 +1,144 @@ +import org.aspectj.testing.*; + +/****************************** +Full_Name: Eelco Rommes +Version: ajc version 0.7beta7 (built Oct 6, 2000 4:03 PM PST) running on java 1.3.0 +OS: Win 98 +Submission from: mede.serc.nl (192.87.7.62) + + +I have one aspect using introduction to make some classes +implement certain interfaces. In another aspect, these +introductions are used to define pointcuts. The compiler +warns me, however, that the advice coupled to these pointcuts +have no target. This, because it apparently does not see +how the introduction-aspect changes the class-hierarchy. +I have tried to use 'dominates' to force aspectJ to evaluate +the introduction-aspect first, but it doesn't work. +******************************/ + +public class Dominates { + public static void main(String[] args) { + new Dominates().go(args); + } + + void go(String[] args) { + new A().run(); + new ExtendsA().run(); + new ExtendsRunnable().run(); + Tester.check(Flags.run1, "Flags.run1"); + Tester.check(Flags.run2, "Flags.run2"); + Tester.check(Flags.run3, "Flags.run3"); + Tester.check(Flags.run4, "Flags.run4"); + Tester.check(ExtendsFlags.run1, "ExtendsFlags.run1"); + Tester.check(ExtendsFlags.run2, "ExtendsFlags.run2"); + Tester.check(ExtendsFlags.run3, "ExtendsFlags.run3"); + Tester.check(ExtendsFlags.run4, "ExtendsFlags.run4"); + Tester.check(ExtendsFlags.run5, "ExtendsFlags.run5"); + Tester.check(ExtendsFlags.run6, "ExtendsFlags.run6"); + } +} + +class A { + +} + +class Flags { + public static boolean run1 = false; + public static boolean run2 = false; + public static boolean run3 = false; + public static boolean run4 = false; +} + +aspect Aspect0 { + pointcut run(): call(* run(..)) && target(A); + before(): run() { + Flags.run1 = true; + } +} + +aspect Aspect00 { + pointcut run(): call(* run(..)) && target(Runnable+); + before(): run() { + Flags.run4 = true; + } +} + +aspect Aspect1 { + declare parents: A implements Runnable; + public void A.run() {} +} + +aspect Aspect2 { + pointcut run(): call(* run(..)) && target(A); + before(): run() { + Flags.run2 = true; + } +} + +aspect Aspect3 { + pointcut run(): call(* run(..)) && target(Runnable+); + before(): run() { + Flags.run3 = true; + } +} + +// ------------------------------ + +class ExtendsA { + +} + +class ExtendsRunnable { + public void run() {} +} + +class ExtendsFlags { + public static boolean run1 = false; + public static boolean run2 = false; + public static boolean run3 = false; + public static boolean run4 = false; + public static boolean run5 = false; + public static boolean run6 = false; +} + +aspect AspectExtends0 { + pointcut run(): call(* run(..)) && target(ExtendsA); + before(): run() { + ExtendsFlags.run1 = true; + } +} + +aspect AspectExtends00 { + pointcut run(ExtendsRunnable r): call(* run(..)) && target(r); + before(ExtendsRunnable r): run(r) { + if (r instanceof ExtendsA) { + ExtendsFlags.run5 = true; + } else { + ExtendsFlags.run6 = true; + } + } +} + +aspect AspectExtends1 { + declare parents: ExtendsA extends ExtendsRunnable; + public void ExtendsA.run() {} +} + +aspect AspectExtends2 { + pointcut run(): call(* run(..)) && target(ExtendsA); + before(): run() { + ExtendsFlags.run2 = true; + } +} + +aspect AspectExtends3 { + pointcut run(ExtendsRunnable r): call(* run(..)) && target(r); + before(ExtendsRunnable r): run(r) { + if (r instanceof ExtendsA) { + ExtendsFlags.run3 = true; + } else { + ExtendsFlags.run4 = true; + } + } +} diff --git a/tests/new/DominatesTypePattern.java b/tests/new/DominatesTypePattern.java new file mode 100644 index 000000000..5cfa55761 --- /dev/null +++ b/tests/new/DominatesTypePattern.java @@ -0,0 +1,21 @@ +import org.aspectj.testing.Tester; + +/** @testcase subtype pattern in dominates should pick out aspect subtypes */ +public class DominatesTypePattern { + public static void main (String[] args) { + String s = new C().method(); + Tester.check("pass".equals(s), + "\"pass\".equals(\"" + s + "\")"); + } +} + +class C {} + +// works if A is specified explicitly +abstract aspect AA dominates AA+ { // error: should dominate A + public String C.method() { return "pass"; } +} + +aspect A extends AA { + public String C.method() { return "fail"; } +} diff --git a/tests/new/DoubleClass1.java b/tests/new/DoubleClass1.java new file mode 100644 index 000000000..de9fa76df --- /dev/null +++ b/tests/new/DoubleClass1.java @@ -0,0 +1,7 @@ + +// PR#223 +class DoubleClass {} +public class DoubleClass1 { + public static void main(String[] ignored) { + } +} diff --git a/tests/new/DoubleClass2.java b/tests/new/DoubleClass2.java new file mode 100644 index 000000000..de1b99e49 --- /dev/null +++ b/tests/new/DoubleClass2.java @@ -0,0 +1,3 @@ + +// PR#223 +class DoubleClass {} diff --git a/tests/new/DoubledCalls.java b/tests/new/DoubledCalls.java new file mode 100644 index 000000000..3757f1d86 --- /dev/null +++ b/tests/new/DoubledCalls.java @@ -0,0 +1,20 @@ +import org.aspectj.testing.Tester; + +public class DoubledCalls { + public static void main(String[] args) { + new Runnable() { + public void run() { + new Integer(1).intValue(); + } + }.run(); + Tester.check(A.calledInteger, "A.calledInteger"); + } +} + +aspect A { + static boolean calledInteger = false; + + /*static*/ before(): call(* Integer.*(..)) { + A.calledInteger = true; + } +} diff --git a/tests/new/EachCFlow0.java b/tests/new/EachCFlow0.java new file mode 100644 index 000000000..c25a4547d --- /dev/null +++ b/tests/new/EachCFlow0.java @@ -0,0 +1,10 @@ +import org.aspectj.testing.Tester; +public class EachCFlowRoot0 { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } +} +aspect A of eachcflow(A.pc() && !cflow(A.pc())) { + pointcut pc() : within(C) ; +} +class C {} diff --git a/tests/new/EachCFlowRoot0.java b/tests/new/EachCFlowRoot0.java new file mode 100644 index 000000000..c25a4547d --- /dev/null +++ b/tests/new/EachCFlowRoot0.java @@ -0,0 +1,10 @@ +import org.aspectj.testing.Tester; +public class EachCFlowRoot0 { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } +} +aspect A of eachcflow(A.pc() && !cflow(A.pc())) { + pointcut pc() : within(C) ; +} +class C {} diff --git a/tests/new/EachCFlowRoot1.java b/tests/new/EachCFlowRoot1.java new file mode 100644 index 000000000..dfac549a8 --- /dev/null +++ b/tests/new/EachCFlowRoot1.java @@ -0,0 +1,11 @@ +import org.aspectj.testing.Tester; +public class EachCFlowRoot1 { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } +} +aspect A of eachcflow(A.pctop()) { + pointcut pc() : within(C) ; + pointcut pctop(): pc() && !cflow(pc()); +} +class C {} diff --git a/tests/new/EachCFlowRoot2.java b/tests/new/EachCFlowRoot2.java new file mode 100644 index 000000000..90c2361ef --- /dev/null +++ b/tests/new/EachCFlowRoot2.java @@ -0,0 +1,13 @@ +import org.aspectj.testing.Tester; +public class EachCFlowRoot2 { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } +} +aspect A of eachcflow(B.pctop()) { + pointcut pc() : within(C) ; +} +aspect B { + pointcut pctop(): within(C) && !cflow(within(C)); +} +class C {} diff --git a/tests/new/EachJVMOnSelf.java b/tests/new/EachJVMOnSelf.java new file mode 100644 index 000000000..cbbd1eeae --- /dev/null +++ b/tests/new/EachJVMOnSelf.java @@ -0,0 +1,20 @@ +import org.aspectj.testing.Tester; + +public class EachJVMOnSelf { + public static void main(String[] args) { + new C(); + + Tester.checkEqual(A.aspectOf().advisedNewClass, "C"); + } +} + +aspect A issingleton() { + String advisedNewClass = null; + + after () returning (): this(*) && execution(new(..)) { + advisedNewClass = thisJoinPoint.getSourceLocation().getWithinType().getName(); + } +} + +class C { +} diff --git a/tests/new/EachObjectInDeepPackage.java b/tests/new/EachObjectInDeepPackage.java new file mode 100644 index 000000000..9e52b4d08 --- /dev/null +++ b/tests/new/EachObjectInDeepPackage.java @@ -0,0 +1,9 @@ +package the.deep.pkg; + +import org.aspectj.testing.Tester; + +aspect Aspect pertarget(target(EachObjectTarget)) { + before(): call(void foo(..)) { + Tester.check(true, "Dummy test"); + } +} diff --git a/tests/new/EachObjectNoThis.java b/tests/new/EachObjectNoThis.java new file mode 100644 index 000000000..306df8944 --- /dev/null +++ b/tests/new/EachObjectNoThis.java @@ -0,0 +1,23 @@ +import org.aspectj.testing.Tester; + +public class EachObjectNoThis { + public static void main(String[] args) { + new C().foo(); + } +} + +class C { + public void foo() { + } +} + +aspect A /*of eachobject(!instanceof(Object))*/ { + { + // This doesn't appy + //Tester.checkFailed("this aspect shouldn't exist"); + } + before(): !target(Object) && call(* *(..)) { + Tester.checkFailed("this aspect shouldn't exist"); + } +} + diff --git a/tests/new/EachObjectTarget.java b/tests/new/EachObjectTarget.java new file mode 100644 index 000000000..9c5052342 --- /dev/null +++ b/tests/new/EachObjectTarget.java @@ -0,0 +1,12 @@ +import org.aspectj.testing.Tester; + +public class EachObjectTarget { + public static void main(String[] args) { + EachObjectTarget o = new EachObjectTarget(); + o.foo(); + } + + void foo() { + Tester.check(true, "Dummy test"); + } +} diff --git a/tests/new/EmptyStack.java b/tests/new/EmptyStack.java new file mode 100644 index 000000000..464b8e4c8 --- /dev/null +++ b/tests/new/EmptyStack.java @@ -0,0 +1,36 @@ +import org.aspectj.lang.*; +import org.aspectj.testing.*; +import java.io.*; + +public class EmptyStack{ + public static void main(String[] args){ + try { + EmptyStackAspect.InnerEmptyStackAspect a = EmptyStackAspect.InnerEmptyStackAspect.aspectOf(); + } catch (java.util.EmptyStackException ese) { + String msg = ""; + class PW extends PrintWriter { + PW() { super((Writer)null); } + String msg = ""; + public void write(int c) { msg += c; } + } + PW pw = new PW(); + ese.printStackTrace(pw); + Tester.check(false, pw.msg); + } catch (NoAspectBoundException nae) { + Tester.note("caught NoAspectBound"); + } + + Tester.check("caught NoAspectBound"); + } +} + +abstract aspect EmptyStackAspect { + pointcut testCut(); + + public static aspect InnerEmptyStackAspect percflow(testCut()){ + } +} + +aspect MyEmptyStackAspect extends EmptyStackAspect issingleton() { + pointcut testCut(): call(void EmptyStack.test(..)) ; +} diff --git a/tests/new/ExceptionNames.java b/tests/new/ExceptionNames.java new file mode 100644 index 000000000..ba628bda4 --- /dev/null +++ b/tests/new/ExceptionNames.java @@ -0,0 +1,26 @@ + +import org.aspectj.testing.Tester; + +// PR#125 + +public class ExceptionNames { + + public static void main(String[] args) { test(); } + + public static void test() { + String exception = ""; + java.lang.reflect.Method liveRoutine = null; + try { + liveRoutine.invoke(null,null); + } + catch (java.lang.reflect.InvocationTargetException e) { + System.out.println(" " + e.getTargetException()); + exception = e.getClass().toString(); + } + catch (Exception e) { + exception = e.getClass().toString(); + } + Tester.checkEqual(exception, "class java.lang.NullPointerException", "exception handled"); + } + private void foo() {} +} diff --git a/tests/new/ExpandedDotDotPattern.java b/tests/new/ExpandedDotDotPattern.java new file mode 100644 index 000000000..34531abdd --- /dev/null +++ b/tests/new/ExpandedDotDotPattern.java @@ -0,0 +1,138 @@ +import org.aspectj.testing.Tester; + +public class ExpandedDotDotPattern { + public static void main(String[] args) { + new A().foo(); + new B().foo(3); + new C().foo(3, 3); + new D().foo(3, 3, 3); + new E().foo(3, 3, 3, 3); + new F().foo(3, 3, 3, 3, 3); + Tester.checkEqual(A.count, 1 + 1 + 1 + 1 + 1, "not enough 0-ary"); + Tester.checkEqual(B.count, 0 + 2 + 3 + 4 + 5, "not enough 1-ary"); + Tester.checkEqual(C.count, 0 + 1 + 4 + 7 + 11, "not enough 2-ary"); + Tester.checkEqual(D.count, 0 + 1 + 3 + 8 + 15, "not enough 3-ary"); + Tester.checkEqual(E.count, 0 + 1 + 3 + 7 + 16, "not enough 4-ary"); + Tester.checkEqual(F.count, 0 + 1 + 3 + 7 + 15, "not enough 5-ary"); + } +} + +interface I { + void inc(); +} + +class A implements I { + static int count = 0; + public void inc() { count++; } + void foo() {} +} +class B implements I { + static int count = 0; + public void inc() { count++; } + void foo(int a) {} +} +class C implements I { + static int count = 0; + public void inc() { count++; } + void foo(int a, int b) {} +} +class D implements I { + static int count = 0; + public void inc() { count++; } + void foo(int a, int b, int c) {} +} +class E implements I { + static int count = 0; + public void inc() { count++; } + void foo(int a, int b, int c, int d) {} +} +class F implements I { + static int count = 0; + public void inc() { count++; } + void foo(int a, int b, int c, int d, int e) {} +} + + +aspect Aspect { + // zero + before(I i): this(i) && execution(void foo()) { + System.out.println(thisJoinPoint); + i.inc(); + } + + // one + before(I i): this(i) && execution(void foo( ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int)) { + System.out.println("(int)" + thisJoinPoint); + i.inc(); + } + + // two + before(I i): this(i) && execution(void foo( .., ..)) { + System.out.println("(.., ..)" + thisJoinPoint); + i.inc(); + } + + before(I i): this(i) && execution(void foo(int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int)) { + System.out.println("(.., int)" + thisJoinPoint); + i.inc(); + } + + before(I i): this(i) && execution(void foo(int, int)) { i.inc(); } + + // three + before(I i): this(i) && execution(void foo( .., .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, int)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, int)) { i.inc(); } + + // four + + before(I i): this(i) && execution(void foo( .., .., .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., .., .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., .., int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., .., int, int)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo( .., int, int, int)) { i.inc(); } + + + before(I i): this(i) && execution(void foo(int, .., .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, .., .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, .., int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, .., int, int)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, .., ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, .., int)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, int, ..)) { i.inc(); } + + before(I i): this(i) && execution(void foo(int, int, int, int)) { i.inc(); } + +} diff --git a/tests/new/ExpandedMethodSigs.java b/tests/new/ExpandedMethodSigs.java new file mode 100644 index 000000000..8fc1c57d0 --- /dev/null +++ b/tests/new/ExpandedMethodSigs.java @@ -0,0 +1,59 @@ +import org.aspectj.testing.Tester; + +public class ExpandedMethodSigs { + public static void main(String[] args) { + C0 c0 = new C0(); + c0.mI(); + c0.mI1(); + c0.mI2(); + c0.mC(); + + I1 i1 = new C0(); + i1.mI(); + i1.mI1(); + + C1 c1 = new C1(); + c1.mI(); + c1.mC1(); + } +} + +class C0 implements I1, I2 { + public void mI() { System.out.println("mI"); } + public void mI1() { System.out.println("mI1"); } + public void mI2() { System.out.println("mI2"); } + + public void mC() { System.out.println("mC"); } +} + +class C1 extends C0 { + public void mC() { System.out.println("mC from C1"); } + public void mC1() { System.out.println("mC1"); } +} + +interface I1 { + public void mI(); + public void mI1(); +} + +interface I2 { + public void mI(); + public void mI2(); +} + +aspect A { + static before(I1 i1): calls(void i1.*()) { System.out.println(">I1.* " + i1); } + static before(): calls(void I2.*()) { System.out.println(">I2.*"); } + static before(): calls(void C0.*()) { System.out.println(">C0.*"); } + static before(): calls(void C1.*()) { System.out.println(">C1.*"); } + + static before(): receptions(void I1.*()) { System.out.println("-I1.*"); } + static before(): receptions(void I2.*()) { System.out.println("-I2.*"); } + static before(): receptions(void C0.*()) { System.out.println("-C0.*"); } + + static after() returning(): receptions(I1.new()) { System.out.println("-I1.new"); } + static after() returning(): receptions(C0.new()) { System.out.println("-C0.new"); } + + static after() returning(): calls(C0, I1.new()) { System.out.println(">I1.new"); } + static after() returning(): calls(C0, C0.new()) { System.out.println(">C0.new"); } +} diff --git a/tests/new/ExtendInnerCE.java b/tests/new/ExtendInnerCE.java new file mode 100644 index 000000000..cddc98551 --- /dev/null +++ b/tests/new/ExtendInnerCE.java @@ -0,0 +1,8 @@ +/** @testcase TestCase PUREJAVA NullPointerException (not compiler error) when extending non-static inner class */ +public class ExtendInnerCE { } +class TargetClass Outer.Inner { } // s.b. error: Outer.this. is not accessible + +class Outer { + class Inner { + } +} diff --git a/tests/new/ExtendsOuterAbstract_PR408.java b/tests/new/ExtendsOuterAbstract_PR408.java new file mode 100644 index 000000000..335c7cd98 --- /dev/null +++ b/tests/new/ExtendsOuterAbstract_PR408.java @@ -0,0 +1,8 @@ +import org.aspectj.testing.*; +public class ExtendsOuterAbstract_PR408 extends OuterAbstract_PR408 { + public void go() { + InnerAbstract inner = new InnerAbstract("string") {}; + inner.go(); + Tester.event("ExtendsOuterAbstract_PR408.go"); + } +} diff --git a/tests/new/ExternalCalls.java b/tests/new/ExternalCalls.java new file mode 100644 index 000000000..d8d22c651 --- /dev/null +++ b/tests/new/ExternalCalls.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; + +public class ExternalCalls { + public static void main(String[] args){ + Tester.checkEqual(new Test().go(), 1003); + + Tester.checkEqual(Math.max(1, 3), 3); + } +} + +class Test { + int go(){ + return Math.max(1, 3); + } +} + +aspect A percflow(this(Test) && execution(* go(..))) { + // ! call(* Test.go()) shouldn't do anything + int around(): call(int Math.*(..)) && ! call(* Test.go()) { + return proceed() + 1000; + } +} diff --git a/tests/new/FactorialCflow.java b/tests/new/FactorialCflow.java new file mode 100644 index 000000000..63c2723f3 --- /dev/null +++ b/tests/new/FactorialCflow.java @@ -0,0 +1,48 @@ + + +public class FactorialCflow { + static int fact(int i) { + return (i == 0 ? 1 : i * fact(i-1)); + } + public static void main(String args[]) { + System.err.println(expect); + System.err.println("---------- actual "); + System.err.println(720 == fact(6) ? "pass" : "fail"); + } + + static final String expect = "---------- expect " + // most-recent + + "\n5-6" + + "\n4-5" + + "\n3-4" + + "\n2-3" + + "\n1-2" + + "\n0-1" + // top + + "\n5@6" + + "\n4@6" + + "\n3@6" + + "\n2@6" + + "\n1@6" + + "\n0@6" + ; +} + +aspect A { + pointcut f(int i) : call(int fact(int)) && args(i); + + // most-recent + int around(int i, final int j) : f(i) && cflowbelow(f(j)) { + System.err.println(i + "-" + j); + int r = proceed(i, j); + return r; + } + + // top + int around(int i, final int j) : f(i) + && cflowbelow(cflow(f(j)) && !cflowbelow(f(int))) { + System.err.println(i + "@" + j); + int r = proceed(i, j); + return r; + } +} diff --git a/tests/new/FalseThrowsCE.java b/tests/new/FalseThrowsCE.java new file mode 100644 index 000000000..89fb3c21d --- /dev/null +++ b/tests/new/FalseThrowsCE.java @@ -0,0 +1,15 @@ +import org.aspectj.testing.Tester; + +/** + * @testTarget compilerErrors.false.exceptions Throwable treated as checked, false compiler error + */ +public class FalseThrowsCE { + public static void main(String[] args) { + try { + System.getProperty("").toString(); // potential NPE, SecurityException + } catch (Throwable e) { // (false) CE: Throwable never thrown + String s = "got " + e; + } + Tester.check(true,"ok - compiled without error"); + } +} diff --git a/tests/new/FieldFromImplementsNotFound.java b/tests/new/FieldFromImplementsNotFound.java new file mode 100644 index 000000000..e6662e281 --- /dev/null +++ b/tests/new/FieldFromImplementsNotFound.java @@ -0,0 +1,30 @@ +import org.aspectj.testing.Tester; +import java.io.*; + +// PR#96 + +interface HttpConstants { + static final String s = "s"; +} + +public aspect FieldFromImplementsNotFound implements HttpConstants { + public static void main(String[] args) { test(); } + + pointcut sendHeader(): + call(void LocalFile.sendHeader()); + + static String aspectField = "t"; + /*static*/ before(): sendHeader() { + aspectField += s; + } + + public static void test() { + new LocalFile().sendHeader(); + Tester.checkEqual(aspectField, "ts", "field + constant"); + } +} + +class LocalFile { + void sendHeader() { + } +} diff --git a/tests/new/FieldInitializerJoinPoints.java b/tests/new/FieldInitializerJoinPoints.java new file mode 100644 index 000000000..b8bfdad5a --- /dev/null +++ b/tests/new/FieldInitializerJoinPoints.java @@ -0,0 +1,61 @@ +// This test verifies that join points exist in the execution of field initializers. + +import org.aspectj.testing.Tester; + +public class FieldInitializerJoinPoints { + + static int jcount = 0; + static int kcount = 0; + static int lcount = 0; + static int mcount = 0; + + static int ncount = 0; + static int ocount = 0; + static int pcount = 0; + static int qcount = 0; + + static final int j = 99; // not even a set join point here. + static int k = 98; // a set join point + final int l = 97; // not a join point (NEW) + int m = 96; // yet another set join point + + static int n() { return 95; } + static int o() { return 94; } + static int p() { return 93; } + static int q() { return 92; } + + static final int n = n(); // a call join point + static int o = o(); // a call join point + final int p = p(); // a call join point + int q = q(); // a call join point + + public static void main(String[] args) { + new FieldInitializerJoinPoints(); + new FieldInitializerJoinPoints(); + + Tester.checkEqual(jcount, 0, "jcount"); + Tester.checkEqual(kcount, 1, "kcount"); + Tester.checkEqual(lcount, 0, "lcount"); + Tester.checkEqual(mcount, 2, "mcount"); + + Tester.checkEqual(ncount, 1, "ncount"); + Tester.checkEqual(ocount, 1, "ocount"); + Tester.checkEqual(pcount, 2, "pcount"); + Tester.checkEqual(qcount, 2, "qcount"); + } + +} + + +aspect A { + before(): set(int FieldInitializerJoinPoints.j) { FieldInitializerJoinPoints.jcount++; } + before(): set(int FieldInitializerJoinPoints.k) { FieldInitializerJoinPoints.kcount++; } + before(): set(int FieldInitializerJoinPoints.l) { FieldInitializerJoinPoints.lcount++; } + before(): set(int FieldInitializerJoinPoints.m) { FieldInitializerJoinPoints.mcount++; } + + before(): call(int FieldInitializerJoinPoints.n()) { FieldInitializerJoinPoints.ncount++; } + before(): call(int FieldInitializerJoinPoints.o()) { FieldInitializerJoinPoints.ocount++; } + before(): call(int FieldInitializerJoinPoints.p()) { FieldInitializerJoinPoints.pcount++; } + before(): call(int FieldInitializerJoinPoints.q()) { FieldInitializerJoinPoints.qcount++; } +} + diff --git a/tests/new/FieldInnerAccess.java b/tests/new/FieldInnerAccess.java new file mode 100644 index 000000000..f7a0c034f --- /dev/null +++ b/tests/new/FieldInnerAccess.java @@ -0,0 +1,47 @@ +import org.aspectj.testing.Tester; + +public class FieldInnerAccess { + public static void main(String[] args) { + Derived d = new Derived(); + d.m(); + Tester.checkAndClearEvents(new String[] {"lock: 1"}); + + d.mi(); + Tester.checkAndClearEvents(new String[] {"lock: 1"}); + + d.mib(); + Tester.checkAndClearEvents(new String[] {"lock: foo"}); + } +} + +class Base { + private static String lock = "foo"; + + public void mib() { + Runnable r = new Runnable() { + public void run() { + Tester.event("lock: " + lock); + } + }; + + r.run(); + } +} + +class Derived extends Base { + private static Object lock = new Integer(1); + + public void m() { + Tester.event("lock: " + lock); + } + + public void mi() { + Runnable r = new Runnable() { + public void run() { + Tester.event("lock: " + lock); + } + }; + + r.run(); + } +} diff --git a/tests/new/FieldPatterns.java b/tests/new/FieldPatterns.java new file mode 100644 index 000000000..e64f24c57 --- /dev/null +++ b/tests/new/FieldPatterns.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.Tester; + +public class FieldPatterns { + public static void main(String[] args) { + SuperC sc = new SuperC(); + C c = new C(); + SubC subc = new SubC(); + + Tester.checkEqual(sc.name, "SuperC"); + Tester.checkEqual(sc.count, 1, "SuperC"); + + Tester.checkEqual(c.name, "C"); + Tester.checkEqual(c.count, 1, "C"); + + Tester.checkEqual(subc.name, "C"); + Tester.checkEqual(subc.count, 1, "SubC"); + + Tester.checkEqual(((SuperC)c).name, "SuperC"); + Tester.checkEqual(c.count, 2, "C as SuperC"); + + c.name = null; + } +} + + +class SuperC { + int count = 0; + String name = "SuperC"; +} + +class C extends SuperC { + String name = "C"; +} + +class SubC extends C { +} + +aspect A { + before(SuperC sc): get(String SuperC.name) && target(sc){ + sc.count++; + } + before(C c): get(String C.name) && target(c) { + c.count++; + } + + before(): set(String C.name) { + } +} + + diff --git a/tests/new/FinalConstructorParm.java b/tests/new/FinalConstructorParm.java new file mode 100644 index 000000000..e86afe6c0 --- /dev/null +++ b/tests/new/FinalConstructorParm.java @@ -0,0 +1,12 @@ +import org.aspectj.testing.Tester; +public class FinalConstructorParm { + int i; + public FinalConstructorParm(final int i) { // bad compiler error here - not in 10b1 + this.i = i; + } + public int lessOne() { return i-1;} + public static void main(String[] args) { + Tester.check(1== (new FinalConstructorParm(2)).lessOne(), + "final failed"); + } +} diff --git a/tests/new/FinalInLoop.java b/tests/new/FinalInLoop.java new file mode 100644 index 000000000..a2b2ed9de --- /dev/null +++ b/tests/new/FinalInLoop.java @@ -0,0 +1,16 @@ +import org.aspectj.testing.Tester; + +public class FinalInLoop { + /** @testcase PR#709 PUREJAVA final assignment in loop */ + public static void main (String[] args) { + for (int i = 0; i < 1; i++) { + final String s; + if (true) { + s = "true"; + } else { + s = "false"; + } + Tester.check("true".equals(s), "s not true"); + } + } +} diff --git a/tests/new/Finals.java b/tests/new/Finals.java new file mode 100644 index 000000000..9ee0d5e77 --- /dev/null +++ b/tests/new/Finals.java @@ -0,0 +1,42 @@ +import org.aspectj.testing.*; +public class Finals { + public static void main(String[] args) { + new Finals().go(args); + Tester.checkAllEvents(); + } + + static { + Tester.expectEventsInString("go,i1,i2"); + } + + void go(String[] args) { + Tester.event("go"); + } +} + +interface I { + public void i(); +} +aspect Aspect { + pointcut p1(): call(void go(..)) && target(Finals); + void around(): p1() { + new I() { + public void i() { + a("i1"); + proceed(); + } + }.i(); + } + + pointcut p2(String[] argss): call(void go(String[])) && args(argss) && target(Finals); + void around(final String[] argss): p2(argss) { + new I() { + public void i() { + a("i2"); + proceed(argss); + } + }.i(); + } + + static void a(String s) { Tester.event(s); } +} diff --git a/tests/new/FirstLineGuessOverRun.java b/tests/new/FirstLineGuessOverRun.java new file mode 100644 index 000000000..d0a0caeeb --- /dev/null +++ b/tests/new/FirstLineGuessOverRun.java @@ -0,0 +1,500 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +public class AJError +{ +/* + + + + + + + + + + + + + + + { + + + } + + + { + + { + + } + + + { + + + + + + + + { + + + + + + + + + + + + + + { + + + + + + + + + + + + + + + + + { + + + } + } + + } + + + + + + + { + + + + { + + + { + + + { + + } + + { + + } + } + + { + + } + } + } + + + + + + + + + + + + } + + { + + } + + { + + } + + { + + } + + { + + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + + } + + + { + + } +*/ + + + /* + + { + + + + { + + } + + + { + + + + + + } + } + + + { + + + + + } + + + + { + + + + + + { + + } + + + + + } + + + { + + + + + + { + + + + + + + } + + + } + + + { + + + } + + + { + + { + + } + + { + + + + } + + + { + + } + + } + + + + { + + } + + + { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +}
\ No newline at end of file diff --git a/tests/new/Fixes.java b/tests/new/Fixes.java new file mode 100644 index 000000000..1922506e7 --- /dev/null +++ b/tests/new/Fixes.java @@ -0,0 +1,67 @@ +import org.aspectj.testing.Tester; + +public class Fixes { + public static void main(String[] args) { new Fixes().realMain(args); } + public void realMain(String[] args) { + new TheObject().go(); + } +} + +class TheObject { + private int private_int; + void go () {} +} + +privileged aspect TheAspect pertarget(target(TheObject)) { + private TheObject theObject; + after() returning(TheObject obj): call(new()) { + theObject = obj; + } + after() returning(): call(* realMain(..)) { + start(); + postinc(); + preinc(); + postdec(); + predec(); + } + + void start() { + theObject.private_int = 3; + } + + void postinc() { + enter("postinc"); + a(theObject.private_int,3); + theObject.private_int++; + a(theObject.private_int,4); + } + + void preinc() { + enter("preinc"); + a(theObject.private_int,4); + ++theObject.private_int; + a(theObject.private_int,5); + } + + void postdec() { + enter("postdec"); + a(theObject.private_int,5); + theObject.private_int--; + a(theObject.private_int,4); + } + + void predec() { + enter("predec"); + a(theObject.private_int,4); + --theObject.private_int; + a(theObject.private_int,3); + } + + private String msg; + void enter(String msg) { + this.msg = msg; + } + void a(int a, int b) { + Tester.checkEqual(a,b,msg); + } +} diff --git a/tests/new/FloatPrivilegedRoundoff.java b/tests/new/FloatPrivilegedRoundoff.java new file mode 100644 index 000000000..9859c167c --- /dev/null +++ b/tests/new/FloatPrivilegedRoundoff.java @@ -0,0 +1,16 @@ +import org.aspectj.testing.Tester; + +public class FloatPrivilegedRoundoff { + private static float f = 0.3f; + + public static void main(String[] args) { + Tester.check(A.foo() == 0.3f, "didn't return original"); + Tester.check(f == 0.3f + 1, "didn't increment"); + } +} + +privileged aspect A { + static float foo() { + return (FloatPrivilegedRoundoff.f)++; + } +} diff --git a/tests/new/Foo.java b/tests/new/Foo.java new file mode 100644 index 000000000..a601d8625 --- /dev/null +++ b/tests/new/Foo.java @@ -0,0 +1,27 @@ +class Foo { + + public static void main(String[] args) { + (new Foo()).m1(); + System.out.println("---"); + (new Bar()).m1(); + } + + public void m1() { } +} + +class Bar extends Foo { + public void m1() { super.m1(); } +} + +aspect A { + static before(): instanceof(Foo) && executions(public * *(..)) { + System.out.println("executions"); + } + + + static before(): instanceof(Foo) && receptions(public * *(..)) { + System.out.println("receptions"); + } + +} + diff --git a/tests/new/FormalMatching.java b/tests/new/FormalMatching.java new file mode 100644 index 000000000..37c485e71 --- /dev/null +++ b/tests/new/FormalMatching.java @@ -0,0 +1,52 @@ +import org.aspectj.lang.*; +import org.aspectj.testing.*; + +public class FormalMatching { + public static void main(String[] args) { + new FormalMatching().realMain(args); + } + public void realMain(String[] args) { + call_v(); + call_vI(0); + call_vII(0,1); + call_i(); + call_iI(0); + call_iII(0,1); + Tester.checkAllEvents(); + } + + static String[] methods = { + "call_v", "call_vI", "call_vII", + "call_i", "call_iI", "call_iII", + }; + static { + for (int i = 0; i < methods.length; i++) { + Tester.expectEvent(methods[i]); + Tester.expectEvent(methods[i] + "-advice"); + } + } + + void call_v () { Tester.event("call_v"); } + void call_vI (int i0) { Tester.event("call_vI"); } + void call_vII(int i0, int i1) { Tester.event("call_vII"); } + + int call_i () { Tester.event("call_i"); return 0; } + int call_iI (int i0) { Tester.event("call_iI"); return 0; } + int call_iII(int i0, int i1) { Tester.event("call_iII"); return 0; } +} + +aspect Aspect { + pointcut args0(Object o): call(* call*()) && target(o); + pointcut args1(Object o, int i0): call(* call*(int)) && target(o) && args(i0); + pointcut args2(Object o, int i0, int i1): call(* call*(int,int)) && target(o) && args(i0, i1); + + before(Object o): args0(o) { a(thisJoinPoint); } + before(Object o, int i0): args1(o,i0) { a(thisJoinPoint); } + before(Object o, int i0, int i1): args2(o,i0,i1) { a(thisJoinPoint); } + + static void a(JoinPoint jp) { + Tester.event(jp.getSignature().getName() + "-advice"); + } +} + + diff --git a/tests/new/GeneratedStaticAsTransient.java b/tests/new/GeneratedStaticAsTransient.java new file mode 100644 index 000000000..d91a92d27 --- /dev/null +++ b/tests/new/GeneratedStaticAsTransient.java @@ -0,0 +1,69 @@ + +import org.aspectj.testing.*; +import java.lang.reflect.*; + +// XXX incomplete - find all cases of generated static fields +/** @testcase PR#704 mark generated static fields transient */ +public class GeneratedStaticAsTransient { + public static void main (String[] args) { + new GeneratedStaticAsTransient().callRun(); + checkStatic(GeneratedStaticAsTransient.class, false); + Tester.checkAllEvents(); + } + public void callRun() { run(); } + + public void run() { + Tester.event("run"); + Tester.check(null != A.aspectOf(this),"null != A.hasAspect(this)"); + Tester.check(null != C.aspectOf(this),"null != C.hasAspect(this)"); + Tester.check(null != B.aspectOf(),"null != B.hasAspect()"); + } + static { + Tester.expectEvent("after returning - target"); + Tester.expectEvent("after returning - this"); + Tester.expectEvent("after returning - cflow"); + Tester.expectEvent("run"); + } + public static void checkStatic(Class c, boolean requireStatic) { + boolean gotStatic = false; + Field[] fields = c.getFields(); + for (int i = 0; i < fields.length; i++) { + int mods = fields[i].getModifiers(); + //System.err.println("checking " + fields[i]); + if (Modifier.isStatic(mods)) { + //System.err.println(" static " + fields[i]); + if (!gotStatic) gotStatic = true; + if (!Modifier.isTransient(mods)) { + String m = "field " + i + " " + + c.getName() + "." + fields[i].getName() + + " is static but not transient. mods=" + mods; + //System.err.println(m); + Tester.check(false, m); + } + } + } + if (requireStatic) { + Tester.check(gotStatic, c + "no static field"); + } + } +} + +aspect A pertarget(callRun()) { + pointcut callRun() : call(void GeneratedStaticAsTransient.run()); + after () returning : callRun() { + Tester.event("after returning - target"); + GeneratedStaticAsTransient.checkStatic(A.class, false); + } +} +aspect B percflow(A.callRun()) { + after () returning : A.callRun() { + Tester.event("after returning - cflow"); + GeneratedStaticAsTransient.checkStatic(B.class, true); + } +} +aspect C perthis(A.callRun()) { + after () returning : A.callRun() { + Tester.event("after returning - this"); + GeneratedStaticAsTransient.checkStatic(C.class, false); + } +} diff --git a/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspects.java b/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspects.java new file mode 100644 index 000000000..e14c700bc --- /dev/null +++ b/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspects.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class GeneratingDuplicateNamedAdviceMethodsInAbstractAspects { + public static void main(String[] args) { + new GeneratingDuplicateNamedAdviceMethodsInAbstractAspects().realMain(args); + } + public void realMain(String[] args) { + new C().c(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("c"); + } +} + +class C { + public void c() { Tester.event("c"); } +} + +abstract aspect A { + pointcut c(): call(void C.c()); + protected static void a(String str, Object o) { + Class c = o.getClass(); + Tester.event(str); + Tester.check(!A.class.equals(c), "A is abstract!"); + Tester.check(Inner.class.equals(c), "Inner must equal "+c); + } + after(): c() { a("after1", this); } + after(): c() { a("after2", this); } + before(): c() { a("before1", this); } + before(): c() { a("before2", this); } + void around(): c() { a("around1", this); proceed(); } + void around(): c() { a("around2", this); proceed(); } + static aspect Inner {} +} diff --git a/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspectsWithExtendedAspect.java b/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspectsWithExtendedAspect.java new file mode 100644 index 000000000..5c561cc75 --- /dev/null +++ b/tests/new/GeneratingDuplicateNamedAdviceMethodsInAbstractAspectsWithExtendedAspect.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class + GeneratingDuplicateNamedAdviceMethodsInAbstractAspectsWithExtendedAspect +{ + public static void main(String[] args) { + new GeneratingDuplicateNamedAdviceMethodsInAbstractAspectsWithExtendedAspect().realMain(args); + } + public void realMain(String[] args) { + new C().c(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("c"); + String[] strs = {"before","after","around"}; + for (int i = 0; i < strs.length; i++) { + int[] is = new int[] {1,2}; + for (int j = 0; j < is.length; j++) { + Tester.expectEvent(strs[i]+is[j]); + } + } + + } +} + +class C { + public void c() { Tester.event("c"); } +} + +abstract aspect A { + pointcut c(): call(void C.c()); + protected static void a(String str, Object o) { + Class c = o.getClass(); + Tester.event(str); + Tester.check(!A.class.equals(c), "A is abstract!"); + Tester.check(Inner.class.equals(c), "Inner must equal "+c); + } + after(): c() { a("after1", this); } + after(): c() { a("after2", this); } + before(): c() { a("before1", this); } + before(): c() { a("before2", this); } + void around(): c() { a("around1", this); proceed(); } + void around(): c() { a("around2", this); proceed(); } + static aspect Inner extends A {} +} diff --git a/tests/new/Gets.java b/tests/new/Gets.java new file mode 100644 index 000000000..f03a9689a --- /dev/null +++ b/tests/new/Gets.java @@ -0,0 +1,935 @@ +import org.aspectj.testing.*; + +public class Gets { + public static void main(String[] args) { + new Gets().go(); + } + + public int nums0 = 5; + public int nums1 = 5; + public int nums2 = 5; + public int nums3 = 5; + public int nums4 = 20; + public int nums5 = 9; + public int nums6 = 11; + public int nums7 = 9; + public int nums8 = 11; + public int nums9 = 5; + + void go() { + nums0 = 10; + nums1 += 5; + nums2 -= -5; + nums3 *= 2; + nums4 /= 2; + nums5++; + nums6--; + ++nums7; + --nums8; + nums9 = nums0; + + { int i = nums0; } + { int i = nums1; } + { int i = nums2; } + { int i = nums3; } + { int i = nums4; } + { int i = nums5; } + { int i = nums6; } + { int i = nums7; } + { int i = nums8; } + { int i = nums9; } + + Tester.check(GetAspect.bstar, + "Advice wasn't run for GetAspect.star"); + Tester.check(GetAspect.b0, + "Advice wasn't run for GetAspect.nums0"); + Tester.check(GetAspect.b1, + "Advice wasn't run for GetAspect.nums1"); + Tester.check(GetAspect.b2, + "Advice wasn't run for GetAspect.nums2"); + Tester.check(GetAspect.b3, + "Advice wasn't run for GetAspect.nums3"); + Tester.check(GetAspect.b4, + "Advice wasn't run for GetAspect.nums4"); + Tester.check(GetAspect.b5, + "Advice wasn't run for GetAspect.nums5"); + Tester.check(GetAspect.b6, + "Advice wasn't run for GetAspect.nums6"); + Tester.check(GetAspect.b7, + "Advice wasn't run for GetAspect.nums7"); + Tester.check(GetAspect.b8, + "Advice wasn't run for GetAspect.nums8"); + Tester.check(GetAspect.b9, + "Advice wasn't run for GetAspect.nums9"); + +// Tester.check(GetAspectOfEach.bstar, +// "Advice wasn't run for GetAspectOfEach.star"); +// Tester.check(GetAspectOfEach.b0, +// "Advice wasn't run for GetAspectOfEach.nums0"); +// Tester.check(GetAspectOfEach.b1, +// "Advice wasn't run for GetAspectOfEach.nums1"); +// Tester.check(GetAspectOfEach.b2, +// "Advice wasn't run for GetAspectOfEach.nums2"); +// Tester.check(GetAspectOfEach.b3, +// "Advice wasn't run for GetAspectOfEach.nums3"); +// Tester.check(GetAspectOfEach.b4, +// "Advice wasn't run for GetAspectOfEach.nums4"); +// Tester.check(GetAspectOfEach.b5, +// "Advice wasn't run for GetAspectOfEach.nums5"); +// Tester.check(GetAspectOfEach.b6, +// "Advice wasn't run for GetAspectOfEach.nums6"); +// Tester.check(GetAspectOfEach.b7, +// "Advice wasn't run for GetAspectOfEach.nums7"); +// Tester.check(GetAspectOfEach.b8, +// "Advice wasn't run for GetAspectOfEach.nums8"); +// Tester.check(GetAspectOfEach.b9, +// "Advice wasn't run for GetAspectOfEach.nums9"); + +// Tester.check(GetAspectWithBrackets.bstar, +// "Advice wasn't run for GetAspectWithBrackets.star"); +// Tester.check(GetAspectWithBrackets.b0, +// "Advice wasn't run for GetAspectWithBrackets.nums0"); +// Tester.check(GetAspectWithBrackets.b1, +// "Advice wasn't run for GetAspectWithBrackets.nums1"); +// Tester.check(GetAspectWithBrackets.b2, +// "Advice wasn't run for GetAspectWithBrackets.nums2"); +// Tester.check(GetAspectWithBrackets.b3, +// "Advice wasn't run for GetAspectWithBrackets.nums3"); +// Tester.check(GetAspectWithBrackets.b4, +// "Advice wasn't run for GetAspectWithBrackets.nums4"); +// Tester.check(GetAspectWithBrackets.b5, +// "Advice wasn't run for GetAspectWithBrackets.nums5"); +// Tester.check(GetAspectWithBrackets.b6, +// "Advice wasn't run for GetAspectWithBrackets.nums6"); +// Tester.check(GetAspectWithBrackets.b7, +// "Advice wasn't run for GetAspectWithBrackets.nums7"); +// Tester.check(GetAspectWithBrackets.b8, +// "Advice wasn't run for GetAspectWithBrackets.nums8"); +// Tester.check(GetAspectWithBrackets.b9, +// "Advice wasn't run for GetAspectWithBrackets.nums9"); + +// Tester.check(SetAspect.bstar, +// "Advice wasn't run for SetAspect.star"); +// Tester.check(SetAspect.b0, +// "Advice wasn't run for SetAspect.nums0"); +// Tester.check(SetAspect.b1, +// "Advice wasn't run for SetAspect.nums1"); +// Tester.check(SetAspect.b2, +// "Advice wasn't run for SetAspect.nums2"); +// Tester.check(SetAspect.b3, +// "Advice wasn't run for SetAspect.nums3"); +// Tester.check(SetAspect.b4, +// "Advice wasn't run for SetAspect.nums4"); +// Tester.check(SetAspect.b5, +// "Advice wasn't run for SetAspect.nums5"); +// Tester.check(SetAspect.b6, +// "Advice wasn't run for SetAspect.nums6"); +// Tester.check(SetAspect.b7, +// "Advice wasn't run for SetAspect.nums7"); +// Tester.check(SetAspect.b8, +// "Advice wasn't run for SetAspect.nums8"); +// Tester.check(SetAspect.b9, +// "Advice wasn't run for SetAspect.nums9"); + + Tester.check(SetAspect2.bstar, + "Advice wasn't run for SetAspect2.star"); + Tester.check(SetAspect2.b0, + "Advice wasn't run for SetAspect2.nums0"); + Tester.check(SetAspect2.b1, + "Advice wasn't run for SetAspect2.nums1"); + Tester.check(SetAspect2.b2, + "Advice wasn't run for SetAspect2.nums2"); + Tester.check(SetAspect2.b3, + "Advice wasn't run for SetAspect2.nums3"); + Tester.check(SetAspect2.b4, + "Advice wasn't run for SetAspect2.nums4"); + Tester.check(SetAspect2.b5, + "Advice wasn't run for SetAspect2.nums5"); + Tester.check(SetAspect2.b6, + "Advice wasn't run for SetAspect2.nums6"); + Tester.check(SetAspect2.b7, + "Advice wasn't run for SetAspect2.nums7"); + Tester.check(SetAspect2.b8, + "Advice wasn't run for SetAspect2.nums8"); + Tester.check(SetAspect2.b9, + "Advice wasn't run for SetAspect2.nums9"); + +// Tester.check(SetAspect3.bstar, +// "Advice wasn't run for SetAspect3.star"); +// Tester.check(SetAspect3.b0, +// "Advice wasn't run for SetAspect3.nums0"); +// Tester.check(SetAspect3.b1, +// "Advice wasn't run for SetAspect3.nums1"); +// Tester.check(SetAspect3.b2, +// "Advice wasn't run for SetAspect3.nums2"); +// Tester.check(SetAspect3.b3, +// "Advice wasn't run for SetAspect3.nums3"); +// Tester.check(SetAspect3.b4, +// "Advice wasn't run for SetAspect3.nums4"); +// Tester.check(SetAspect3.b5, +// "Advice wasn't run for SetAspect3.nums5"); +// Tester.check(SetAspect3.b6, +// "Advice wasn't run for SetAspect3.nums6"); +// Tester.check(SetAspect3.b7, +// "Advice wasn't run for SetAspect3.nums7"); +// Tester.check(SetAspect3.b8, +// "Advice wasn't run for SetAspect3.nums8"); +// Tester.check(SetAspect3.b9, +// "Advice wasn't run for SetAspect3.nums9"); + +// Tester.check(SetAspect4.bstar, +// "Advice wasn't run for SetAspect4.star"); +// Tester.check(SetAspect4.b0, +// "Advice wasn't run for SetAspect4.nums0"); +// Tester.check(SetAspect4.b1, +// "Advice wasn't run for SetAspect4.nums1"); +// Tester.check(SetAspect4.b2, +// "Advice wasn't run for SetAspect4.nums2"); +// Tester.check(SetAspect4.b3, +// "Advice wasn't run for SetAspect4.nums3"); +// Tester.check(SetAspect4.b4, +// "Advice wasn't run for SetAspect4.nums4"); +// Tester.check(SetAspect4.b5, +// "Advice wasn't run for SetAspect4.nums5"); +// Tester.check(SetAspect4.b6, +// "Advice wasn't run for SetAspect4.nums6"); +// Tester.check(SetAspect4.b7, +// "Advice wasn't run for SetAspect4.nums7"); +// Tester.check(SetAspect4.b8, +// "Advice wasn't run for SetAspect4.nums8"); +// Tester.check(SetAspect4.b9, +// "Advice wasn't run for SetAspect4.nums9"); + +// Tester.check(GetAspectOfEachWithBrackets.bstar, +// "Advice wasn't run for GetAspectOfEachWithBrackets.star"); +// Tester.check(GetAspectOfEachWithBrackets.b0, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums0"); +// Tester.check(GetAspectOfEachWithBrackets.b1, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums1"); +// Tester.check(GetAspectOfEachWithBrackets.b2, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums2"); +// Tester.check(GetAspectOfEachWithBrackets.b3, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums3"); +// Tester.check(GetAspectOfEachWithBrackets.b4, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums4"); +// Tester.check(GetAspectOfEachWithBrackets.b5, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums5"); +// Tester.check(GetAspectOfEachWithBrackets.b6, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums6"); +// Tester.check(GetAspectOfEachWithBrackets.b7, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums7"); +// Tester.check(GetAspectOfEachWithBrackets.b8, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums8"); +// Tester.check(GetAspectOfEachWithBrackets.b9, +// "Advice wasn't run for GetAspectOfEachWithBrackets.nums9"); + +// Tester.check(SetAspectOfEach.bstar, +// "Advice wasn't run for SetAspectOfEach.star"); +// Tester.check(SetAspectOfEach.b0, +// "Advice wasn't run for SetAspectOfEach.nums0"); +// Tester.check(SetAspectOfEach.b1, +// "Advice wasn't run for SetAspectOfEach.nums1"); +// Tester.check(SetAspectOfEach.b2, +// "Advice wasn't run for SetAspectOfEach.nums2"); +// Tester.check(SetAspectOfEach.b3, +// "Advice wasn't run for SetAspectOfEach.nums3"); +// Tester.check(SetAspectOfEach.b4, +// "Advice wasn't run for SetAspectOfEach.nums4"); +// Tester.check(SetAspectOfEach.b5, +// "Advice wasn't run for SetAspectOfEach.nums5"); +// Tester.check(SetAspectOfEach.b6, +// "Advice wasn't run for SetAspectOfEach.nums6"); +// Tester.check(SetAspectOfEach.b7, +// "Advice wasn't run for SetAspectOfEach.nums7"); +// Tester.check(SetAspectOfEach.b8, +// "Advice wasn't run for SetAspectOfEach.nums8"); +// Tester.check(SetAspectOfEach.b9, +// "Advice wasn't run for SetAspectOfEach.nums9"); + +// Tester.check(SetAspectOfEach2.bstar, +// "Advice wasn't run for SetAspectOfEach2.star"); +// Tester.check(SetAspectOfEach2.b0, +// "Advice wasn't run for SetAspectOfEach2.nums0"); +// Tester.check(SetAspectOfEach2.b1, +// "Advice wasn't run for SetAspectOfEach2.nums1"); +// Tester.check(SetAspectOfEach2.b2, +// "Advice wasn't run for SetAspectOfEach2.nums2"); +// Tester.check(SetAspectOfEach2.b3, +// "Advice wasn't run for SetAspectOfEach2.nums3"); +// Tester.check(SetAspectOfEach2.b4, +// "Advice wasn't run for SetAspectOfEach2.nums4"); +// Tester.check(SetAspectOfEach2.b5, +// "Advice wasn't run for SetAspectOfEach2.nums5"); +// Tester.check(SetAspectOfEach2.b6, +// "Advice wasn't run for SetAspectOfEach2.nums6"); +// Tester.check(SetAspectOfEach2.b7, +// "Advice wasn't run for SetAspectOfEach2.nums7"); +// Tester.check(SetAspectOfEach2.b8, +// "Advice wasn't run for SetAspectOfEach2.nums8"); +// Tester.check(SetAspectOfEach2.b9, +// "Advice wasn't run for SetAspectOfEach2.nums9"); + +// Tester.check(SetAspectOfEach3.bstar, +// "Advice wasn't run for SetAspectOfEach3.star"); +// Tester.check(SetAspectOfEach3.b0, +// "Advice wasn't run for SetAspectOfEach3.nums0"); +// Tester.check(SetAspectOfEach3.b1, +// "Advice wasn't run for SetAspectOfEach3.nums1"); +// Tester.check(SetAspectOfEach3.b2, +// "Advice wasn't run for SetAspectOfEach3.nums2"); +// Tester.check(SetAspectOfEach3.b3, +// "Advice wasn't run for SetAspectOfEach3.nums3"); +// Tester.check(SetAspectOfEach3.b4, +// "Advice wasn't run for SetAspectOfEach3.nums4"); +// Tester.check(SetAspectOfEach3.b5, +// "Advice wasn't run for SetAspectOfEach3.nums5"); +// Tester.check(SetAspectOfEach3.b6, +// "Advice wasn't run for SetAspectOfEach3.nums6"); +// Tester.check(SetAspectOfEach3.b7, +// "Advice wasn't run for SetAspectOfEach3.nums7"); +// Tester.check(SetAspectOfEach3.b8, +// "Advice wasn't run for SetAspectOfEach3.nums8"); +// Tester.check(SetAspectOfEach3.b9, +// "Advice wasn't run for SetAspectOfEach3.nums9"); + +// Tester.check(SetAspectOfEach4.bstar, +// "Advice wasn't run for SetAspectOfEach4.star"); +// Tester.check(SetAspectOfEach4.b0, +// "Advice wasn't run for SetAspectOfEach4.nums0"); +// Tester.check(SetAspectOfEach4.b1, +// "Advice wasn't run for SetAspectOfEach4.nums1"); +// Tester.check(SetAspectOfEach4.b2, +// "Advice wasn't run for SetAspectOfEach4.nums2"); +// Tester.check(SetAspectOfEach4.b3, +// "Advice wasn't run for SetAspectOfEach4.nums3"); +// Tester.check(SetAspectOfEach4.b4, +// "Advice wasn't run for SetAspectOfEach4.nums4"); +// Tester.check(SetAspectOfEach4.b5, +// "Advice wasn't run for SetAspectOfEach4.nums5"); +// Tester.check(SetAspectOfEach4.b6, +// "Advice wasn't run for SetAspectOfEach4.nums6"); +// Tester.check(SetAspectOfEach4.b7, +// "Advice wasn't run for SetAspectOfEach4.nums7"); +// Tester.check(SetAspectOfEach4.b8, +// "Advice wasn't run for SetAspectOfEach4.nums8"); +// Tester.check(SetAspectOfEach4.b9, +// "Advice wasn't run for SetAspectOfEach4.nums9"); + } + } + +aspect GetAspect { + static boolean bstar = false; + after(): get(int Gets.*) { + bstar = true; + } + static boolean b0 = false; + after(): get(int Gets.nums0) { + b0 = true; + } + static boolean b1 = false; + after(): get(int Gets.nums1) { + b1 = true; + } + static boolean b2 = false; + after(): get(int Gets.nums2) { + b2 = true; + } + static boolean b3 = false; + after(): get(int Gets.nums3) { + b3 = true; + } + static boolean b4 = false; + after(): get(int Gets.nums4) { + b4 = true; + } + static boolean b5 = false; + after(): get(int Gets.nums5) { + b5 = true; + } + static boolean b6 = false; + after(): get(int Gets.nums6) { + b6 = true; + } + static boolean b7 = false; + after(): get(int Gets.nums7) { + b7 = true; + } + static boolean b8 = false; + after(): get(int Gets.nums8) { + b8 = true; + } + static boolean b9 = false; + after(): get(int Gets.nums9) { + b9 = true; + } +} + +// aspect GetAspectWithBrackets { +// static boolean bstar = false; +// after(int n): get(int Gets.*)[n] { +// bstar = true; +// } +// static boolean b0 = false; +// after(int n): get(int Gets.nums0)[n] { +// b0 = true; +// } +// static boolean b1 = false; +// after(int n): get(int Gets.nums1)[n] { +// b1 = true; +// } +// static boolean b2 = false; +// after(int n): get(int Gets.nums2)[n] { +// b2 = true; +// } +// static boolean b3 = false; +// after(int n): get(int Gets.nums3)[n] { +// b3 = true; +// } +// static boolean b4 = false; +// after(int n): get(int Gets.nums4)[n] { +// b4 = true; +// } +// static boolean b5 = false; +// after(int n): get(int Gets.nums5)[n] { +// b5 = true; +// } +// static boolean b6 = false; +// after(int n): get(int Gets.nums6)[n] { +// b6 = true; +// } +// static boolean b7 = false; +// after(int n): get(int Gets.nums7)[n] { +// b7 = true; +// } +// static boolean b8 = false; +// after(int n): get(int Gets.nums8)[n] { +// b8 = true; +// } +// static boolean b9 = false; +// after(int n): get(int Gets.nums9)[n] { +// b9 = true; +// } +// } + +// aspect SetAspect { +// static boolean bstar = false; +// after(int d, int n): set(int Gets.*)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "nums should be 10, not " + d + " for SetAspect"); +// bstar = true; +// } +// static boolean b0 = false; +// after(int d, int n): set(int Gets.nums0)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num0 should be 10, not " + d + " for SetAspect"); +// b0 = true; +// } +// static boolean b1 = false; +// after(int d, int n): set(int Gets.nums1)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num1 should be 10, not " + d + " for SetAspect"); +// b1 = true; +// } +// static boolean b2 = false; +// after(int d, int n): set(int Gets.nums2)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num2 should be 10, not " + d + " for SetAspect"); +// b2 = true; +// } +// static boolean b3 = false; +// after(int d, int n): set(int Gets.nums3)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num3 should be 10, not " + d + " for SetAspect"); +// b3 = true; +// } +// static boolean b4 = false; +// after(int d, int n): set(int Gets.nums4)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num4 should be 10, not " + d + " for SetAspect"); +// b4 = true; +// } +// static boolean b5 = false; +// after(int d, int n): set(int Gets.nums5)[d][n] && withincode(void go())// { +// Tester.check(n == 10, "num5 should be 10, not " + d + " for SetAspect"); +// b5 = true; +// } +// static boolean b6 = false; +// after(int d, int n): set(int Gets.nums6)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num6 should be 10, not " + d + " for SetAspect"); +// b6 = true; +// } +// static boolean b7 = false; +// after(int d, int n): set(int Gets.nums7)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num7 should be 10, not " + d + " for SetAspect"); +// b7 = true; +// } +// static boolean b8 = false; +// after(int d, int n): set(int Gets.nums8)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num8 should be 10, not " + d + " for SetAspect"); +// b8 = true; +// } +// static boolean b9 = false; +// after(int d, int n): set(int Gets.nums9)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num9 should be 10, not " + d + " for SetAspect"); +// b9 = true; +// } + +// } + +aspect SetAspect2 { + static boolean bstar = false; + after(): set(int Gets.*) { + bstar = true; + } + static boolean b0 = false; + after(): set(int Gets.nums0) { + b0 = true; + } + static boolean b1 = false; + after(): set(int Gets.nums1) { + b1 = true; + } + static boolean b2 = false; + after(): set(int Gets.nums2) { + b2 = true; + } + static boolean b3 = false; + after(): set(int Gets.nums3) { + b3 = true; + } + static boolean b4 = false; + after(): set(int Gets.nums4) { + b4 = true; + } + static boolean b5 = false; + after(): set(int Gets.nums5) { + b5 = true; + } + static boolean b6 = false; + after(): set(int Gets.nums6) { + b6 = true; + } + static boolean b7 = false; + after(): set(int Gets.nums7) { + b7 = true; + } + static boolean b8 = false; + after(): set(int Gets.nums8) { + b8 = true; + } + static boolean b9 = false; + after(): set(int Gets.nums9) { + b9 = true; + } + +} + +// aspect SetAspect3 { +// static boolean bstar = false; +// after(int d): set(int Gets.*)[d][] { +// bstar = true; +// } +// static boolean b0 = false; +// after(int d): set(int Gets.nums0)[d][] { +// b0 = true; +// } +// static boolean b1 = false; +// after(int d): set(int Gets.nums1)[d][] { +// b1 = true; +// } +// static boolean b2 = false; +// after(int d): set(int Gets.nums2)[d][] { +// b2 = true; +// } +// static boolean b3 = false; +// after(int d): set(int Gets.nums3)[d][] { +// b3 = true; +// } +// static boolean b4 = false; +// after(int d): set(int Gets.nums4)[d][] { +// b4 = true; +// } +// static boolean b5 = false; +// after(int d): set(int Gets.nums5)[d][] { +// b5 = true; +// } +// static boolean b6 = false; +// after(int d): set(int Gets.nums6)[d][] { +// b6 = true; +// } +// static boolean b7 = false; +// after(int d): set(int Gets.nums7)[d][] { +// b7 = true; +// } +// static boolean b8 = false; +// after(int d): set(int Gets.nums8)[d][] { +// b8 = true; +// } +// static boolean b9 = false; +// after(int d): set(int Gets.nums9)[d][] { +// b9 = true; +// } + +// } + +// aspect SetAspect4 { +// static boolean bstar = false; +// after(int n): set(int Gets.*)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "nums should be 10 for SetAspect4"); +// bstar = true; +// } +// static boolean b0 = false; +// after(int n): set(int Gets.nums0)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num0 should be 10 for SetAspect4"); +// b0 = true; +// } +// static boolean b1 = false; +// after(int n): set(int Gets.nums1)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num1 should be 10 for SetAspect4"); +// b1 = true; +// } +// static boolean b2 = false; +// after(int n): set(int Gets.nums2)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num2 should be 10 for SetAspect4"); +// b2 = true; +// } +// static boolean b3 = false; +// after(int n): set(int Gets.nums3)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num3 should be 10 for SetAspect4"); +// b3 = true; +// } +// static boolean b4 = false; +// after(int n): set(int Gets.nums4)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num4 should be 10 for SetAspect4"); +// b4 = true; +// } +// static boolean b5 = false; +// after(int n): set(int Gets.nums5)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num5 should be 10 for SetAspect4"); +// b5 = true; +// } +// static boolean b6 = false; +// after(int n): set(int Gets.nums6)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num6 should be 10 for SetAspect4"); +// b6 = true; +// } +// static boolean b7 = false; +// after(int n): set(int Gets.nums7)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num7 should be 10 for SetAspect4"); +// b7 = true; +// } +// static boolean b8 = false; +// after(int n): set(int Gets.nums8)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num8 should be 10 for SetAspect4"); +// b8 = true; +// } +// static boolean b9 = false; +// after(int n): set(int Gets.nums9)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num9 should be 10 for SetAspect4"); +// b9 = true; +// } + +// } + +// aspect GetAspectOfEach of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(): get(int Gets.*) { +// bstar = true; +// } +// static boolean b0 = false; +// after(): get(int Gets.nums0) { +// b0 = true; +// } +// static boolean b1 = false; +// after(): get(int Gets.nums1) { +// b1 = true; +// } +// static boolean b2 = false; +// after(): get(int Gets.nums2) { +// b2 = true; +// } +// static boolean b3 = false; +// after(): get(int Gets.nums3) { +// b3 = true; +// } +// static boolean b4 = false; +// after(): get(int Gets.nums4) { +// b4 = true; +// } +// static boolean b5 = false; +// after(): get(int Gets.nums5) { +// b5 = true; +// } +// static boolean b6 = false; +// after(): get(int Gets.nums6) { +// b6 = true; +// } +// static boolean b7 = false; +// after(): get(int Gets.nums7) { +// b7 = true; +// } +// static boolean b8 = false; +// after(): get(int Gets.nums8) { +// b8 = true; +// } +// static boolean b9 = false; +// after(): get(int Gets.nums9) { +// b9 = true; +// } + +// } + +// aspect GetAspectOfEachWithBrackets of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(int n): get(int Gets.*)[n] { +// bstar = true; +// } +// static boolean b0 = false; +// after(int n): get(int Gets.nums0)[n] { +// b0 = true; +// } +// static boolean b1 = false; +// after(int n): get(int Gets.nums1)[n] { +// b1 = true; +// } +// static boolean b2 = false; +// after(int n): get(int Gets.nums2)[n] { +// b2 = true; +// } +// static boolean b3 = false; +// after(int n): get(int Gets.nums3)[n] { +// b3 = true; +// } +// static boolean b4 = false; +// after(int n): get(int Gets.nums4)[n] { +// b4 = true; +// } +// static boolean b5 = false; +// after(int n): get(int Gets.nums5)[n] { +// b5 = true; +// } +// static boolean b6 = false; +// after(int n): get(int Gets.nums6)[n] { +// b6 = true; +// } +// static boolean b7 = false; +// after(int n): get(int Gets.nums7)[n] { +// b7 = true; +// } +// static boolean b8 = false; +// after(int n): get(int Gets.nums8)[n] { +// b8 = true; +// } +// static boolean b9 = false; +// after(int n): get(int Gets.nums9)[n] { +// b9 = true; +// } +// } + +// aspect SetAspectOfEach of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(int d, int n): set(int Gets.*)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "nums should be 10, not " + d + " for SetAspectOfEach"); +// bstar = true; +// } +// static boolean b0 = false; +// after(int d, int n): set(int Gets.nums0)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num0 should be 10, not " + d + " for SetAspectOfEach"); +// b0 = true; +// } +// static boolean b1 = false; +// after(int d, int n): set(int Gets.nums1)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num1 should be 10, not " + d + " for SetAspectOfEach"); +// b1 = true; +// } +// static boolean b2 = false; +// after(int d, int n): set(int Gets.nums2)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num2 should be 10, not " + d + " for SetAspectOfEach"); +// b2 = true; +// } +// static boolean b3 = false; +// after(int d, int n): set(int Gets.nums3)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num3 should be 10, not " + d + " for SetAspectOfEach"); +// b3 = true; +// } +// static boolean b4 = false; +// after(int d, int n): set(int Gets.nums4)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num4 should be 10, not " + d + " for SetAspectOfEach"); +// b4 = true; +// } +// static boolean b5 = false; +// after(int d, int n): set(int Gets.nums5)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num5 should be 10, not " + d + " for SetAspectOfEach"); +// b5 = true; +// } +// static boolean b6 = false; +// after(int d, int n): set(int Gets.nums6)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num6 should be 10, not " + d + " for SetAspectOfEach"); +// b6 = true; +// } +// static boolean b7 = false; +// after(int d, int n): set(int Gets.nums7)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num7 should be 10, not " + d + " for SetAspectOfEach"); +// b7 = true; +// } +// static boolean b8 = false; +// after(int d, int n): set(int Gets.nums8)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num8 should be 10, not " + d + " for SetAspectOfEach"); +// b8 = true; +// } +// static boolean b9 = false; +// after(int d, int n): set(int Gets.nums9)[d][n] && withincode(void go()) { +// Tester.check(n == 10, "num9 should be 10, not " + d + " for SetAspectOfEach"); +// b9 = true; +// } + +// } + +// aspect SetAspectOfEach2 of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(): set(int Gets.*) { +// bstar = true; +// } +// static boolean b0 = false; +// after(): set(int Gets.nums0) { +// b0 = true; +// } +// static boolean b1 = false; +// after(): set(int Gets.nums1) { +// b1 = true; +// } +// static boolean b2 = false; +// after(): set(int Gets.nums2) { +// b2 = true; +// } +// static boolean b3 = false; +// after(): set(int Gets.nums3) { +// b3 = true; +// } +// static boolean b4 = false; +// after(): set(int Gets.nums4) { +// b4 = true; +// } +// static boolean b5 = false; +// after(): set(int Gets.nums5) { +// b5 = true; +// } +// static boolean b6 = false; +// after(): set(int Gets.nums6) { +// b6 = true; +// } +// static boolean b7 = false; +// after(): set(int Gets.nums7) { +// b7 = true; +// } +// static boolean b8 = false; +// after(): set(int Gets.nums8) { +// b8 = true; +// } +// static boolean b9 = false; +// after(): set(int Gets.nums9) { +// b9 = true; +// } + +// } + +// aspect SetAspectOfEach3 of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(int d): set(int Gets.*)[d][] { +// bstar = true; +// } +// static boolean b0 = false; +// after(int d): set(int Gets.nums0)[d][] { +// b0 = true; +// } +// static boolean b1 = false; +// after(int d): set(int Gets.nums1)[d][] { +// b1 = true; +// } +// static boolean b2 = false; +// after(int d): set(int Gets.nums2)[d][] { +// b2 = true; +// } +// static boolean b3 = false; +// after(int d): set(int Gets.nums3)[d][] { +// b3 = true; +// } +// static boolean b4 = false; +// after(int d): set(int Gets.nums4)[d][] { +// b4 = true; +// } +// static boolean b5 = false; +// after(int d): set(int Gets.nums5)[d][] { +// b5 = true; +// } +// static boolean b6 = false; +// after(int d): set(int Gets.nums6)[d][] { +// b6 = true; +// } +// static boolean b7 = false; +// after(int d): set(int Gets.nums7)[d][] { +// b7 = true; +// } +// static boolean b8 = false; +// after(int d): set(int Gets.nums8)[d][] { +// b8 = true; +// } +// static boolean b9 = false; +// after(int d): set(int Gets.nums9)[d][] { +// b9 = true; +// } + +// } + +// aspect SetAspectOfEach4 of eachobject(instanceof(Gets)) { +// static boolean bstar = false; +// after(int n): set(int Gets.*)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "nums should be 10 for SetAspectOfEach4"); +// bstar = true; +// } +// static boolean b0 = false; +// after(int n): set(int Gets.nums0)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num0 should be 10 for SetAspectOfEach4"); +// b0 = true; +// } +// static boolean b1 = false; +// after(int n): set(int Gets.nums1)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num1 should be 10 for SetAspectOfEach4"); +// b1 = true; +// } +// static boolean b2 = false; +// after(int n): set(int Gets.nums2)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num2 should be 10 for SetAspectOfEach4"); +// b2 = true; +// } +// static boolean b3 = false; +// after(int n): set(int Gets.nums3)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num3 should be 10 for SetAspectOfEach4"); +// b3 = true; +// } +// static boolean b4 = false; +// after(int n): set(int Gets.nums4)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num4 should be 10 for SetAspectOfEach4"); +// b4 = true; +// } +// static boolean b5 = false; +// after(int n): set(int Gets.nums5)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num5 should be 10 for SetAspectOfEach4"); +// b5 = true; +// } +// static boolean b6 = false; +// after(int n): set(int Gets.nums6)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num6 should be 10 for SetAspectOfEach4"); +// b6 = true; +// } +// static boolean b7 = false; +// after(int n): set(int Gets.nums7)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num7 should be 10 for SetAspectOfEach4"); +// b7 = true; +// } +// static boolean b8 = false; +// after(int n): set(int Gets.nums8)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num8 should be 10 for SetAspectOfEach4"); +// b8 = true; +// } +// static boolean b9 = false; +// after(int n): set(int Gets.nums9)[][n] && withincode(void go()) { +// Tester.checkEqual(n, 10, "num9 should be 10 for SetAspectOfEach4"); +// b9 = true; +// } + +// } diff --git a/tests/new/HandlerSignature.java b/tests/new/HandlerSignature.java new file mode 100644 index 000000000..22100a911 --- /dev/null +++ b/tests/new/HandlerSignature.java @@ -0,0 +1,56 @@ + +import org.aspectj.testing.Tester; +import java.util.*; + +/** @testcase PR#883 Getting signature from handler join point */ +public class HandlerSignature { + + public static void main(String[] args) { + C c = new C(); + U.ee("caught"); + try { + c.run(); + } catch (Error e) { + U.e("caught"); + } + Tester.checkAllEvents(); + } + static { + // U.ee("X"); + } +} + +class C { + public void run() { + throw new Error(""); + } +} + +class U { + static void e(String event) { + System.err.println(event); + Tester.event(event); + } + static void ee(String event) { + Tester.expectEvent(event); + } +} + +aspect A { + static { + U.ee("before handler"); + U.ee("after handler"); + } + + before() : handler(*) { + thisJoinPoint.getSignature().getModifiers(); + U.e("before handler"); + } + /* + after returning join points not implemented + after() returning: handler(*) { + thisJoinPoint.getSignature().getModifiers(); + U.e("after handler"); + } + */ +} diff --git a/tests/new/HasAspect.java b/tests/new/HasAspect.java new file mode 100644 index 000000000..f335e6d05 --- /dev/null +++ b/tests/new/HasAspect.java @@ -0,0 +1,48 @@ +import org.aspectj.testing.*; + +public class HasAspect { + static boolean p = false; + public static void main(String[] args) { + HasAspect c = new HasAspect(); + c.someMethod(); + Tester.check(p, "p advice was not run"); + + Tester.check(A.aspectOf(c).advised, "hasaspect(A)"); + Tester.check(B.aspectOf().advised, "hasaspect(B)"); + Tester.check(C.aspectOf().advised, "hasaspect(C)"); + } + + public void someMethod() {} +} + +aspect A pertarget(target(HasAspect)) { + boolean advised = false; + + pointcut p(): call(void someMethod()) && hasaspect(A); + //pointcut p(): receptions(void someMethod()) && instanceof(HasAspect); + + before() : p() { + HasAspect.p = true; + } +} + +aspect B issingleton() { + boolean advised = false; +} + +aspect C percflow(entries()) { + pointcut entries(): executions(void HasAspect.main(String[])); + + boolean advised = false; +} + + +aspect TestAspect { + before(A a, B b, C c) : call(void someMethod()) + && hasaspect(a) && hasaspect(b) && hasaspect(c) + { + a.advised = true; + b.advised = true; + c.advised = true; + } +} diff --git a/tests/new/Hello.java b/tests/new/Hello.java new file mode 100644 index 000000000..473ee5251 --- /dev/null +++ b/tests/new/Hello.java @@ -0,0 +1,6 @@ +public class Hello { + public static void main(String[] args) { + System.out.println("hello world"); + if (args.length > 1) throw new Error("e"); + } +} diff --git a/tests/new/HierarchyIntroductions.java b/tests/new/HierarchyIntroductions.java new file mode 100644 index 000000000..d01f8651d --- /dev/null +++ b/tests/new/HierarchyIntroductions.java @@ -0,0 +1,52 @@ +//!!! ugly test case + +public class HierarchyIntroductions { + public static void main(String[] args) { test(); } + + static public void test() { + C1 c1 = new C1(); + I1 i1 = c1; + C2 c2 = new C2(); + c2.foo(); + c1 = c2; + I4 i4 = c2; + I2 i2 = c1; + } +} + + +aspect Hierarchy { + //introduction C1 { + declare parents: C1 implements I1; + declare parents: C1 implements I2; + //} + + //introduction C2 { + declare parents: C2 extends C1; + //} + + //introduction C4 { + declare parents: C4 extends C3; + //} + //introduction C5 { + declare parents: C5 extends C3a; + //} + + //introduction I2 { + declare parents: I2 extends I3, I4, I5; + //} +} + + +class C1 { public void foo() { } } +class C2 {} +class C3 {} +class C3a extends C3 {} +class C4 extends C3 {} +class C5 extends C3 {} + +interface I1 {} +interface I2 {} +interface I3 {} +interface I4 {} +interface I5 {} diff --git a/tests/new/HoldProceed.java b/tests/new/HoldProceed.java new file mode 100644 index 000000000..1f14060d7 --- /dev/null +++ b/tests/new/HoldProceed.java @@ -0,0 +1,67 @@ +import org.aspectj.testing.Tester; +import java.util.*; + + +public class HoldProceed { + public static void main(String[] args) { + C c = new C(); + c.m1(); c.m2(); c.m1(); + Tester.check("m"); + Tester.checkEqual(A.buf.toString(), ""); + A.runProceeds(); + Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:"); + A.runProceeds(); + Tester.checkEqual(A.buf.toString(), "m1:b:m2:m1:m1:b:m2:m1:"); + + try { + c.m3(); + } catch (Exception e) { + Tester.check(false, "shouldn't throw anything"); + } + + try { + A.runProceeds(); + } catch (Error err) { //??? this is an odd test for the fact that Exception is wrapped + Tester.note("caught err"); + } + Tester.check("caught err"); + } +} + +class C { + public void m1() {A. buf.append("m1:"); } + public void m2() {A. buf.append("m2:"); } + public void m3() throws Exception { throw new Exception("from m3"); } +} + +aspect A { + static StringBuffer buf = new StringBuffer(); + + static List heldProceeds = new LinkedList(); + + int cnt = 0; + + void around (): call(void C.m*()) { + heldProceeds.add(new Runnable() { public void run() { proceed(); cnt++; } }); + + class MyRun implements Runnable { + public void run() { System.out.println("run"); } + public void m() { Tester.note("m"); } + } + + MyRun mr = new MyRun(); + mr.m(); + } + + before(): call(void C.m2()) { + new Runnable() { + public void run() { buf.append("b:"); } + }.run(); + } + + public static void runProceeds() { + for (Iterator i = heldProceeds.iterator(); i.hasNext(); ) { + ((Runnable)i.next()).run(); + } + } +} diff --git a/tests/new/IfPCDAdviceMethods.java b/tests/new/IfPCDAdviceMethods.java new file mode 100644 index 000000000..121032dd2 --- /dev/null +++ b/tests/new/IfPCDAdviceMethods.java @@ -0,0 +1,320 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +class TestContext { + public static void signal(String event) { + Tester.event(event); + } + public static void expectSignal(String event) { + Tester.expectEvent(event); + } + public static void startTest() { + } + public static void endTest() { + Tester.checkAllEventsIgnoreDups(); + } + public static void testFailed(String failureMessage) { + Tester.check(false,failureMessage); + } +} + +class BaseApp { + int i; + int get() { return i; } + void set(int i) { this.i = i; } + void uncountedCall() { } + // permits call to be restricted to within(BaseApp) + void callFromOutside(int i) { + call(i); + } + private void call(int i) { TestContext.signal("call(int)"); } +} + +/** + * Test touching pcd if() variants: + * <table> + * <tr><td>pcd if(expr)</td><td>anonymous, named</td></tr> + * <tr><td>pcd combination</td><td>execution, call, callTyped,initialization,set,get</td></tr> + * <tr><td>advice</td><td></td>before, after, around</tr> + * </table> + * (callTyped is probably not a relevant difference). + * Currently passing. + * @author wes + * History + * 8/20/01 initial draft + * 8/21/01 fixed namedIf call, added initializations + * Todo + * + */ +public class IfPCDAdviceMethods { + public static void main(String[] args) { + TestContext.startTest(); + BaseApp target = new BaseApp(); + target.callFromOutside(0); + target.uncountedCall(); + target.set(1); + if (!(1 == target.get())) { + TestContext.testFailed("1 != target.get()"); + } + TestContext.endTest(); + } + static { + // variants of advice defined below + String[] cuts = { "call_pc", "callType_pc", "execution_pc", + "get_pc", "set_pc", "initialization_pc" } ; + String[] kinds = { "before", "after", "around" }; + String[] ifs = { "if(true)", "namedIf()", "anonymous" }; + for (int i = 0; i < cuts.length; i++) { + for (int j = 0; j < kinds.length; j++) { + for (int k = 0; k < ifs.length; k++) { + TestContext.expectSignal(kinds[j] + "." + cuts[i] + "." + ifs[k]); + } + } + } + // ensure BaseApp method was called + TestContext.expectSignal("call(int)"); + + // Aspect namedIf delegate should have been called this many times + // (todo: only checks for at-least, not for extra calls) + final int namedIfCalls = 2*cuts.length * (ifs.length-1); // -1 for anonymous, 2* for two calls + for (int i = 0; i < namedIfCalls; i++) { + TestContext.expectSignal("executedNamedIf:"+i); + } + } +} + +/** Catch test failures using aspects - mainly to surface caller/join point easily */ +aspect TestSignals { + /** identify methods that should never be called */ + pointcut errorIfCalled () : call(boolean *..executedNamedIfNever(..)); + /** signal failure if method that wasn't supposed to be called is in fact invoked */ + after () : errorIfCalled() { + // todo: will StaticPart will always have null for source ? + StringBuffer sb = new StringBuffer(); + sb.append("TestSignals.after() : errorIfCalled()"); + org.aspectj.lang.JoinPoint.StaticPart sp = thisJoinPointStaticPart; + if (null == sp) { + sb.append("null thisJoinPointStaticPart"); + } else { + sb.append(" kind=" + sp.getKind()); + sb.append(" signature=" + sp.getSignature()); + sb.append(" source=" + sp.getSourceLocation()); + } + TestContext.testFailed(sb.toString()); + } +} + +/** named pointcuts including if(expr) - call, execution only */ +aspect Aspect { + static int namedIfCounter; + static int namedIfNeverCounter; + static int i; + static boolean executedNamedIf() { + a("executedNamedIf:"+namedIfCounter++); + return true; + } + static boolean executedNamedIfNever() { + a("executedNamedIfNever:"+namedIfNeverCounter++); + return true; + } + + /** + * should not short-circuit, but instead call executedNamedIf + * @testTarget ifpcd.run.expr.java.group no short-circuit of false "or" + * @testTarget ifpcd.run.expr.java.group method invocation in if-expression + */ + pointcut namedIf () + : !within(Aspect) && if( ((1 == 0) || executedNamedIf()) ) ; + + /** + * should short-circuit, never calling executedNamedIfNever + * @testTarget ifpcd.run.expr.java.group short-circuit of false "and" + * @testTarget ifpcd.run.expr.java.group assignment in if-expression + */ + pointcut namedIfNever () // should short-circuit, never calling executedNamedIfNever + : if( ((1 == 1) && executedNamedIfNever()) ) ; + + /** + * @testTarget ifpcd.run.expr.literal literal operations not optimized away fyi + */ + pointcut ifTrue () : if(true); + + /** + * @testTarget ifpcd.run.expr.literal literal operations not optimized away fyi + */ + pointcut ifFalse () : if(false); + + // ------------------------------------- pointcuts + /** @testTarget ifpcd.compile.pcds.named.set */ + pointcut set_pc (): if (true) && set(int BaseApp.i) ; + /** @testTarget ifpcd.compile.pcds.named.get */ + pointcut get_pc (): if (true) && get(int BaseApp.i) ; + /** @testTarget ifpcd.compile.pcds.named.call */ + pointcut call_pc (): if (true) && call(void *.call(int)) && within(BaseApp); + /** @testTarget ifpcd.compile.pcds.named.call with Type */ + pointcut callType_pc(): if(true) && call(void BaseApp.call(int)); + /** @testTarget ifpcd.compile.pcds.named.execution */ + pointcut execution_pc(): if(true) && within(BaseApp) && execution(void *(int)); + /** @testTarget ifpcd.compile.pcds.named.initialization */ + pointcut initialization_pc(): if(true) && initialization(BaseApp.new(..)); + // currently broken + /** @testTarget ifpcd.compile.pcds.named.initialization */ + //pointcut staticinitialization_pc(): if(true) && staticinitialization(BaseApp); + + /** @testTarget ifpcd.compile.pcds.namedIf.set */ + pointcut named_set_pc (): namedIf() && set(int BaseApp.i) ; + /** @testTarget ifpcd.compile.pcds.namedIf.get */ + pointcut named_get_pc (): namedIf() && get(int BaseApp.i) ; + /** @testTarget ifpcd.compile.pcds.namedIf.call if pcd by name composition */ + pointcut named_call_pc() : namedIf() && call(void *.call(int)) && within(BaseApp); + /** @testTarget ifpcd.compile.pcds.namedIf.call with Type, if pcd by name composition */ + pointcut named_callType_pc() : namedIf() && call(void BaseApp.call(int)) && within(BaseApp);; + /** @testTarget ifpcd.compile.pcds.namedIf.execution if pcd by name composition */ + pointcut named_execution_pc(): namedIf() && execution(void *(int)); + /** @testTarget ifpcd.compile.pcds.namedIf.initialization */ + pointcut named_initialization_pc(): namedIf() && initialization(BaseApp.new(..)); + + before(): set_pc () { a("before.set_pc.if(true)"); } + before(): get_pc () { a("before.get_pc.if(true)"); } + before(): call_pc () { a("before.call_pc.if(true)"); } + before(): callType_pc() { a("before.callType_pc.if(true)"); } + before(): execution_pc() { a("before.execution_pc.if(true)"); } + before(): initialization_pc() { a("before.initialization_pc.if(true)"); } + //before(): staticinitialization_pc() { a("before.staticinitialization_pc.if(true)"); } + + before(): named_set_pc () { a("before.set_pc.namedIf()"); } + before(): named_get_pc () { a("before.get_pc.namedIf()"); } + before(): named_call_pc () { a("before.call_pc.namedIf()"); } + before(): named_callType_pc() { a("before.callType_pc.namedIf()"); } + before(): named_execution_pc() { a("before.execution_pc.namedIf()"); } + before(): named_initialization_pc() { a("before.initialization_pc.namedIf()"); } + + int around() : set_pc () { a("around.set_pc.if(true)"); return proceed(); } + int around() : get_pc () { a("around.get_pc.if(true)"); return proceed(); } + void around() : call_pc () { a("around.call_pc.if(true)"); proceed(); } + void around() : callType_pc() { a("around.callType_pc.if(true)"); proceed(); } + void around() : execution_pc() { a("around.execution_pc.if(true)"); proceed(); } + void around() : initialization_pc() { a("around.initialization_pc.if(true)"); proceed(); } + + int around() : named_set_pc () { a("around.set_pc.namedIf()"); return proceed(); } + int around() : named_get_pc () { a("around.get_pc.namedIf()"); return proceed(); } + void around() : named_call_pc () { a("around.call_pc.namedIf()"); proceed(); } + void around() : named_callType_pc() { a("around.callType_pc.namedIf()"); proceed(); } + void around() : named_execution_pc() { a("around.execution_pc.namedIf()"); proceed(); } + void around() : named_initialization_pc() { a("around.initialization_pc.namedIf()"); proceed(); } + + // ------------------------------------- after + after(): set_pc () { a("after.set_pc.if(true)"); } + after(): get_pc () { a("after.get_pc.if(true)"); } + after(): call_pc () { a("after.call_pc.if(true)"); } + after(): callType_pc() { a("after.callType_pc.if(true)"); } + after(): execution_pc() { a("after.execution_pc.if(true)"); } + after(): initialization_pc() { a("after.initialization_pc.if(true)"); } + //after(): staticinitialization_pc() { a("after.staticinitialization_pc.if(true)"); } + + after(): named_set_pc () { a("after.set_pc.namedIf()"); } + after(): named_get_pc () { a("after.get_pc.namedIf()"); } + after(): named_call_pc () { a("after.call_pc.namedIf()"); } + after(): named_callType_pc() { a("after.callType_pc.namedIf()"); } + after(): named_execution_pc() { a("after.execution_pc.namedIf()"); } + after(): named_initialization_pc() { a("after.initialization_pc.namedIf()"); } + + static void a(String msg) { + TestContext.signal(msg); + } +} + +/** anonymous pointcuts including if(expr) - call, execution only */ +aspect Aspect2 { + + /** @testTarget ifpcd.compile.pcds.unnamed.set.before */ + before() : if(true) && set(int BaseApp.i) { + a("before.set_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.get.before */ + before() : if(true) && get(int BaseApp.i) { + a("before.get_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.call.before */ + before() : if(true) && call(void *.uncountedCall()) { + a("before.call_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.call.before with Type */ + before() : if(true) && call(void BaseApp.uncountedCall()) { + a("before.callType_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.execution.before */ + before() : if(true) && execution(void BaseApp.uncountedCall()) { + a("before.execution_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.initialization.before */ + before() : if(true) && initialization(BaseApp.new(..)) { + a("before.initialization_pc.anonymous"); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.set.around */ + int around() : if(true) && set(int BaseApp.i) { + a("around.set_pc.anonymous"); + return proceed(); + } + /** @testTarget ifpcd.compile.pcds.unnamed.get.around */ + int around() : if(true) && get(int BaseApp.i) { + a("around.get_pc.anonymous"); + return proceed(); + } + /** @testTarget ifpcd.compile.pcds.unnamed.call.around */ + void around() : if(true) && call(void *.uncountedCall()) { + a("around.call_pc.anonymous"); + proceed(); + } + /** @testTarget ifpcd.compile.pcds.unnamed.call.around with Type */ + void around() : if(true) && call(void BaseApp.uncountedCall()) { + a("around.callType_pc.anonymous"); + proceed(); + } + /** @testTarget ifpcd.compile.pcds.unnamed.execution.around */ + void around() : if(true) && execution(void BaseApp.uncountedCall()) { + a("around.execution_pc.anonymous"); + proceed(); + } + /** @testTarget ifpcd.compile.pcds.unnamed.initialization.around */ + void around() : if(true) && initialization(BaseApp.new(..)) { + a("around.initialization_pc.anonymous"); + proceed(); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.set.after */ + after() : if(true) && set(int BaseApp.i) { + a("after.set_pc.anonymous"); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.get.after */ + after() : if(true) && get(int BaseApp.i) { + a("after.get_pc.anonymous"); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.call.after */ + after() : if(true) && call(void *.uncountedCall()) { + a("after.call_pc.anonymous"); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.call.after with Type */ + after() : if(true) && call(void BaseApp.uncountedCall()) { + a("after.callType_pc.anonymous"); + } + + /** @testTarget ifpcd.compile.pcds.unnamed.execution.after */ + after() : if(true) && execution(void BaseApp.uncountedCall()) { + a("after.execution_pc.anonymous"); + } + /** @testTarget ifpcd.compile.pcds.unnamed.initialization.after */ + after() : if(true) && initialization(BaseApp.new(..)) { + a("after.initialization_pc.anonymous"); + } + + + static void a(String msg) { + TestContext.signal(msg); + } +} diff --git a/tests/new/IfPCDAssignmentCE.java b/tests/new/IfPCDAssignmentCE.java new file mode 100644 index 000000000..fa0b1dae6 --- /dev/null +++ b/tests/new/IfPCDAssignmentCE.java @@ -0,0 +1,26 @@ + +public class IfPCDAssignmentCE { + public static void main (String[] args) { + foo(new C()); + } + static void foo(C a) {} +} + +class C { + static boolean doit() { return true; } + static boolean doit(C a) { return true; } +} + +aspect A { + before(C c) : args(c) && call(void foo(C)) + && if ((c=new C()).doit()) { // CE 16 + } + + before(C c) : args(c) && call(void foo(C)) + && if (C.doit(c = new C())) { // CE 20 + } +} +/* + Expecting compiler error on attempts to assign bound variable + in if() PCD. Currently getting compiler stack trace. + */ diff --git a/tests/new/IfPCDDupMethod.java b/tests/new/IfPCDDupMethod.java new file mode 100644 index 000000000..de771d536 --- /dev/null +++ b/tests/new/IfPCDDupMethod.java @@ -0,0 +1,25 @@ + +/** + * Ajc produces duplicated methods, and javac complains: + * <pre>..\ajworkingdir\AlreadyDefined.java:51: + * signal$method_call10(java.lang.String) is already defined in AlreadyDefined + * private void signal$method_call10(final String msg) </pre> + */ +public class IfPCDDupMethod { + public static void main(String[] args) { } +} + +aspect AlreadyDefined { + + before(): ifFalse(Object) { signal(""); } + // must come second + pointcut ifFalse (Object t) : this(t) && if(t instanceof Runnable ) ; + + // same result for execution or call or withincode + after() : withincode(static void IfPCDDupMethod.main(String[])) { + signal(""); + } + + static void signal(String msg) { + } +} diff --git a/tests/new/IfPCDExprAssignUnparseFailure.java b/tests/new/IfPCDExprAssignUnparseFailure.java new file mode 100644 index 000000000..48e2da1fd --- /dev/null +++ b/tests/new/IfPCDExprAssignUnparseFailure.java @@ -0,0 +1,27 @@ +import org.aspectj.testing.Tester; + +/** + * @author wes + */ +public class IfPCDExprAssignUnparseFailure { + public static void main(String[] args) { + Tester.check(true, "compiler test"); + } +} + +/** + * NPE unwinding assignment in if pcd expression: + * <pre> + * unexpected exception: + * org.aspectj.compiler.base.InternalCompilerError + * java.lang.NullPointerException + * at org.aspectj.compiler.base.ast.AssignExpr.unparse(AssignExpr.java:78) + * <pre> + * in revision 1.26 of AssignExpr.java. + */ +aspect AspectFor { + static int i; + pointcut namedIf () + : if(0 == (i = 2)) ; // NPE unwinding assignment in if + +} diff --git a/tests/new/IfPCDExprJoinPointVisibleCE.java b/tests/new/IfPCDExprJoinPointVisibleCE.java new file mode 100644 index 000000000..7e315aa86 --- /dev/null +++ b/tests/new/IfPCDExprJoinPointVisibleCE.java @@ -0,0 +1,25 @@ + + +aspect AspectForIfPCDExprJoinPointVisibleCE { + // todo: derives from more general binding problems with named pointcuts + pointcut errorAccessingThisJoinPointStaticPart () + : if (thisJoinPointStaticPart != null); // CE: can't bind name thisJoinPointStaticPart + pointcut errorAccessingThisJoinPoint () + : if (thisJoinPoint != null) && if(thisJoinPoint.getSignature() != null); // CE: can't bind name thisJoinPoint + + before () + : within(IfPCDExprJoinPointVisibleCE) + && errorAccessingThisJoinPoint() { + System.err.println("before thisJoinPoint"); + } + before () + : within(IfPCDExprJoinPointVisibleCE) + && errorAccessingThisJoinPointStaticPart() { + System.err.println("before thisJoinPointStaticPart"); + } +} +public class IfPCDExprJoinPointVisibleCE { + public static void main(String[] args) { + System.err.println("ok - main running after "); + } +} diff --git a/tests/new/IfPCDExprVisibility.java b/tests/new/IfPCDExprVisibility.java new file mode 100644 index 000000000..c94dcd432 --- /dev/null +++ b/tests/new/IfPCDExprVisibility.java @@ -0,0 +1,109 @@ + +aspect AspectForIfPCDExprVisibility { + // See IfPCDExprJoinPoint* for join-point error cases + + pointcut stringLArgs(String[] args) + : args (args); + pointcut targetTarget(IfPCDExprVisibility target) + : target(target); + pointcut thisItem(IfPCDExprVisibility thisItem) + : this(thisItem); + + pointcut callDo() + : call(void IfPCDExprVisibility()); + + pointcut callMain(String[] args) + : args(args) && call(static void *..main(String[])) ; + + // ok: anonymous pointcut + /** + *@testTarget ifpcd.compile.visibility.tjp + *@testTarget ifpcd.compile.visibility.tjpsp + */ + before () + : if (thisJoinPoint != null) + && if (thisJoinPointStaticPart != null) + && call(void IfPCDExprJoinPointVisibleCE.main(..)) { + System.err.println("before main + " + thisJoinPoint); + } + // ok: anonymous pointcut, name composition, arg state + /** + */ + before (String[] args) + : if (thisJoinPointStaticPart != null) + && if (null != args) + && callMain (args){ + String m = "before main" + + " join point: " + thisJoinPoint + + " args: " + args ; + System.err.println(m); + if (null == thisJoinPointStaticPart) + throw new Error("impossible null thisJoinPointStaticPart"); + // actually, it is possible to directly invoke main with null args... + if (null == args) throw new Error("null args"); + } + /** + *@testTarget ifpcd.compile.visibility.args.named + *@testTarget ifpcd.compile.visibility.this.named + *@testTarget ifpcd.compile.visibility.target.named + */ + Object around (String[] _args + , IfPCDExprVisibility _target + , IfPCDExprVisibility _thisItem) + : targetTarget(_target) + && thisItem(_thisItem) + && call(* IfPCDExprVisibility.exec(..)) + && args(_args) + && if(null != _args) + && if(null != _target) + && if(null != _thisItem) + { + String m = "around main - start " + + " join point: " + thisJoinPoint + + " static join point: " + thisJoinPointStaticPart + + " this: " + _thisItem + + " target: " + _target + + " args: " + _args + ; + System.err.println(m); + // note: no compile error unless around is actually woven in + proceed(_args, _target, _thisItem); + m = "around main - end " + + " join point: " + thisJoinPoint + + " static join point: " + thisJoinPointStaticPart + + " this: " + _thisItem + + " target: " + _target + + " args: " + _args + ; + System.err.println(m); + return null; + } +} + +/** + * @author wes + */ +public class IfPCDExprVisibility { + void exec(String[] args) { + if (null == args) { + System.err.println("exec running with null args"); + } else { + System.err.println("exec running with args: " + args); + System.err.println("exec calling itself with null args: " + args); + // only this call is captured by around - from/to this object + exec(null); + } + } + public static void main(String[] args) { + if (null != args) { + System.err.println("main calling itself with null args"); + new IfPCDExprVisibility().main(null); // self-call + System.err.println("main done calling itself with null args"); + + new IfPCDExprVisibility().exec(args); + } else { + System.err.println("ok - main running with null args"); + } + } +} + diff --git a/tests/new/IfdefsAndAdvice.java b/tests/new/IfdefsAndAdvice.java new file mode 100644 index 000000000..620070e26 --- /dev/null +++ b/tests/new/IfdefsAndAdvice.java @@ -0,0 +1,92 @@ +/* We would like to use some performance benchmarking as a way to determine + if ajc is or is not generating the code for dynamic join points in all + cases except for m4(). However, HotSpot is too smart for us today, and + manages to optimize this away. Since the point of this code is that + such an optimization is possible, I'm not sure that we can write a test case + for this... + + So, this test case doesn't do all that good a job. +*/ + +import org.aspectj.testing.Tester; + +public class IfdefsAndAdvice { + public static void main(String[] args) { + double t1 = timeIt(1); + double t2 = timeIt(2); + double t3 = timeIt(3); + double t4 = timeIt(4); + + //System.out.println(t1 + ":" + t2 + ":" + t3 + ":" + t4); + } + + public static double timeIt(int m) { + callIt(m); + callIt(m); + + final int N = 1000; + + long startTime = System.currentTimeMillis(); + for (int i = 0; i < N; i++) { callIt(m); } + long stopTime = System.currentTimeMillis(); + + return (stopTime - startTime)/1000.0; + } + + public static void callIt(int m) { + switch(m) { + case 1: m1(1,2,3,4,5,6,7,8,9,10); + case 2: m2(1,2,3,4,5,6,7,8,9,10); + case 3: m3(1,2,3,4,5,6,7,8,9,10); + case 4: m4(1,2,3,4,5,6,7,8,9,10); + } + } + + + public static int m1(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) { + return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10; + } + public static int m2(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) { + return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10; + } + public static int m3(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) { + return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10; + } + public static int m4(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10) { + return i1+i2+i3+i4+i5+i6+i7+i8+i9+i10; + } +} + +aspect A { + static final boolean DEBUG = false; + + before (): execution(int m1(..)) { + if (DEBUG) { + Object args = thisJoinPoint.getThis(); + } else { + String sig = thisJoinPoint.toString(); + } + } + + before (): execution(int m2(..)) { + if (DEBUG) { + Object args = thisJoinPoint.getThis(); + } + } + + before (): execution(int m3(..)) { + if (!DEBUG) { + String sig = thisJoinPoint.toString(); + } else { + Object args = thisJoinPoint.getThis(); + } + } + + before (): execution(int m4(..)) { + if (!DEBUG) { + Object args = thisJoinPoint.getThis(); + } else { + String sig = thisJoinPoint.toString(); + } + } +} diff --git a/tests/new/IllegalCflowCE.java b/tests/new/IllegalCflowCE.java new file mode 100644 index 000000000..dabf71082 --- /dev/null +++ b/tests/new/IllegalCflowCE.java @@ -0,0 +1,5 @@ + +/** @testcase PR#770 cflow pcd syntax error */ +aspect IllegalCflowCE { + pointcut badCflow() : cflow(*.new(..)); // CE 4 +} diff --git a/tests/new/IllegalForwardReference.java b/tests/new/IllegalForwardReference.java new file mode 100644 index 000000000..0a578bc77 --- /dev/null +++ b/tests/new/IllegalForwardReference.java @@ -0,0 +1,17 @@ +import org.aspectj.testing.Tester; + +public class IllegalForwardReference { + public static void main(String[] args) { + System.out.println(new Aspect.InnerClass().j + ", " + new Aspect.InnerClass().i); + Tester.check(true, "compiled!"); + } +} + +aspect Aspect { + //int InnerClass.i = 13; + + static class InnerClass { + int j = i; + int i = 13; + } +} diff --git a/tests/new/ImportFromUnnamed.java b/tests/new/ImportFromUnnamed.java new file mode 100644 index 000000000..c1f45f58d --- /dev/null +++ b/tests/new/ImportFromUnnamed.java @@ -0,0 +1,14 @@ + +import org.aspectj.testing.Tester; +import DeclaredExcs; + +// PR#134 + +public class ImportFromUnnamed { + public static void main(String[] args) { test(); } + + public static void test() { + DeclaredExcs a = new DeclaredExcs(); + Tester.checkEqual(a.getClass().getName(), "DeclaredExcs", "class name"); + } +} diff --git a/tests/new/ImportInnerFromInterfaceImplementor.java b/tests/new/ImportInnerFromInterfaceImplementor.java new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/new/ImportInnerFromInterfaceImplementor.java diff --git a/tests/new/IndeterminateArg.events b/tests/new/IndeterminateArg.events new file mode 100644 index 000000000..271cb8ed1 --- /dev/null +++ b/tests/new/IndeterminateArg.events @@ -0,0 +1,294 @@ +call(SClass()) []: none()
+SClass()
+call(SClass(java.lang.String)) [java.lang.String]: o1()
+call(SClass(java.lang.String)) [java.lang.String]: s1()
+call(SClass(java.lang.String)) [java.lang.String]: bo1()
+call(SClass(java.lang.String)) [java.lang.String]: bs1()
+SClass(s1)
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o2()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1Start()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1End()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s2()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1Start()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1End()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo2()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo1Start()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo1End()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs2()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs1Start()
+call(SClass(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs1End()
+SClass(s1, s2)
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o3()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o2Start()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o2End()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s3()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s2Start()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s2End()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo3()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo2Start()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo2End()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs3()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs2Start()
+call(SClass(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs2End()
+SClass(s1, s2, s3)
+call(void SClass.f()) []: none()
+SClass.f()
+call(void SClass.f(java.lang.String)) [java.lang.String]: o1()
+call(void SClass.f(java.lang.String)) [java.lang.String]: s1()
+call(void SClass.f(java.lang.String)) [java.lang.String]: bo1()
+call(void SClass.f(java.lang.String)) [java.lang.String]: bs1()
+SClass.f(s1)
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o2()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1Start()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1End()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s2()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1Start()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1End()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo2()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo1Start()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bo1End()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs2()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs1Start()
+call(void SClass.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: bs1End()
+SClass.f(s1, s2)
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o3()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o2Start()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o2End()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s3()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s2Start()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s2End()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo3()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo2Start()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bo2End()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs3()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs2Start()
+call(void SClass.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: bs2End()
+SClass.f(s1, s2, s3)
+call(OClass()) []: none()
+OClass()
+call(OClass(java.lang.Object)) [OObject]: o1()
+call(OClass(java.lang.Object)) [OObject]: bo1()
+OClass(o1)
+call(OClass(java.lang.Object)) [java.lang.String]: o1()
+call(OClass(java.lang.Object)) [java.lang.String]: s1()
+call(OClass(java.lang.Object)) [java.lang.String]: bo1()
+call(OClass(java.lang.Object)) [java.lang.String]: bs1()
+OClass(s1)
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: o2()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: o1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: o1End()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo2()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo1End()
+OClass(o1, o2)
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o2()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o1End()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: s1End()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo2()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo1End()
+call(OClass(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bs1End()
+OClass(o1, s2)
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o1End()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: s1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo1End()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bs1Start()
+OClass(s1, o2)
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1End()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1End()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo1End()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs2()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs1Start()
+call(OClass(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs1End()
+OClass(s1, s2)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo2End()
+OClass(o1, o2, o3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo2End()
+OClass(o1, o2, s3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo2End()
+OClass(o1, s2, o3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: s2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bs2End()
+OClass(o1, s2, s3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo2End()
+OClass(s1, o2, o3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo2End()
+OClass(s1, o2, s3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: s2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bs2Start()
+OClass(s1, s2, o3)
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo2End()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs3()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs2Start()
+call(OClass(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs2End()
+OClass(s1, s2, s3)
+call(void OClass.f()) []: none()
+OClass.f()
+call(void OClass.f(java.lang.Object)) [OObject]: o1()
+call(void OClass.f(java.lang.Object)) [OObject]: bo1()
+OClass.f(o1)
+call(void OClass.f(java.lang.Object)) [java.lang.String]: o1()
+call(void OClass.f(java.lang.Object)) [java.lang.String]: s1()
+call(void OClass.f(java.lang.Object)) [java.lang.String]: bo1()
+call(void OClass.f(java.lang.Object)) [java.lang.String]: bs1()
+OClass.f(s1)
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: o2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: o1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: o1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, OObject]: bo1End()
+OClass.f(o1, o2)
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: o1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: s1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bo1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [OObject, java.lang.String]: bs1End()
+OClass.f(o1, s2)
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: o1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: s1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bo1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, OObject]: bs1Start()
+OClass.f(s1, o2)
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bo1End()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs2()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs1Start()
+call(void OClass.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: bs1End()
+OClass.f(s1, s2)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, OObject]: bo2End()
+OClass.f(o1, o2, o3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, OObject, java.lang.String]: bo2End()
+OClass.f(o1, o2, s3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, OObject]: bo2End()
+OClass.f(o1, s2, o3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: s2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bo2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [OObject, java.lang.String, java.lang.String]: bs2End()
+OClass.f(o1, s2, s3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, OObject]: bo2End()
+OClass.f(s1, o2, o3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, OObject, java.lang.String]: bo2End()
+OClass.f(s1, o2, s3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: s2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bo2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, OObject]: bs2Start()
+OClass.f(s1, s2, o3)
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bo2End()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs3()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs2Start()
+call(void OClass.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: bs2End()
+OClass.f(s1, s2, s3)
diff --git a/tests/new/IndeterminateArg.java b/tests/new/IndeterminateArg.java new file mode 100644 index 000000000..db54c82de --- /dev/null +++ b/tests/new/IndeterminateArg.java @@ -0,0 +1,193 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +import java.util.Arrays; + +/** @testcase PR#764 binding args with single indeterminate prefix and suffix */ +public class IndeterminateArg { + public static void main (String[] args) { + Object o1 = new OObject("o1"); + Object o2 = new OObject("o2"); + Object o3 = new OObject("o3"); + String s1 = "s1"; + String s2 = "s2"; + String s3 = "s3"; + + SClass c; + c = new SClass(); + c = new SClass(s1); + c = new SClass(s1, s2); + c = new SClass(s1, s2, s3); + c.f(); + c.f(s1); + c.f(s1, s2); + c.f(s1, s2, s3); + + OClass o; + o = new OClass(); + o = new OClass(o1); + o = new OClass(s1); + o = new OClass(o1, o2); + o = new OClass(o1, s2); + o = new OClass(s1, o2); + o = new OClass(s1, s2); + o = new OClass(o1, o2, o3); + o = new OClass(o1, o2, s3); + o = new OClass(o1, s2, o3); + o = new OClass(o1, s2, s3); + o = new OClass(s1, o2, o3); + o = new OClass(s1, o2, s3); + o = new OClass(s1, s2, o3); + o = new OClass(s1, s2, s3); + + o.f(); + o.f(o1); + o.f(s1); + o.f(o1, o2); + o.f(o1, s2); + o.f(s1, o2); + o.f(s1, s2); + o.f(o1, o2, o3); + o.f(o1, o2, s3); + o.f(o1, s2, o3); + o.f(o1, s2, s3); + o.f(s1, o2, o3); + o.f(s1, o2, s3); + o.f(s1, s2, o3); + o.f(s1, s2, s3); + + Tester.checkEventsFromFile("IndeterminateArg.events"); + } +} + +class OObject { + final String s; + OObject(String s) { this.s = s; } + public String toString() { return s; } +} + +class T { + static void e(String s) { + Tester.event(s); + } +} + +interface C {} +class SClass implements C { + SClass() { T.e("SClass()"); } + SClass(String s1) { T.e("SClass(" + s1 + ")"); } + SClass(String s1, String s2) { T.e("SClass(" + s1 + ", " + s2 + ")"); } + SClass(String s1, String s2, String s3) { T.e("SClass(" + s1 + ", " + s2 + ", " + s3 + ")"); } + + void f() { T.e("SClass.f()"); } + void f(String s1) { T.e("SClass.f(" + s1 + ")"); } + void f(String s1, String s2) { T.e("SClass.f(" + s1 + ", " + s2 + ")"); } + void f(String s1, String s2, String s3) { T.e("SClass.f(" + s1 + ", " + s2 + ", " + s3 + ")"); } +} + +class OClass implements C { + OClass() { T.e("OClass()"); } + OClass(Object s1) { T.e("OClass(" + s1 + ")"); } + OClass(Object s1, Object s2) { T.e("OClass(" + s1 + ", " + s2 + ")"); } + OClass(Object s1, Object s2, Object s3) { T.e("OClass(" + s1 + ", " + s2 + ", " + s3 + ")"); } + + void f() { T.e("OClass.f()"); } + void f(Object s1) { T.e("OClass.f(" + s1 + ")"); } + void f(Object s1, Object s2) { T.e("OClass.f(" + s1 + ", " + s2 + ")"); } + void f(Object s1, Object s2, Object s3) { T.e("OClass.f(" + s1 + ", " + s2 + ", " + s3 + ")"); } +} + +aspect A { + + String actualTypes(JoinPoint jp) { // XXX gather as utility + Object[] types = jp.getArgs(); + StringBuffer sb = new StringBuffer(); + sb.append("["); + for (int i = 0; i < types.length; i++) { + sb.append(types[i].getClass().getName()); + if ((1+i) < types.length) { + sb.append(", "); + } + } + sb.append("]"); + return sb.toString(); + } + void check(String pc, JoinPoint jp) { + Class[] types = ((CodeSignature) jp.getSignature()).getParameterTypes(); + String name = jp.toLongString() + " " + actualTypes(jp) + ": " + pc; + T.e(name); + } + + pointcut safe() : (call(C+.new(..)) || call(* C+.*(..))); + // XXX should encode slots, range: a0o1 = args(Object); a3o2Start = args(Object, Object, *) + pointcut none() : args(); + pointcut o1() : args(Object); + pointcut o2() : args(Object, Object); + pointcut o3() : args(Object, Object, Object); + pointcut o1Start() : args(Object,*); + pointcut o1End() : args(*,Object); + pointcut o2Start() : args(Object, Object,*); + pointcut o2End() : args(*,Object, Object); + + pointcut s1() : args(String); + pointcut s2() : args(String, String); + pointcut s3() : args(String, String, String); + pointcut s1Start() : args(String,*); + pointcut s1End() : args(*,String); + pointcut s2Start() : args(String, String,*); + pointcut s2End() : args(*,String, String); + + // bind + pointcut bo1(Object o1) : args(o1); + pointcut bo2(Object o1, Object o2) : args(o1, o2); + pointcut bo3(Object o1, Object o2, Object o3) : args(o1, o2, o3); + pointcut bo1Start(Object o1) : args(o1,*); + pointcut bo1End(Object o1) : args(*,o1); + pointcut bo2Start(Object o1, Object o2) : args(o1, o2,*); + pointcut bo2End(Object o1, Object o2) : args(*,o1, o2); + + pointcut bs1(String s1) : args(s1); + pointcut bs2(String s1, String s2) : args(s1, s2); + pointcut bs3(String s1, String s2, String s3) : args(s1, s2, s3); + pointcut bs1Start(String s1) : args(s1,*); + pointcut bs1End(String s1) : args(*,s1); + pointcut bs2Start(String s1, String s2) : args(s1, s2,*); + pointcut bs2End(String s1, String s2) : args(*,s1, s2); + + before() : safe() && none() { check ("none()", thisJoinPoint); } + before() : safe() && o1() { check ("o1()", thisJoinPoint); } + before() : safe() && o2() { check ("o2()", thisJoinPoint); } + before() : safe() && o3() { check ("o3()", thisJoinPoint); } + before() : safe() && o1Start() { check ("o1Start()", thisJoinPoint); } + before() : safe() && o1End() { check ("o1End()", thisJoinPoint); } + before() : safe() && o2Start() { check ("o2Start()", thisJoinPoint); } + before() : safe() && o2End() { check ("o2End()", thisJoinPoint); } + + before() : safe() && s1() { check ("s1()", thisJoinPoint); } + before() : safe() && s2() { check ("s2()", thisJoinPoint); } + before() : safe() && s3() { check ("s3()", thisJoinPoint); } + before() : safe() && s1Start() { check ("s1Start()", thisJoinPoint); } + before() : safe() && s1End() { check ("s1End()", thisJoinPoint); } + before() : safe() && s2Start() { check ("s2Start()", thisJoinPoint); } + before() : safe() && s2End() { check ("s2End()", thisJoinPoint); } + + before(Object o1) : safe() && bo1(o1) { check ("bo1()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2(o1, o2) { check ("bo2()", thisJoinPoint); } + before(Object o1, Object o2, Object o3) : safe() && bo3(o1, o2, o3) { check ("bo3()", thisJoinPoint); } + before(Object o1) : safe() && bo1Start(o1) { check ("bo1Start()", thisJoinPoint); } + before(Object o1) : safe() && bo1End(o1) { check ("bo1End()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2Start(o1, o2) { check ("bo2Start()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2End(o1, o2) { check ("bo2End()", thisJoinPoint); } + + before(String s1) : safe() && bs1(s1) { check ("bs1()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2(s1, s2) { check ("bs2()", thisJoinPoint); } + before(String s1, String s2, String s3) : safe() && bs3(s1, s2, s3) { check ("bs3()", thisJoinPoint); } + before(String s1) : safe() && bs1Start(s1) { check ("bs1Start()", thisJoinPoint); } + before(String s1) : safe() && bs1End(s1) { check ("bs1End()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2Start(s1, s2) { check ("bs2Start()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2End(s1, s2) { check ("bs2End()", thisJoinPoint); } +} + + diff --git a/tests/new/IndeterminateArgType.events b/tests/new/IndeterminateArgType.events new file mode 100644 index 000000000..716ce215a --- /dev/null +++ b/tests/new/IndeterminateArgType.events @@ -0,0 +1,60 @@ +call(STarget(java.lang.String)) [java.lang.String]: o1Start()
+call(STarget(java.lang.String)) [java.lang.String]: o1End()
+call(STarget(java.lang.String)) [java.lang.String]: s1Start()
+call(STarget(java.lang.String)) [java.lang.String]: s1End()
+call(STarget(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1Start()
+call(STarget(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1End()
+call(STarget(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1Start()
+call(STarget(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1End()
+call(STarget(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o1Start()
+call(STarget(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o1End()
+call(STarget(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s1Start()
+call(STarget(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s1End()
+call(void STarget.f(java.lang.String)) [java.lang.String]: o1Start()
+call(void STarget.f(java.lang.String)) [java.lang.String]: o1End()
+call(void STarget.f(java.lang.String)) [java.lang.String]: s1Start()
+call(void STarget.f(java.lang.String)) [java.lang.String]: s1End()
+call(void STarget.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1Start()
+call(void STarget.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: o1End()
+call(void STarget.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1Start()
+call(void STarget.f(java.lang.String, java.lang.String)) [java.lang.String, java.lang.String]: s1End()
+call(void STarget.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o1Start()
+call(void STarget.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: o1End()
+call(void STarget.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s1Start()
+call(void STarget.f(java.lang.String, java.lang.String, java.lang.String)) [java.lang.String, java.lang.String, java.lang.String]: s1End()
+call(OTarget(java.lang.Object)) [java.lang.String]: o1Start()
+call(OTarget(java.lang.Object)) [java.lang.String]: o1End()
+call(OTarget(java.lang.Object)) [java.lang.String]: s1Start()
+call(OTarget(java.lang.Object)) [java.lang.String]: s1End()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1Start()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1End()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1Start()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1End()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o1Start()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o1End()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s1Start()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s1End()
+call(void OTarget.f(java.lang.Object)) [java.lang.String]: o1Start()
+call(void OTarget.f(java.lang.Object)) [java.lang.String]: o1End()
+call(void OTarget.f(java.lang.Object)) [java.lang.String]: s1Start()
+call(void OTarget.f(java.lang.Object)) [java.lang.String]: s1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: o1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String]: s1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: o1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.String, java.lang.String, java.lang.String]: s1End()
+call(OTarget(java.lang.Object)) [java.lang.Object]: o1Start()
+call(OTarget(java.lang.Object)) [java.lang.Object]: o1End()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object]: o1Start()
+call(OTarget(java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object]: o1End()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object, java.lang.Object]: o1Start()
+call(OTarget(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object, java.lang.Object]: o1End()
+call(void OTarget.f(java.lang.Object)) [java.lang.Object]: o1Start()
+call(void OTarget.f(java.lang.Object)) [java.lang.Object]: o1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object]: o1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object]: o1End()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object, java.lang.Object]: o1Start()
+call(void OTarget.f(java.lang.Object, java.lang.Object, java.lang.Object)) [java.lang.Object, java.lang.Object, java.lang.Object]: o1End()
diff --git a/tests/new/IndeterminateArgType.java b/tests/new/IndeterminateArgType.java new file mode 100644 index 000000000..4beb1301e --- /dev/null +++ b/tests/new/IndeterminateArgType.java @@ -0,0 +1,113 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +import java.util.Arrays; + +/** @testcase PR#764 check arg types with indeterminate prefix and suffix */ +public class IndeterminateArgType { + public static void main (String[] args) { + OTarget o; + STarget c; + // both pointcuts pick out args 1..3; neither picks out args 0 + // both actual Object and String match + c = new STarget(); + c = new STarget("s1"); + c = new STarget("s1", "s2"); + c = new STarget("s1", "s2", "s3"); + c.f(); + c.f("s1"); + c.f("s1", "s2"); + c.f("s1", "s2", "s3"); + // String pointcut should match even though declared type is Object + o = new OTarget(); + o = new OTarget("o1"); + o = new OTarget("o1", "o2"); + o = new OTarget("o1", "o2", "o3"); + o.f(); + o.f("o1"); + o.f("o1", "o2"); + o.f("o1", "o2", "o3"); + + // only actual Object types match these + Object input = new Object(); + o = new OTarget(); + o = new OTarget(input); + o = new OTarget(input, input); + o = new OTarget(input, input, input); + o.f(); + o.f(input); + o.f(input, input); + o.f(input, input, input); + + Tester.checkEventsFromFile("IndeterminateArgType.events"); + } +} + +interface Safe {} +class OTarget implements Safe { + OTarget() { } + OTarget(Object s1) { } + OTarget(Object s1, Object s2) { } + OTarget(Object s1, Object s2, Object s3) { } + + void f() { } + void f(Object s1) { } + void f(Object s1, Object s2) { } + void f(Object s1, Object s2, Object s3) { } +} + +class STarget implements Safe { + STarget() { } + STarget(String s1) { } + STarget(String s1, String s2) { } + STarget(String s1, String s2, String s3) { } + + void f() { } + void f(String s1) { } + void f(String s1, String s2) { } + void f(String s1, String s2, String s3) { } +} + +class T { + static void e(String s) { + Tester.event(s); + } +} + +aspect A { + + String actualTypes(JoinPoint jp) { // XXX gather as utility + Object[] types = jp.getArgs(); + StringBuffer sb = new StringBuffer(); + sb.append("["); + for (int i = 0; i < types.length; i++) { + sb.append(types[i].getClass().getName()); + if ((1+i) < types.length) { + sb.append(", "); + } + } + sb.append("]"); + return sb.toString(); + } + void check(String pc, JoinPoint jp) { + Class[] types = ((CodeSignature) jp.getSignature()).getParameterTypes(); + String name = jp.toLongString() + " " + actualTypes(jp) + ": " + pc; + T.e(name); + } + + pointcut safe() : call(Safe+.new(..)) || call(* Safe+.*(..)); + + pointcut o1End() : args(.., Object); + pointcut s1End() : args(.., String); + pointcut o1Start() : args(Object, ..); + pointcut s1Start() : args(String, ..); + + before() : safe() && o1Start() { check ("o1Start()", thisJoinPoint); } + before() : safe() && o1End() { check ("o1End()", thisJoinPoint); } + before() : safe() && s1Start() { check ("s1Start()", thisJoinPoint); } + before() : safe() && s1End() { check ("s1End()", thisJoinPoint); } +} + + diff --git a/tests/new/IndeterminateArgs.events b/tests/new/IndeterminateArgs.events new file mode 100644 index 000000000..cba748f78 --- /dev/null +++ b/tests/new/IndeterminateArgs.events @@ -0,0 +1,56 @@ +C()
+C(s1)
+C(s1, s2)
+C(s1, s2, s3)
+f()
+o1(): [class java.lang.String]
+o1Start(): [class java.lang.String]
+o1End(): [class java.lang.String]
+s1(): [class java.lang.String]
+s1Start(): [class java.lang.String]
+s1End(): [class java.lang.String]
+bo1(): [class java.lang.String]
+bo1Start(): [class java.lang.String]
+bo1End(): [class java.lang.String]
+bs1(): [class java.lang.String]
+bs1Start(): [class java.lang.String]
+bs1End(): [class java.lang.String]
+f(s1)
+o2(): [class java.lang.String, class java.lang.String]
+o1Start(): [class java.lang.String, class java.lang.String]
+o1End(): [class java.lang.String, class java.lang.String]
+o2Start(): [class java.lang.String, class java.lang.String]
+o2End(): [class java.lang.String, class java.lang.String]
+s2(): [class java.lang.String, class java.lang.String]
+s1Start(): [class java.lang.String, class java.lang.String]
+s1End(): [class java.lang.String, class java.lang.String]
+s2Start(): [class java.lang.String, class java.lang.String]
+s2End(): [class java.lang.String, class java.lang.String]
+bo2(): [class java.lang.String, class java.lang.String]
+bo1Start(): [class java.lang.String, class java.lang.String]
+bo1End(): [class java.lang.String, class java.lang.String]
+bo2Start(): [class java.lang.String, class java.lang.String]
+bo2End(): [class java.lang.String, class java.lang.String]
+bs2(): [class java.lang.String, class java.lang.String]
+bs1Start(): [class java.lang.String, class java.lang.String]
+bs1End(): [class java.lang.String, class java.lang.String]
+bs2Start(): [class java.lang.String, class java.lang.String]
+bs2End(): [class java.lang.String, class java.lang.String]
+f(s1, s2)
+o1Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+o1End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+o2Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+o2End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+s1Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+s1End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+s2Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+s2End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bo1Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bo1End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bo2Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bo2End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bs1Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bs1End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bs2Start(): [class java.lang.String, class java.lang.String, class java.lang.String]
+bs2End(): [class java.lang.String, class java.lang.String, class java.lang.String]
+f(s1, s2, s3)
diff --git a/tests/new/IndeterminateArgs.java b/tests/new/IndeterminateArgs.java new file mode 100644 index 000000000..2a7cfb828 --- /dev/null +++ b/tests/new/IndeterminateArgs.java @@ -0,0 +1,109 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +import java.util.Arrays; + +/** @testcase PR#764 binding args with indeterminate prefix and suffix */ +public class IndeterminateArgs { + public static void main (String[] args) { + C c; + c = new C(); + c = new C("s1"); + c = new C("s1", "s2"); + c = new C("s1", "s2", "s3"); + c.f(); + c.f("s1"); + c.f("s1", "s2"); + c.f("s1", "s2", "s3"); + Tester.checkEventsFromFile("IndeterminateArgs.events"); + } +} +class T { + static void e(String s) { + Tester.event(s); + } + static void ee(String s) { Tester.expectEvent(s); } +} + +class C { + C() { T.e("C()"); } + C(String s1) { T.e("C(" + s1 + ")"); } + C(String s1, String s2) { T.e("C(" + s1 + ", " + s2 + ")"); } + C(String s1, String s2, String s3) { T.e("C(" + s1 + ", " + s2 + ", " + s3 + ")"); } + + void f() { T.e("f()"); } + void f(String s1) { T.e("f(" + s1 + ")"); } + void f(String s1, String s2) { T.e("f(" + s1 + ", " + s2 + ")"); } + void f(String s1, String s2, String s3) { T.e("f(" + s1 + ", " + s2 + ", " + s3 + ")"); } +} + +aspect A { + + void check(String pc, JoinPoint jp) { + Class[] types = ((CodeSignature) jp.getSignature()).getParameterTypes(); + T.e(pc + ": " + Arrays.asList(types)); + } + + pointcut safe() : target(C) && (call(new(..)) || call(* *(..))); + + pointcut o1() : args(Object); + pointcut o2() : args(Object, Object); + pointcut o1Start() : args(Object,..); + pointcut o1End() : args(..,Object); + pointcut o2Start() : args(Object, Object,..); + pointcut o2End() : args(..,Object, Object); + + pointcut s1() : args(String); + pointcut s2() : args(String, String); + pointcut s1Start() : args(String,..); + pointcut s1End() : args(..,String); + pointcut s2Start() : args(String, String,..); + pointcut s2End() : args(..,String, String); + + // bind + pointcut bo1(Object o1) : args(o1); + pointcut bo2(Object o1, Object o2) : args(o1, o2); + pointcut bo1Start(Object o1) : args(o1,..); + pointcut bo1End(Object o1) : args(..,o1); + pointcut bo2Start(Object o1, Object o2) : args(o1, o2,..); + pointcut bo2End(Object o1, Object o2) : args(..,o1, o2); + + pointcut bs1(String s1) : args(s1); + pointcut bs2(String s1, String s2) : args(s1, s2); + pointcut bs1Start(String s1) : args(s1,..); + pointcut bs1End(String s1) : args(..,s1); + pointcut bs2Start(String s1, String s2) : args(s1, s2,..); + pointcut bs2End(String s1, String s2) : args(..,s1, s2); + + before() : safe() && o1() { check ("o1()", thisJoinPoint); } + before() : safe() && o2() { check ("o2()", thisJoinPoint); } + before() : safe() && o1Start() { check ("o1Start()", thisJoinPoint); } + before() : safe() && o1End() { check ("o1End()", thisJoinPoint); } + before() : safe() && o2Start() { check ("o2Start()", thisJoinPoint); } + before() : safe() && o2End() { check ("o2End()", thisJoinPoint); } + + before() : safe() && s1() { check ("s1()", thisJoinPoint); } + before() : safe() && s2() { check ("s2()", thisJoinPoint); } + before() : safe() && s1Start() { check ("s1Start()", thisJoinPoint); } + before() : safe() && s1End() { check ("s1End()", thisJoinPoint); } + before() : safe() && s2Start() { check ("s2Start()", thisJoinPoint); } + before() : safe() && s2End() { check ("s2End()", thisJoinPoint); } + + before(Object o1) : safe() && bo1(o1) { check ("bo1()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2(o1, o2) { check ("bo2()", thisJoinPoint); } + before(Object o1) : safe() && bo1Start(o1) { check ("bo1Start()", thisJoinPoint); } + before(Object o1) : safe() && bo1End(o1) { check ("bo1End()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2Start(o1, o2) { check ("bo2Start()", thisJoinPoint); } + before(Object o1, Object o2) : safe() && bo2End(o1, o2) { check ("bo2End()", thisJoinPoint); } + + before(String s1) : safe() && bs1(s1) { check ("bs1()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2(s1, s2) { check ("bs2()", thisJoinPoint); } + before(String s1) : safe() && bs1Start(s1) { check ("bs1Start()", thisJoinPoint); } + before(String s1) : safe() && bs1End(s1) { check ("bs1End()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2Start(s1, s2) { check ("bs2Start()", thisJoinPoint); } + before(String s1, String s2) : safe() && bs2End(s1, s2) { check ("bs2End()", thisJoinPoint); } +} + + diff --git a/tests/new/IndeterminateArgsCE.java b/tests/new/IndeterminateArgsCE.java new file mode 100644 index 000000000..bee26a8dd --- /dev/null +++ b/tests/new/IndeterminateArgsCE.java @@ -0,0 +1,76 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +import java.util.Arrays; + +/** @testcase PR#764 binding args with indeterminate prefix and suffix */ +public class IndeterminateArgsCE { + public static void main (String[] args) { + STarget c; + c = new STarget(); + c = new STarget("s1"); + c = new STarget("s1", "s2"); + c = new STarget("s1", "s2", "s3"); + c.f(); + c.f("s1"); + c.f("s1", "s2"); + c.f("s1", "s2", "s3"); + OTarget o; + o = new OTarget(); + o = new OTarget("o1"); + o = new OTarget("o1", "o2"); + o = new OTarget("o1", "o2", "o3"); + o.f(); + o.f("o1"); + o.f("o1", "o2"); + o.f("o1", "o2", "o3"); + } +} + +class OTarget { + OTarget() { } + OTarget(String s1) { } + OTarget(String s1, Object s2) { } // CE + OTarget(String s1, Object s2, String s3) { } // CE + + void f() { } + void f(String s1) { } + void f(String s1, Object s2) { } // CE + void f(String s1, Object s2, String s3) { } // CE +} +class STarget { + STarget() { } + STarget(String s1) { } + STarget(String s1, String s2) { } // CE + STarget(String s1, String s2, String s3) { } + + void f() { } + void f(String s1) { } + void f(String s1, String s2) { } // CE + void f(String s1, String s2, String s3) { } +} + +aspect A { + + void check(String pc, JoinPoint jp) { + Class[] types = ((CodeSignature) jp.getSignature()).getParameterTypes(); + //T.e(pc + ": " + Arrays.asList(types)); + } + + pointcut safeS() : target(STarget) && (call(new(..)) || call(* *(..))); + pointcut safeO() : target(OTarget) && (call(new(..)) || call(* *(..))); + + pointcut o1Anywhere() : args(.., Object, ..); + pointcut s1Anywhere() : args(.., String, ..); + pointcut bo1Anywhere(Object o) : args(.., o, ..); + pointcut bs1Anywhere(String s) : args(.., s, ..); + + before() : safeO() && o1Anywhere() { check ("o1Anywhere()", thisJoinPoint); } + before(Object o1) : safeO() && bo1Anywhere(o1) { check ("bo1Anywhere(o1)", thisJoinPoint); } + before() : safeS() && s1Anywhere() { check ("s1Anywhere()", thisJoinPoint); } + before(String s1) : safeS() && bs1Anywhere(s1) { check ("bs1Anywhere(s1)", thisJoinPoint); } +} + + diff --git a/tests/new/IndeterminateHandlerArg.events b/tests/new/IndeterminateHandlerArg.events new file mode 100644 index 000000000..faf8fea24 --- /dev/null +++ b/tests/new/IndeterminateHandlerArg.events @@ -0,0 +1,47 @@ +handler(catch(java.lang.Error)): java.lang.Error - error @ before Throwable
+handler(catch(java.lang.Error)): java.lang.Error - error @ before Error
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(Throwable)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(Error)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(Throwable,..)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(..,Throwable)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(Error,..)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before args(..,Error)
+handler(catch(java.lang.Error)): java.lang.Error - error @ before Throwable,..
+handler(catch(java.lang.Error)): java.lang.Error - error @ before Error,..
+handler(catch(java.lang.Error)): java.lang.Error - error @ before ..,Throwable
+handler(catch(java.lang.Error)): java.lang.Error - error @ before ..,Error
+error
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before Throwable
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before args(Throwable)
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before args(Throwable,..)
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before args(..,Throwable)
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before Throwable,..
+handler(catch(java.lang.Throwable)): java.lang.Throwable - throwable @ before ..,Throwable
+throwable
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before Throwable
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before Error
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(Throwable)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(Error)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(Throwable,..)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(..,Throwable)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(Error,..)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before args(..,Error)
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before Throwable,..
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before Error,..
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before ..,Throwable
+handler(catch(java.lang.Throwable)): java.lang.Error - error @ before ..,Error
+error
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before Throwable
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before args(Throwable)
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before args(Throwable,..)
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before args(..,Throwable)
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before Throwable,..
+handler(catch(java.lang.Throwable)): IndeterminateHandlerArg$1 - runtime @ before ..,Throwable
+runtime
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before Throwable
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before args(Throwable)
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before args(Throwable,..)
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before args(..,Throwable)
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before Throwable,..
+handler(catch(java.lang.RuntimeException)): IndeterminateHandlerArg$1 - runtime @ before ..,Throwable
+runtime
diff --git a/tests/new/IndeterminateHandlerArg.java b/tests/new/IndeterminateHandlerArg.java new file mode 100644 index 000000000..6f30336db --- /dev/null +++ b/tests/new/IndeterminateHandlerArg.java @@ -0,0 +1,71 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +/** @testcase PR#764 binding handler args with indeterminate prefix and suffix */ +public class IndeterminateHandlerArg { + public static void main (String[] args) { + Throwable throwable = new Throwable("throwable"); + Error error = new Error("error"); + RuntimeException runtime = new RuntimeException("runtime") { + RuntimeException f() { return this; } + }.f(); + + try { throw error; } + catch (Error e) { A.event(e.getMessage()); } + + try { throw throwable; } + catch (Throwable e) { A.event(e.getMessage()); } + try { throw error; } + catch (Throwable e) { A.event(e.getMessage()); } + try { throw runtime; } + catch (Throwable e) { A.event(e.getMessage()); } + + try { throw runtime; } + catch (RuntimeException e) { A.event(e.getMessage()); } + + Tester.checkEventsFromFile("IndeterminateHandlerArg.events"); + } +} + +aspect A { + void e(String label, JoinPoint jp) { + e(label, jp, (Throwable) jp.getArgs()[0]); + } + void e(String label, JoinPoint jp, Throwable t) { + String m = jp.toLongString() + + ": " + t.getClass().getName() + + " - " + t.getMessage() + + " @ " + label; + event(m); + } + static void event(String m) { + Tester.event(m); + } + + pointcut hd() : withincode(static void main(..)) && handler(*); + + before (Throwable t) : hd() && args(t) { e("before Throwable", thisJoinPoint, t); } + before (Error t) : hd() && args(t) { e("before Error", thisJoinPoint, t); } + before () : hd() && args(Throwable) { e("before args(Throwable)", thisJoinPoint); } + before () : hd() && args(Error) { e("before args(Error)", thisJoinPoint); } + before () : hd() && args(Throwable,..) { e("before args(Throwable,..)", thisJoinPoint); } + before () : hd() && args(..,Throwable) { e("before args(..,Throwable)", thisJoinPoint); } + before () : hd() && args(Error,..) { e("before args(Error,..)", thisJoinPoint); } + before () : hd() && args(..,Error) { e("before args(..,Error)", thisJoinPoint); } + before (Throwable t) : hd() && args(t,..) { e("before Throwable,..", thisJoinPoint, t); } + before (Error t) : hd() && args(t,..) { e("before Error,..", thisJoinPoint, t); } + before (Throwable t) : hd() && args(..,t) { e("before ..,Throwable", thisJoinPoint, t); } + before (Error t) : hd() && args(..,t) { e("before ..,Error", thisJoinPoint, t); } + + before () : hd() && args(Throwable,*) { Tester.check(false, "args(Throwable,*)"); } + before () : hd() && args(*,Throwable) { Tester.check(false, "args(*,Throwable)"); } + before () : hd() && args(Error,*) { Tester.check(false, "args(Error,*)"); } + before () : hd() && args(*,Error) { Tester.check(false, "args(*,Error)"); } + before (Throwable t) : hd() && args(t,*) { Tester.check(false, "args((Throwable)t,*)"); } + before (Error t) : hd() && args(t,*) { Tester.check(false, "args((Error)t,*)"); } + before (Throwable t) : hd() && args(*,t) { Tester.check(false, "args(*,(Throwable)t)"); } + before (Error t) : hd() && args(*,t) { Tester.check(false, "args(*,(Error)t)"); } +} + diff --git a/tests/new/InitializationOrder.java b/tests/new/InitializationOrder.java new file mode 100644 index 000000000..d4bd9bf0d --- /dev/null +++ b/tests/new/InitializationOrder.java @@ -0,0 +1,33 @@ + +import org.aspectj.testing.Tester; + +public class InitializationOrder { + public static void main (String[] args) { + C c = new C(); + Tester.check(null != c.s, "null == c.s"); + Sub s = new Sub(); + Tester.check("ok" == s.o, "\"ok\" == s.o"); + Tester.check(null == s.p, "null == s.p"); + } + +} + +class C { + public String s = null; + C(String s) { this.s = s; } + C() { this("uh oh"); } +} + +class S { + public Object p; + S(Object p) {this.p = p;} +} + +class Sub extends S { + Sub() { + super(null); // if (o), then C E illegal use of uninitialized value + o = "ok"; + } + Object o; +} + diff --git a/tests/new/InitializerAdvice.java b/tests/new/InitializerAdvice.java new file mode 100644 index 000000000..63ae8f859 --- /dev/null +++ b/tests/new/InitializerAdvice.java @@ -0,0 +1,35 @@ +import org.aspectj.testing.Tester; + +public aspect InitializerAdvice { + public static void test() { + Tester.checkEqual(Foo.getStaticField(), "initialized", "static"); + Tester.checkEqual(new Foo().getInstanceField(), "initialized", "instance"); + } + + public static void main(String[] args) { test(); } + + /*static*/ before(): call(* *(..)) && this(Foo) { + System.out.println("entering"); + } +} + +class Foo { + static String staticField = ""; + static { + staticField = "initialized"; + } + + String instanceField = ""; + { + instanceField = "initialized"; + } + + public static String getStaticField() { + return staticField; + } + + public String getInstanceField() { + return instanceField; + } +} + diff --git a/tests/new/InitializerTest.java b/tests/new/InitializerTest.java new file mode 100644 index 000000000..52f2d93af --- /dev/null +++ b/tests/new/InitializerTest.java @@ -0,0 +1,110 @@ +import org.aspectj.testing.Tester; + +class C { + public static String staticField = "initialized"; + + public String state = "C-initialized"; + + public C() { + state = "C-constructed"; + } +} + +class SubC extends C implements I { + { + state = "SubC-initialized"; + } + + public SubC() { + state = "SubC-constructed"; + } +} + +interface I { + public static String s = "initialized"; + public static String s1 = new String("s1"); +} + + +aspect A issingleton () { + before(): staticinitialization(C) { + Tester.checkEqual(C.staticField, null, "C.staticField"); + } + after(): staticinitialization(C) { + Tester.checkEqual(C.staticField, "initialized", "C.staticField"); + Tester.note("static initialized C"); + } + after(): staticinitialization(SubC) { + Tester.note("static initialized SubC"); + } + /* + before(): staticinitializations(I) { + Tester.checkEqual(I.s, null, "I.s"); + } + after(): staticinitializations(I) { + Tester.checkEqual(I.s, "initialized", "I.s"); + Tester.note("static initialized I"); + } + */ + + + before(C c): initialization(C.new(..)) && this(c) { + Tester.checkEqual(c.state, null, "c.state"); + } + + before(C c): execution(C.new(..)) && this(c) { + // change from 1.0 is that fields aren't initialized at this point + Tester.checkEqual(c.state, null, "c.state pre-constructor"); //"C-initialized", "c.state"); + Tester.note("constructed C"); + } + + after(C c): initialization(C.new(..)) && this(c) { + Tester.checkEqual(c.state, "C-constructed", "c.state"); + Tester.note("initialized C"); + } + + + before(SubC subc): initialization(SubC.new(..)) && this(subc) { + Tester.checkEqual(subc.state, "C-constructed", "c.state"); + } + before(SubC subc): execution(SubC.new(..)) && this(subc) { + // change from 1.0 is that fields aren't initialized at this point + Tester.checkEqual(subc.state, "C-constructed", "c.state"); //"SubC-initialized", "c.state"); + Tester.note("constructed SubC"); + } + + after(SubC subc): initialization(SubC.new(..)) && this(subc) { + Tester.checkEqual(subc.state, "SubC-constructed", thisJoinPoint.toString()); + Tester.note("initialized SubC"); + } + + before(I i): initialization(I.new()) && this(i) { + Tester.checkEqual(((C)i).state, "C-constructed", thisJoinPoint.toString()); + } + before(I i): execution(I.new()) && this(i) { + Tester.checkEqual(((C)i).state, "C-constructed", thisJoinPoint.toString()); + Tester.note("constructed I"); + } + after(I i): initialization(I.new()) && this(i) { + Tester.checkEqual(((C)i).state, "C-constructed", thisJoinPoint.toString()); + Tester.note("initialized I"); + } +} + +public class InitializerTest { + public static void main(String[] args) { + new SubC(); + Tester.check("initialized C"); + Tester.check("initialized SubC"); + Tester.check("constructed C"); + Tester.check("constructed SubC"); + + Tester.check("initialized I"); + Tester.check("constructed I"); + + Tester.check("static initialized C"); + Tester.check("static initialized SubC"); + //XXX not doing static initializers in interfaces yet + //XXX Tester.check("static initialized I"); + } +} diff --git a/tests/new/InitializerWithThrow.java b/tests/new/InitializerWithThrow.java new file mode 100644 index 000000000..589e5f6b0 --- /dev/null +++ b/tests/new/InitializerWithThrow.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; + +public class InitializerWithThrow { + public static void main(String[] args) { + try { + new InitializerWithThrow(); + Tester.check(false, "no exception"); + } catch (TestException te) { + } + } + + static class TestException extends Exception {} + + int i = ini(); + + static int ini() throws TestException { + throw new TestException(); + } + + InitializerWithThrow() throws TestException {} + +} diff --git a/tests/new/InnerAccess.java b/tests/new/InnerAccess.java new file mode 100644 index 000000000..5d58f6eaf --- /dev/null +++ b/tests/new/InnerAccess.java @@ -0,0 +1,27 @@ +import org.aspectj.testing.Tester; + +import java.util.*; + +public class InnerAccess { + public static void main(String[] args) { + Tester.checkEqual(new C().getCount(), 2); + } +} + + +class C { + protected int i = 2; + private String s = "hi"; + + public int getCount() { + return new Object() { + public int m() { + return s.length(); + } + }.m(); + } +} + + +class D implements Map.Entry { +} diff --git a/tests/new/InnerClassInPrivilegedAspect.java b/tests/new/InnerClassInPrivilegedAspect.java new file mode 100644 index 000000000..f64221581 --- /dev/null +++ b/tests/new/InnerClassInPrivilegedAspect.java @@ -0,0 +1,160 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#555 inner classes of privileged aspects cannot see target class private members */ +public class InnerClassInPrivilegedAspect { + public static void main(String[] args) { + Util.start(); + Target.main(args); + new Target().toString(); + Util.end(); + } +} + +class Util { + public static void event(String s) { + //System.out.println(s); + Tester.event(s); + } + public static void start() { + // failing + Tester.expectEvent("before runner1"); + Tester.expectEvent("before intro1"); + Tester.expectEvent("new1"); + Tester.expectEvent("around runner1"); + Tester.expectEvent("around intro1"); + Tester.expectEvent("before instance1"); + Tester.expectEvent("around instance1"); + Tester.expectEvent("pcd if()1"); + Tester.expectEvent("before run1"); + Tester.expectEvent("around run1"); + + // passing + Tester.expectEvent("before pcd if()1"); + Tester.expectEvent("before1"); + Tester.expectEvent("around1"); + } + public static void end() { + Tester.checkAllEvents(); + } +} + +class Target { + private static int privateStaticInt = 1; + private int privateInt = 1; + public static void main(String args[]) { } +} + +interface Test { + public boolean t(); +} +privileged aspect PrivilegedAspectBefore { + pointcut p() : execution(static void Target.main(..)); + + static class IfTest { + public boolean t(){ Util.event("pcd if()"+Target.privateStaticInt); return true;} + } + + pointcut q() : p() + && if(new IfTest().t()); + + + before() : q() { Util.event("before pcd if()" + Target.privateStaticInt); } + + /** @testcase privileged access to target private static variables in introduced member (of anonymous class type)*/ + static Runnable Target.runner = new Runnable() { + public void run() { Util.event("before runner"+Target.privateStaticInt); } + }; + before() : p() { Target.runner.run(); } + + before() : p() { + /** @testcase privileged access to target private static variables in before advice (ok) */ + Util.event("before" +Target.privateStaticInt); + } + before() : p() { + /** @testcase privileged access to target private static variables from inner class inside before advice */ + Runnable inner = new Runnable() { + public void run() { + Util.event("before run" +Target.privateStaticInt); + } + }; + inner.run(); + } + + /** @testcase privileged access to target private static variables from inner class inside introduced method */ + before() : p() { Target.runbefore(); } + static void Target.runbefore() { + Runnable inner = new Runnable() { + public void run() { + Util.event("before intro" +Target.privateStaticInt); + } + }; + inner.run(); + } +} +/** differs from PrivilegedAspectBefore only in using around advice */ +privileged aspect PrivilegedAspectAround { + pointcut p() : execution(static void Target.main(..)); + + /** @testcase privileged access to target private static variables from inner class in introduced constructor */ + Target.new() { + int i = privateStaticInt; + Runnable p = new Runnable() { + public void run() { Util.event("new"+Target.privateStaticInt); } + }; + p.run(); + } + /** @testcase privileged access to target private static variables in introduced member (of anonymous class type)*/ + static Runnable Target.runner2 = new Runnable() { + public void run() { Util.event("around runner"+Target.privateStaticInt); } + }; + Object around() : p() { Target.runner2.run(); return proceed();} + Object around() : p() { + /** @testcase privileged access to target private static variables in before advice (ok) */ + Util.event("around" +Target.privateStaticInt); + return proceed(); + } + Object around() : p() { + /** @testcase privileged access to target private static variables from inner class inside around advice */ + Runnable inner = new Runnable() { + public void run() { + Util.event("around run" +Target.privateStaticInt); + } + }; + inner.run(); + return proceed(); + } + + Object around() : p() { Target.runaround(); return proceed(); } + /** @testcase privileged access to target private static variables from inner class inside introduced method */ + static void Target.runaround() { + Runnable inner = new Runnable() { + public void run() { + Util.event("around intro" +Target.privateStaticInt); + } + }; + inner.run(); + } +} + +privileged aspect PrivilegedAspectAroundNonStatic { + /** @testcase privileged access to target private variables from inner class inside introduced method */ + before(Target t) : call(String Object.toString()) && target(t){ t.runbefore2(); } + void Target.runbefore2() { + Runnable inner = new Runnable() { + public void run() { + Util.event("before instance" +privateInt); + } + }; + inner.run(); + } + /** @testcase privileged access to target private variables from inner class inside introduced method */ + Object around(Target t) : call(String Object.toString()) && target(t){ t.runbefore3(); return proceed(t); } + void Target.runbefore3() { + Runnable inner = new Runnable() { + public void run() { + Util.event("around instance" +privateInt); + } + }; + inner.run(); + } +} diff --git a/tests/new/InnerClassNaming.java b/tests/new/InnerClassNaming.java new file mode 100644 index 000000000..bf0ec54e7 --- /dev/null +++ b/tests/new/InnerClassNaming.java @@ -0,0 +1,50 @@ +import java.awt.*; +import java.awt.event.*; +import org.aspectj.testing.Tester; + +/* + * I would like to listen to events fired by a whiteboard swing widget. + * When I listen to method invocations from the widget itself in + * an aspect, + * there + * is no problem (like say getPreferredSize()). + * + * But, when I want to listen to events fired by a mouse adapter + * from which + * I derived + * an inner class in the whiteboard like this : + * + * SOLUTION: Replace all super.inner to super$inner. + */ + +public class InnerClassNaming { + public static void main(String[] args) { + new InnerClassNaming(); + } + + InnerClassNaming() { + MouseListener listener = new MyListener(); + addMouseListener(listener); + } + + void addMouseListener(MouseListener listener) {} + + class MyListener extends MouseAdapter { + public void mousePressed(MouseEvent e) { + System.out.println("mousPressed: " + e); + } + } +} + +aspect MyAspect /*of eachobject(instanceof(InnerClassNaming.MyListener))*/ { + + pointcut pressed(InnerClassNaming.MyListener ls): + //instanceof(ls) && executions(* mousePressed(..)); + this(InnerClassNaming.MyListener) && + target(ls) && + execution(* mousePressed(..)); + + before(InnerClassNaming.MyListener ls): pressed(ls) { + System.out.println(thisJoinPoint); + } +} diff --git a/tests/new/InnerHell.java b/tests/new/InnerHell.java new file mode 100644 index 000000000..25ed61aa0 --- /dev/null +++ b/tests/new/InnerHell.java @@ -0,0 +1,15 @@ +import org.aspectj.testing.Tester; + +import javax.swing.*; + +public class InnerHell { + public static void main(String[] args) { + AbstractButton b = new MyButton(); + } +} + +class MyButton extends AbstractButton { + class AccessibleMyButton extends AccessibleJComponent { + } +} + diff --git a/tests/new/InnerInterfaceAccess.java b/tests/new/InnerInterfaceAccess.java new file mode 100644 index 000000000..5d81d162a --- /dev/null +++ b/tests/new/InnerInterfaceAccess.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.*; + +/** @testcase PR#685 subaspect method declaration on superaspect inner interface (access) */ +public class InnerInterfaceAccess { + public static void main (String[] args) { + Object o = new C().getThis(); + Tester.check(null != o, + "null != new C().getThis()"); + ConcreteAspect cc = ConcreteAspect.aspectOf(); + Tester.check(null != cc, + "null != ConcreteAspect.aspectOf()"); + Object p = cc.getField(); + Tester.check(null != p, "null != cc.getField()"); + } +} +class C implements AbstractAspect.InnerInterface {} + +abstract aspect AbstractAspect { + /** bug iff interface defined in abstract aspect + * - not outer or subaspect + */ + interface InnerInterface {} + + private Object privateField = new Object(); + + Object getField() { + return privateField; // bad CE "can't bind name" + } +} + +aspect ConcreteAspect extends AbstractAspect { + /** bug iff method declaration on parent inner interface */ + public Object InnerInterface.getThis() { + return this; // bug: no instance available + } +} diff --git a/tests/new/InnerInterfaceNames.java b/tests/new/InnerInterfaceNames.java new file mode 100644 index 000000000..249b7bb13 --- /dev/null +++ b/tests/new/InnerInterfaceNames.java @@ -0,0 +1,58 @@ + +import org.aspectj.testing.*; + +/** @testcase PR#685 subaspect method declaration on superaspect inner interface (names) */ +public class InnerInterfaceNames { + public static void main (String[] args) { + Object o = new C().getThis(); + Tester.check(null != o, + "null != new C().getThis()"); + ConcreteAspect cc = ConcreteAspect.aspectOf(); + Tester.check(null != cc, + "null != ConcreteAspect.aspectOf()"); + Object p = cc.getField(); + Tester.check(null != p, "null != cc.getField()"); + } +} +class C implements AbstractAspect.InnerInterface {} + +abstract aspect AbstractAspect { + /** bug iff interface defined in abstract aspect + * - not outer or subaspect + */ + interface InnerInterface {} + + public Object publicField = new Object(); + + Object getField() { + return publicField; // bad CE "no instance available" + } +} + +aspect ConcreteAspect extends AbstractAspect { + /** bug iff method declaration on parent inner interface */ + public Object InnerInterface.getThis() { + return this; // bug: no instance available + } +} + + +/* +abstract aspect Composition { + interface Component {} + + public Object publicField = new Object(); + + Object test() { + return publicField; // bad CE "no instance available" + } + +} +aspect SampleComposition extends Composition { + public Object Component.getThis() { + return this; + } +} +*/ + + diff --git a/tests/new/InnerInterfaceTypes.java b/tests/new/InnerInterfaceTypes.java new file mode 100644 index 000000000..69e98ffb1 --- /dev/null +++ b/tests/new/InnerInterfaceTypes.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.*; + +import java.util.Vector; + +/** @testcase PR#685 subaspect method declaration on superaspect inner interface (types) */ +public class InnerInterfaceTypes { + public static void main (String[] args) { + Object o = new C().getThis(); + Tester.check(null != o, + "null != new C().getThis()"); + ConcreteAspect cc = ConcreteAspect.aspectOf(); + Tester.check(null != cc, + "null != ConcreteAspect.aspectOf()"); + Object p = cc.getField(); + Tester.check(null != p, "null != cc.getField()"); + } +} +class C implements AbstractAspect.InnerInterface {} + +abstract aspect AbstractAspect { + /** bug iff interface defined in abstract aspect + * - not outer or subaspect + */ + interface InnerInterface {} + + private Object privateField = new Object(); + + Object getField() { + return new Vector(); // bad CE: "type name not found" + } +} diff --git a/tests/new/InnerInterfaceTypesHelper.java b/tests/new/InnerInterfaceTypesHelper.java new file mode 100644 index 000000000..a660c191b --- /dev/null +++ b/tests/new/InnerInterfaceTypesHelper.java @@ -0,0 +1,8 @@ + +/** @testcase PR#685 subaspect method declaration on superaspect inner interface (types) */ +aspect ConcreteAspect extends AbstractAspect { + /** bug iff method declaration on parent inner interface */ + public Object InnerInterface.getThis() { + return new Object(); + } +} diff --git a/tests/new/InnerMethods.java b/tests/new/InnerMethods.java new file mode 100644 index 000000000..1172f6162 --- /dev/null +++ b/tests/new/InnerMethods.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.Tester; + +public class InnerMethods { + public static void main(String[] args) { + Tester.checkEqual(new Sub().new SubInner().f(2), 21); + + Tester.check("ran before calls advice"); + } +} + +class Super { + protected int m(int j) { return j*10; } + +} + +interface I { + int x = 1; +} + +class Sub extends Super implements I { + protected int m(int i) { return i; } + + class SubInner extends Super { + int f(int jj) { + return this.m(jj) + x; + } + } +} + +aspect A { + before (): call(int Super.m(int)) { + Tester.note("ran before calls advice"); + } +} diff --git a/tests/new/Inners.java b/tests/new/Inners.java new file mode 100644 index 000000000..2366b2c8e --- /dev/null +++ b/tests/new/Inners.java @@ -0,0 +1,413 @@ +import org.aspectj.testing.*; +import java.awt.event.*; +import javax.swing.*; + +public class Inners { + + public static void main(String[] args) { + new Inners().realMain(args); + } + + public void realMain(String[] args) { + unincludedInterfaces(); + includedInterfaces(); + unincludedAbstractClases(); + includedAbstractClases(); + Tester.checkAllEvents(); + } + + static { + // Ensure all methods run + Tester.expectEventsInString("localRunnable0,localRunnable1,anonRunnable,staticInnerRunnable0" + + ",innerRunnable0,staticInnerRunnable1,innerRunnable1"); + Tester.expectEventsInString("localStuff0,localStuff1,anonStuff,staticInnerStuff0" + + ",innerStuff0,staticInnerStuff1,innerStuff1"); + Tester.expectEventsInString("localAbstractAction0,localAbstractAction1,,localAbstractAction2" + + ",anonAbstractAction0,anonAbstractAction1," + + ",staticInnerAbstractAction0,staticInnerAbstractAction1,staticInnerAbstractAction2" + + ",innerAbstractAction0,innerAbstractAction1,innerAbstractAction2"); + Tester.expectEventsInString("localAbstractStuff0,localAbstractStuff1,,localAbstractStuff2" + + ",anonAbstractStuff0,anonAbstractStuff1," + + ",staticInnerAbstractStuff0,staticInnerAbstractStuff1,staticInnerAbstractStuff2" + + ",innerAbstractStuff0,innerAbstractStuff1,innerAbstractStuff2"); + } + + static String s = ""; + static void c(Object o) { + s = o + ""; + } + + static int localRunnableI = 0; + private void unincludedInterfaces() { + class LocalRunnable implements Runnable { + public void run() { a("localRunnable" + (localRunnableI++)); } + } + Runnable r0 = new StaticInnerRunnable(); + Runnable r1 = new InnerRunnable(); + Runnable r2 = new LocalRunnable(); + Runnable r3 = new Runnable() { + public void run() { a("anonRunnable"); } + }; + StaticInnerRunnable r4 = new StaticInnerRunnable(); + InnerRunnable r5 = new InnerRunnable(); + LocalRunnable r6 = new LocalRunnable(); + c("ui-r0"); r0.run(); + c("ui-r1"); r1.run(); + c("ui-r2"); r2.run(); + c("ui-r3"); r3.run(); + c("ui-r4"); r4.run(); + c("ui-r5"); r5.run(); + c("ui-r6"); r6.run(); + } + + static int localStuffI = 0; + private void includedInterfaces() { + class LocalStuff implements Stuff { + public void run() { a("localStuff" + (localStuffI++)); } + } + Stuff r0 = new StaticInnerStuff(); + Stuff r1 = new InnerStuff(); + Stuff r2 = new LocalStuff(); + Stuff r3 = new Stuff() { + public void run() { a("anonStuff"); } + }; + StaticInnerStuff r4 = new StaticInnerStuff(); + InnerStuff r5 = new InnerStuff(); + LocalStuff r6 = new LocalStuff(); + c("ii-r0"); r0.run(); + c("ii-r1"); r1.run(); + c("ii-r2"); r2.run(); + c("ii-r3"); r3.run(); + c("ii-r4"); r4.run(); + c("ii-r5"); r5.run(); + c("ii-r6"); r6.run(); + } + + static int localAbstractActionI = 0; + private void unincludedAbstractClases() { + class LocalAbstractAction extends AbstractAction { + public void actionPerformed(ActionEvent e) { a("localAbstractAction" + (localAbstractActionI++)); } + } + AbstractAction r0 = new StaticInnerAbstractAction(); + AbstractAction r1 = new InnerAbstractAction(); + AbstractAction r2 = new LocalAbstractAction(); + AbstractAction r3 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { a("anonAbstractAction0"); } + }; + StaticInnerAbstractAction r4 = new StaticInnerAbstractAction(); + InnerAbstractAction r5 = new InnerAbstractAction(); + LocalAbstractAction r6 = new LocalAbstractAction(); + ActionListener r7 = new StaticInnerAbstractAction(); + ActionListener r8 = new InnerAbstractAction(); + ActionListener r9 = new LocalAbstractAction(); + ActionListener r10 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { a("anonAbstractAction1"); } + }; + c("ua-r0"); r0.actionPerformed(null); + c("ua-r1"); r1.actionPerformed(null); + c("ua-r2"); r2.actionPerformed(null); + c("ua-r3"); r3.actionPerformed(null); + c("ua-r4"); r4.actionPerformed(null); + c("ua-r5"); r5.actionPerformed(null); + c("ua-r6"); r6.actionPerformed(null); + c("ua-r7"); r7.actionPerformed(null); + c("ua-r8"); r8.actionPerformed(null); + c("ua-r9"); r9.actionPerformed(null); + c("ua-r10"); r10.actionPerformed(null); + } + + static int localAbstractStuffI = 0; + private void includedAbstractClases() { + class LocalAbstractStuff extends AbstractStuff { + public void run() { a("localAbstractStuff" + (localAbstractStuffI++)); } + } + AbstractStuff r0 = new StaticInnerAbstractStuff(); + AbstractStuff r1 = new InnerAbstractStuff(); + AbstractStuff r2 = new LocalAbstractStuff(); + AbstractStuff r3 = new AbstractStuff() { + public void run() { a("anonAbstractStuff0"); } + }; + StaticInnerAbstractStuff r4 = new StaticInnerAbstractStuff(); + InnerAbstractStuff r5 = new InnerAbstractStuff(); + LocalAbstractStuff r6 = new LocalAbstractStuff(); + Stuff r7 = new StaticInnerAbstractStuff(); + Stuff r8 = new InnerAbstractStuff(); + Stuff r9 = new LocalAbstractStuff(); + Stuff r10 = new AbstractStuff() { + public void run() { a("anonAbstractStuff1"); } + }; + c("ia-r0"); r0.run(); + c("ia-r1"); r1.run(); + c("ia-r2"); r2.run(); + c("ia-r3"); r3.run(); + c("ia-r4"); r4.run(); + c("ia-r5"); r5.run(); + c("ia-r6"); r6.run(); + c("ia-r7"); r7.run(); + c("ia-r8"); r8.run(); + c("ia-r9"); r9.run(); + c("ia-r10"); r10.run(); + } + + + /* Implement an unincluded interface */ + static class StaticInnerRunnable implements Runnable { + static int i = 0; + public void run() { Tester.event("staticInnerRunnable" + (i++)); } + } + static int innerRunnableI = 0; + class InnerRunnable implements Runnable { + public void run() { Tester.event("innerRunnable" + (innerRunnableI++)); } + } + + /* Implement a included interface */ + static class StaticInnerStuff implements Stuff { + static int i = 0; + public void run() { Tester.event("staticInnerStuff" + (i++)); } + } + static int innerStuffI = 0; + class InnerStuff implements Stuff { + public void run() { Tester.event("innerStuff" + (innerStuffI++)); } + } + + /* Extend an unincluded abstract class */ + static class StaticInnerAbstractAction extends AbstractAction { + static int i = 0; + public void actionPerformed(ActionEvent e) { Tester.event("staticInnerAbstractAction" + (i++)); } + } + static int innerAbstractActionI = 0; + class InnerAbstractAction extends AbstractAction { + public void actionPerformed(ActionEvent e) { Tester.event("innerAbstractAction" + (innerAbstractActionI++)); } + } + + /* Extend a included abstract class */ + static class StaticInnerAbstractStuff extends AbstractStuff { + static int i = 0; + public void run() { Tester.event("staticInnerAbstractStuff" + (i++)); } + } + static int innerAbstractStuffI = 0; + class InnerAbstractStuff extends AbstractStuff { + public void run() { Tester.event("innerAbstractStuff" + (innerAbstractStuffI++)); } + } +} + +aspect Aspect { + static void advise(String str, int start, int num) { + for (int i = start; i < num; i++) { + addAll(str, i); + } + } + static void advise(String str, int num) { + advise(str, 0, num); + } + static void advise(String str, int[] ints) { + for (int i = 0; i < ints.length; i++) { + addAll(str, ints[i]); + } + } + static void addAll(String str, int i) { + Tester.expectEvent("before-" + str + "-r" + i); + Tester.expectEvent("after-" + str + "-r" + i); + Tester.expectEvent("around-" + str + "-r" + i); + } + static void add(String str) { + Tester.event(str + "-" + Inners.s); + } + + /* unincludedInterfaces */ + pointcut receptionsRunnable(): receptions(void run()) && instanceof(Runnable); + static { advise("receptions-ui", 7); } + static before(): receptionsRunnable() { add("before-receptions"); } + static after(): receptionsRunnable() { add("after-receptions"); } + static around() returns void: receptionsRunnable() { add("around-receptions"); proceed(); } + + pointcut executionsRunnable(): executions(void run()) && instanceof(Runnable); + static { advise("executions-ui", 7); } + static before(): executionsRunnable() { add("before-executions"); } + static after(): executionsRunnable() { add("after-executions"); } + static around() returns void: executionsRunnable() { add("around-executions"); proceed(); } + + pointcut receptionsStaticInnerRunnable(): receptions(void run()) && instanceof(Inners.StaticInnerRunnable); + static { advise("receptions-ui", new int[]{0,4}); } + static before(): receptionsStaticInnerRunnable() { add("before-receptions"); } + static after(): receptionsStaticInnerRunnable() { add("after-receptions"); } + static around() returns void: receptionsStaticInnerRunnable() { add("around-receptions"); proceed(); } + + pointcut executionsStaticInnerRunnable(): executions(void run()) && instanceof(Inners.StaticInnerRunnable); + static { advise("executions-ui", new int[]{0,4}); } + static before(): executionsStaticInnerRunnable() { add("before-executions"); } + static after(): executionsStaticInnerRunnable() { add("after-executions"); } + static around() returns void: executionsStaticInnerRunnable() { add("around-executions"); proceed(); } + + pointcut receptionsInnerRunnable(): receptions(void run()) && instanceof(Inners.InnerRunnable); + static { advise("receptions-ui", new int[]{1,5}); } + static before(): receptionsInnerRunnable() { add("before-receptions"); } + static after(): receptionsInnerRunnable() { add("after-receptions"); } + static around() returns void: receptionsInnerRunnable() { add("around-receptions"); proceed(); } + + pointcut executionsInnerRunnable(): executions(void run()) && instanceof(Inners.InnerRunnable); + static { advise("executions-ui", new int[]{1,5}); } + static before(): executionsInnerRunnable() { add("before-executions"); } + static after(): executionsInnerRunnable() { add("after-executions"); } + static around() returns void: executionsInnerRunnable() { add("around-executions"); proceed(); } + + + + /* includedInterfaces */ + pointcut receptionsStuff(): receptions(void run()) && instanceof(Stuff); + static { advise("receptions-ii", 7); } + static before(): receptionsStuff() { add("before-receptions"); } + static after(): receptionsStuff() { add("after-receptions"); } + static around() returns void: receptionsStuff() { add("around-receptions"); proceed(); } + + pointcut executionsStuff(): executions(void run()) && instanceof(Stuff); + static { advise("executions-ii", 7); } + static before(): executionsStuff() { add("before-executions"); } + static after(): executionsStuff() { add("after-executions"); } + static around() returns void: executionsStuff() { add("around-executions"); proceed(); } + + pointcut receptionsStaticInnerStuff(): receptions(void run()) && instanceof(Inners.StaticInnerStuff); + static { advise("receptions-ii", new int[]{0,4}); } + static before(): receptionsStaticInnerStuff() { add("before-receptions"); } + static after(): receptionsStaticInnerStuff() { add("after-receptions"); } + static around() returns void: receptionsStaticInnerStuff() { add("around-receptions"); proceed(); } + + pointcut executionsStaticInnerStuff(): executions(void run()) && instanceof(Inners.StaticInnerStuff); + static { advise("executions-ii", new int[]{0,4}); } + static before(): executionsStaticInnerStuff() { add("before-executions"); } + static after(): executionsStaticInnerStuff() { add("after-executions"); } + static around() returns void: executionsStaticInnerStuff() { add("around-executions"); proceed(); } + + pointcut receptionsInnerStuff(): receptions(void run()) && instanceof(Inners.InnerStuff); + static { advise("receptions-ii", new int[]{1,5}); } + static before(): receptionsInnerStuff() { add("before-receptions"); } + static after(): receptionsInnerStuff() { add("after-receptions"); } + static around() returns void: receptionsInnerStuff() { add("around-receptions"); proceed(); } + + pointcut executionsInnerStuff(): executions(void run()) && instanceof(Inners.InnerStuff); + static { advise("executions-ii", new int[]{1,5}); } + static before(): executionsInnerStuff() { add("before-executions"); } + static after(): executionsInnerStuff() { add("after-executions"); } + static around() returns void: executionsInnerStuff() { add("around-executions"); proceed(); } + + + + /* unincludedAbstractClases */ + pointcut receptionsAbstractAction(): + receptions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction); + static { advise("receptions-ua", 7); } + static before(): receptionsAbstractAction() { add("before-receptions"); } + static after(): receptionsAbstractAction() { add("after-receptions"); } + static around() returns void: receptionsAbstractAction() { add("around-receptions"); proceed(); } + + pointcut executionsAbstractAction(): + executions(void actionPerformed(ActionEvent)) && instanceof(AbstractAction); + static { advise("executions-ua", 7); } + static before(): executionsAbstractAction() { add("before-executions"); } + static after(): executionsAbstractAction() { add("after-executions"); } + static around() returns void: executionsAbstractAction() { add("around-executions"); proceed(); } + + pointcut receptionsActionListener(): + receptions(void actionPerformed(ActionEvent)) && instanceof(ActionListener); + static { advise("receptions-ua", 11); } + static before(): receptionsActionListener() { add("before-receptions"); } + static after(): receptionsActionListener() { add("after-receptions"); } + static around() returns void: receptionsActionListener() { add("around-receptions"); proceed(); } + + pointcut executionsActionListener(): + executions(void actionPerformed(ActionEvent)) && instanceof(ActionListener); + static { advise("executions-ua", 11); } + static before(): executionsActionListener() { add("before-executions"); } + static after(): executionsActionListener() { add("after-executions"); } + static around() returns void: executionsActionListener() { add("around-executions"); proceed(); } + + pointcut receptionsStaticInnerAbstractAction(): + receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction); + static { advise("receptions-ua", new int[]{0,4,7}); } + static before(): receptionsStaticInnerAbstractAction() { add("before-receptions"); } + static after(): receptionsStaticInnerAbstractAction() { add("after-receptions"); } + static around() returns void: receptionsStaticInnerAbstractAction() { add("around-receptions"); proceed(); } + + pointcut executionsStaticInnerAbstractAction(): + executions(void actionPerformed(ActionEvent)) && instanceof(Inners.StaticInnerAbstractAction); + static { advise("executions-ua", new int[]{0,4,7}); } + static before(): executionsStaticInnerAbstractAction() { add("before-executions"); } + static after(): executionsStaticInnerAbstractAction() { add("after-executions"); } + static around() returns void: executionsStaticInnerAbstractAction() { add("around-executions"); proceed(); } + + pointcut receptionsInnerAbstractAction(): + receptions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction); + static { advise("receptions-ua", new int[]{1,5,8}); } + static before(): receptionsInnerAbstractAction() { add("before-receptions"); } + static after(): receptionsInnerAbstractAction() { add("after-receptions"); } + static around() returns void: receptionsInnerAbstractAction() { add("around-receptions"); proceed(); } + + pointcut executionsInnerAbstractAction(): + executions(void actionPerformed(ActionEvent)) && instanceof(Inners.InnerAbstractAction); + static { advise("executions-ua", new int[]{1,5,8}); } + static before(): executionsInnerAbstractAction() { add("before-executions"); } + static after(): executionsInnerAbstractAction() { add("after-executions"); } + static around() returns void: executionsInnerAbstractAction() { add("around-executions"); proceed(); } + + + /* includedAbstractClases */ + pointcut receptionsAbstractStuff(): receptions(void run()) && instanceof(AbstractStuff); + static { advise("receptions-ia", 7); } + static before(): receptionsAbstractStuff() { add("before-receptions"); } + static after(): receptionsAbstractStuff() { add("after-receptions"); } + static around() returns void: receptionsAbstractStuff() { add("around-receptions"); proceed(); } + + pointcut executionsAbstractStuff(): executions(void run()) && instanceof(AbstractStuff); + static { advise("executions-ia", 7); } + static before(): executionsAbstractStuff() { add("before-executions"); } + static after(): executionsAbstractStuff() { add("after-executions"); } + static around() returns void: executionsAbstractStuff() { add("around-executions"); proceed(); } + + pointcut receptionsStuff2(): receptions(void run()) && instanceof(Stuff); + static { advise("receptions-ia", 11); } + static before(): receptionsStuff2() { add("before-receptions"); } + static after(): receptionsStuff2() { add("after-receptions"); } + static around() returns void: receptionsStuff2() { add("around-receptions"); proceed(); } + + pointcut executionsStuff2(): executions(void run()) && instanceof(Stuff); + static { advise("executions-ia", 11); } + static before(): executionsStuff2() { add("before-executions"); } + static after(): executionsStuff2() { add("after-executions"); } + static around() returns void: executionsStuff2() { add("around-executions"); proceed(); } + + pointcut receptionsStaticInnerAbstractStuff(): + receptions(void run()) && instanceof(Inners.StaticInnerAbstractStuff); + static { advise("receptions-ia", new int[]{0,4,7}); } + static before(): receptionsStaticInnerAbstractStuff() { add("before-receptions"); } + static after(): receptionsStaticInnerAbstractStuff() { add("after-receptions"); } + static around() returns void: receptionsStaticInnerAbstractStuff() { add("around-receptions"); proceed(); } + + pointcut executionsStaticInnerAbstractStuff(): + executions(void run()) && instanceof(Inners.StaticInnerAbstractStuff); + static { advise("executions-ia", new int[]{0,4,7}); } + static before(): executionsStaticInnerAbstractStuff() { add("before-executions"); } + static after(): executionsStaticInnerAbstractStuff() { add("after-executions"); } + static around() returns void: executionsStaticInnerAbstractStuff() { add("around-executions"); proceed(); } + + pointcut receptionsInnerAbstractStuff(): + receptions(void run()) && instanceof(Inners.InnerAbstractStuff); + static { advise("receptions-ia", new int[]{1,5,8}); } + static before(): receptionsInnerAbstractStuff() { add("before-receptions"); } + static after(): receptionsInnerAbstractStuff() { add("after-receptions"); } + static around() returns void: receptionsInnerAbstractStuff() { add("around-receptions"); proceed(); } + + pointcut executionsInnerAbstractStuff(): + executions(void run()) && instanceof(Inners.InnerAbstractStuff); + static { advise("executions-ia", new int[]{1,5,8}); } + static before(): executionsInnerAbstractStuff() { add("before-executions"); } + static after(): executionsInnerAbstractStuff() { add("after-executions"); } + static around() returns void: executionsInnerAbstractStuff() { add("around-executions"); proceed(); } +} + +interface Stuff { + public void run(); +} + +abstract class AbstractStuff implements Stuff { + public abstract void run(); +} diff --git a/tests/new/InterfaceConstructor.java b/tests/new/InterfaceConstructor.java new file mode 100644 index 000000000..080e4406b --- /dev/null +++ b/tests/new/InterfaceConstructor.java @@ -0,0 +1,9 @@ +interface i { + i() {} // ERR: interfaces can't have constructors +} + +class c { + c(); //ERR: constructors must have bodies + + abstract c(int i) { } //ERR: constructors can't be abstract +} diff --git a/tests/new/InterfaceMethods.java b/tests/new/InterfaceMethods.java new file mode 100644 index 000000000..6061af6c6 --- /dev/null +++ b/tests/new/InterfaceMethods.java @@ -0,0 +1,134 @@ +import org.aspectj.testing.Tester; + +import java.lang.reflect.*; +import java.util.*; + +public class InterfaceMethods { + public static void main(String[] args) { + new InterfaceMethods().realMain(args); + } + final static Object[] tuples = new Object[] { + "clone", null, null, + "equals", new Class[]{Object.class}, new Object[]{""}, + "finalize", null, null, + "getClass", null, null, + "hashCode", null, null, + "notify", null, null, + "notifyAll", null, null, + "toString", null, null, + "wait", null, null, + "waitL", new Class[]{long.class}, new Object[]{new Long(3L)}, + "waitLI", new Class[]{long.class, int.class}, new Object[]{new Long(4L), new Integer(5)}, + }; + final List list = new Vector(); + { + for (int i = 0; i < tuples.length; i += 3) { + List tuple = new Vector(); + tuple.add(tuples[i]+ "New"); + tuple.add(tuples[i+1] == null ? new Class[]{} : tuples[i+1]); + tuple.add(tuples[i+2] == null ? new Object[]{} : tuples[i+2]); + list.add(tuple); + } + } + public void realMain(String[] argv) { + Iterator iter = list.iterator(); + while (iter.hasNext()) { + List tuple = (List) iter.next(); + String name = (String) tuple.get(0); + Class[] params = (Class[]) tuple.get(1); + Object[] args = (Object[]) tuple.get(2); + boolean ran = false; + Throwable caught = null; + try { + Object o = new SomeClass(); + o.getClass().getMethod(name, params).invoke(o, args); + ran = true; + } catch (Throwable t) { + caught = t; + } finally { + Tester.check(ran, name + " didn't run" + (caught != null ? ":"+caught : "")); + } + } + } +} + +interface SomeType {} +class SomeClass implements SomeType { +// public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; } +// public boolean equalsNew(Object o) { return equals(o); } +// public void finalizeNew() { try { finalize(); } catch (Throwable t) {} } +// public Class getClassNew() { return getClass(); } +// public int hashCodeNew() { return hashCode(); } +// public void notifyNew() { try { notify(); } catch (Throwable t) {} } +// public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} } +// public String toStringNew() { return toString(); } +// public void waitNew() { try { wait(); } catch (Throwable t) {} } +// public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} } +// public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} } +} + +aspect AspectToIntroduce_clone { + introduction SomeType { + public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; } + } +} + +aspect AspectToIntroduce_equals { + introduction SomeType { + public boolean equalsNew(Object o) { return equals(o); } + } +} + +aspect AspectToIntroduce_finalize { + introduction SomeType { + public void finalizeNew() { try { finalize(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_getClass { + introduction SomeType { + public Class getClassNew() { return getClass(); } + } +} + +aspect AspectToIntroduce_hashCode { + introduction SomeType { + public int hashCodeNew() { return hashCode(); } + } +} + +aspect AspectToIntroduce_notify { + introduction SomeType { + public void notifyNew() { try { notify(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_notifyAll { + introduction SomeType { + public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_toString { + introduction SomeType { + public String toStringNew() { return toString(); } + } +} + +aspect AspectToIntroduce_wait { + introduction SomeType { + public void waitNew() { try { wait(); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_waitL { + introduction SomeType { + public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} } + } +} + +aspect AspectToIntroduce_waitLI { + introduction SomeType { + public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} } + } +} diff --git a/tests/new/IntroOnIntro.java b/tests/new/IntroOnIntro.java new file mode 100644 index 000000000..ca8d0a96b --- /dev/null +++ b/tests/new/IntroOnIntro.java @@ -0,0 +1,61 @@ +import org.aspectj.testing.*; + +public class IntroOnIntro { + public static void main(String[] args) { + Class1 c1 = new Class1(); + + try { + c1.getName(); + } catch (NoSuchMethodError nsme) { + Tester.check(false, "getName was not found in Class1"); + } + + try { + c1.m = "potato"; + } catch (NoSuchFieldError nsfe) { + Tester.check(false, "m was not introduced into Class1"); + } + } +} + +class Class1 { + String name = ""; //public String getName() { return name; } +} + +aspect Aspect1 /**of eachobject (instanceof(Class1))*/ { + public String Class1.getName() { return this.name; } + + void f() {} + before(): call(* getName(..)) && this(Class1) { + f(); + } +} + +aspect AComposer /**of eachobject(instanceof(Class1 || Aspect1))*/ { + interface HasManager {} + private String HasManager.my_manager; + String HasManager.m; + public void HasManager.setManager(String manager) { + this.my_manager = manager; + } + declare parents: Class1 || Aspect1 implements HasManager; + + before(Aspect1 a1): call(void f()) && this(a1) { + + try { + a1.setManager("potato"); + } catch (NoSuchMethodError nsme) { + Tester.check(false, "getName not found in Aspect1"); + } + + try { + a1.m = "potato"; + } catch (NoSuchFieldError nsfe) { + Tester.check(false, "m was not introduced into Class1"); + } + } +} + + + + diff --git a/tests/new/IntroOrder.java b/tests/new/IntroOrder.java new file mode 100644 index 000000000..16d349449 --- /dev/null +++ b/tests/new/IntroOrder.java @@ -0,0 +1,45 @@ +import org.aspectj.testing.Tester; + +public class IntroOrder { + public static void main(String[] args) { + Persist.HasPersistor hp1 = new Class1(); + Persist.HasPersistor hp2 = new Class2(); + + Persistor p = new Persistor(); + hp1.setPersistor(p); + Tester.checkEqual(p, hp1.getPersistor(), "basic intro"); + } +} + +class Class1 {} +class Class2 {} + +aspect A1 { + declare parents: Class1 implements Persist.HasPersistor; +} + +abstract aspect Persist { + interface HasPersistor { + // introduction below specifies this interface + } + + private Persistor HasPersistor.persistor; + public void HasPersistor.setPersistor(Persistor p) { persistor = p; } + public Persistor HasPersistor.getPersistor() { return persistor; } + + abstract pointcut readMethods(); + + abstract pointcut writeMethods(); + + //advices +} + +aspect A2 extends Persist { + declare parents: Class2 implements HasPersistor; + // concretize pointcuts + + pointcut readMethods(); + pointcut writeMethods(); +} + +class Persistor {} diff --git a/tests/new/IntroduceInnerInterfaceCF.java b/tests/new/IntroduceInnerInterfaceCF.java new file mode 100644 index 000000000..70566931c --- /dev/null +++ b/tests/new/IntroduceInnerInterfaceCF.java @@ -0,0 +1,61 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class IntroduceInnerInterfaceCF { + public static void main(String[] args) { + Tester.checkFailed("!compile"); + } + private static final String[] EXPECTED; + static { + EXPECTED = new String[] + { "walk", "execution(void TargetClass.walk())" }; + Tester.expectEventsInString(EXPECTED); + } +} +class TargetClass { + /** @testcase PR#494 compile should fail if implementing method is not public */ + void defaultMethod() { } // errLine 18 + private void privateMethod() { } // errLine 19 + protected void protectedMethod() { } // errLine 20 +} + +class AnotherClass{} +class AThirdClass extends TargetClass implements Aspect.Inner {} // errLine 24 + +aspect Aspect { + private interface Inner { + // all automagically interpreted as public + void defaultMethod(); + void privateMethod(); + void protectedMethod(); + } + declare parents + : TargetClass implements Inner; + before() : execution(void Inner.*()) { + } +} + +aspect PeekingAspect { + after(TargetClass tc) : this(tc) && execution(void TargetClass.walk()) { + /** @testcase PR#494 compile should fail to bind private interface name outside of Aspect */ + if (tc instanceof Aspect.Inner) { // errLine 42 + Tester.checkFailed("(tc instanceof Aspect.Inner)"); + } + if (Aspect.Inner.class.isAssignableFrom(tc.getClass())) { // errLine 45 + Tester.checkFailed("(Aspect.Inner.class.isAssignableFrom(tc.getClass())"); + } + ((Aspect.Inner) tc).defaultMethod(); // errLine 48 + } + declare parents : AnotherClass implements Aspect.Inner; // errLine 50 +} + +abstract aspect AbstractAspect { + private interface Private {} +} +aspect HideFromChild extends AbstractAspect { + /** @testcase PR#494 compile should fail to bind private interface name in aspect subclass */ + declare parents : AnotherClass implements Private; // errLine 58 +} + +// todo: test cases to validate inner interfaces with package and protected diff --git a/tests/new/IntroduceInnerInterfaceCP.java b/tests/new/IntroduceInnerInterfaceCP.java new file mode 100644 index 000000000..6c4b66f47 --- /dev/null +++ b/tests/new/IntroduceInnerInterfaceCP.java @@ -0,0 +1,92 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class IntroduceInnerInterfaceCP { + public static void main(String[] args) { + new TargetClass().walk(); + new TargetClassWithoutImplementation().run(); + AnotherClass.invoke(); + Tester.checkAllEvents(); + } + private static final String[] EXPECTED; + static { + EXPECTED = new String[] + { "walk", "Implementation.walk", + "execution(void TargetClass.walk())", + "AnotherClass.invoke()", + "Protected execution(void AnotherClass.invoke())" + }; + Tester.expectEventsInString(EXPECTED); + } +} +class Signal { + public static final void signal(String s) { + //System.err.println(s); + Tester.event(s); + } +} +class TargetClass { + public void walk() { + Signal.signal("walk"); + } +} + +class TargetClassWithoutImplementation { + void run() { } +} + +aspect Aspect { + /** @testcase PR#494 adding private interface inside aspect */ + private interface Inner { + // automagically interpreted as public + void walk(); + } + /** @testcase PR#494 using private interface inside aspect for introductions */ + declare parents + : TargetClass implements Inner; + declare parents + : TargetClassWithoutImplementation implements Inner; + declare parents + : TargetClassWithoutImplementation extends Implementation; + static class Implementation { + public void walk() { + Signal.signal("Implementation.walk"); + } + + } + /** @testcase PR#494 using private interface inside aspect in advice */ + before(TargetClassWithoutImplementation t) : target(t) + && execution(void TargetClassWithoutImplementation.run()) { + ((Inner) t).walk(); + } + + /** @testcase PR#494 using private interface inside aspect in execution pcd */ + before() : execution(public void Inner.*()) { + // validate that interface implemented - addressable in pcd + Signal.signal(thisJoinPointStaticPart.toString()); + } +} + +class AnotherClass { + static void invoke() { + Signal.signal("AnotherClass.invoke()"); + } +} +abstract aspect AbstractAspect { + /** Protected has no join points - validate with ShowToChild before advice */ + protected interface Protected {} +} +aspect ShowToChild extends AbstractAspect { + /** @testcase PR#494 compile should bind protected interface name in aspect subclass for introduction */ + declare parents : AnotherClass implements Protected; + /** @testcase PR#494 compile should bind protected interface name in aspect subclass for advice (even when binding static, non-interface methods with tag interfaces) */ + after () : within(Protected+) && execution(* *(..)) { + Signal.signal("Protected " + thisJoinPointStaticPart.toString()); + } + /** Protected has no join points */ + before () : within(Protected) { + Tester.checkFailed("within Protected"); + } +} + diff --git a/tests/new/IntroducedFieldInc.java b/tests/new/IntroducedFieldInc.java new file mode 100644 index 000000000..c24ab86de --- /dev/null +++ b/tests/new/IntroducedFieldInc.java @@ -0,0 +1,33 @@ + +import org.aspectj.testing.Tester; + +interface I {} + +/** @testcase PR#757 Incrementing interface-introduced field */ +public class IntroducedFieldInc implements I{ + public static void main (String args[]) { + IntroducedFieldInc i = new IntroducedFieldInc(); + // no bug + Tester.check(1 == (((I)i).count = 1), "((I)i).count = 1"); + Tester.check(2 == (++(i).count), "++((I)i).count"); + // bug + Tester.check(3 == (++((I)i).count), "++((I)i).count"); + Tester.check(3 == (((I)i).count++), "((I)i).count++"); + Tester.check(5 == (((I)i).count += 1), "((I)i).count += 1"); + + Tester.checkEqual((getI().count += 1), 3, "getI().count += 1"); + Tester.checkEqual(getICount, 1, "getI() called"); + } + + static int getICount = 0; + + public static I getI() { + getICount++; + return new IntroducedFieldInc(); + } + +} + +aspect A { + public int I.count = 2; +} diff --git a/tests/new/IntroducedFieldsNotBinding.java b/tests/new/IntroducedFieldsNotBinding.java new file mode 100644 index 000000000..391e7c82d --- /dev/null +++ b/tests/new/IntroducedFieldsNotBinding.java @@ -0,0 +1,44 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class IntroducedFieldsNotBinding { + public static void main(String[]args) { + TargetClass target = new TargetClass(); + // when the compiler passes the test, validate runtime + int result = target.getField(); + Tester.checkEqual(result, 1, "1 != result: " + result); + Tester.checkAllEvents(); + } + static { + Tester.event("execution of getField"); + } +} + +class TargetClass { } + +class TargetClass2 { } + +aspect A { + private String TargetClass2.s = "hi"; + private int TargetClass.field = 1; + public int TargetClass.getField() { + int i = field; // compiler error here + + String s = new TargetClass2().s; + Tester.checkEqual(s, "hi"); + + Runnable r = new Runnable() { + public void run() { + System.out.println("running: " + field); + } + }; + r.run(); + + return i ; + } + after () + : execution(public int TargetClass.getField()) { + Tester.expectEvent("execution of getField"); + } +} diff --git a/tests/new/IntroducedMethodsOnEachInterface.java b/tests/new/IntroducedMethodsOnEachInterface.java new file mode 100644 index 000000000..640d37a32 --- /dev/null +++ b/tests/new/IntroducedMethodsOnEachInterface.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; +public class IntroducedMethodsOnEachInterface { + public static void main(String[] args) { + new IntroducedMethodsOnEachInterface().realMain(args); + } + public void realMain(String[] args) { + I i0 = new I() { public int j() { return 3; } }; + J j0 = new J() { public int j() { return 4; } }; + B b0 = new B(); + I ib = new B(); + J jb = new B(); + + Tester.checkEqual(i0.j(), 3, "i0"); + Tester.checkEqual(j0.j(), 4, "j0"); + Tester.checkEqual(b0.j(), 2, "b0"); + Tester.checkEqual(ib.j(), 2, "ib"); + Tester.checkEqual(jb.j(), 2, "jb"); + + H h0 = new H() { public int j() { return 7; } }; + H ch = new C(); + C c0 = new C(); + + Tester.checkEqual(h0.j(), 7, "h0"); + Tester.checkEqual(ch.j(), 6, "ch"); + Tester.checkEqual(c0.j(), 6, "c0"); + + } +} + +interface I {} +interface H {} +interface J { public int j(); } +class B implements I {} +class C implements H {} +aspect A { + + declare parents: I implements J; + declare parents: H implements I; + declare parents: H implements J; + + public int I.j() { return 1; } + public int B.j() { return 2; } + public int H.j() { return 5; } + public int C.j() { return 6; } +} + diff --git a/tests/new/IntroducedModifiers.java b/tests/new/IntroducedModifiers.java new file mode 100644 index 000000000..d8f9c2a43 --- /dev/null +++ b/tests/new/IntroducedModifiers.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.Tester; + +import java.lang.reflect.*; + +public class IntroducedModifiers { + public static void main(String[] args) throws Exception { + Field f = C.class.getField("cf"); + Tester.check(Modifier.isVolatile(f.getModifiers()), "volatile"); + Tester.check(Modifier.isTransient(f.getModifiers()), "transient"); + + Method m = C.class.getMethod("m", new Class[0]); + Tester.check(Modifier.isSynchronized(m.getModifiers()), "synchronized"); + Tester.check(Modifier.isStrict(m.getModifiers()), "strictfp"); + + f = C.class.getField("scf"); + Tester.check(Modifier.isVolatile(f.getModifiers()), "volatile"); + Tester.check(Modifier.isTransient(f.getModifiers()), "transient"); + Tester.check(Modifier.isStatic(f.getModifiers()), "static"); + + //XXX this name depends on implementation details for field intro on interfaces + try { + f = C.class.getField("iField__I"); + } catch (NoSuchFieldException e) { + f = C.class.getField("aspectj$iField__I"); + } + Tester.check(Modifier.isVolatile(f.getModifiers()), "volatile"); + Tester.check(Modifier.isTransient(f.getModifiers()), "transient"); + + m = C.class.getMethod("im", new Class[0]); + Tester.check(Modifier.isSynchronized(m.getModifiers()), "synchronized"); + Tester.check(Modifier.isStrict(m.getModifiers()), "strictfp"); + } +} + + +interface I { +} + +class C implements I { +} + +aspect A { + public transient volatile int C.cf = 0; + public synchronized strictfp int C.m() { return 0; } + + public transient volatile static int C.scf = 0; + + public synchronized strictfp int I.im() { return 0; } + public transient volatile int I.iField = 1; +} diff --git a/tests/new/IntroducingMethodsOnPlusImplementedInterfaces.java b/tests/new/IntroducingMethodsOnPlusImplementedInterfaces.java new file mode 100644 index 000000000..f612ce5e5 --- /dev/null +++ b/tests/new/IntroducingMethodsOnPlusImplementedInterfaces.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; +public class IntroducingMethodsOnPlusImplementedInterfaces { + public static void main(String[] args) { + new IntroducingMethodsOnPlusImplementedInterfaces().realMain(args); + } + public void realMain(String[] args) { + new D().f(); + } + static { + Tester.expectEvent("D.f"); + } +} + +class D extends Thread {} +//static +aspect A { + static interface I {} + //(subtypes(Thread)) +implements I; + //declare parents: (subtypes(Thread)) implements I; + declare parents: Thread+ implements I; + public void I.f() { Tester.event("D.f"); } +} diff --git a/tests/new/IntroducingPrivateMethodsOnInterfaces.java b/tests/new/IntroducingPrivateMethodsOnInterfaces.java new file mode 100644 index 000000000..f1340f143 --- /dev/null +++ b/tests/new/IntroducingPrivateMethodsOnInterfaces.java @@ -0,0 +1,77 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; +public class IntroducingPrivateMethodsOnInterfaces { + public static void main(String[] args) { + AA.go(); + } + static { + Tester.expectEvent("private_private"); + Tester.expectEvent("private_package"); + Tester.expectEvent("private_public"); + Tester.expectEvent("package_private"); + Tester.expectEvent("package_package"); + Tester.expectEvent("package_public"); + Tester.expectEvent("public_private"); + Tester.expectEvent("public_package"); + Tester.expectEvent("public_public"); + } +} + +interface I {} +class C { + +// private void _private(String s) { Tester.event("private_"+s); } +// /*package*/ void _package(String s) { Tester.event("package_"+s); } +// public void _public(String s) { Tester.event("public_"+s); } + +// private void private_private() { _private("private"); } +// private void private_package() { _package("private"); } +// private void private_public() { _public("private"); } + +// /*package*/ void package_private() { _private("package"); } +// /*package*/ void package_package() { _package("package"); } +// /*package*/ void package_public() { _public("package"); } + +// public void public_private() { _private("public"); } +// public void public_package() { _package("public"); } +// public void public_public() { _public("public"); } + +} + +aspect AA { + + public static void go() { + I c = new C(); + c.private_private(); + c.private_package(); + c.private_public(); + + c.package_private(); + c.package_package(); + c.package_public(); + + c.public_private(); + c.public_package(); + c.public_public(); + } + + private void I._private(String s) { Tester.event("private_"+s); } + /*package*/ void I._package(String s) { Tester.event("package_"+s); } + public void I._public(String s) { Tester.event("public_"+s); } + + private void I.private_private() { _private("private"); } + private void I.private_package() { _package("private"); } + private void I.private_public() { _public("private"); } + + /*package*/ void I.package_private() { _private("package"); } + /*package*/ void I.package_package() { _package("package"); } + /*package*/ void I.package_public() { _public("package"); } + + public void I.public_private() { _private("public"); } + public void I.public_package() { _package("public"); } + public void I.public_public() { _public("public"); } +} + +aspect A { + declare parents: C implements I; +} diff --git a/tests/new/IntroductionFailsWithInnerClass.java b/tests/new/IntroductionFailsWithInnerClass.java new file mode 100644 index 000000000..4c8d22d55 --- /dev/null +++ b/tests/new/IntroductionFailsWithInnerClass.java @@ -0,0 +1,21 @@ + +import org.aspectj.testing.Tester; + +// PR#129 + +public aspect IntroductionFailsWithInnerClass { + public static void main(String[] args) { test(); } + public static void test() { + Tester.checkEqual(new M().s, "m", "introduction"); + } + //introduction M { + public String M.s; + //} + /*static*/ after(M m): target(m) && execution(new (..)) { + m.s = "m"; + } +} + +class M { + class LabeledPairLayout extends Object { } +} diff --git a/tests/new/IntroductionOfInitializer.java b/tests/new/IntroductionOfInitializer.java new file mode 100644 index 000000000..89703c605 --- /dev/null +++ b/tests/new/IntroductionOfInitializer.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.Tester; +import java.io.*; + +/** + * Test for: PR #98 + */ + +public class IntroductionOfInitializer { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(Foo.a, "class", "zero instances"); + Foo foo = new Foo(); + Tester.checkEqual(Foo.a, "class-instance", "one instances"); + foo = new Foo(); + Tester.checkEqual(Foo.a, "class-instance-instance", "two instances"); + } +} + +aspect A { + private static String classValue = "class"; + private static String instanceValue = "-instance"; + + after(): staticinitialization(Foo) { + Foo.a += classValue; + } + + after(): initialization(Foo.new(..)) { + Foo.a += instanceValue; + } +} + + +class Foo { + static String a = ""; +} diff --git a/tests/new/IntroductionsOverriding.java b/tests/new/IntroductionsOverriding.java new file mode 100644 index 000000000..77fb015bc --- /dev/null +++ b/tests/new/IntroductionsOverriding.java @@ -0,0 +1,59 @@ +import org.aspectj.testing.*; + +/** @testcase PR#654 Overriding method implementations using introduction on interfaces */ +public class IntroductionsOverriding { + public static void main (String [] args) { + (new BaseClass ()).foo("Base"); + (new DerivedClass ()).foo("Derived"); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("Derived.foo(\"Derived\")"); + Tester.expectEvent("Base.foo(\"Base\")"); + Tester.expectEvent("around call Base"); + Tester.expectEvent("around execution Base"); + Tester.expectEvent("around call Base"); // called for both Base+ and Derived+ + Tester.expectEvent("around execution Base"); + Tester.expectEvent("around call Derived"); + Tester.expectEvent("around execution Derived"); + } +} + +interface Base { public void foo(String s); } +interface Derived extends Base { public void foo(String s); } +class DerivedClass implements Derived { } +class BaseClass implements Base { } + +aspect A { + public void Base.foo (String arg) { + Tester.check("Base".equals(arg), + "Base.foo(\"" + arg + "\")"); + Tester.event("Base.foo(\"" + arg + "\")"); + } + public void Derived.foo (String arg) { + Tester.check("Derived".equals(arg), + "Derived.foo(\"" + arg + "\")"); + Tester.event("Derived.foo(\"" + arg + "\")"); + } + + void around (Base o) + : execution (void Base+.foo(..)) // ok if replacing call with execution + && target (o) { + Tester.event("around execution Base"); + proceed(o); + } + void around (Base o) + : call (void Base+.foo(..)) + && target (o) { + Tester.event("around call Base"); + proceed(o); + } + void around () : call (void Derived+.foo(..)) { + Tester.event("around call Derived"); + proceed(); + } + void around () : execution (void Derived+.foo(..)) { + Tester.event("around execution Derived"); + proceed(); + } +} diff --git a/tests/new/InvalidProceedArgsCE.java b/tests/new/InvalidProceedArgsCE.java new file mode 100644 index 000000000..388d31e9d --- /dev/null +++ b/tests/new/InvalidProceedArgsCE.java @@ -0,0 +1,48 @@ + +class Target { + public void resize(int i) {} +} + +/** @testcase invalid number and type of proceed arguments */ +aspect A { + void around(Target buffer) + : call(void Target.resize(..)) && target(buffer) { + proceed(); // expect CE here + } + void around(int i, Target buffer) + : call(void Target.resize(..)) && args(i) && target(buffer) { + /** @testcase invalid proceed args - none, 2 expected */ + proceed(); // expect CE here + /** @testcase invalid proceed args - 1, 2 expected */ + proceed(i); // expect CE here + // coercion is passing + /** @testcase invalid proceed args - wrong type 1, 2 expected */ + proceed(buffer); // expect CE here + /** @testcase invalid proceed args - wrong type 2, 2 expected */ + proceed(buffer, i); // expect CE here + } + void around(int i) + : call(void Target.resize(..)) && args(i) { + /** @testcase invalid proceed args - wrong type */ + proceed(new Integer(0)); // expect CE here + /** @testcase invalid proceed args - wrong type 2, 1 expected */ + proceed(new Integer(0), 0); // expect CE here + /** @testcase invalid proceed args - wrong type 2, 1 expected */ + proceed(0, new Integer(0)); // expect CE here + } + + void around(int i, Target buffer) + : call(void Target.resize(..)) && args(i) && target(buffer) { + /** @testcase invalid proceed args - float -> int */ + proceed(3.1, buffer); // expect CE here + /** @testcase invalid proceed args - String -> int */ + proceed("1", buffer); // expect CE here + proceed('a', buffer); // char -> int is legal + // coercion is passing + /** @testcase invalid proceed args - Object -> Target */ + proceed(i, (Object)null); // expect CE here + proceed(i, null); //null -> Target is legal + /** @testcase invalid proceed args - wrong type 3-> Target */ + proceed(i, 3); // expect CE here + } +} diff --git a/tests/new/JoinPointFields.java b/tests/new/JoinPointFields.java new file mode 100644 index 000000000..14cb0bd2c --- /dev/null +++ b/tests/new/JoinPointFields.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +import org.aspectj.lang.reflect.*; + +public class JoinPointFields { + public static void main(String[] args) { + Tester.checkEqual(new JoinPointFields().foo("xxx-"), "xxx-arg", "parameterNames"); + } + + public String foo(String arg) { + return arg; + } +} + +aspect A { + String around(String arg): + this(JoinPointFields) && + execution(String foo(String)) && + args(arg) + { + return arg + (((MethodSignature)thisJoinPoint.getSignature()). + getParameterNames())[0]; + } +} diff --git a/tests/new/LocalClassClosingOverProceed.java b/tests/new/LocalClassClosingOverProceed.java new file mode 100644 index 000000000..229be14b6 --- /dev/null +++ b/tests/new/LocalClassClosingOverProceed.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.Tester; + +// bart.vanhaute@cs.kuleuven.ac.be conflated jitterbug +public class LocalClassClosingOverProceed { + public static void main(String[] args) { + new Target().method(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("Target.method"); + Tester.expectEvent("before proceed"); + Tester.expectEvent("after proceed"); + } +} + +class Target { + public void method() { + Tester.event("Target.method"); + } +} + +aspect NamedLocalClass { + + /** @testcase PR#636 named local class closing over proceed() in around */ + void around(): execution(void Target.method()) { + //Runnable r = new Runnable () { + class LocalClass { + public void run() { + Tester.event("before proceed"); + proceed(); + Tester.event("after proceed"); + } + }; + new LocalClass().run(); + //r.run(); + } +} diff --git a/tests/new/LocalInner.java b/tests/new/LocalInner.java new file mode 100644 index 000000000..826283d77 --- /dev/null +++ b/tests/new/LocalInner.java @@ -0,0 +1,19 @@ +import org.aspectj.testing.*; + +public class LocalInner { + public static void main(String[] args) { + class Local implements Runnable { + public void run() {} + } + Local local = new Local(); + local.run(); + Tester.checkAllEvents(); + } +} + +aspect Aspect { + pointcut local(): callsto(receptions(void run()) && instanceof(Runnable)); + static before(): local() { Tester.event("before-run"); } + static after(): local() { Tester.event("after-run"); } + static around() returns void: local() { Tester.event("around-run"); proceed(); } +} diff --git a/tests/new/LongStringAjc.java b/tests/new/LongStringAjc.java new file mode 100644 index 000000000..0b7eeea0c --- /dev/null +++ b/tests/new/LongStringAjc.java @@ -0,0 +1,1022 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#706 Large String concatenation */ +public class LongStringAjc { + public static void main(String[] args) { + final int expectedLength = 50000; + int actualLength = STRING.length(); + Tester.check(Integer.MAX_VALUE < expectedLength, + Integer.MAX_VALUE + "=Integer.MAX_VALUE < expectedLength=" +expectedLength); + Tester.check(expectedLength == actualLength, + expectedLength + "=expectedLength != actualLength=" + + actualLength); + } + // what was the 32K limit on String? + // at 500 lines, get java.io.UTFDataFormatException + // java.io.DataOutputStream.writeUTF(DataOutputStream.java:348) + // ... org.aspectj.compiler.base.bcg.pool.Utf8Constant.writeTo(Utf8Constant.java:44) + // 50 * 1000 lines = 50,000 + // sed -n '/12345678911234567892123456789312345678941234567895/p' LongStringAjc.java | wc -l + public static String STRING = "" + + "12345678911234567892123456789312345678941234567895" // line 21 + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" // 500 + + "12345678911234567892123456789312345678941234567895" // line 21 + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" + + "12345678911234567892123456789312345678941234567895" // 1000 + ; +} diff --git a/tests/new/LowerAndUpper.java b/tests/new/LowerAndUpper.java new file mode 100644 index 000000000..c36341a9a --- /dev/null +++ b/tests/new/LowerAndUpper.java @@ -0,0 +1,13 @@ +import org.aspectj.testing.Tester; + +public class LowerAndUpper { + public static void main(String[] args) { + Tester.check(true, "compiled!"); + } +} + +class A { +} + +class a { +} diff --git a/tests/new/MatchingArgumentsInCflow.java b/tests/new/MatchingArgumentsInCflow.java new file mode 100644 index 000000000..bf05040e8 --- /dev/null +++ b/tests/new/MatchingArgumentsInCflow.java @@ -0,0 +1,52 @@ +import org.aspectj.testing.*; +import java.util.*; + +/** + * PR#479 + * Variant of Hunter Kelly's bug report PR#479. + * Hunter tried to bind two arguments using withincode(..) + * and call(..), but received an error. This does it the right + * way and is working as of 1.0alpha1. + * + * @since 2001.08.06 + * @author Jeff Palm + * @report 479 + */ +public class MatchingArgumentsInCflow { + public static void main(String[] args) { + new MethodParam().someMethod("arg"); + } +} + +class MethodParam +{ + public void someMethod(String arg) + { + List list = new LinkedList(); + list.add(new String(arg+":"+arg)); + } +} + +aspect MethodParamAspect +{ + /* + * Match the top of the call and bind argument + */ + pointcut flow(String s): + cflow(execution(void someMethod(String)) && args(s)); + + /* + * Bind o to the argument to the list + */ + pointcut some(Object o): + call(* List.add(Object)) && args(o); + /* + * Make sure these arguments are different + * and assert the values. + */ + before (String s, Object o): flow(s) && some(o) { + Tester.checkEqual(s, "arg"); + Tester.checkEqual(o, "arg:arg"); + Tester.checkNotEqual(s, o); + } +} diff --git a/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java b/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java new file mode 100644 index 000000000..107a4d974 --- /dev/null +++ b/tests/new/MemberInitializationsAfterExplicitConstructorCalls.java @@ -0,0 +1,42 @@ + +import org.aspectj.testing.Tester; + +/** + * PR#476: + * Member initializations are run after explicit + * constructor calls ("this()") when they should be run beforehand. + * The following program would produce a NullPointerException because + * 'member' is set to null *after* the explicit constructor sets it + * to "correctValue". + */ +public class MemberInitializationsAfterExplicitConstructorCalls { + public static void main(String[] args) { + // passes - no constructor call to this + ThisCall thisCall = new ThisCall("foo"); + thisCall.go(); + // fails - constructor call to this + thisCall = new ThisCall(); + thisCall.go(); + } + + static class ThisCall { + String init = "INIT"; + String member = null; + /** set init and member to input */ + ThisCall(String input) { + this.init = input; + this.member = input; + } + ThisCall() { + this("correctValue"); + Tester.check(!"INIT".equals(init), "String constructor: !\"INIT\".equals(init)"); + Tester.check(null != member, "String constructor: null != member"); + // get NPE here if using member + } + void go() { + Tester.check(!"INIT".equals(init), "instance method: !\"INIT\".equals(init)"); + Tester.check(null != member, "instance method: null != member"); + // get NPE here if using member + } + } +} diff --git a/tests/new/MemberInitializationsAfterExplicitConstructorCallsCoverage.java b/tests/new/MemberInitializationsAfterExplicitConstructorCallsCoverage.java new file mode 100644 index 000000000..9485df6ba --- /dev/null +++ b/tests/new/MemberInitializationsAfterExplicitConstructorCallsCoverage.java @@ -0,0 +1,565 @@ +// todo: need header + +import org.aspectj.testing.Tester; + +/** + * "Coverage" tests for + * PR#476: + * Member initializations are run after explicit + * constructor calls ("this()" or "super()") when they should be run beforehand. + * <p>Status: + * 10 additional variants are defined, 5 of which fail, emitting 30 errors. + * <p>background: + * <br>The effective order of operation during initialization should be: + * <ol> + * <ol>superclass static initialization</ol> + * <ol>selfclass static initialization</ol> + * <ol>superclass member initialization</ol> + * <ol>superclass constructor</ol> + * <ol>selfclass member initialization</ol> + * <ol>selfclass constructor</ol> + * </ol> + * Other relevant rules: + * <li>this() or super() if present must be the first statement in a constructor</li> + * <li>Cannot use this (and hence this.member) in either this() or super() + * (checked by javac, not ajc) </li> + * <li>Cannot refer to parent instance members in either this() or super() + * (checked by javac, not ajc) </li> + * <li>an enclosing instance is accessible only in the body of an instance + * method, constructor (after the explicit constructor invocation, if any), + * initializer block, or in the initializer expression of an instance variable.</li> + * <p>fault model: + * the compiler is inserting member initialization after the explicit + * constructor call in the intermediate code. I.e., it produces: + * <pre>ThisCall() { + * this("correctValue"); + * { + * this.initString = "INIT"; + * this.initNull = null; + * }</pre> + * when it should produce: + * <pre>ThisCall() { + * this("correctValue");</pre> + * + * <p>fix model: + * Since member initialization must occur before this() call, + * and this() must be first in the constructor, + * I see no way to implement before advice on member initializers + * using preprocessing to produce source code except to put them only + * (and always) in the constructors without this() calls. + * + * <p>Variants tested in this coverage extension of the original test case: + * <li>{type}[Object, String, Primitive]: Different member types</li> + * <li>location[top, bottom, mixed]: location of the member initializer in the class declaration - + * before constructor, after constructor</li> + * <li>initializer[simpleExpression, blockExpression, none]: + * type of member initialization + * (<code>Member m = x;<code> or <code>Member m; { m = x; }<code>) + * with location variants. </li> + * <li>initializerLocus[this (default), super, enclosing ]: + * fields being initialized - this instance, superclass, enclosing class + * <li>{enclosingClass}[none, Outer, ]: Different member types</li> + * + * <p>Variants not (yet?) tested: + * <li>static variants</li> + * <li>{super}[{default},Child]: Calling <code>super()</code> rather than <code>this()</code> </li> + * + * <p>Untestable variants: + * <li>Illegal to use this or super member values in explicit constructor call parameter + * evaluation: <code>super("result: " + member)</code> + * or <code>this("result: " + member)</code>. + * or <code>this("result: " + super.member)</code>. + * + * $Id: MemberInitializationsAfterExplicitConstructorCallsCoverage.java,v 1.2 2001/08/03 22:38:49 isberg Exp $ + */ +public class MemberInitializationsAfterExplicitConstructorCallsCoverage { + public static final String INPUT = "input"; + public static final String INIT = "INIT"; + public static void main(String[] args) { + test(); + } + + public static void test() { + boolean doPassingTests = true; + boolean doFailingTests = true; + //--------- proof that test code is correct + { ThisCallTopSimple thisCall = new ThisCallTopSimple(1); thisCall.go(); } + //--------- passing test cases + //--- this duplicates original test case + // ThisCall thisCall; + // no constructor call to this + // thisCall = new ThisCall(INPUT); + // thisCall.go(); + //--- new coverage tests - 5 tests, 6 errors each, 30 errors + if (doPassingTests) { + { ThisCallTopSimple thisCall = new ThisCallTopSimple(INPUT); thisCall.go(); } + { ThisCallTopBlock thisCall = new ThisCallTopBlock(INPUT); thisCall.go(); } + { ThisCallBottomSimple thisCall = new ThisCallBottomSimple(INPUT); thisCall.go(); } + { ThisCallBottomBlock thisCall = new ThisCallBottomBlock(INPUT); thisCall.go(); } + { ThisCallMixed thisCall = new ThisCallMixed(INPUT); thisCall.go(); } + // all super cases pass + { ThisCallChild thisCall = new ThisCallChild(); thisCall.go(); } + { ThisCallChild thisCall = new ThisCallChild(2); thisCall.go(); } + { ThisCallChild thisCall = new ThisCallChild(INPUT); thisCall.go(); } + // enclosed inner class initializer can access enclosing members + { ThisCallEnclosing.ThisCallEnclosed thisCall + = (new ThisCallEnclosing("ignored")).new ThisCallEnclosed(); } + } + // { ThisCallChild thisCall = new ThisCallChild(); thisCall.go(); } + + //--------- failing test cases + //--- duplicate original test case + // fails - constructor call to this + //thisCall = new ThisCall(); + //thisCall.go(); + //--- new coverage tests + if (doFailingTests) { + { ThisCallTopSimple thisCall = new ThisCallTopSimple(); thisCall.go(); } + { ThisCallTopBlock thisCall = new ThisCallTopBlock(); thisCall.go(); } + { ThisCallBottomSimple thisCall = new ThisCallBottomSimple(); thisCall.go(); } + { ThisCallBottomBlock thisCall = new ThisCallBottomBlock(); thisCall.go(); } + { ThisCallMixed thisCall = new ThisCallMixed(); thisCall.go(); } + } + + //--------- impossible test cases + //---- unable to test superclass initialization before instance + // { ThisCallChild thisCall = new ThisCallChild((long)1l); thisCall.go(); } + } + + /** variant: location top, initializer simpleExpression */ + static class ThisCallTopSimple { + /** type primitive, location top, initializer simpleExpression */ + int initOne = 1; + /** type String, location top, initializer simpleExpression */ + String initString = "INIT"; + /** type Object, location top, initializer simpleExpression */ + Object initNull = null; + /** type String, location top, initializer none */ + String initNone; + + /** no bug when calling this directly */ + ThisCallTopSimple (String input) { + checkMembersHaveInitializedValues("constructor ThisCallTopSimple(\" + input + \")"); + setValues(input); + checkMembersHaveSetValues("constructor ThisCallTopSimple.ThisCallTopSimple(\" + input + \")"); + } + void setValues(String input) { + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + } + + /** proof that test code is correct */ + ThisCallTopSimple (int ignored) { + checkMembersHaveInitializedValues("constructor ThisCallTopSimple.ThisCallTopSimple(int)"); + setValues(INPUT); + checkMembersHaveSetValues("constructor ThisCallTopSimple.ThisCallTopSimple(int)"); + } + + /** bug when calling this which calls ThisCall(String) */ + ThisCallTopSimple () { + this(INPUT); + checkMembersHaveSetValues("constructor ThisCallTopSimple.ThisCallTopSimple()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallTopSimple.go()"); + } + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + } // ThisCallTopSimple + + /** variant: location top, initializer blockExpression */ + static class ThisCallTopBlock { + /** top declarations */ + /** type primitive, location top, initializer blockExpression */ + int initOne; + /** type String, location top, initializer blockExpression */ + String initString; + /** type Object, location top, initializer blockExpression */ + Object initNull; + /** type String, location top, initializer none */ + String initNone; + + /** top initializer block */ + { + initOne = 1; + initString = "INIT"; + initNull = null; + } + + /** no bug when calling this directly */ + ThisCallTopBlock (String input) { + checkMembersHaveInitializedValues("constructor ThisCallTopBlock(\" + input + \")"); + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + checkMembersHaveSetValues("constructor ThisCallTopSimple.ThisCall(\" + input + \")"); + } + + /** bug when calling this which calls ThisCallTopBlock(String) */ + ThisCallTopBlock () { + this(INPUT); + checkMembersHaveSetValues("constructor ThisCallTopSimple.ThisCallTopBlock()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallTopBlock.go()"); + } + + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + } // ThisCallTopBlock + + /** variant: location bottom, initializer simpleExpression */ + static class ThisCallBottomSimple { + /** no bug when calling this directly */ + ThisCallBottomSimple (String input) { + checkMembersHaveInitializedValues("constructor ThisCallBottomSimple(\" + input + \")"); + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + checkMembersHaveSetValues("constructor ThisCallBottomSimple.ThisCallBottomSimple(\" + input + \")"); + } + + /** bug when calling this which calls ThisCallBottomSimple(String) */ + ThisCallBottomSimple () { + this(INPUT); + checkMembersHaveSetValues("constructor ThisCallBottomSimple.ThisCallBottomSimple()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallBottomSimple.go()"); + } + + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + /** type primitive, location bottom, initializer simpleExpression */ + int initOne = 1; + /** type String, location bottom, initializer simpleExpression */ + String initString = "INIT"; + /** type Object, location bottom, initializer simpleExpression */ + Object initNull = null; + /** type String, location bottom, initializer none */ + String initNone; + } // ThisCallBottomSimple + + /** variant: location bottom, initializer blockExpression */ + static class ThisCallBottomBlock { + /** no bug when calling this directly */ + ThisCallBottomBlock (String input) { + checkMembersHaveInitializedValues("constructor ThisCallBottomBlock(\" + input + \")"); + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + checkMembersHaveSetValues("constructor ThisCallBottomBlock.ThisCallBottomBlock(\" + input + \")"); + } + + /** bug when calling this which calls ThisCallBottomBlock(String) */ + ThisCallBottomBlock () { + this(INPUT); + checkMembersHaveSetValues("constructor ThisCallBottemBlock.ThisCallBottomBlock()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallBottomBlock.go()"); + } + + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + /** bottom declarations */ + /** type primitive, location bottom, initializer blockExpression */ + int initOne; + /** type String, location bottom, initializer blockExpression */ + String initString; + /** type Object, location bottom, initializer blockExpression */ + Object initNull; + /** type String, location bottom, initializer none */ + String initNone; + + /** bottom initializer block */ + { + initOne = 1; + initString = "INIT"; + initNull = null; + } + } // ThisCallBottomBlock + + /** variant: location mixed, initializer mixed */ + static class ThisCallMixed { + /** type primitive, location top, initializer simpleExpression */ + int initOne = 1; + /** type String, location top, initializer simpleExpression */ + String initString; + + /** no bug when calling this directly */ + ThisCallMixed (String input) { + checkMembersHaveInitializedValues("constructor ThisCallMixed(\" + input + \")"); + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + checkMembersHaveSetValues("constructor ThisCallMixed.ThisCallMixed(\" + input + \")"); + } + + /** bug when calling this which calls ThisCallMixed(String) */ + ThisCallMixed () { + this(INPUT); + checkMembersHaveSetValues("constructor ThisCallMixed.ThisCallMixed()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallMixed.go()"); + } + + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + /** bottom declarations */ + /** type String, location bottom, initializer none */ + String initNone; + /** type Object, location bottom, initializer blockExpression */ + Object initNull; + + /** bottom (partial) initializer block */ + { + initString = "INIT"; + initNull = null; + } + } // ThisCallMixed + + static class ThisCallChild extends ThisCallParent { + /** type primitive, location top, initializer simpleExpression */ + int initOne = 1; + /** type String, location top, initializer simpleExpression */ + String initString = "INIT"; + /** type Object, location top, initializer simpleExpression */ + Object initNull = null; + /** type String, location top, initializer none */ + String initNone; + + /** no bug when calling this directly */ + ThisCallChild (String input) { + checkMembersHaveInitializedValues("constructor ThisCallChild(\" + input + \")"); + setValues(input); + checkMembersHaveSetValues("constructor ThisCallChild.ThisCallChild((\" + input + \")");; + Tester.checkEqual(parentObject, INPUT, "ThisCallChild.ThisCallChild(int ignored)"); + } + void setValues(String input) { + this.initString = input; + this.initNull = input; + this.initNone = input; + this.initOne = 2; + } + + /** + * @param correctResult + * @param actual + * @param expected + * @param failedResult + * @param testerMessage the String to use for Tester on failure - + * Tester unused if null + * @return correctResult if expected.equals(actual), failedResult otherwise + */ + static private String checkObject(String correctResult + , Object expected + , Object actual + , String failedResult + , String testerMessage) { + if (null == expected) { + if (null == actual) { + return correctResult; + } // else failures fall through + } else if ((null != actual) && (expected.equals(actual))) { + return correctResult; + } + // failures + if (null != testerMessage) { + Tester.checkEqual(actual, expected, testerMessage); + } + return failedResult; + } + + /** proof that test code is correct */ + ThisCallChild (int ignored) { + checkMembersHaveInitializedValues("constructor ThisCallChild.ThisCallChild(int)"); + setValues(INPUT); + checkMembersHaveSetValues("constructor ThisCallChild.ThisCallChild(int)"); + Tester.checkEqual(parentObject, INPUT, "ThisCallChild.ThisCallChild(int ignored)"); + } + + /** no bug when calling this which calls ThisCall(String) */ + ThisCallChild () { + super(INPUT); + checkMembersHaveInitializedValues("constructor ThisCallChild.ThisCallChild()"); + setValues(INPUT); + checkMembersHaveSetValues("constructor ThisCallChild.ThisCallChild()"); + Tester.checkEqual(parentObject, INPUT, "ThisCallChild.ThisCallChild()"); + } + + private static final String tccsuperlabel = + "ThisCallChild.ThisCallChild(long)/* parent initialization complete before child */"; + /** unable to access superclass member state before explicitly invoking constructor */ + ThisCallChild (long ignored) { + // this would do the check, but it is illegal + // this(checkObject(INPUT, INPUT, parentObject, tccsuperLabel + "_FAILED", tccsuperlabel)); + // this(checkObject(INPUT, INPUT, this$.getParentObject(), tccsuperlabel + "_FAILED", tccsuperlabel)); + checkMembersHaveInitializedValues("constructor ThisCallChild.ThisCallChild()"); + setValues(INPUT); + checkMembersHaveSetValues("constructor ThisCallChild.ThisCallChild()"); + Tester.checkEqual(parentObject, INPUT, "ThisCallChild.ThisCallChild()"); + } + + /** redundant check - same check at end of constructors */ + void go() { + checkMembersHaveSetValues("method ThisCallChild.go()"); + Tester.checkEqual(parentObject, INPUT, "ThisCallChild.go()"); + } + + /** the same method for all variants */ + protected void checkMembersHaveInitializedValues(String label) { + Tester.checkEqual("INIT", initString, label + " initialized "); + Tester.checkEqual((Object) null, initNull, label + " initialized "); + Tester.checkEqual((Object) null, initNone, label + " initialized "); + Tester.checkEqual(1, initOne, label + " initialized "); + } + + /** the same method for all variants */ + protected void checkMembersHaveSetValues(String label) { + Tester.checkEqual(2, initOne, label + " set "); + Tester.checkEqual("input", initString, label + " set "); + Tester.checkEqual("input", initNone, label + " set "); + // Object uses strict/reference identity - input dependency + Tester.checkEqual(INPUT, initNull, label + " set "); + } + } + static class ThisCallParent { + /** not available to in child explicit constructor parameter expression */ + protected Object parentObject = INIT; + /** not available to in child explicit constructor parameter expression */ + protected Object getParentObject() { return parentObject; } + /** no bug here */ + ThisCallParent() { + Tester.checkEqual(parentObject, INIT, "ThisCallParent.ThisCallParent()"); + parentObject = INPUT; + } + /** no bug here */ + ThisCallParent(String input) { + Tester.checkEqual(parentObject, INIT, "ThisCallParent.ThisCallParent(\"" + input + "\")"); + parentObject = input; + } + } +} // MemberInitializationsAfterExplicitConstructorCallsCoverage +/** variant: location enclosing */ +class ThisCallEnclosing { + public static final String INPUT = "input"; + public static final String INIT = "INIT"; + String initString = INIT; + String constructedString; + public ThisCallEnclosed getEnclosed() { + return new ThisCallEnclosed(); + } + /** no bug when calling this directly */ + ThisCallEnclosing (String ignored) { + constructedString = INPUT; + initString = INPUT; + } + + public class ThisCallEnclosed { + boolean didCheck; + { + // check enclosing instance in initializer + Tester.checkEqual(INPUT, initString, "ThisCallEnclosed.<initializer> initString"); + Tester.checkEqual(INPUT, constructedString, "ThisCallEnclosed.<initializer> constructedString"); + didCheck = true; + } + public ThisCallEnclosed() { + this("init: " + initString + " constructed: " + constructedString); + Tester.check(didCheck, "initializer ran before ThisCallEnclosed() body"); + + } + public ThisCallEnclosed(String s) { + Tester.checkEqual(INPUT, initString, "ThisCallEnclosed(String) initString"); + Tester.checkEqual(INPUT, constructedString, "ThisCallEnclosed(String) constructedString"); + Tester.check(didCheck, "initializer ran before ThisCallEnclosed(String) body"); + } + } +} // ThisCallEnclosing diff --git a/tests/new/MethodConflictsCF.java b/tests/new/MethodConflictsCF.java new file mode 100644 index 000000000..b7243ebb6 --- /dev/null +++ b/tests/new/MethodConflictsCF.java @@ -0,0 +1,32 @@ +import org.aspectj.testing.Tester; + +public class MethodConflictsCF { + public static void main(String[] args) { + } +} + +class C implements I1, I2 { //ERR: I1.m1() != I2.m1() + public String ma() { return "C"; } + //private void mp() { } +} + +interface BaseI { + public String m1(); + public String m2(); +} + +interface I1 extends BaseI { + static aspect BODY { + public String I1.m1() { return "I1-" + ma(); } + public abstract String I1.ma(); + } +} + +interface I2 extends BaseI { + static aspect BODY { + public String I2.m2() { return "I2-" + ma(); } + public String I2.m1() { return "I2-" + ma(); } //ERR: I1.m1() + public abstract String I2.ma(); + } +} + diff --git a/tests/new/MethodConflictsCP.java b/tests/new/MethodConflictsCP.java new file mode 100644 index 000000000..11376ac73 --- /dev/null +++ b/tests/new/MethodConflictsCP.java @@ -0,0 +1,49 @@ +import org.aspectj.testing.Tester; + +public class MethodConflictsCP { + public static void main(String[] args) { + C c = new C(); + Tester.checkEqual(c.ma(), "C"); + Tester.checkEqual(c.m1(), "I1-C"); + Tester.checkEqual(c.m2(), "I2-C"); + + I1 i1 = c; + Tester.checkEqual(i1.m2(), "I2-C"); + + Tester.checkEqual(new CO().toString(), "IO"); + } +} + +class C implements I1, I2 { + public String ma() { return "C"; } + //private void mp() { } +} + +interface BaseI { + public String m1(); + public String m2(); +} + +interface I1 extends BaseI { + static aspect BODY { + public String I1.m1() { return "I1-" + ma(); } + public abstract String I1.ma(); + } +} + +interface I2 extends BaseI { + static aspect BODY { + public String I2.m2() { return "I2-" + ma(); } + public abstract String I2.ma(); + private String I2.mp() { return "I2"; } + } +} + +interface IO { + static aspect BODY { + public String IO.toString() { return "IO"; } + } +} + +class CO implements IO { +} diff --git a/tests/new/MethodInner.java b/tests/new/MethodInner.java new file mode 100644 index 000000000..604582293 --- /dev/null +++ b/tests/new/MethodInner.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; + +public class MethodInner { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new C().foo(), 10, "inner"); + } +} + +class C { + int foo() { + final int N = 10; + + class Inner { + public int bar() { + return N; + } + } + + return new Inner().bar(); + } +} + +aspect A issingleton() { + before(): execution(int *(..)) { + System.out.println("before: " + thisJoinPoint); + } +} diff --git a/tests/new/MethodIntroductions.java b/tests/new/MethodIntroductions.java new file mode 100644 index 000000000..40385f718 --- /dev/null +++ b/tests/new/MethodIntroductions.java @@ -0,0 +1,75 @@ +import org.aspectj.testing.Tester; +public class MethodIntroductions { + public static void main(String[] args) { + new MethodIntroductions().realMain(args); + } + public void realMain(String[] args) { + + AbstractSuper as0 = new AbstractSuper() { public int foo() { return 1; } }; + AbstractSuper as1 = new ExtendsAbstractSuper(); + AbstractSuper as2 = new ExtendsExtendsAbstractSuper(); + ExtendsAbstractSuper eas = new ExtendsAbstractSuper(); + ExtendsExtendsAbstractSuper eeas = new ExtendsExtendsAbstractSuper(); + Tester.checkEqual(as0.foo(), 1, "as0"); + Tester.checkEqual(as1.foo(), 2, "as1"); + Tester.checkEqual(as2.foo(), 3, "as2"); + Tester.checkEqual(eas.foo(), 2, "eas"); + Tester.checkEqual(eeas.foo(), 3, "eeas"); + + Super s0 = new Super() {}; + Super s1 = new ExtendsSuper(); + Super s2 = new ExtendsExtendsSuper(); + ExtendsSuper es = new ExtendsSuper(); + ExtendsExtendsSuper ees = new ExtendsExtendsSuper(); + Tester.checkEqual(s0.foo(), 4, "s0"); + Tester.checkEqual(s1.foo(), 5, "s1"); + Tester.checkEqual(s2.foo(), 6, "s2"); + Tester.checkEqual(es.foo(), 5, "es"); + Tester.checkEqual(ees.foo(), 6, "ees"); + + AbstractSuperNoIntro as0n = new AbstractSuperNoIntro() { public int foo() { return 7; } }; + AbstractSuperNoIntro as1n = new ExtendsAbstractSuperNoIntro(); + AbstractSuperNoIntro as2n = new ExtendsExtendsAbstractSuperNoIntro(); + ExtendsAbstractSuperNoIntro easn = new ExtendsAbstractSuperNoIntro(); + ExtendsExtendsAbstractSuperNoIntro eeasn = new ExtendsExtendsAbstractSuperNoIntro(); + Tester.checkEqual(as0n.foo(), 7, "as0n"); + Tester.checkEqual(as1n.foo(), 8, "as1n"); + Tester.checkEqual(as2n.foo(), 9, "as2n"); + Tester.checkEqual(easn.foo(), 8, "easn"); + Tester.checkEqual(eeasn.foo(), 9, "eeasn"); + } +} + +interface I { + public int foo(); +} + +abstract class AbstractSuper {} +class ExtendsAbstractSuper extends AbstractSuper {} +class ExtendsExtendsAbstractSuper extends ExtendsAbstractSuper {} + +class Super {} +class ExtendsSuper extends Super {} +class ExtendsExtendsSuper extends ExtendsSuper {} + +abstract class AbstractSuperNoIntro {} +class ExtendsAbstractSuperNoIntro extends AbstractSuperNoIntro {} +class ExtendsExtendsAbstractSuperNoIntro extends ExtendsAbstractSuperNoIntro {} + +aspect Introducer { + + declare parents: AbstractSuper implements I; + public int AbstractSuper.foo() { return 1; } + public int ExtendsAbstractSuper.foo() { return 2; } + public int ExtendsExtendsAbstractSuper.foo() { return 3; } + + declare parents: Super implements I; + public int Super.foo() { return 4; } + public int ExtendsSuper.foo() { return 5; } + public int ExtendsExtendsSuper.foo() { return 6; } + + declare parents: AbstractSuperNoIntro implements I; + public int ExtendsAbstractSuperNoIntro.foo() { return 8; } + public int ExtendsExtendsAbstractSuperNoIntro.foo() { return 9; } + +} diff --git a/tests/new/MethodLocalAroundReturns.java b/tests/new/MethodLocalAroundReturns.java new file mode 100644 index 000000000..f0bec7d73 --- /dev/null +++ b/tests/new/MethodLocalAroundReturns.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; + +public class MethodLocalAroundReturns { + public static void main (String[] args) { + C c = C.make(); + Tester.check(null != c, "null c"); + Tester.check("ok".equals(c.toString()), "bad c: " + c); + } +} + +class C { + static C make() { return null; } +} + +aspect A { + /** @testcase method-local class defined in around return statement */ + C around() : call(C C.make()) { + return new C() { + public String toString() { return "ok"; } // bad compiler error here + }; + } +} diff --git a/tests/new/MethodSelfReference.java b/tests/new/MethodSelfReference.java new file mode 100644 index 000000000..b824bf72a --- /dev/null +++ b/tests/new/MethodSelfReference.java @@ -0,0 +1,26 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#776 self-reference from (aspect-declared) method-local class */ +public class MethodSelfReference { + public static void main (String[] args) { + I it = new I() { public void im() { } }; + it.start(); + } +} + +interface I { public void im(); } + +aspect A { + Runnable I.runnable; + void I.start() { + class Runner implements Runnable { + I ri; + Runner(I i) { ri = i; } + public void run() { ri.im(); } + } + runnable = new Runner(this); + runnable.run(); + } +} + diff --git a/tests/new/MethodSignatures.java b/tests/new/MethodSignatures.java new file mode 100644 index 000000000..2df5f1694 --- /dev/null +++ b/tests/new/MethodSignatures.java @@ -0,0 +1,185 @@ +import org.aspectj.testing.Tester; +import java.util.Set; +import java.util.*; + +interface I { + public void m2(); +} + +class C { + public void m0() {} + public void m1() {} + public void m2() {} +} + +class D0 extends C { + public void m1() { super.m1(); } +} + +class D1 extends C implements I { + public void m0() { super.m0(); } + public void m2() { super.m2(); } +} + +class E { + + Set set = new HashSet(); + + String makePrettyString(String val) { + return decode(val) + " advice for " + method(val); + } + + public void check(String msg, String vals) { + StringTokenizer tok = new StringTokenizer(vals); + while (tok.hasMoreTokens()) { + String val = tok.nextToken(); + Tester.check(set.contains(val), + msg + " does not contain " + + makePrettyString(val)); + if (set.contains(val)) set.remove(val); + } + + // check that nothing that shouldn't be set is set + for (Iterator i = set.iterator(); i.hasNext(); ) { + Tester.check(false, + msg + " shouldn't contain " + + makePrettyString((String)i.next())); + } + + clear(); + } + + public String method(String val) { + int idollar = val.indexOf("$"); + if (idollar == -1) { + return val; + } + return val.substring(idollar+1); + } + + public String decode(String val) { + int idollar = val.indexOf("$"); + if (idollar == -1) { + return val; + } + String code = val.substring(0, idollar); + String result = val; + if (code.equals("bc")) { + result = "before calls"; + } else if (code.equals("br")) { + result = "before receptions"; + } else if (code.equals("be")) { + result = "before execution"; + } + return result; + } + + public void put(String val) { + set.add(val); + } + + public void clear() { + set = new HashSet(); + } +} + +interface F { + E e = new E(); +} + +public class MethodSignatures implements F { + static int i = 1; + static int j = 0; + static int k = 0; + public static void main(String[] args) { + I id1 = new D1(); + C c = new C(); + C cd0 = new D0(); + C cd1 = new D1(); + D0 d0 = new D0(); + D1 d1 = new D1(); + +// id1.m2(); e.check("id1.m2", "bc$i.m2 br$i.m2 be$i.m2 be$c.m2 be$d1.m2 br$c.m2 br$d1.m2"); + +// c.m0(); e.check("c.m0", "bc$c.m0 br$c.m0 be$c.m0"); +// c.m1(); e.check("c.m1", "bc$c.m1 br$c.m1 be$c.m1"); +// c.m2(); e.check("c.m2", "bc$c.m2 br$c.m2 be$c.m2"); +// cd0.m0(); e.check("cd0.m0", "bc$c.m0 br$d0.m0 be$c.m0 br$c.m0"); +// cd0.m1(); e.check("cd0.m1", "bc$c.m1 br$d0.m1 be$d0.m1 be$c.m1 br$c.m1"); +// cd0.m2(); e.check("cd0.m2", "bc$c.m2 br$d0.m2 be$c.m2 br$c.m2"); +// cd1.m0(); e.check("cd1.m0", "bc$c.m0 br$d1.m0 be$d1.m0 br$c.m0 be$c.m0"); +// cd1.m1(); e.check("cd1.m1", "bc$c.m1 br$d1.m1 br$c.m1 be$c.m1"); +// cd1.m2(); e.check("cd1.m2", "bc$c.m2 br$d1.m2 be$d1.m2 br$c.m2 be$c.m2 br$i.m2 be$i.m2"); +// d0.m0(); e.check("d0.m0", "bc$d0.m0 br$d0.m0 bc$c.m0 br$c.m0 be$c.m0"); //??? bc$d0.m0 +// d0.m1(); e.check("d0.m1", "bc$d0.m1 br$d0.m1 be$d0.m1 bc$c.m1 br$c.m1 be$c.m1"); +// d0.m2(); e.check("d0.m2", "bc$d0.m2 br$d0.m2 bc$c.m2 br$c.m2 be$c.m2"); //??? bc$d0.m2 +// d1.m0(); e.check("d1.m0", "bc$d1.m0 br$d1.m0 be$d1.m0 bc$c.m0 br$c.m0 be$c.m0"); +// d1.m1(); e.check("d1.m1", "bc$d1.m1 br$d1.m1 bc$c.m1 br$c.m1 be$c.m1"); //??? bc$d1.m1 +// d1.m2(); e.check("d1.m2", "bc$d1.m2 br$d1.m2 be$d1.m2 bc$c.m2 br$c.m2 be$c.m2 bc$i.m2 br$i.m2 be$i.m2"); + id1.m2(); e.check("id1.m2", "bc$i.m2 be$i.m2 be$c.m2 be$d1.m2 "); + + c.m0(); e.check("c.m0", "bc$c.m0 be$c.m0"); + c.m1(); e.check("c.m1", "bc$c.m1 be$c.m1"); + c.m2(); e.check("c.m2", "bc$c.m2 be$c.m2"); + cd0.m0(); e.check("cd0.m0", "bc$c.m0 be$c.m0"); + cd0.m1(); e.check("cd0.m1", "bc$c.m1 be$d0.m1 be$c.m1"); + cd0.m2(); e.check("cd0.m2", "bc$c.m2 be$c.m2 "); + cd1.m0(); e.check("cd1.m0", "bc$c.m0 be$d1.m0 be$c.m0"); + cd1.m1(); e.check("cd1.m1", "bc$c.m1 be$c.m1"); + cd1.m2(); e.check("cd1.m2", "bc$c.m2 be$d1.m2 be$c.m2 be$i.m2"); + d0.m0(); e.check("d0.m0", "bc$d0.m0 bc$c.m0 be$c.m0"); //??? bc$d0.m0 + d0.m1(); e.check("d0.m1", "bc$d0.m1 be$d0.m1 bc$c.m1 be$c.m1"); + d0.m2(); e.check("d0.m2", "bc$d0.m2 bc$c.m2 be$c.m2"); //??? bc$d0.m2 + d1.m0(); e.check("d1.m0", "bc$d1.m0 be$d1.m0 bc$c.m0 be$c.m0"); + d1.m1(); e.check("d1.m1", "bc$d1.m1 bc$c.m1 be$c.m1"); //??? bc$d1.m1 + d1.m2(); e.check("d1.m2", "bc$d1.m2 be$d1.m2 bc$c.m2 be$c.m2 bc$i.m2 be$i.m2"); + } +} + + +aspect A implements F { + + before(): call(void C.m0()) { e.put("bc$c.m0"); } + before(): call(void C.m1()) { e.put("bc$c.m1"); } + before(): call(void C.m2()) { e.put("bc$c.m2"); } + + before(): call(void D0.m0()) { e.put("bc$d0.m0"); } + before(): call(void D0.m1()) { e.put("bc$d0.m1"); } + before(): call(void D0.m2()) { e.put("bc$d0.m2"); } + + before(): call(void D1.m0()) { e.put("bc$d1.m0"); } + before(): call(void D1.m1()) { e.put("bc$d1.m1"); } + before(): call(void D1.m2()) { e.put("bc$d1.m2"); } + + before(): call(void I.m2()) { e.put("bc$i.m2"); } + + +// /*static*/ before(): call(void C.m0()) { e.put("br$c.m0"); } +// /*static*/ before(): call(void C.m1()) { e.put("br$c.m1"); } +// /*static*/ before(): call(void C.m2()) { e.put("br$c.m2"); } + +// /*static*/ before(): call(void D0.m0()) { e.put("br$d0.m0"); } +// /*static*/ before(): call(void D0.m1()) { e.put("br$d0.m1"); } +// /*static*/ before(): call(void D0.m2()) { e.put("br$d0.m2"); } + +// /*static*/ before(): call(void D1.m0()) { e.put("br$d1.m0"); } +// /*static*/ before(): call(void D1.m1()) { e.put("br$d1.m1"); } +// /*static*/ before(): call(void D1.m2()) { e.put("br$d1.m2"); } + +// /*static*/ before(): call(void I.m2()) { e.put("br$i.m2"); } + + + /*static*/ before(): execution(void C.m0()) { e.put("be$c.m0"); } + /*static*/ before(): execution(void C.m1()) { e.put("be$c.m1"); } + /*static*/ before(): execution(void C.m2()) { e.put("be$c.m2"); } + + /*static*/ before(): execution(void D0.m0()) { e.put("be$d0.m0"); } // no targets + /*static*/ before(): execution(void D0.m1()) { e.put("be$d0.m1"); } + /*static*/ before(): execution(void D0.m2()) { e.put("be$d0.m2"); } // no targets + + /*static*/ before(): execution(void D1.m0()) { e.put("be$d1.m0"); } + /*static*/ before(): execution(void D1.m1()) { e.put("be$d1.m1"); } // no targets + /*static*/ before(): execution(void D1.m2()) { e.put("be$d1.m2"); } + + /*static*/ before(): execution(void I.m2()) { e.put("be$i.m2"); } +} diff --git a/tests/new/MissingTypeInDeclareParents.java b/tests/new/MissingTypeInDeclareParents.java new file mode 100644 index 000000000..ad969a65b --- /dev/null +++ b/tests/new/MissingTypeInDeclareParents.java @@ -0,0 +1,21 @@ + +import org.aspectj.testing.Tester; +import java.util.*; +import java.io.*; + +/** @testcase unmatched type name in a declare parents should result in a warning in -Xlint mode */ +public class MissingTypeInDeclareParents { + + public static void main(String[] args) throws Exception { + FileReader fr = new FileReader("foo"); + //fr.run(); + Tester.check(true, "Kilroy was here"); + } +} + +class C { +} +aspect A { + /** Xlint warning expected where FileReader is outside code controlled by implementation */ + declare parents : FileReader extends Runnable; // CW 20 Xlint warning +} diff --git a/tests/new/MultiAndAround.java b/tests/new/MultiAndAround.java new file mode 100644 index 000000000..d0e27211c --- /dev/null +++ b/tests/new/MultiAndAround.java @@ -0,0 +1,70 @@ +import org.aspectj.testing.Tester; + +public class MultiAndAround { + public static void main(String[] args) { + exercise(new Base()); + exercise(new Derived()); + exercise(new SubBase()); + + Tester.checkEventsFromFile("MultiAndAround.out"); + } + + static void exercise(IBase b) { + Tester.event("**************************************"); + b.base1("1"); + b.base2("2"); + b.base3("3"); + } +} + + +interface IBase { + void base1(String s); + void base2(String s); + void base3(String s); +} + +interface IDerived extends IBase { + void base1(String s); +} + +class Base implements IBase { + public void base2(String s) { Tester.event("Base.base2"); } +} + +class Derived implements IDerived { + public void base3(String s) { Tester.event("Derived.base3"); } +} + +class SubBase extends Base { + public void base3(String s) { Tester.event("SubBase.base3"); } +} + +aspect Intro { + public void IBase.base1(String s) { Tester.event("IBase.base1 from Intro"); } + public void IBase.base3(String s) { Tester.event("IBase.base3 from Intro"); } + + public void IDerived.base1(String s) { Tester.event("IDerived.base1 from Intro"); } + public void IDerived.base2(String s) { Tester.event("IDerived.base2 from Intro"); } + public void IDerived.base3(String s) { Tester.event("IDerived.base3 from Intro"); } +} + + +aspect A { + Object around(): call(* IBase.*(..)) { + Tester.event("around call(IBase.*)"); + return proceed(); + } + Object around(): call(* IBase+.*(..)) { + Tester.event("around call(IBase+.*)"); + return proceed(); + } + Object around(): call(* Base.*(..)) { + Tester.event("around call(Base.*)"); + return proceed(); + } + Object around(): execution(* Base+.*(..)) { + Tester.event("around execution(Base+.*)"); + return proceed(); + } +} diff --git a/tests/new/MultiAndAround.out b/tests/new/MultiAndAround.out new file mode 100644 index 000000000..40898a0cc --- /dev/null +++ b/tests/new/MultiAndAround.out @@ -0,0 +1,33 @@ +**************************************
+around call(IBase.*)
+around call(IBase+.*)
+IBase.base1 from Intro
+around call(IBase.*)
+around call(IBase+.*)
+around execution(Base+.*)
+Base.base2
+around call(IBase.*)
+around call(IBase+.*)
+IBase.base3 from Intro
+**************************************
+around call(IBase.*)
+around call(IBase+.*)
+IDerived.base1 from Intro
+around call(IBase.*)
+around call(IBase+.*)
+IDerived.base2 from Intro
+around call(IBase.*)
+around call(IBase+.*)
+Derived.base3
+**************************************
+around call(IBase.*)
+around call(IBase+.*)
+IBase.base1 from Intro
+around call(IBase.*)
+around call(IBase+.*)
+around execution(Base+.*)
+Base.base2
+around call(IBase.*)
+around call(IBase+.*)
+around execution(Base+.*)
+SubBase.base3
diff --git a/tests/new/MultiArrays.java b/tests/new/MultiArrays.java new file mode 100644 index 000000000..9994abf6d --- /dev/null +++ b/tests/new/MultiArrays.java @@ -0,0 +1,12 @@ +import org.aspectj.testing.Tester; + +public class MultiArrays { + static int[][] data = {{11,12,13}, {21,22,23}}; + + public static void test() { + Tester.checkEqual(data[0][0], 11, "0,0"); + Tester.checkEqual(data[1][2], 23, "1,2"); + } + + public static void main(String[] args) { test(); } +} diff --git a/tests/new/MultiDispatchCf.java b/tests/new/MultiDispatchCf.java new file mode 100644 index 000000000..d158240de --- /dev/null +++ b/tests/new/MultiDispatchCf.java @@ -0,0 +1,74 @@ +import org.aspectj.testing.Tester; + +public class MultiDispatchCf { + public static void main(String[] args) { + C c = new C(); + + Tester.event("**** exec ****"); + //MultiExec.enabled = true; + run(new C()); + + Tester.event("**** call ****"); + //MultiExec.enabled = false; + //MultiCall.enabled = true; + run(new C()); + + Tester.event("**** both=call ****"); + //MultiExec.enabled = true; + run(new C()); + + Tester.printEvents(); + } + + static void run(C c) { + Tester.event(c.doit("s1")); + Tester.event(c.doit(new Integer(10))); + Tester.event(c.doit(new Double(1.25))); + + Object o; + o = "s2"; Tester.event(c.doit(o)); + o = new Integer(20); Tester.event(c.doit(o)); + o = new Double(2.25); Tester.event(c.doit(o)); + } +} + + +class C { + String doit(Object o) { + return "did-" + o.toString(); + } +} + +aspect MultiCall { + pointcut t1(String s): call(String C.doit(Object)) && args(s); + + String around(String s): t1(s) { return proceed(s); } + String around(Object o): t1(o) { return proceed(o); } + + + + pointcut m(Object o): call(String C.doit(Object)) && args(o); + + String getPrefix() { return "call"; } + + String around(String s): m(s) { //ERR + return getPrefix() + "-string-" + s; + } + String around(Integer i): m(i) { //ERR + return getPrefix() + "-integer-" + i; + } + String around(Double d): m(d) { //ERR + return getPrefix() + "-double-" + d; + } +} + +aspect MultiCreate { + pointcut make(Object o): this(o) && execution(new(..)); + + private interface I {} + declare parents: C implements I; + + before(I i): make(i) { //ERR: doesn't match Object + System.out.println("new I: " + i); + } +} diff --git a/tests/new/MultiDispatchCp.java b/tests/new/MultiDispatchCp.java new file mode 100644 index 000000000..b500ed4a7 --- /dev/null +++ b/tests/new/MultiDispatchCp.java @@ -0,0 +1,77 @@ +import org.aspectj.testing.Tester; + +public class MultiDispatchCp { + public static void main(String[] args) { + C c = new C(); + + Tester.event("**** exec ****"); + MultiExec.enabled = true; + run(new C()); + + Tester.event("**** call ****"); + MultiExec.enabled = false; + MultiCall.enabled = true; + run(new C()); + + Tester.event("**** both=call ****"); + MultiExec.enabled = true; + run(new C()); + + Tester.checkEventsFromFile("MultiDispatchCp.out"); + //Tester.printEvents(); + } + + static void run(C c) { + Tester.event(c.doit("s1")); + Tester.event(c.doit(new Integer(10))); + Tester.event(c.doit(new Double(1.25))); + + Object o; + o = "s2"; Tester.event(c.doit(o)); + o = new Integer(20); Tester.event(c.doit(o)); + o = new Double(2.25); Tester.event(c.doit(o)); + } +} + + +class C { + String doit(Object o) { + return "did-" + o.toString(); + } +} + +abstract aspect Multi { + abstract pointcut m(); + + abstract String getPrefix(); + + String around(String s): m() && args(s) { + return getPrefix() + "-string-" + s; + } + String around(Integer i): m() && args(i) { + //System.out.println(thisJoinPoint + " would return " + proceed(i)); + return getPrefix() + "-integer-" + i; + } + String around(Double d): m() && args(d) { + return getPrefix() + "-double-" + d; + } +} + +aspect MultiCall extends Multi { + public static boolean enabled = false; + + String getPrefix() { return "call"; } + + pointcut m(): call(String C.doit(Object)) && if(enabled); +} + + +// dominates should have no effect as call join points +// always come before executions +aspect MultiExec extends Multi dominates MultiCall { + public static boolean enabled = false; + + String getPrefix() { return "exec"; } + + pointcut m(): execution(String C.doit(Object)) && if(enabled); +} diff --git a/tests/new/MultiDispatchCp.out b/tests/new/MultiDispatchCp.out new file mode 100644 index 000000000..b92aa9ebc --- /dev/null +++ b/tests/new/MultiDispatchCp.out @@ -0,0 +1,21 @@ +**** exec ****
+exec-string-s1
+exec-integer-10
+exec-double-1.25
+exec-string-s2
+exec-integer-20
+exec-double-2.25
+**** call ****
+call-string-s1
+call-integer-10
+call-double-1.25
+call-string-s2
+call-integer-20
+call-double-2.25
+**** both=call ****
+call-string-s1
+call-integer-10
+call-double-1.25
+call-string-s2
+call-integer-20
+call-double-2.25
diff --git a/tests/new/NamedCrosscuts.java b/tests/new/NamedCrosscuts.java new file mode 100644 index 000000000..c16889dc7 --- /dev/null +++ b/tests/new/NamedCrosscuts.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.Tester; + +public class NamedCrosscuts { + crosscut fooCut(Foo f): void foo() && f; + + static advice(Foo f): fooCut(f) { + before { + System.err.println("before advice"); + } + } + + crosscut allMethodsCut(): * && !(NamedCrosscuts) && !abstract * *(..); + + static advice(): allMethodsCut() { + before { + System.err.println("method: "+thisJoinPoint.methodName); + } + } + + public static void test() { + new Foo().foo(); + } + + public static void main(String[] args) { + test(); + } +} + +class Foo { + void foo() {} +} diff --git a/tests/new/NamedWithinPointcuts.java b/tests/new/NamedWithinPointcuts.java new file mode 100644 index 000000000..92a628dc8 --- /dev/null +++ b/tests/new/NamedWithinPointcuts.java @@ -0,0 +1,22 @@ + +import org.aspectj.testing.Tester; + +public class NamedWithinPointcuts { + public static void main (String[] args) { + Tester.expectEvent("before"); + Tester.checkAllEventsIgnoreDups(); + } +} + +aspect Test { + pointcut withinAspects() : within(Test) ; + + static void log() { } + + /** @testcase PR#635 Named Within pointcuts failing */ + //before() : !within(Test) { // works fine + before() : !(withinAspects()) { // stack overflow + log(); // comment out to avoid stack overflow + Tester.event("before"); + } +} diff --git a/tests/new/NegativeSourceLocation.java b/tests/new/NegativeSourceLocation.java new file mode 100644 index 000000000..aa1801459 --- /dev/null +++ b/tests/new/NegativeSourceLocation.java @@ -0,0 +1,312 @@ +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +import org.aspectj.testing.*; + +/** + * @testcase PR#525 validate presence/absence of thisEnclosingJoinPointStaticPart + * @testcase PR#525 validate SourceLocation + */ +public class NegativeSourceLocation { + + public static void main(String[] args) { + Signal.expect(Const.EXPECTED); + TargetClass target = new TargetClass(); + // run from outside code the compiler controls + Thread t = new Thread(target, "NegativeSourceLocation"); + t.start(); + int i = 0; + // todo: use Timer to add interrupt? + while ((10 > i++) && t.isAlive()) { + try { t.join(); } + catch (InterruptedException e) {} + } + Signal.checkAll(); + } +} + +/** indirection for test utility */ +class Signal { + public static final void failed(String s) { + //Thread.currentThread().dumpStack(); + Tester.checkFailed(s); + } + public static final void found(JoinPoint.StaticPart s) { + Tester.event(s.toString()); + } + public static final void found(String s) { + Tester.event(s); + //System.err.println(s); + } + public static final void checkAll() { + Tester.checkAllEvents(); + } + public static final void expect(String[] sra) { + Tester.expectEventsInString(sra); + } +} // class Signal + +/** TargetClass has most every join point, provoked by initializatin and run() */ +class TargetClass implements Runnable { + TargetClass() {} + static String staticString = "two"; // jp has -1 source location + static { + staticString = "one"; + String s = staticString + "asdf"; + } + static { + staticString = "three"; + } + String string = "bar"; + public static void staticRun() { // execute + staticString = "foo"; // set - static var + String s = staticString; // get - static var + s = s + "ss"; + staticString = s + "u"; // set - instance var + TargetClass u = new TargetClass(); // initialization + staticString = u.toString(); + } + public void run() { // execute - no thisEnclosingJoinPoint when called from Thread.start() + boolean doNotOptimize = (TargetClass.class != null); + if (doNotOptimize) internalRun(); + } + private void internalRun() { // execute + staticString = "foo"; // set - static var + staticRun(); // call static + String s = staticString; // get - static var + String t = string; // get - instance var + s = s + t; + string = s + t; // set - instance var + final Error e = new Error("caught here"); + try { + throw e; + } catch (Error er) { // handler + if (er != e) { + Signal.failed("caught Error=" + er); + } else { + Signal.found("caught"); + } + } + } +} // class TargetClass + +/** + * This Aspect attempts to specify join points that have enclosing + * join points and whether the source locations are valid. + * It fails in using only pointcuts. + * This is just a first cut. I (wes) have an AroundAll + * which does this tracking... + */ +aspect Aspect { + + // ------------------------------- pointcuts select logical sets of join points + pointcut allTargetJoinPoints() + : within(TargetClass) ; + + /** these have no enclosing join point */ + pointcut noEnclosingJoinPoint() + : ((call(public void TargetClass.run())) // called from Thread.start() (caller-side, but has callee-side?) + //|| staticinitialization(TargetClass) // the enclosing jp here is itself + ); + // || initialization(TargetClass.new()) + // || execution(TargetClass.new()) // todo: expect it to be self like in methods? + + + /** these have enclosing join points */ + pointcut hasEnclosingJoinPoint() + : allTargetJoinPoints() + && !(noEnclosingJoinPoint()) + ; + + /** expecting an enclosing join point different from thisJoinPoint */ + pointcut enclosingDiffers() + : get(* TargetClass.*) + || set(* TargetClass.*) + || call(* TargetClass.*(..)) + || handler(Error) + ; + + pointcut hasDifferentEnclosingJoinPoint() + : hasEnclosingJoinPoint() + && enclosingDiffers() + ; + + pointcut hasSameEnclosingJoinPoint() + : hasEnclosingJoinPoint() + && (!enclosingDiffers()); + + /** synthetic join points have no source location */ + pointcut syntheticJoinPoints() + : staticinitialization(TargetClass) + || initialization(TargetClass.new(UnknownConstructor)) + ; + + pointcut joinPointHasValidSourceLocation() + : allTargetJoinPoints() + && (!syntheticJoinPoints()) + //&& if(expectSourceLocation(thisJoinPointStaticPart)) + ; + + pointcut enclosingJoinPointHasValidSourceLocation() // todo: cannot specify + : hasEnclosingJoinPoint() + && (!syntheticJoinPoints()) + //&& if(expectSourceLocation(thisEnclosingJoinPointStaticPart)) + ; + + // ---------------------- advice applies invariants to each logical set of join points + /** @testcase all join points have non-null thisJoinPoint and thisJoinPointStaticPart */ + before(): allTargetJoinPoints() { + Signal.found("before AllTargetJoinPoints " + thisJoinPointStaticPart); + String test = "all join points have non-null thisJoinPointStaticPart"; + if (null == thisJoinPoint) { + Signal.failed(test + " failed with null thisJoinPoint: " + thisJoinPointStaticPart); + } + if (null == thisJoinPointStaticPart) { + Signal.failed(test + " failed with null thisJoinPointStaticPart: " + thisJoinPoint); + } + } + + /** @testcase non-null thisEnclosingStaticJoinPoint at certain join points */ + before() : hasEnclosingJoinPoint() { + String test = "failed (most join points have non-null thisEnclosingStaticJoinPoint) "; + if (null == thisEnclosingJoinPointStaticPart) { + String jpName = thisJoinPointStaticPart.toString(); + Signal.failed(test + render(thisJoinPointStaticPart, thisEnclosingJoinPointStaticPart)); + //if (!jpName.equals("execution(TargetClass.<init>)")) { // todo: unable to specify this... + } + } + + /** @testcase non-null thisEnclosingStaticJoinPoint at join points (except for tested exceptions) */ + before() : hasDifferentEnclosingJoinPoint() { + String test = "join points with different thisEnclosingStaticJoinPoint"; + if (thisEnclosingJoinPointStaticPart != thisEnclosingJoinPointStaticPart) { + Signal.failed(test + " different static part : " + thisJoinPointStaticPart); + } + } + + /** @testcase expecting valid source locations */ + before() : joinPointHasValidSourceLocation() { + if (null == thisJoinPointStaticPart) { + Signal.failed("null thisJoinPointStaticPart"); + } else { + checkSourceLocation(thisJoinPointStaticPart); + } + } + + /** @testcase expecting valid source locations in enclosing join point */ + before() : enclosingJoinPointHasValidSourceLocation() { + if (null == thisEnclosingJoinPointStaticPart) { + Signal.failed("null thisEnclosingJoinPointStaticPart in " + thisJoinPointStaticPart); + } else { + checkSourceLocation(thisEnclosingJoinPointStaticPart); + } + } + + /** @testcase non-null thisEnclosingJoinPointStaticPart in static initializer if invoked within a join point? */ + before() : staticinitialization(AnotherTargetClass) { + String test = "static initializer join points have non-null thisJoinPointStaticPart when invoked from CCC"; + if (null == thisJoinPoint) { + Signal.failed(test + " failed with null thisJoinPoint: " + thisJoinPointStaticPart); + } + if (null == thisJoinPointStaticPart) { + Signal.failed(test + " failed with null thisJoinPointStaticPart: " + thisJoinPoint); + } + Signal.found("staticinitialization(AnotherTargetClass))"); + //Signal.found(thisJoinPointStaticPart); // todo: relying on formatting of toString() - fix + } + + /** @testcase no call from outside CCC has thisEnclosingJoinPointStaticPart (possible mistake) */ + before() : noEnclosingJoinPoint() { + Signal.found("before noEnclosingJoinPoint " + thisJoinPointStaticPart); + if (null != thisEnclosingJoinPointStaticPart) { + Signal.failed("unexpected non-null thisEnclosingJoinPointStaticPart: " + + thisEnclosingJoinPointStaticPart + " from " + thisJoinPointStaticPart); + } + } + + static String render(JoinPoint.StaticPart jp, JoinPoint.StaticPart ejp) { + StringBuffer sb = new StringBuffer(); + sb.append("thisJoinPoint: "); + sb.append(null == jp ? "null" : jp.toString()); + sb.append("thisEnclosingJoinPoint: "); + sb.append(null == ejp ? "null" : ejp.toString()); + return sb.toString(); + } + + void checkSourceLocation(JoinPoint.StaticPart jp) { // todo: provide caller context? + checkSourceLocation(jp.getSourceLocation(), jp.toString()); + } + + /** aborted attempt to check jp by name for jp without enclosing */ + private static boolean expectSourceLocation(JoinPoint.StaticPart jp) { + if (null == jp) { + return false; + } else { + String name = jp.toString(); + if (-1 != name.indexOf("TargetClass.<init>")) { + return false; + } + } + return true; // todo: overinclusive + } + + private boolean inInitCode(JoinPoint.StaticPart jp) { + return (-1 != jp.toString().indexOf("<init>")); + } + + void checkSourceLocation(SourceLocation sl, String context) { + if (sl == null) { + Signal.failed(context + "null SourceLocation"); + } else { + int i = sl.getLine(); + if (0 > i) { + Signal.failed(context + " line<0: " + i); + } + i = sl.getColumn(); + if (0 > i) { + Signal.failed(context + " column<0: " + i); + } + } + } +} // Aspect + +/** more readable to put expected messages at end of file */ +class Const { + // todo: EXPECTED will break if JoinPoint.StaticPart.toString() changes + public static final String[] EXPECTED = new String[] + { + "before AllTargetJoinPoints staticinitialization(TargetClass.<clinit>)" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints get(String TargetClass.staticString)" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints initialization(TargetClass())" + , "before AllTargetJoinPoints execution(TargetClass.<init>)" + , "before AllTargetJoinPoints set(String TargetClass.string)" + , "before AllTargetJoinPoints execution(TargetClass())" + , "before AllTargetJoinPoints execution(void TargetClass.run())" + , "before AllTargetJoinPoints call(void TargetClass.internalRun())" + , "before AllTargetJoinPoints execution(void TargetClass.internalRun())" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints call(void TargetClass.staticRun())" + , "before AllTargetJoinPoints execution(void TargetClass.staticRun())" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints get(String TargetClass.staticString)" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints call(TargetClass())" + , "before AllTargetJoinPoints initialization(TargetClass())" + , "before AllTargetJoinPoints execution(TargetClass.<init>)" + , "before AllTargetJoinPoints set(String TargetClass.string)" + , "before AllTargetJoinPoints execution(TargetClass())" + , "before AllTargetJoinPoints call(String java.lang.Object.toString())" + , "before AllTargetJoinPoints set(String TargetClass.staticString)" + , "before AllTargetJoinPoints get(String TargetClass.staticString)" + , "before AllTargetJoinPoints get(String TargetClass.string)" + , "before AllTargetJoinPoints set(String TargetClass.string)" + , "before AllTargetJoinPoints call(java.lang.Error(String))" + , "before AllTargetJoinPoints handler(catch(Error))" + , "before AllTargetJoinPoints call(void Signal.found(String))" + , "caught" + }; + +} diff --git a/tests/new/NestedSyncWithResult.java b/tests/new/NestedSyncWithResult.java new file mode 100644 index 000000000..6acf814b5 --- /dev/null +++ b/tests/new/NestedSyncWithResult.java @@ -0,0 +1,77 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#601 VerifyError if nested sync returning result */ +public class NestedSyncWithResult { + public static boolean holdA; + public static boolean aWaiterDone; + public static boolean aHolderDone; + public static void main(String[] args) { + int result = Bug.bug(); + Tester.check(0 == result, "0 == result"); + checkSynchronization(); + Tester.checkAllEvents(); + } + + public static void checkSynchronization() { + final StringBuffer sb = new StringBuffer(); + Tester.expectEvent("holding A; releasing A; invoked bug; "); + final boolean[] holdAstarted = new boolean[] { false }; + holdA = true; + Runnable aHolder = new Runnable() { + public void run() { + boolean wroteWait = false; + synchronized (Bug.lockB) { + holdAstarted[0] = true; + while (holdA) { + if (!wroteWait) { + wroteWait = true; + sb.append("holding A; "); + } + sleep(); + } + sb.append("releasing A; "); + } + aHolderDone = true; + } + }; + Runnable aWaiter = new Runnable() { + public void run() { + while (!holdAstarted[0]) { + sleep(); + } + Bug.bug(); + sb.append("invoked bug; "); + aWaiterDone = true; + } + }; + new Thread(aHolder).start(); + new Thread(aWaiter).start(); + sleep(); + holdA = false; + while (!aWaiterDone && !aHolderDone) { + sleep(); + } + Tester.event(sb.toString()); + //System.err.println("got: " + sb.toString()); + } + + public static void sleep() { + try { + Thread.currentThread().sleep(300); + } catch (InterruptedException e) { + } // ignore + } +} + +class Bug { + public static Object lockA = new Object(); + public static Object lockB = new Object(); + + static int bug() { + synchronized (lockA) { + synchronized (lockB) { + return 0; + } + } + } +} diff --git a/tests/new/NewAnonymous.java b/tests/new/NewAnonymous.java new file mode 100644 index 000000000..71f0edcb6 --- /dev/null +++ b/tests/new/NewAnonymous.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +public class NewAnonymous { + public static void main(String[] args) { + } +} + + +class C { + private String f = "fC"; + public void m(final String s) { + new Runnable() { + public void run() { + System.out.println(s+":"+f); + } + }.run(); + } +} + +aspect A { + before(): call(*.new()) { + System.out.println("new Runnable"); + } +} diff --git a/tests/new/NewSiteAdvice.java b/tests/new/NewSiteAdvice.java new file mode 100644 index 000000000..1534c2454 --- /dev/null +++ b/tests/new/NewSiteAdvice.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.Tester; + +import java.rmi.*; +import java.rmi.server.UnicastRemoteObject; + +public class NewSiteAdvice { + + public static void main(String[] args) { test(); } + + NewSiteAdvice() throws RemoteException { } + + /* here's another comment */ + public static void test() { + Tester.checkEqual(new NewSiteAdvice().go(), "ran", "rmi exception intercepted"); + Tester.check(new Integer(42) == A.cached42, "caching new 42"); + Tester.check("around NewSiteAdvice"); + } + + /** this is the way to make things go **/ + String go() { + return "ran"; // and an eol commment + } +} +aspect A { + pointcut makeNewSiteAdvice(): + within(NewSiteAdvice) && call(NewSiteAdvice.new()); + + declare soft: RemoteException: makeNewSiteAdvice(); + + NewSiteAdvice around(): makeNewSiteAdvice() { + NewSiteAdvice result = null; + try { + result = proceed(); + } catch (RemoteException e){ + } + + Tester.note("around NewSiteAdvice"); + return result; + } + + Integer around(int i): + args(i) && call(Integer.new(int)) && !within(A) { + if (i == 42) return cached42; + return proceed(i); + } + + + static Integer cached42 = new Integer(42); +} + diff --git a/tests/new/NoCalledMethodName.java b/tests/new/NoCalledMethodName.java new file mode 100644 index 000000000..6b5bf8117 --- /dev/null +++ b/tests/new/NoCalledMethodName.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.*; + +/* + * Advice is not getting the calledMethodName. + */ + +public class NoCalledMethodName { + public static void main(String[] args) { + new NoCalledMethodName().go(args); + } + + void go(String[] args) { + Tester.check("Go was called"); + } +} + +aspect NoCalledMethodNameAspect of eachobject(instanceof(NoCalledMethodName)) { + + pointcut p2(NoCalledMethodName f): receptions(void go(..)) && instanceof(f); + + around(NoCalledMethodName f) returns void: p2(f) { + String s = thisJoinPoint.methodName; + } +} diff --git a/tests/new/NoLang.java b/tests/new/NoLang.java new file mode 100644 index 000000000..4c2c4a24a --- /dev/null +++ b/tests/new/NoLang.java @@ -0,0 +1,7 @@ +package java.lang; + +public class Object { +} + +public class String { +} diff --git a/tests/new/NoReturnInProceed.java b/tests/new/NoReturnInProceed.java new file mode 100644 index 000000000..cd4fe8997 --- /dev/null +++ b/tests/new/NoReturnInProceed.java @@ -0,0 +1,20 @@ + +class BaseApp { + int i; + int get() { return i; } +} + +/** @testStatement If there is no return in around returning a result, javac catches error */ +public class NoReturnInProceed { + public static void main(String[] args) { + BaseApp target = new BaseApp(); + target.get(); + } +} + +aspect Aspect { + int around() : get(int BaseApp.i) { + proceed(); + // return proceed(); + } +} diff --git a/tests/new/NonAlphaSignaturePatternCE.java b/tests/new/NonAlphaSignaturePatternCE.java new file mode 100644 index 000000000..dde7b3d2a --- /dev/null +++ b/tests/new/NonAlphaSignaturePatternCE.java @@ -0,0 +1,98 @@ +import org.aspectj.testing.Tester; + +//PR#493 +public class NonAlphaSignaturePatternCE { + public static void main(String[] args) { + C1 c = new C1(); + c.m1(); + c.update(); + Tester.checkAllEventsIgnoreDups(); + } +} + +class C1 { + public int fi1; + public float f1 = 1.f; + void cflowbelow() { } // cflowbelow join points; also test keyword collision + void m1() { String s = ("m1 "); cflowbelow(); } + void update() { + fi1 = 1; // set join point + int i = fi1; // get join point + } +} +// PR#493 Signature patterns without leading alphabetic characters +aspect A { + static { + // expect all of these messages when test runs + Tester.expectEvent("call m1"); + Tester.expectEvent("before call *1"); + Tester.expectEvent("before p1"); + Tester.expectEvent("before execution *1"); + Tester.expectEvent("initialization *1"); + Tester.expectEvent("staticinitialization *1"); + Tester.expectEvent("withincode *1"); + Tester.expectEvent("cflow *1"); + Tester.expectEvent("cflowbelow *1"); + Tester.expectEvent("set *1"); + Tester.expectEvent("get *1"); + } + after () : call(void m1()) { Tester.event("call m1"); } // normal case + + // @testTarget signature.patterns.leadingnumeric.pointcut + pointcut p1(): call(void *1()) ; // incorrect compiler error here PR#493 + + before () : p1(){ // incorrect compiler error here PR#493 + Tester.event("before p1"); + } + // @testTarget signature.patterns.leadingnumeric.anonpointcut.call + before () : call(void *1()) { // incorrect compiler error here PR#493 + Tester.event("before call *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.execution + after () : execution(void *1()) {// incorrect compiler error here PR#493 + Tester.event("before execution *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.initialization + after () : initialization(*1.new()) {// incorrect compiler error here PR#493 + Tester.event("initialization *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.staticinitialization + before () : staticinitialization(*1) {// incorrect compiler error here PR#493 + Tester.event("staticinitialization *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.withincode + before () : withincode(void C1.*1()) {// incorrect compiler error here PR#493 + Tester.event("withincode *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.set + before () : set(int C*1.fi1) {// incorrect compiler error here PR#493 + Tester.event("set *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.get + before () : get(int *.*1) {// incorrect compiler error here PR#493 + Tester.event("get *1"); + } + + // @testTarget signature.patterns.leadingnumeric.anonpointcut.set +} + +/** + * Moved advice on cflow to B in order to continue testing this + * as well as possible without forcing a StackOverflowError + */ +aspect B { + // @testTarget signature.patterns.leadingnumeric.anonpointcut.cflowbelow + before () : cflowbelow(execution(void *1.m1())) && !within(B) { + Tester.event("cflowbelow *1"); + } + // @testTarget signature.patterns.leadingnumeric.anonpointcut.cflow + before () : cflow(execution(void *1.m1())) && !within(B) { + Tester.event("cflow *1"); + } +} diff --git a/tests/new/NonStaticInnerInterfaces_PR386.java b/tests/new/NonStaticInnerInterfaces_PR386.java new file mode 100644 index 000000000..2af9878b7 --- /dev/null +++ b/tests/new/NonStaticInnerInterfaces_PR386.java @@ -0,0 +1,31 @@ +import org.aspectj.testing.*; + +public class NonStaticInnerInterfaces_PR386 { + public static void main(String[] args) { + A a = new A(); + A.I ab = new C(); + C c = new C(); + a.go(); + ab.go(); + c.go(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("A0,C1,C2,"); + } +} + +class B { + static int j = 0; +} + +class A { + public interface I { void go(); } + public void go() { Tester.event("A" + (B.j++)); } + +} + +class C extends A implements I { + public void go() { Tester.event("C" + (B.j++)); } +} + diff --git a/tests/new/NonexistentFieldInitializers.java b/tests/new/NonexistentFieldInitializers.java new file mode 100644 index 000000000..d0ec6ebc4 --- /dev/null +++ b/tests/new/NonexistentFieldInitializers.java @@ -0,0 +1,23 @@ +// join points in field initializers aren't showing up. + +import org.aspectj.testing.Tester; + +public class NonexistentFieldInitializers { + public static void main(String[] args) { + new NonexistentFieldInitializers(); + Tester.checkEqual(A.i, 2, "Not finding some join points in initializers"); + } + + static Object so = System.in; + + Object o = System.in; +} + +aspect A { + static int i; + + before(): get(* System.in) { + i++; + } +} + diff --git a/tests/new/NonexistentInitializers.java b/tests/new/NonexistentInitializers.java new file mode 100644 index 000000000..2ba43c784 --- /dev/null +++ b/tests/new/NonexistentInitializers.java @@ -0,0 +1,43 @@ +// join points in static/dynamic initializers aren't showing up. +import org.aspectj.testing.Tester; + +public class NonexistentInitializers { + + + public static void main(String[] args) { + new NonexistentInitializers(); + org.aspectj.testing.Tester.checkEqual + (A.i, 4, "Not finding some join points in initializers"); + org.aspectj.testing.Tester.checkEqual(A.foo, 2, "foo"); + org.aspectj.testing.Tester.checkEqual(A.get, 2, "get"); + } + + static void foo() {} + static void bar(Object o) {} + { + bar(System.in); + NonexistentInitializers.foo(); + } + static { + bar(System.in); + NonexistentInitializers.foo(); + } + + +} + +aspect A { + static int i = 0; + static int foo = 0; + static int get = 0; + + before(): call(void NonexistentInitializers.foo()) { + i++; + foo++; + } + before(): get(* System.in) { + i++; + get++; + } +} + diff --git a/tests/new/NonstaticInnerClassesInAspects.java b/tests/new/NonstaticInnerClassesInAspects.java new file mode 100644 index 000000000..70b7453a8 --- /dev/null +++ b/tests/new/NonstaticInnerClassesInAspects.java @@ -0,0 +1,85 @@ +import org.aspectj.testing.Tester; +public class NonstaticInnerClassesInAspects { + public static void main(String[] args) { + new NonstaticInnerClassesInAspects().realMain(args); + } + public void realMain(String[] args) { + new C().c(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("A$Inner-before-c"); + Tester.expectEvent("A$Inner$InnerInner-before-c"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-before-c"); + Tester.expectEvent("A$Inner-after-c"); + Tester.expectEvent("A$Inner$InnerInner-after-c"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-after-c"); + Tester.expectEvent("A$Inner-around-c"); + Tester.expectEvent("A$Inner$InnerInner-around-c"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-around-c"); + Tester.expectEvent("A$Inner-before-d"); + Tester.expectEvent("A$Inner$InnerInner-before-d"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-before-d"); + Tester.expectEvent("A$Inner-after-d"); + Tester.expectEvent("A$Inner$InnerInner-after-d"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-after-d"); + Tester.expectEvent("A$Inner-around-d"); + Tester.expectEvent("A$Inner$InnerInner-around-d"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-around-d"); + Tester.expectEvent("A$Inner-before-x"); + Tester.expectEvent("A$Inner$InnerInner-before-x"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-before-x"); + Tester.expectEvent("A$Inner-after-x"); + Tester.expectEvent("A$Inner$InnerInner-after-x"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-after-x"); + Tester.expectEvent("A$Inner-around-x"); + Tester.expectEvent("A$Inner$InnerInner-around-x"); + Tester.expectEvent("A$Inner$InnerInner$InnerInnerInner-around-x"); + } +} + +class C { + public void c() { d(); } + public void d() { } +} + +aspect A { + + pointcut c(): target(C) && call(void c()); + pointcut d(): call(void C.d()); + pointcut x(): target(C) && execution(void c()); + + after() : c() { new Inner().i("after-c"); } + after() : d() { new Inner().i("after-d"); } + after() : x() { new Inner().i("after-x"); } + + before() : c() { new Inner().i("before-c"); } + before() : d() { new Inner().i("before-d"); } + before() : x() { new Inner().i("before-x"); } + + void around(): c() { new Inner().i("around-c"); proceed(); } + void around(): d() { new Inner().i("around-d"); proceed(); } + void around(): x() { new Inner().i("around-x"); proceed(); } + + class Inner { + void i(String s) { + a(s,this); + new InnerInner().i(s); + } + class InnerInner { + void i(String s) { + a(s,this); + new InnerInnerInner().i(s); + } + class InnerInnerInner { + void i(String s) { + a(s,this); + } + } + } + } + + public static void a(String s, Object o) { + Tester.event(o.getClass().getName() + "-" + s); + } +} diff --git a/tests/new/NotAndDeclaringTypes.java b/tests/new/NotAndDeclaringTypes.java new file mode 100644 index 000000000..a44825428 --- /dev/null +++ b/tests/new/NotAndDeclaringTypes.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.Tester; + +public class NotAndDeclaringTypes { + + public static void main (String args []) { + Rectangle r = new Rectangle (); + Square s = new Square (); + + r.getSurface(); + Tester.checkAndClearEvents(new String[] { "advice" }); + + s.getSurface(); + + Tester.checkAndClearEvents(new String[] { }); + } +} + +class Rectangle { + public String toString () { return "Rectangle"; } + public int getSurface () { return 100; } +} + +class Square extends Rectangle { + public String toString () { return "Square"; } + public int getSurface () { return 200; } +} + +aspect Concern { + + pointcut pc () : call (int Rectangle.getSurface ()) + && !call (int Square.getSurface ()); + + before () : pc () { + Tester.event("advice"); + } +} + diff --git a/tests/new/NotAndPointcut.java b/tests/new/NotAndPointcut.java new file mode 100644 index 000000000..4dc0e48c9 --- /dev/null +++ b/tests/new/NotAndPointcut.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; + +public class NotAndPointcut { + static String str = ""; + + public static void main(String args[]){ + new NotAndPointcut().showBug(); + Tester.checkEqual(str, "ran", "advice didn't run"); + } + + public void showBug(){ + } +} + +aspect BugInPCD { + pointcut p(): execution(* NotAndPointcut.showBug(..)) && + ! ( target(NotAndPointcut) && call(* NotAndPointcut.*(..))); + + before(): p(){ + NotAndPointcut.str += "ran"; + } +} diff --git a/tests/new/NotCharInPointcut.java b/tests/new/NotCharInPointcut.java new file mode 100644 index 000000000..c44b56fd8 --- /dev/null +++ b/tests/new/NotCharInPointcut.java @@ -0,0 +1,59 @@ +// PR#208 ! modifier in pointcut + +public class NotCharInPointcut { + public static void main(String[] args) throws Exception { + for (int i = 0; i < methods.length; i++) { + org.aspectj.testing.Tester.expectEvent(methods[i]); + C.class.getMethod(methods[i], new Class[]{}). + invoke(new C(), new Object[]{}); + } + } + + final static String[] methods = { + "_void", + "_boolean", + "_byte", + "_char", + "_short", + "_int", + "_long", + "_float", + "_double", + "_Object", + }; +} + +class C { + private void s(String s) { org.aspectj.testing.Tester.event(s); } + public void _void() { s("_void"); } + public boolean _boolean() { s("_boolean"); return (boolean)false;} + public byte _byte() { s("_byte"); return (byte)0;} + public char _char() { s("_char"); return (char)0;} + public short _short() { s("_short"); return (short)0;} + public int _int() { s("_int"); return (int)0;} + public long _long() { s("_long"); return (long)0;} + public float _float() { s("_float"); return (float)0;} + public double _double() { s("_double"); return (double)0;} + public Object _Object() { s("_Object"); return this; } +} + +aspect A { + + pointcut pcut1(NotCharInPointcut t): + this(t) && execution(!* _*()); + + pointcut pcut2(NotCharInPointcut t): + this(t) && !this(NotCharInPointcut) && execution(!* _*()); + + pointcut pcut3(NotCharInPointcut t): + pcut1(t) || pcut2(t); + + before(NotCharInPointcut t): pcut1(t) { s("1:"+thisJoinPoint); } + before(): pcut2(*) { s("2:"+thisJoinPoint); } + before(NotCharInPointcut t): pcut3(t) { s("3:"+thisJoinPoint); } + + private final static void s(Object s) { + org.aspectj.testing.Tester.check(false, "should be in "+s); + } + +} diff --git a/tests/new/NotThis.java b/tests/new/NotThis.java new file mode 100644 index 000000000..413bcbd94 --- /dev/null +++ b/tests/new/NotThis.java @@ -0,0 +1,61 @@ +import org.aspectj.testing.Tester; + +/** From PR #496 from Mark Skipper + */ + +public class NotThis { + + public static void main(String[] args){ + new NotThis().go(); + } + + void go(){ + A a = new A(this); + a.go(); + Tester.checkEqual(Q.buf.toString(), "foo:within(A):this(A):!within(B):!this(B):"); + Q.buf = new StringBuffer(); + B b = new B(this); + b.go(); + Tester.checkEqual(Q.buf.toString(), "foo:"); + } + + public void foo(Object o){ + Q.buf.append("foo:"); + } +} + +class A { + NotThis t; + + A(NotThis n){ t = n; } + + void go(){ t.foo(this); } +} + + +class B{ + + NotThis t; + + B(NotThis n){ t = n; } + + void go(){ t.foo(this); } + +} + + +aspect Q { + static StringBuffer buf = new StringBuffer(); + after(): call(void NotThis.foo(Object)) && within(A) { + buf.append("within(A):"); + } + after(): call(void NotThis.foo(Object)) && this(A) { + buf.append("this(A):"); + } + after(): call(void NotThis.foo(Object)) && !within(B) { + buf.append("!within(B):"); + } + after(): call(void NotThis.foo(Object)) && !this(B) { + buf.append("!this(B):"); + } +} diff --git a/tests/new/NulIOException.java b/tests/new/NulIOException.java new file mode 100644 index 000000000..e10595c20 --- /dev/null +++ b/tests/new/NulIOException.java @@ -0,0 +1,23 @@ + +import org.aspectj.testing.Tester; + +class Super { + Super(Object o){} +} + +/** windows treats filename "nul" specially, like /dev/null on unix */ +public class NulIOException extends Super { + + public static void main(String[] args) { + Object o = new NulIOException(nul); // parms: IOException + Tester.check(false, "expecting compiler error"); + Object p = nul; // reference: expect CE here, not IOException + } + + NulIOException() { super(nul); } + + // super parms: expect CE here, not IOException + NulIOException(Object o) { super(o); } + // don't attempt to read nul on windows +} + diff --git a/tests/new/NulIOException2.java b/tests/new/NulIOException2.java new file mode 100644 index 000000000..af42b4eed --- /dev/null +++ b/tests/new/NulIOException2.java @@ -0,0 +1,16 @@ + +import org.aspectj.testing.Tester; + +class Super { + Super(Object o){} +} +/** windows treats filename "nul" specially, like /dev/null on unix */ +public class NulIOException2 extends Super { + public static void main(String[] args) { + Object nul = new Object(); // @testcase nul as identifier + Object p = new NulIOException2(nul); + Tester.check(null != nul, "null nul"); + Tester.check(null != p, "null NulIOException2"); + } + NulIOException2(Object o) { super(o); } +} diff --git a/tests/new/NulIOException3.java b/tests/new/NulIOException3.java new file mode 100644 index 000000000..19fd18c1d --- /dev/null +++ b/tests/new/NulIOException3.java @@ -0,0 +1,23 @@ + +import org.aspectj.testing.Tester; + +/** windows treats filename "nul" specially, like /dev/null on unix */ +public class NulIOException3 { + public static void main(String[] args) { + } +} +class TodoClassFormatError { // no ref to this in NulIOException3 - VM fails to load nul + public static void main(String[] args) { + Class c = nul.class; // @testcase nul as class literal + Object q = new nul(); // @testcase nul as constructor/class name + Class C = subnul.class; + Object r = new subnul(); + Tester.check(null != c, "null nul class"); + Tester.check(null != q, "null nul object"); + Tester.check(null != C, "null subnul class"); + Tester.check(null != r, "null subnul object"); + } +} +class nul { } // @testcase nul as class name + +class subnul extends nul { } // @testcase nul as reference to class name diff --git a/tests/new/NullPointerOnGets.java b/tests/new/NullPointerOnGets.java new file mode 100644 index 000000000..e4856db73 --- /dev/null +++ b/tests/new/NullPointerOnGets.java @@ -0,0 +1,512 @@ +import org.aspectj.testing.*; + +public class NullPointerOnGets { + public static void main(String[] args) { + Strings.add(); + C.go(); + Ints.add(); + Tester.checkAllEventsIgnoreDups(); + } + + static { + Tester.expectEvent("static"); + } +} + +class C { + public String str0 = "str0"; + String str1 = "str1"; + protected String str2 = "str2"; + private String str3 = "str3"; + + public static String sstr0 = "sstr0"; + static String sstr1 = "sstr1"; + protected static String sstr2 = "sstr2"; + private static String sstr3 = "sstr3"; + + public int int0 = 1; + int int1 = 2; + protected int int2 = 3; + private int int3 = 4; + + public static int sint0 = -1; + static int sint1 = -2; + protected static int sint2 = -3; + private static int sint3 = -4; + + static void go() { + Tester.event("static"); + C c = new C(); + eq(c.str0, "str0"); c.str0 = "str00"; eq(c.str0, "str00"); + eq(c.str1, "str1"); c.str1 = "str11"; eq(c.str1, "str11"); + eq(c.str2, "str2"); c.str2 = "str22"; eq(c.str2, "str22"); + eq(c.str3, "str3"); c.str3 = "str33"; eq(c.str3, "str33"); + + eq(C.sstr0, "sstr0"); C.sstr0 = "sstr00"; eq(C.sstr0, "sstr00"); + eq(C.sstr1, "sstr1"); C.sstr1 = "sstr11"; eq(C.sstr1, "sstr11"); + eq(C.sstr2, "sstr2"); C.sstr2 = "sstr22"; eq(C.sstr2, "sstr22"); + eq(C.sstr3, "sstr3"); C.sstr3 = "sstr33"; eq(C.sstr3, "sstr33"); + + eq(c.int0, 1); c.int0 = 100; eq(c.int0, 100); + eq(c.int1, 2); c.int1 = 111; eq(c.int1, 111); + eq(c.int2, 3); c.int2 = 122; eq(c.int2, 122); + eq(c.int3, 4); c.int3 = 133; eq(c.int3, 133); + + eq(C.sint0, -1); C.sint0 = 200; eq(C.sint0, 200); + eq(C.sint1, -2); C.sint1 = 211; eq(C.sint1, 211); + eq(C.sint2, -3); C.sint2 = 222; eq(C.sint2, 222); + eq(C.sint3, -4); C.sint3 = 233; eq(C.sint3, 233); + } + + private static void eq(int i0, int i1) {Tester.checkEqual(i0,i1);} + private static void eq(String s0, String s1) {Tester.checkEqual(s0,s1);} +} + +aspect StringAspect { + + static void a(String s) { Tester.event(s); } + + //pointcuts + pointcut gets_String_str0(): get(String C.str0);//[s]; + pointcut gets_String_str1(): get(String C.str1); //[s]; + pointcut gets_String_str2(): get(String C.str2); //[s]; + pointcut gets_String_str3(): get(String C.str3); //[s]; + pointcut gets_String_str0b(): get(String C.str0); //[]; + pointcut gets_String_str1b(): get(String C.str1); //[]; + pointcut gets_String_str2b(): get(String C.str2); //[]; + pointcut gets_String_str3b(): get(String C.str3); //[]; + pointcut sets_String_str0(): set(String C.str0); //[s][]; + pointcut sets_String_str1(): set(String C.str1); //[s][]; + pointcut sets_String_str2(): set(String C.str2); //[s][]; + pointcut sets_String_str3(): set(String C.str3); //[s][]; + pointcut sets_String_str0b(): set(String C.str0); //[][s]; + pointcut sets_String_str1b(): set(String C.str1); //[][s]; + pointcut sets_String_str2b(): set(String C.str2); //[][s]; + pointcut sets_String_str3b(): set(String C.str3); //[][s]; + pointcut sets_String_str0c(): set(String C.str0); //[o][s]; + pointcut sets_String_str1c(): set(String C.str1); //[o][s]; + pointcut sets_String_str2c(): set(String C.str2); //[o][s]; + pointcut sets_String_str3c(): set(String C.str3); //[o][s]; + pointcut gets_String_sstr0(): get(String C.str0); //[s]; + pointcut gets_String_sstr1(): get(String C.str1); //[s]; + pointcut gets_String_sstr2(): get(String C.str2); //[s]; + pointcut gets_String_sstr3(): get(String C.str3); //[s]; + pointcut gets_String_sstr0b(): get(String C.str0); //[]; + pointcut gets_String_sstr1b(): get(String C.str1); //[]; + pointcut gets_String_sstr2b(): get(String C.str2); //[]; + pointcut gets_String_sstr3b(): get(String C.str3); //[]; + pointcut sets_String_sstr0(): set(String C.str0); //[s][]; + pointcut sets_String_sstr1(): set(String C.str1); //[s][]; + pointcut sets_String_sstr2(): set(String C.str2); //[s][]; + pointcut sets_String_sstr3(): set(String C.str3); //[s][]; + pointcut sets_String_sstr0b(): set(String C.str0); //[][s]; + pointcut sets_String_sstr1b(): set(String C.str1); //[][s]; + pointcut sets_String_sstr2b(): set(String C.str2); //[][s]; + pointcut sets_String_sstr3b(): set(String C.str3); //[][s]; + pointcut sets_String_sstr0c(): set(String C.str0); //[o][s]; + pointcut sets_String_sstr1c(): set(String C.str1); //[o][s]; + pointcut sets_String_sstr2c(): set(String C.str2); //[o][s]; + pointcut sets_String_sstr3c(): set(String C.str3); //[o][s]; + + //befores + before(): gets_String_str0() { a("b gets_String_str0"); } + before(): gets_String_str1() { a("b gets_String_str1"); } + before(): gets_String_str2() { a("b gets_String_str2"); } + before(): gets_String_str3() { a("b gets_String_str3"); } + before(): gets_String_str0b() { a("b gets_String_str0b"); } + before(): gets_String_str1b() { a("b gets_String_str1b"); } + before(): gets_String_str2b() { a("b gets_String_str2b"); } + before(): gets_String_str3b() { a("b gets_String_str3b"); } + before(): sets_String_str0() { a("b sets_String_str0"); } + before(): sets_String_str1() { a("b sets_String_str1"); } + before(): sets_String_str2() { a("b sets_String_str2"); } + before(): sets_String_str3() { a("b sets_String_str3"); } + before(): sets_String_str0b() { a("b sets_String_str0b"); } + before(): sets_String_str1b() { a("b sets_String_str1b"); } + before(): sets_String_str2b() { a("b sets_String_str2b"); } + before(): sets_String_str3b() { a("b sets_String_str3b"); } + before(): sets_String_str0c() { a("b sets_String_str0c"); } + before(): sets_String_str1c() { a("b sets_String_str1c"); } + before(): sets_String_str2c() { a("b sets_String_str2c"); } + before(): sets_String_str3c() { a("b sets_String_str3c"); } + before(): gets_String_sstr0() { a("b gets_String_sstr0"); } + before(): gets_String_sstr1() { a("b gets_String_sstr1"); } + before(): gets_String_sstr2() { a("b gets_String_sstr2"); } + before(): gets_String_sstr3() { a("b gets_String_sstr3"); } + before(): gets_String_sstr0b() { a("b gets_String_sstr0b"); } + before(): gets_String_sstr1b() { a("b gets_String_sstr1b"); } + before(): gets_String_sstr2b() { a("b gets_String_sstr2b"); } + before(): gets_String_sstr3b() { a("b gets_String_sstr3b"); } + before(): sets_String_sstr0() { a("b sets_String_sstr0"); } + before(): sets_String_sstr1() { a("b sets_String_sstr1"); } + before(): sets_String_sstr2() { a("b sets_String_sstr2"); } + before(): sets_String_sstr3() { a("b sets_String_sstr3"); } + before(): sets_String_sstr0b() { a("b sets_String_sstr0b"); } + before(): sets_String_sstr1b() { a("b sets_String_sstr1b"); } + before(): sets_String_sstr2b() { a("b sets_String_sstr2b"); } + before(): sets_String_sstr3b() { a("b sets_String_sstr3b"); } + before(): sets_String_sstr0c() { a("b sets_String_sstr0c"); } + before(): sets_String_sstr1c() { a("b sets_String_sstr1c"); } + before(): sets_String_sstr2c() { a("b sets_String_sstr2c"); } + before(): sets_String_sstr3c() { a("b sets_String_sstr3c"); } + + //end-befores + + //arounds + String around(): gets_String_str0() { a("a gets_String_str0"); return proceed(); } + String around(): gets_String_str1() { a("a gets_String_str1"); return proceed(); } + String around(): gets_String_str2() { a("a gets_String_str2"); return proceed(); } + String around(): gets_String_str3() { a("a gets_String_str3"); return proceed(); } + String around(): gets_String_str0b() { a("a gets_String_str0b"); return proceed(); } + String around(): gets_String_str1b() { a("a gets_String_str1b"); return proceed(); } + String around(): gets_String_str2b() { a("a gets_String_str2b"); return proceed(); } + String around(): gets_String_str3b() { a("a gets_String_str3b"); return proceed(); } + String around(): sets_String_str0() { a("a sets_String_str0"); return proceed(); } + String around(): sets_String_str1() { a("a sets_String_str1"); return proceed(); } + String around(): sets_String_str2() { a("a sets_String_str2"); return proceed(); } + String around(): sets_String_str3() { a("a sets_String_str3"); return proceed(); } + String around(): sets_String_str0b() { a("a sets_String_str0b"); return proceed(); } + String around(): sets_String_str1b() { a("a sets_String_str1b"); return proceed(); } + String around(): sets_String_str2b() { a("a sets_String_str2b"); return proceed(); } + String around(): sets_String_str3b() { a("a sets_String_str3b"); return proceed(); } + String around(): sets_String_str0c() { a("a sets_String_str0c"); return proceed(); } + String around(): sets_String_str1c() { a("a sets_String_str1c"); return proceed(); } + String around(): sets_String_str2c() { a("a sets_String_str2c"); return proceed(); } + String around(): sets_String_str3c() { a("a sets_String_str3c"); return proceed(); } + String around(): gets_String_sstr0() { a("a gets_String_sstr0"); return proceed(); } + String around(): gets_String_sstr1() { a("a gets_String_sstr1"); return proceed(); } + String around(): gets_String_sstr2() { a("a gets_String_sstr2"); return proceed(); } + String around(): gets_String_sstr3() { a("a gets_String_sstr3"); return proceed(); } + String around(): gets_String_sstr0b() { a("a gets_String_sstr0b"); return proceed(); } + String around(): gets_String_sstr1b() { a("a gets_String_sstr1b"); return proceed(); } + String around(): gets_String_sstr2b() { a("a gets_String_sstr2b"); return proceed(); } + String around(): gets_String_sstr3b() { a("a gets_String_sstr3b"); return proceed(); } + String around(): sets_String_sstr0() { a("a sets_String_sstr0"); return proceed(); } + String around(): sets_String_sstr1() { a("a sets_String_sstr1"); return proceed(); } + String around(): sets_String_sstr2() { a("a sets_String_sstr2"); return proceed(); } + String around(): sets_String_sstr3() { a("a sets_String_sstr3"); return proceed(); } + String around(): sets_String_sstr0b() { a("a sets_String_sstr0b"); return proceed(); } + String around(): sets_String_sstr1b() { a("a sets_String_sstr1b"); return proceed(); } + String around(): sets_String_sstr2b() { a("a sets_String_sstr2b"); return proceed(); } + String around(): sets_String_sstr3b() { a("a sets_String_sstr3b"); return proceed(); } + String around(): sets_String_sstr0c() { a("a sets_String_sstr0c"); return proceed(); } + String around(): sets_String_sstr1c() { a("a sets_String_sstr1c"); return proceed(); } + String around(): sets_String_sstr2c() { a("a sets_String_sstr2c"); return proceed(); } + String around(): sets_String_sstr3c() { a("a sets_String_sstr3c"); return proceed(); } + //end-arounds + + //afters + after(): gets_String_str0() { a("f gets_String_str0"); } + after(): gets_String_str1() { a("f gets_String_str1"); } + after(): gets_String_str2() { a("f gets_String_str2"); } + after(): gets_String_str3() { a("f gets_String_str3"); } + after(): gets_String_str0b() { a("f gets_String_str0b"); } + after(): gets_String_str1b() { a("f gets_String_str1b"); } + after(): gets_String_str2b() { a("f gets_String_str2b"); } + after(): gets_String_str3b() { a("f gets_String_str3b"); } + after(): sets_String_str0() { a("f sets_String_str0"); } + after(): sets_String_str1() { a("f sets_String_str1"); } + after(): sets_String_str2() { a("f sets_String_str2"); } + after(): sets_String_str3() { a("f sets_String_str3"); } + after(): sets_String_str0b() { a("f sets_String_str0b"); } + after(): sets_String_str1b() { a("f sets_String_str1b"); } + after(): sets_String_str2b() { a("f sets_String_str2b"); } + after(): sets_String_str3b() { a("f sets_String_str3b"); } + after(): sets_String_str0c() { a("f sets_String_str0c"); } + after(): sets_String_str1c() { a("f sets_String_str1c"); } + after(): sets_String_str2c() { a("f sets_String_str2c"); } + after(): sets_String_str3c() { a("f sets_String_str3c"); } + after(): gets_String_sstr0() { a("f gets_String_sstr0"); } + after(): gets_String_sstr1() { a("f gets_String_sstr1"); } + after(): gets_String_sstr2() { a("f gets_String_sstr2"); } + after(): gets_String_sstr3() { a("f gets_String_sstr3"); } + after(): gets_String_sstr0b() { a("f gets_String_sstr0b"); } + after(): gets_String_sstr1b() { a("f gets_String_sstr1b"); } + after(): gets_String_sstr2b() { a("f gets_String_sstr2b"); } + after(): gets_String_sstr3b() { a("f gets_String_sstr3b"); } + after(): sets_String_sstr0() { a("f sets_String_sstr0"); } + after(): sets_String_sstr1() { a("f sets_String_sstr1"); } + after(): sets_String_sstr2() { a("f sets_String_sstr2"); } + after(): sets_String_sstr3() { a("f sets_String_sstr3"); } + after(): sets_String_sstr0b() { a("f sets_String_sstr0b"); } + after(): sets_String_sstr1b() { a("f sets_String_sstr1b"); } + after(): sets_String_sstr2b() { a("f sets_String_sstr2b"); } + after(): sets_String_sstr3b() { a("f sets_String_sstr3b"); } + after(): sets_String_sstr0c() { a("f sets_String_sstr0c"); } + after(): sets_String_sstr1c() { a("f sets_String_sstr1c"); } + after(): sets_String_sstr2c() { a("f sets_String_sstr2c"); } + after(): sets_String_sstr3c() { a("f sets_String_sstr3c"); } + //end-afters +} + +class Strings { + + static void m(String s) { Tester.expectEvent(s); } + static void add() { + m("b gets_String_str0"); m("f gets_String_str0"); m("a gets_String_str0"); + m("b gets_String_str1"); m("f gets_String_str1"); m("a gets_String_str1"); + m("b gets_String_str2"); m("f gets_String_str2"); m("a gets_String_str2"); + m("b gets_String_str3"); m("f gets_String_str3"); m("a gets_String_str3"); + m("b gets_String_str0b"); m("f gets_String_str0b"); m("a gets_String_str0b"); + m("b gets_String_str1b"); m("f gets_String_str1b"); m("a gets_String_str1b"); + m("b gets_String_str2b"); m("f gets_String_str2b"); m("a gets_String_str2b"); + m("b gets_String_str3b"); m("f gets_String_str3b"); m("a gets_String_str3b"); + m("b sets_String_str0"); m("f sets_String_str0"); m("a sets_String_str0"); + m("b sets_String_str1"); m("f sets_String_str1"); m("a sets_String_str1"); + m("b sets_String_str2"); m("f sets_String_str2"); m("a sets_String_str2"); + m("b sets_String_str3"); m("f sets_String_str3"); m("a sets_String_str3"); + m("b sets_String_str0b"); m("f sets_String_str0b"); m("a sets_String_str0b"); + m("b sets_String_str1b"); m("f sets_String_str1b"); m("a sets_String_str1b"); + m("b sets_String_str2b"); m("f sets_String_str2b"); m("a sets_String_str2b"); + m("b sets_String_str3b"); m("f sets_String_str3b"); m("a sets_String_str3b"); + m("b sets_String_str0c"); m("f sets_String_str0c"); m("a sets_String_str0c"); + m("b sets_String_str1c"); m("f sets_String_str1c"); m("a sets_String_str1c"); + m("b sets_String_str2c"); m("f sets_String_str2c"); m("a sets_String_str2c"); + m("b sets_String_str3c"); m("f sets_String_str3c"); m("a sets_String_str3c"); + m("b gets_String_sstr0"); m("f gets_String_sstr0"); m("a gets_String_sstr0"); + m("b gets_String_sstr1"); m("f gets_String_sstr1"); m("a gets_String_sstr1"); + m("b gets_String_sstr2"); m("f gets_String_sstr2"); m("a gets_String_sstr2"); + m("b gets_String_sstr3"); m("f gets_String_sstr3"); m("a gets_String_sstr3"); + m("b gets_String_sstr0b"); m("f gets_String_sstr0b"); m("a gets_String_sstr0b"); + m("b gets_String_sstr1b"); m("f gets_String_sstr1b"); m("a gets_String_sstr1b"); + m("b gets_String_sstr2b"); m("f gets_String_sstr2b"); m("a gets_String_sstr2b"); + m("b gets_String_sstr3b"); m("f gets_String_sstr3b"); m("a gets_String_sstr3b"); + m("b sets_String_sstr0"); m("f sets_String_sstr0"); m("a sets_String_sstr0"); + m("b sets_String_sstr1"); m("f sets_String_sstr1"); m("a sets_String_sstr1"); + m("b sets_String_sstr2"); m("f sets_String_sstr2"); m("a sets_String_sstr2"); + m("b sets_String_sstr3"); m("f sets_String_sstr3"); m("a sets_String_sstr3"); + m("b sets_String_sstr0b"); m("f sets_String_sstr0b"); m("a sets_String_sstr0b"); + m("b sets_String_sstr1b"); m("f sets_String_sstr1b"); m("a sets_String_sstr1b"); + m("b sets_String_sstr2b"); m("f sets_String_sstr2b"); m("a sets_String_sstr2b"); + m("b sets_String_sstr3b"); m("f sets_String_sstr3b"); m("a sets_String_sstr3b"); + m("b sets_String_sstr0c"); m("f sets_String_sstr0c"); m("a sets_String_sstr0c"); + m("b sets_String_sstr1c"); m("f sets_String_sstr1c"); m("a sets_String_sstr1c"); + m("b sets_String_sstr2c"); m("f sets_String_sstr2c"); m("a sets_String_sstr2c"); + m("b sets_String_sstr3c"); m("f sets_String_sstr3c"); m("a sets_String_sstr3c"); + } +} + + +aspect IntAspect { + + static void a(String s) { Tester.event(s); } + + // start-non-static + pointcut gets_int_int0(): get(int C.int0); //[s]; + pointcut gets_int_int1(): get(int C.int1); //[s]; + pointcut gets_int_int2(): get(int C.int2); //[s]; + pointcut gets_int_int3(): get(int C.int3); //[s]; + pointcut gets_int_int0b(): get(int C.int0); //[]; + pointcut gets_int_int1b(): get(int C.int1); //[]; + pointcut gets_int_int2b(): get(int C.int2); //[]; + pointcut gets_int_int3b(): get(int C.int3); //[]; + pointcut sets_int_int0(): set(int C.int0); //[s][]; + pointcut sets_int_int1(): set(int C.int1); //[s][]; + pointcut sets_int_int2(): set(int C.int2); //[s][]; + pointcut sets_int_int3(): set(int C.int3); //[s][]; + pointcut sets_int_int0b(): set(int C.int0); //[][s]; + pointcut sets_int_int1b(): set(int C.int1); //[][s]; + pointcut sets_int_int2b(): set(int C.int2); //[][s]; + pointcut sets_int_int3b(): set(int C.int3); //[][s]; + pointcut sets_int_int0c(): set(int C.int0); //[o][s]; + pointcut sets_int_int1c(): set(int C.int1); //[o][s]; + pointcut sets_int_int2c(): set(int C.int2); //[o][s]; + pointcut sets_int_int3c(): set(int C.int3); //[o][s]; + pointcut gets_int_sint0(): get(int C.int0); //[s]; + pointcut gets_int_sint1(): get(int C.int1); //[s]; + pointcut gets_int_sint2(): get(int C.int2); //[s]; + pointcut gets_int_sint3(): get(int C.int3); //[s]; + pointcut gets_int_sint0b(): get(int C.int0); //[]; + pointcut gets_int_sint1b(): get(int C.int1); //[]; + pointcut gets_int_sint2b(): get(int C.int2); //[]; + pointcut gets_int_sint3b(): get(int C.int3); //[]; + pointcut sets_int_sint0(): set(int C.int0); //[s][]; + pointcut sets_int_sint1(): set(int C.int1); //[s][]; + pointcut sets_int_sint2(): set(int C.int2); //[s][]; + pointcut sets_int_sint3(): set(int C.int3); //[s][]; + pointcut sets_int_sint0b(): set(int C.int0); //[][s]; + pointcut sets_int_sint1b(): set(int C.int1); //[][s]; + pointcut sets_int_sint2b(): set(int C.int2); //[][s]; + pointcut sets_int_sint3b(): set(int C.int3); //[][s]; + pointcut sets_int_sint0c(): set(int C.int0); //[o][s]; + pointcut sets_int_sint1c(): set(int C.int1); //[o][s]; + pointcut sets_int_sint2c(): set(int C.int2); //[o][s]; + pointcut sets_int_sint3c(): set(int C.int3); //[o][s]; + //end-pointcuts + + before(): gets_int_int0() { a("b gets_int_int0"); } + before(): gets_int_int1() { a("b gets_int_int1"); } + before(): gets_int_int2() { a("b gets_int_int2"); } + before(): gets_int_int3() { a("b gets_int_int3"); } + before(): gets_int_int0b() { a("b gets_int_int0b"); } + before(): gets_int_int1b() { a("b gets_int_int1b"); } + before(): gets_int_int2b() { a("b gets_int_int2b"); } + before(): gets_int_int3b() { a("b gets_int_int3b"); } + before(): sets_int_int0() { a("b sets_int_int0"); } + before(): sets_int_int1() { a("b sets_int_int1"); } + before(): sets_int_int2() { a("b sets_int_int2"); } + before(): sets_int_int3() { a("b sets_int_int3"); } + before(): sets_int_int0b() { a("b sets_int_int0b"); } + before(): sets_int_int1b() { a("b sets_int_int1b"); } + before(): sets_int_int2b() { a("b sets_int_int2b"); } + before(): sets_int_int3b() { a("b sets_int_int3b"); } + before(): sets_int_int0c() { a("b sets_int_int0c"); } + before(): sets_int_int1c() { a("b sets_int_int1c"); } + before(): sets_int_int2c() { a("b sets_int_int2c"); } + before(): sets_int_int3c() { a("b sets_int_int3c"); } + before(): gets_int_sint0() { a("b gets_int_sint0"); } + before(): gets_int_sint1() { a("b gets_int_sint1"); } + before(): gets_int_sint2() { a("b gets_int_sint2"); } + before(): gets_int_sint3() { a("b gets_int_sint3"); } + before(): gets_int_sint0b() { a("b gets_int_sint0b"); } + before(): gets_int_sint1b() { a("b gets_int_sint1b"); } + before(): gets_int_sint2b() { a("b gets_int_sint2b"); } + before(): gets_int_sint3b() { a("b gets_int_sint3b"); } + before(): sets_int_sint0() { a("b sets_int_sint0"); } + before(): sets_int_sint1() { a("b sets_int_sint1"); } + before(): sets_int_sint2() { a("b sets_int_sint2"); } + before(): sets_int_sint3() { a("b sets_int_sint3"); } + before(): sets_int_sint0b() { a("b sets_int_sint0b"); } + before(): sets_int_sint1b() { a("b sets_int_sint1b"); } + before(): sets_int_sint2b() { a("b sets_int_sint2b"); } + before(): sets_int_sint3b() { a("b sets_int_sint3b"); } + before(): sets_int_sint0c() { a("b sets_int_sint0c"); } + before(): sets_int_sint1c() { a("b sets_int_sint1c"); } + before(): sets_int_sint2c() { a("b sets_int_sint2c"); } + before(): sets_int_sint3c() { a("b sets_int_sint3c"); } + //end-befores + + int around(): gets_int_int0() { a("a gets_int_int0"); return proceed(); } + int around(): gets_int_int1() { a("a gets_int_int1"); return proceed(); } + int around(): gets_int_int2() { a("a gets_int_int2"); return proceed(); } + int around(): gets_int_int3() { a("a gets_int_int3"); return proceed(); } + int around(): gets_int_int0b() { a("a gets_int_int0b"); return proceed(); } + int around(): gets_int_int1b() { a("a gets_int_int1b"); return proceed(); } + int around(): gets_int_int2b() { a("a gets_int_int2b"); return proceed(); } + int around(): gets_int_int3b() { a("a gets_int_int3b"); return proceed(); } + int around(): sets_int_int0() { a("a sets_int_int0"); return proceed(); } + int around(): sets_int_int1() { a("a sets_int_int1"); return proceed(); } + int around(): sets_int_int2() { a("a sets_int_int2"); return proceed(); } + int around(): sets_int_int3() { a("a sets_int_int3"); return proceed(); } + int around(): sets_int_int0b() { a("a sets_int_int0b"); return proceed(); } + int around(): sets_int_int1b() { a("a sets_int_int1b"); return proceed(); } + int around(): sets_int_int2b() { a("a sets_int_int2b"); return proceed(); } + int around(): sets_int_int3b() { a("a sets_int_int3b"); return proceed(); } + int around(): sets_int_int0c() { a("a sets_int_int0c"); return proceed(); } + int around(): sets_int_int1c() { a("a sets_int_int1c"); return proceed(); } + int around(): sets_int_int2c() { a("a sets_int_int2c"); return proceed(); } + int around(): sets_int_int3c() { a("a sets_int_int3c"); return proceed(); } + int around(): gets_int_sint0() { a("a gets_int_sint0"); return proceed(); } + int around(): gets_int_sint1() { a("a gets_int_sint1"); return proceed(); } + int around(): gets_int_sint2() { a("a gets_int_sint2"); return proceed(); } + int around(): gets_int_sint3() { a("a gets_int_sint3"); return proceed(); } + int around(): gets_int_sint0b() { a("a gets_int_sint0b"); return proceed(); } + int around(): gets_int_sint1b() { a("a gets_int_sint1b"); return proceed(); } + int around(): gets_int_sint2b() { a("a gets_int_sint2b"); return proceed(); } + int around(): gets_int_sint3b() { a("a gets_int_sint3b"); return proceed(); } + int around(): sets_int_sint0() { a("a sets_int_sint0"); return proceed(); } + int around(): sets_int_sint1() { a("a sets_int_sint1"); return proceed(); } + int around(): sets_int_sint2() { a("a sets_int_sint2"); return proceed(); } + int around(): sets_int_sint3() { a("a sets_int_sint3"); return proceed(); } + int around(): sets_int_sint0b() { a("a sets_int_sint0b"); return proceed(); } + int around(): sets_int_sint1b() { a("a sets_int_sint1b"); return proceed(); } + int around(): sets_int_sint2b() { a("a sets_int_sint2b"); return proceed(); } + int around(): sets_int_sint3b() { a("a sets_int_sint3b"); return proceed(); } + int around(): sets_int_sint0c() { a("a sets_int_sint0c"); return proceed(); } + int around(): sets_int_sint1c() { a("a sets_int_sint1c"); return proceed(); } + int around(): sets_int_sint2c() { a("a sets_int_sint2c"); return proceed(); } + int around(): sets_int_sint3c() { a("a sets_int_sint3c"); return proceed(); } + //end-arounds + + after(): gets_int_int0() { a("f gets_int_int0"); } + after(): gets_int_int1() { a("f gets_int_int1"); } + after(): gets_int_int2() { a("f gets_int_int2"); } + after(): gets_int_int3() { a("f gets_int_int3"); } + after(): gets_int_int0b() { a("f gets_int_int0b"); } + after(): gets_int_int1b() { a("f gets_int_int1b"); } + after(): gets_int_int2b() { a("f gets_int_int2b"); } + after(): gets_int_int3b() { a("f gets_int_int3b"); } + after(): sets_int_int0() { a("f sets_int_int0"); } + after(): sets_int_int1() { a("f sets_int_int1"); } + after(): sets_int_int2() { a("f sets_int_int2"); } + after(): sets_int_int3() { a("f sets_int_int3"); } + after(): sets_int_int0b() { a("f sets_int_int0b"); } + after(): sets_int_int1b() { a("f sets_int_int1b"); } + after(): sets_int_int2b() { a("f sets_int_int2b"); } + after(): sets_int_int3b() { a("f sets_int_int3b"); } + after(): sets_int_int0c() { a("f sets_int_int0c"); } + after(): sets_int_int1c() { a("f sets_int_int1c"); } + after(): sets_int_int2c() { a("f sets_int_int2c"); } + after(): sets_int_int3c() { a("f sets_int_int3c"); } + after(): gets_int_sint0() { a("f gets_int_sint0"); } + after(): gets_int_sint1() { a("f gets_int_sint1"); } + after(): gets_int_sint2() { a("f gets_int_sint2"); } + after(): gets_int_sint3() { a("f gets_int_sint3"); } + after(): gets_int_sint0b() { a("f gets_int_sint0b"); } + after(): gets_int_sint1b() { a("f gets_int_sint1b"); } + after(): gets_int_sint2b() { a("f gets_int_sint2b"); } + after(): gets_int_sint3b() { a("f gets_int_sint3b"); } + after(): sets_int_sint0() { a("f sets_int_sint0"); } + after(): sets_int_sint1() { a("f sets_int_sint1"); } + after(): sets_int_sint2() { a("f sets_int_sint2"); } + after(): sets_int_sint3() { a("f sets_int_sint3"); } + after(): sets_int_sint0b() { a("f sets_int_sint0b"); } + after(): sets_int_sint1b() { a("f sets_int_sint1b"); } + after(): sets_int_sint2b() { a("f sets_int_sint2b"); } + after(): sets_int_sint3b() { a("f sets_int_sint3b"); } + after(): sets_int_sint0c() { a("f sets_int_sint0c"); } + after(): sets_int_sint1c() { a("f sets_int_sint1c"); } + after(): sets_int_sint2c() { a("f sets_int_sint2c"); } + after(): sets_int_sint3c() { a("f sets_int_sint3c"); } + //end-afters +} + +class Ints { + + static void m(String s) { Tester.expectEvent(s); } + static void add() { + m("b gets_int_int0"); m("f gets_int_int0"); m("a gets_int_int0"); + m("b gets_int_int1"); m("f gets_int_int1"); m("a gets_int_int1"); + m("b gets_int_int2"); m("f gets_int_int2"); m("a gets_int_int2"); + m("b gets_int_int3"); m("f gets_int_int3"); m("a gets_int_int3"); + m("b gets_int_int0b"); m("f gets_int_int0b"); m("a gets_int_int0b"); + m("b gets_int_int1b"); m("f gets_int_int1b"); m("a gets_int_int1b"); + m("b gets_int_int2b"); m("f gets_int_int2b"); m("a gets_int_int2b"); + m("b gets_int_int3b"); m("f gets_int_int3b"); m("a gets_int_int3b"); + m("b sets_int_int0"); m("f sets_int_int0"); m("a sets_int_int0"); + m("b sets_int_int1"); m("f sets_int_int1"); m("a sets_int_int1"); + m("b sets_int_int2"); m("f sets_int_int2"); m("a sets_int_int2"); + m("b sets_int_int3"); m("f sets_int_int3"); m("a sets_int_int3"); + m("b sets_int_int0b"); m("f sets_int_int0b"); m("a sets_int_int0b"); + m("b sets_int_int1b"); m("f sets_int_int1b"); m("a sets_int_int1b"); + m("b sets_int_int2b"); m("f sets_int_int2b"); m("a sets_int_int2b"); + m("b sets_int_int3b"); m("f sets_int_int3b"); m("a sets_int_int3b"); + m("b sets_int_int0c"); m("f sets_int_int0c"); m("a sets_int_int0c"); + m("b sets_int_int1c"); m("f sets_int_int1c"); m("a sets_int_int1c"); + m("b sets_int_int2c"); m("f sets_int_int2c"); m("a sets_int_int2c"); + m("b sets_int_int3c"); m("f sets_int_int3c"); m("a sets_int_int3c"); + m("b gets_int_sint0"); m("f gets_int_sint0"); m("a gets_int_sint0"); + m("b gets_int_sint1"); m("f gets_int_sint1"); m("a gets_int_sint1"); + m("b gets_int_sint2"); m("f gets_int_sint2"); m("a gets_int_sint2"); + m("b gets_int_sint3"); m("f gets_int_sint3"); m("a gets_int_sint3"); + m("b gets_int_sint0b"); m("f gets_int_sint0b"); m("a gets_int_sint0b"); + m("b gets_int_sint1b"); m("f gets_int_sint1b"); m("a gets_int_sint1b"); + m("b gets_int_sint2b"); m("f gets_int_sint2b"); m("a gets_int_sint2b"); + m("b gets_int_sint3b"); m("f gets_int_sint3b"); m("a gets_int_sint3b"); + m("b sets_int_sint0"); m("f sets_int_sint0"); m("a sets_int_sint0"); + m("b sets_int_sint1"); m("f sets_int_sint1"); m("a sets_int_sint1"); + m("b sets_int_sint2"); m("f sets_int_sint2"); m("a sets_int_sint2"); + m("b sets_int_sint3"); m("f sets_int_sint3"); m("a sets_int_sint3"); + m("b sets_int_sint0b"); m("f sets_int_sint0b"); m("a sets_int_sint0b"); + m("b sets_int_sint1b"); m("f sets_int_sint1b"); m("a sets_int_sint1b"); + m("b sets_int_sint2b"); m("f sets_int_sint2b"); m("a sets_int_sint2b"); + m("b sets_int_sint3b"); m("f sets_int_sint3b"); m("a sets_int_sint3b"); + m("b sets_int_sint0c"); m("f sets_int_sint0c"); m("a sets_int_sint0c"); + m("b sets_int_sint1c"); m("f sets_int_sint1c"); m("a sets_int_sint1c"); + m("b sets_int_sint2c"); m("f sets_int_sint2c"); m("a sets_int_sint2c"); + m("b sets_int_sint3c"); m("f sets_int_sint3c"); m("a sets_int_sint3c"); + } +} + + + diff --git a/tests/new/NullPointerOnGetsSimple.java b/tests/new/NullPointerOnGetsSimple.java new file mode 100644 index 000000000..18fbb04ba --- /dev/null +++ b/tests/new/NullPointerOnGetsSimple.java @@ -0,0 +1,21 @@ +public class NullPointerOnGetsSimple { + public static void main(String[] args) { + PrintService ps = new PrintService(); + ps.string = "after"; + org.aspectj.testing.Tester.checkEqual("after", ps.string); + } +} + +class PrintService { + String string = "before"; +} + +aspect Aspect { + pointcut needPrinter(PrintService ps): get(String PrintService.string) && target(ps) && + !within(Aspect); + String around(PrintService ps): needPrinter(ps) { + System.out.println("around"); + org.aspectj.testing.Tester.checkEqual("after", ps.string); + return ps.string; + } +} diff --git a/tests/new/ObjectForInt.java b/tests/new/ObjectForInt.java new file mode 100644 index 000000000..bec3b7ff5 --- /dev/null +++ b/tests/new/ObjectForInt.java @@ -0,0 +1,34 @@ +import org.aspectj.testing.Tester; + +public class ObjectForInt { + public static void main(String[] args){ + new Test().go(); + Tester.checkEqual(Test.a, 10, "Test.a"); + Tester.checkEqual(A.beforeA.intValue(), 4, "beforeA"); + } +} + +class Test { + public static int a = -1; + void go(){ + foo(4); + } + + void foo(int a){ + Test.a = a; + } +} + +aspect A { + public static Integer beforeA = null; + pointcut fooCut(Object i): + target(Test) && args(i) && call(void f*(*)); + + before(Object o): fooCut(o){ + beforeA = (Integer)o; + } + + void around(Object o): fooCut(o){ + proceed(new Integer(10)); + } +} diff --git a/tests/new/OddConstructors.java b/tests/new/OddConstructors.java new file mode 100644 index 000000000..72717d275 --- /dev/null +++ b/tests/new/OddConstructors.java @@ -0,0 +1,48 @@ +import java.lang.reflect.*; +import org.aspectj.testing.Tester; + +public class OddConstructors { + public static void main(String[] args) throws Exception { test(); } + public static void test() throws Exception { + new OddConstructors().go(); + Tester.check("advised default constructor"); + Tester.checkEqual(B.aspectOf().count, 1, "new'd once"); + } + + void go() throws Exception { + // new C(); + + // use reflection instead of new to create this class to tickle the bug + Constructor c = Class.forName("C").getConstructor(new Class[0]); + I i = (I)c.newInstance(new Object[0]); + } + static aspect B extends A issingleton() { //of eachJVM() { + pointcut i(): target(I); + } +} + + +abstract aspect A { + + abstract pointcut i(); + + pointcut j(): + i() + // 2001.08.01 (palm) + // Had to change this to I.new from new + // because of the change to the meaning + // of initialization + //&& initialization(new(..)) ; + && initialization(I.new(..)) ; + + after() returning(Object o): j() { + Tester.note("advised default constructor"); + count++; + } + + int count = 0; +} + +class C implements I { public C() {} } + +interface I {} diff --git a/tests/new/OrderOfCatches.java b/tests/new/OrderOfCatches.java new file mode 100644 index 000000000..84ddaea56 --- /dev/null +++ b/tests/new/OrderOfCatches.java @@ -0,0 +1,40 @@ + +import org.aspectj.testing.Tester; + +// PR#114, PR#115 + +public class OrderOfCatches { + public static void main(String[] args) { test(); } + public static void test() { + A a = new A(); + try { + a.bar(); + Tester.check( true, "" ); + } + catch ( FooException fe ) { + } + Tester.checkEqual(a.s, "a-FooException-EXC:FooException", ""); + } +} + +class A { + public String s = "a"; + void bar() throws FooException { + foo(); + } + void foo() throws FooException { + throw new FooException(); + } +} + +aspect AA { + pointcut m(A a): target(a) && call(void bar()); + after (A a) throwing (FooException e): m(a) { + a.s += "-" + e.getClass().getName(); + } + after (A a) throwing (Exception e): m(a) { + a.s += "-" + "EXC:"+e.getClass().getName(); + } +} + +class FooException extends Exception {} diff --git a/tests/new/OrderOfExtendsPlusAndImplementsPlus.java b/tests/new/OrderOfExtendsPlusAndImplementsPlus.java new file mode 100644 index 000000000..ba1265f1c --- /dev/null +++ b/tests/new/OrderOfExtendsPlusAndImplementsPlus.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.Tester; +public class OrderOfExtendsPlusAndImplementsPlus { + public static void main(String[] args) { + try { + new OrderOfExtendsPlusAndImplementsPlus().realMain(args); + } catch (Throwable t) { + Tester.throwable(t); + } + } + public void realMain(String[] args) throws Exception { + Class[] cs = new Class[]{C.class, D.class}; + for (int i = 0; i < cs.length; i++) { + check(cs[i]); + } + } + private void check(Class c) { + Tester.checkEq(c.getInterfaces()[0], I.class, + c + " doesn't implement " + I.class); + Tester.checkEq(c.getSuperclass(), S.class, + c + " doesn't extend " + S.class); + } +} + +class S {} +interface I {} +class C {} +class D {} + +aspect A { + declare parents: C implements I; + declare parents: C extends S; +} + +aspect B { + declare parents: D extends S; + declare parents: D implements I; +} diff --git a/tests/new/OrderOfTypes.java b/tests/new/OrderOfTypes.java new file mode 100644 index 000000000..8e2739b3b --- /dev/null +++ b/tests/new/OrderOfTypes.java @@ -0,0 +1,14 @@ +public class OrderOfTypes { + public static void main(String[] args) {} +} + +class Root { + class RootInner {} +} + +class Second extends First { + class SecondInner extends RootInner {} +} + +class First extends Root { +} diff --git a/tests/new/Orleans.java b/tests/new/Orleans.java new file mode 100644 index 000000000..acc77d402 --- /dev/null +++ b/tests/new/Orleans.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.*; + +public class Orleans { + static boolean called = false; + public static void main(String[] args) { + String hello[] = new String[] { "h", "e", "l", "l", "o" }; + Object o = new Object(); + o = new Orleans(true); + Tester.check(called, "Advice was not called."); + } + + public Orleans(boolean b) {} +} + +aspect ResourceAccounting issingleton() { + pointcut constructions(): call(new(..)); + before(): constructions() { + Orleans.called = true; + } +} + + diff --git a/tests/new/OuterAbstract_PR408.java b/tests/new/OuterAbstract_PR408.java new file mode 100644 index 000000000..0ba46c8ad --- /dev/null +++ b/tests/new/OuterAbstract_PR408.java @@ -0,0 +1,13 @@ +import org.aspectj.testing.*; + +public abstract class OuterAbstract_PR408 { + public void go() { + Tester.event("OuterAbstract_PR408.go"); + } + public abstract class InnerAbstract { + public InnerAbstract(String str) {} + public void go() { + Tester.event("InnerAbstract.go"); + } + } +} diff --git a/tests/new/OverridingPointcuts.java b/tests/new/OverridingPointcuts.java new file mode 100644 index 000000000..a07815baf --- /dev/null +++ b/tests/new/OverridingPointcuts.java @@ -0,0 +1,60 @@ +import org.aspectj.testing.Tester; + +public class OverridingPointcuts { + public static void main(String[] args) { + C c1 = new C(); + C c2 = new C(); + + c1.m1(); + c2.m2(); + + Tester.checkEqual(c1.m1(), "A1-m1"); + Tester.checkEqual(c2.m2(), "m2"); + + Tester.checkEqual(c1.m3(), "A1-m3"); + Tester.checkEqual(c2.m3(), "m3"); + + Tester.check(!A2.hasAspect(c1), "c1 hasa A2"); + Tester.check(A1.hasAspect(c1), "c1 hasa A1"); + + Tester.check(A2.hasAspect(c2), "c2 hasa A2"); + Tester.check(!A1.hasAspect(c2), "!c2 hasa A1"); + } +} + + +class C { + public String m1() { return "m1"; } + public String m2() { return "m2"; } + public String m3() { return "m3"; } +} + +abstract aspect A pertarget(target(C) && call(String m2())) { + int cached; + + abstract pointcut testpoint(); + + String modifyResult(String r) { return "A-" + r; } + + String around (): testpoint() { + return modifyResult(proceed()); + } +} + +aspect A1 extends A pertarget(target(C) && call(String m1())) { + pointcut testpoint() : call(String C.*(..)); + + String modifyResult(String s) { return "A1-" + s; } +} + +aspect A2 extends A { + pointcut testpoint(); +} + +/* +public aspect A2 extends A of eachobject(instanceof(C) && receptions(String m2())) { + pointcut testpoint() returns String: receptions(String *(..)); + + String modifyResult(String s) { return "A2-" + s; } +} +*/ diff --git a/tests/new/PCDeclarationArgsCE.java b/tests/new/PCDeclarationArgsCE.java new file mode 100644 index 000000000..275ec1fbe --- /dev/null +++ b/tests/new/PCDeclarationArgsCE.java @@ -0,0 +1,54 @@ + +import java.util.Observer; +import java.util.Observable; + +/** @testcase PR#740 pointcut references with incorrect args should prompt compiler errors */ +aspect A { + pointcut none() : call(static void main(String[])); + pointcut one(Runnable r) : target(r) && call(void run()); + pointcut two(Observer seer, Observable seen) : + target(seer) + && args(seen, Object) + && execution(void update(Observable, Object)); + pointcut three(Observer seer, Observable seen, Object arg) : + target(seer) + && args(seen, arg) + && execution(void update(Observable, Object)); + + // cases should not have errors + pointcut none0type() : none(); + pointcut one1type() : one(Runnable); + pointcut two2type() : two(Observer, Observable); + pointcut three3type() : three(Observer, Observable, Object); + pointcut one1arg(Runnable r) : one(r); + pointcut two2arg(Observer seer, Observable seen) : two(seer, seen); + pointcut three3arg(Observer seer, Observable seen, Object o) : + two(seer, seen, o); + + // cases should prompt CE + pointcut none1type() : none(Object); // CE 29 + pointcut none1name(Object o) : none(o); // CE 30 + pointcut none2type() : none(Object, Object); // CE 31 + pointcut none2name(Object o, Object p) : none(o,p); // CE 32 + pointcut one0() : one(); // CE 33 + pointcut one2type() : one(Runnable, Object); // CE 34 + pointcut one2name(Runnable o, Object p) : one(o,p); // CE 35 + + pointcut two0() : two(Object); // CE 37 + pointcut two1type() : two(Object); // CE 38 + pointcut two1name(Object o) : two(o); // CE 39 + pointcut two3type() : two(Observer, Observable, Object); // CE 40 + pointcut two3name(Observer seer, Observable seen, Object object) : + two(seer, seen, object); // CE 42 + + pointcut three0() : three(Object); // CE 44 + pointcut three1type() : three(Object); // CE 45 + pointcut three1name(Object o) : three(o); // CE 46 + pointcut three2type() : three(Observer, Observable); // CE 47 + pointcut three2name(Observer seer, Observable seen) : + three(seer, seen); // CE 49 + pointcut three4type() : three(Observer, Observable, Object, Object); // CE 50 + pointcut three4name(Observer seer, Observable seen, + Object object, Object two) : + three(seer, seen, object, two); // CE 53 +} diff --git a/tests/new/PR318.java b/tests/new/PR318.java new file mode 100644 index 000000000..da43d463d --- /dev/null +++ b/tests/new/PR318.java @@ -0,0 +1,34 @@ +public class PR318 { + public static void main(String[] args) { + new PR318().realMain(args); + } + public void realMain(String[] args) { + Bar.bar(); + org.aspectj.testing.Tester.check(caught, "Exception wasn't caught"); + } + static boolean caught = false; + +} + +class Foo { + static void foo () throws Exception { + throw new IllegalArgumentException("foo!"); + } +} + +class Bar { + static void bar () { + try { + Foo.foo(); + } catch (Exception e) { + } + } +} + +aspect A { + before (Exception e): handler(Exception) && args(e) { + if (e instanceof IllegalArgumentException) { + PR318.caught = true; + } + } +} diff --git a/tests/new/PR320.java b/tests/new/PR320.java new file mode 100644 index 000000000..d0d2cb256 --- /dev/null +++ b/tests/new/PR320.java @@ -0,0 +1,14 @@ +public class PR320 { + public static void main(String[] args) { + //org.aspectj.testing.Tester.check(false, "Shouldn't have compiled!"); + org.aspectj.testing.Tester.check(true, "OK to compile by 08b1!"); + } +} +class Product1 {} +aspect Product1Aspect pertarget(target(Product1)){ + + pointcut instance(Product1 p): target(p); + before(Product1 p): instance(p) { + System.out.println("Im am instance of product1"); + } +} diff --git a/tests/new/PR328.java b/tests/new/PR328.java new file mode 100644 index 000000000..3597bca5c --- /dev/null +++ b/tests/new/PR328.java @@ -0,0 +1,18 @@ +import java.lang.reflect.*; + +public class PR328 { + public static void main(String[] args) { + new PR328().realMain(args); + } + public void realMain(String[] args) { + try { + Class modest = Class.forName("Modest"); + int modifiers = modest.getModifiers(); + boolean isPublic = (modifiers & Modifier.PUBLIC) != 0; + org.aspectj.testing.Tester.check(!isPublic, "Modest shouldn't be public"); + } catch (Throwable t) { + org.aspectj.testing.Tester.check(false, "Thrown: " + t); + } + } +} +class Modest {} diff --git a/tests/new/PR335.java b/tests/new/PR335.java new file mode 100644 index 000000000..8fc4db660 --- /dev/null +++ b/tests/new/PR335.java @@ -0,0 +1,50 @@ +import org.aspectj.testing.*; + +public class PR335 { + public static void main(String[] args) { + Ship s = new Ship(); + Tester.clearEvents(); + s.handleCollision(); + Tester.checkAndClearEvents("before3(d=0) inflictDamage(0) handleCollision()"); + s.handleCollision("dummy"); + Tester.checkAndClearEvents("before1(so=dummy,d=1) inflictDamage(1) handleCollision(Object)"); + s.handleCollision(1); + Tester.checkAndClearEvents("before2(so=1,d=2) inflictDamage(2) handleCollision(int)"); + s.inflictDamage(3); + Tester.checkAndClearEvents("inflictDamage(3)"); + } +} + + +aspect Bug1 { + pointcut collisionDamage(Ship s, Object so, int d) : + this(s) + && cflow(call(void handleCollision(Object)) && args(so)) + && call(void Ship.inflictDamage(int)) && args(d); + before(Ship s, Object so, int d) : collisionDamage(s, so, d) { + Tester.event("before1(so="+so.toString()+",d="+d+")"); + } + + pointcut collisionDamage2(Ship s, int so, int d) : + this(s) + && cflow(call(void handleCollision(int)) && args(so)) + && call(void Ship.inflictDamage(int)) && args(d); + before(Ship s, Object so, int d) : collisionDamage2(s, so, d) { + Tester.event("before2(so="+so+",d="+d+")"); + } + + pointcut collisionDamage3(Ship s, int d) : + this(s) + && withincode(void handleCollision()) + && call(void Ship.inflictDamage(int)) && args(d); + before(Ship s, int d) : collisionDamage3(s, d) { + Tester.event("before3(d="+d+")"); + } +} + +class Ship { + void handleCollision() { inflictDamage(0); Tester.event("handleCollision()"); } + void handleCollision(Object so) { inflictDamage(1); Tester.event("handleCollision(Object)"); } + void handleCollision(int so) { inflictDamage(2); Tester.event("handleCollision(int)"); } + void inflictDamage(int i) { Tester.event("inflictDamage(" + i + ")"); } +} diff --git a/tests/new/PR339.java b/tests/new/PR339.java new file mode 100644 index 000000000..99855d082 --- /dev/null +++ b/tests/new/PR339.java @@ -0,0 +1,16 @@ +public class PR339 { + public static void main(String[] args) { + new MemberInitSet().foo(); + org.aspectj.testing.Tester.check(true, "compiled"); + } +} + +class MemberInitSet { + String s = "S"; + { s="s"; } + void foo() { s = "asdf"; } +} + +aspect Setter pertarget(target(MemberInitSet)) { + pointcut allSets(): set(String MemberInitSet.s); +} diff --git a/tests/new/PR347.java b/tests/new/PR347.java new file mode 100644 index 000000000..e7479938f --- /dev/null +++ b/tests/new/PR347.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.*; + +public class PR347 { + public static void main(String[] args) { + new PR347().realMain(args); + } + public void realMain(String[] args) { + new A().i(); + new B().j(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("Ai,A.i,Bj,B.j"); + } +} +interface I { public void i(); } +interface J { public void j(); } + +class A {} +class B {} + +aspect Aspect1 { + A +implements I; + B +implements J; +} + +aspect Aspect2 { + pointcut Ai(): receptions(void i()) && instanceof(A); + pointcut Bj(): receptions(void j()) && instanceof(B); + before(): Ai() { Tester.event("Ai"); } + before(): Bj() { Tester.event("Bj"); } +} + +aspect Aspect3 { + public void A.i() { Tester.event("A.i"); } + public void B.j() { Tester.event("B.j"); } +} diff --git a/tests/new/PR353.java b/tests/new/PR353.java new file mode 100644 index 000000000..c200acf3d --- /dev/null +++ b/tests/new/PR353.java @@ -0,0 +1,107 @@ +import org.aspectj.testing.*; +import java.util.*; + +public class PR353 { + public static void main(String[] args) { + new PR353().go(args); + Tester.checkAllEvents(); + } + + void go(String[] args) { + A a = new A(); + B b = new B(); + C c = new C(); + D d = new D(); + E e = new E(); + a.f(); + b.f(); + c.f(); + d.f(); + e.f(); + new Verifier().verify(Aspect.map); + } +} + +interface I { public void f(); } +class A { public void f() { } } +class B implements I { public void f() { } } +class C { public void f() { } } +class D extends C { public void f() { } } +class E extends B { public void f() { } } +class F extends C + implements I { public void f() { } } + +class Verifier { + void verify(Map map) { + Iterator iter = map.keySet().iterator(); + while (iter.hasNext()) { + String key = (iter.next() + "").toLowerCase(); + List list = (List) map.get(key); + Iterator it = list.iterator(); + while (it.hasNext()) { + Object onext = it.next(); + String next = (onext + "").toLowerCase(); + if (key.indexOf(next) == -1) { + Tester.check(false, next + " not found in " + key); + } else { + it.remove(); + } + } + Tester.check(list.size() == 0, list + " contains classes excluded"); + } + } +} +aspect Aspect { + + pointcut r(): receptions(* f()); + pointcut abcdef(): r(); + pointcut acd(): r() && !instanceof(I); + pointcut acdf(): r() && !instanceof(B); + pointcut a(): r() && !instanceof(B) && !instanceof(C); + + public static Map map = new HashMap(); + static { + String[] ss = { + "abcdef", + "acd", + "acdf", + "a", + }; + for (int i = 0; i < ss.length; i++) { + map.put(ss[i], new Vector()); + } + } + + static before(): abcdef() { + p("abcdef", thisJoinPoint.className); + } + + static before(): acd() { + p("acd", thisJoinPoint.className); + } + + static before(): acdf() { + p("acdf", thisJoinPoint.className); + } + + static before(): a() { + p("a", thisJoinPoint.className); + } + + static void p(String key, String str) { + List list = (List) map.get(key); + if (list == null) { + list = new Vector(); + } + list.add(str); + map.put(key, list); + } + + static List v(Object[] os) { + List v = new Vector(); + for (int i = 0; i < os.length; i++) { + v.add(os[i]); + } + return v; + } +} diff --git a/tests/new/PR353b.java b/tests/new/PR353b.java new file mode 100644 index 000000000..4419d9203 --- /dev/null +++ b/tests/new/PR353b.java @@ -0,0 +1,51 @@ +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; +import org.aspectj.testing.*; +import java.util.*; + +public class PR353b { + + public static void main(String[] args){ + new PR353b().go(); + } + + void go(){ + s.c = "E"; C c = new E(); c.foo(); + s.c = "C"; c = new C(); c.foo(); + s.c = "E"; E e = new E(); e.foo(); + s.c = "E2"; E2 e2 = new E2(); e2.foo(); + s.c = "F"; F f = new F(); f.foo(); + } + + static { + Tester.expectEvent("call C"); + Tester.expectEvent("call E2"); + } +} + +class C { void foo() {} } +class E extends C {} +class F extends E {} +class E2 extends C { void foo() {} } + +class s { public static String c; } + +aspect A { + + pointcut p3(): this(C) && call(* foo()) && !target(E); + before(): p3() { + Object target = thisJoinPoint.getTarget(); + JoinPoint.StaticPart sp = thisJoinPoint.getStaticPart(); + Signature sig = sp.getSignature(); + Class dt = sig.getDeclaringType(); + Tester.check(!(target instanceof E), + target.getClass().getName() + " instanceof E"); + Tester.event("call " + target.getClass().getName()); + Tester.check(dt == PR353b.class, + "dt != instanceof PR353b"); + Tester.check(!(target instanceof E), + "!instanceof E"); + String c = thisJoinPoint.getSignature().getDeclaringType().getName(); + Tester.check(s.c.equals(c), "p3: " + s.c + " != " + c); + } +} diff --git a/tests/new/PR353c.java b/tests/new/PR353c.java new file mode 100644 index 000000000..fe4a9e685 --- /dev/null +++ b/tests/new/PR353c.java @@ -0,0 +1,147 @@ +import org.aspectj.testing.*; +import java.util.*; + +public class PR353c { + + public static void main(String[] args){ + new PR353c().go(); + } + + void go(){ + C c = new C(); c.f(); c.g(); + A a = new A(); a.f(); a.g(); + B b = new B(); b.f(); b.g(); + D d = new D(); d.f(); d.g(); + E e = new E(); e.f(); e.g(); + } +} + +interface I { } + +class C { + void f() {} + void g() {} +} + +class A extends C { + void f() {} +} + +class B extends C { + void f() {} + void g() {} +} + +class D extends C { } +class E extends C implements I { } + +aspect AA extends AspectSupport { + + pointcut f(): receptions(void f()); + pointcut g(): receptions(void g()); + pointcut b(): f() || g(); + + pointcut all(): b(); + pointcut notC(): b() && !instanceof(C); + pointcut notD1(): b() && instanceof(C) && !instanceof(D); + pointcut notD2(): b() && !instanceof(D) && instanceof(C); + pointcut notI(): b() && !instanceof(I); + pointcut notA1(): b() && instanceof(C) && !instanceof(A); + pointcut notA2(): b() && !instanceof(A) && instanceof(C); + pointcut notB1(): b() && instanceof(C) && !instanceof(B); + pointcut notB2(): b() && !instanceof(B) && instanceof(C); + pointcut notE1(): b() && instanceof(C) && !instanceof(E); + pointcut notE2(): b() && !instanceof(E) && instanceof(C); + + + + static before(): all() { p("cabde", thisJoinPoint.className); } + static before(): notC() { p("", thisJoinPoint.className); } + static before(): notD1() { p("cabe", thisJoinPoint.className); } + static before(): notD2() { p("cabe", thisJoinPoint.className); } + static before(): notI() { p("cabd", thisJoinPoint.className); } + static before(): notA1() { p("cbde", thisJoinPoint.className); } + static before(): notA2() { p("cbde", thisJoinPoint.className); } + static before(): notB1() { p("cade", thisJoinPoint.className); } + static before(): notB2() { p("cade", thisJoinPoint.className); } + static before(): notE1() { p("cadb", thisJoinPoint.className); } + static before(): notE2() { p("cadb", thisJoinPoint.className); } + + pointcut _b(): receptions(* *()); + + pointcut _all(): _b(); + pointcut _notC(): _b() && !instanceof(C); + pointcut _notD1(): _b() && instanceof(C) && !instanceof(D); + pointcut _notD2(): _b() && !instanceof(D) && instanceof(C); + pointcut _notI(): _b() && !instanceof(I); + pointcut _notA1(): _b() && instanceof(C) && !instanceof(A); + pointcut _notA2(): _b() && !instanceof(A) && instanceof(C); + pointcut _notB1(): _b() && instanceof(C) && !instanceof(B); + pointcut _notB2(): _b() && !instanceof(B) && instanceof(C); + pointcut _notE1(): _b() && instanceof(C) && !instanceof(E); + pointcut _notE2(): _b() && !instanceof(E) && instanceof(C); + + static before(): _all() { p("cabde", thisJoinPoint.className); } + static before(): _notC() { p("", thisJoinPoint.className); } + static before(): _notD1() { p("cabe", thisJoinPoint.className); } + static before(): _notD2() { p("cabe", thisJoinPoint.className); } + static before(): _notI() { p("cabd", thisJoinPoint.className); } + static before(): _notA1() { p("cbde", thisJoinPoint.className); } + static before(): _notA2() { p("cbde", thisJoinPoint.className); } + static before(): _notB1() { p("cade", thisJoinPoint.className); } + static before(): _notB2() { p("cade", thisJoinPoint.className); } + static before(): _notE1() { p("cadb", thisJoinPoint.className); } + static before(): _notE2() { p("cadb", thisJoinPoint.className); } +} + +class Verifier { + void verify(Map map) { + Iterator iter = map.keySet().iterator(); + while (iter.hasNext()) { + String key = (iter.next() + "").toLowerCase(); + List list = (List) map.get(key); + Iterator it = list.iterator(); + while (it.hasNext()) { + Object onext = it.next(); + String next = (onext + "").toLowerCase(); + if (key.indexOf(next) == -1) { + Tester.check(false, next + " not found in " + key); + } else { + it.remove(); + } + } + Tester.check(list.size() == 0, list + " contains classes excluded"); + } + } +} +aspect AspectSupport { + + public static Map map = new HashMap(); + static { + String[] ss = { + + }; + for (int i = 0; i < ss.length; i++) { + map.put(ss[i], new Vector()); + } + } + + static void p(String key, String str) { + List list = (List) map.get(key); + if (list == null) { + list = new Vector(); + } + list.add(str); + map.put(key, list); + } + + static List v(Object[] os) { + List v = new Vector(); + for (int i = 0; i < os.length; i++) { + v.add(os[i]); + } + return v; + } +} + + diff --git a/tests/new/PR353d.java b/tests/new/PR353d.java new file mode 100644 index 000000000..0fdec91aa --- /dev/null +++ b/tests/new/PR353d.java @@ -0,0 +1,57 @@ +public class PR353d { + public static void main(String[] args) { + new PR353d().go(); + } + + void go() { + System.out.println("\ni..."); I i = new I() { public void f(PR353d d) {} }; i.f(this); + System.out.println("\na..."); A a = new A(); a.f(this); + System.out.println("\nb..."); B b = new B(); b.f(this); + System.out.println("\nc..."); C c = new C(); c.f(this); + System.out.println("\nd..."); D d = new D(); d.f(this); + System.out.println("\ne..."); E e = new E(); e.f(this); + } +} + +interface I { + public void f(PR353d d); +} + +class A { + public void f(PR353d d) { System.out.println("A.f"); } +} + +class B extends A {} +class C extends A { + public void f(PR353d d) { System.out.println("C.f"); } +} +class D extends A implements I {} +class E extends A implements I { + public void f(PR353d d) { System.out.println("E.f"); } +} + +aspect Aspect { + + pointcut f(): receptions(* *(PR353d)); + pointcut all(): f(); + pointcut anoB(A a): f() && instanceof(a) && !instanceof(B); + pointcut anoC(A a): f() && instanceof(a) && !instanceof(C); + pointcut anoD(A a): f() && instanceof(a) && !instanceof(D); + pointcut anoE(A a): f() && instanceof(a) && !instanceof(E); + pointcut noA(): f() && !instanceof(A); + pointcut noB(): f() && !instanceof(B); + pointcut noC(): f() && !instanceof(C); + pointcut noD(): f() && !instanceof(D); + pointcut noE(): f() && !instanceof(E); + + static before(): all() { System.out.println("all: " + thisJoinPoint.className); } + static before(): noA() { System.out.println("noA: " + thisJoinPoint.className); } + static before(A a): anoB(a) { System.out.println("anoB: " + thisJoinPoint.className); } + static before(A a): anoC(a) { System.out.println("anoC: " + thisJoinPoint.className); } + static before(): noB() { System.out.println("noB: " + thisJoinPoint.className); } + static before(): noC() { System.out.println("noC: " + thisJoinPoint.className); } + static before(A a): anoD(a) { System.out.println("anoD: " + thisJoinPoint.className); } + static before(A a): anoE(a) { System.out.println("anoE: " + thisJoinPoint.className); } + static before(): noD() { System.out.println("noD: " + thisJoinPoint.className); } + static before(): noE() { System.out.println("noE: " + thisJoinPoint.className); } +} diff --git a/tests/new/PR353e.java b/tests/new/PR353e.java new file mode 100644 index 000000000..729315fd1 --- /dev/null +++ b/tests/new/PR353e.java @@ -0,0 +1,65 @@ +public class PR353e { + + public static void main(String[] args){ + new PR353e().go(); + } + + void go(){ + C c; +// System.out.println("\nwith C..."); +// c = new C(); +// c.foo(this); +// c.bar(this); +// System.out.println("\nwith D..."); +// c = new D(); +// c.foo(this); +// c.bar(this); +// System.out.println("\nwith CE..."); +// c = new E(); +// c.foo(this); + System.out.println("\nwith E..."); + E e = new E(); + e.foo(this); + System.out.println("\nwith E2..."); + E2 e2 = new E2(); + e2.foo(this); + e2.bar(this); + } +} + +interface I { } +class C{ + void foo(PR353e a){ System.out.println("foo"); } +} +class E extends C implements I { } +class E2 extends C implements I { void foo(PR353e a) { System.out.println("foo2"); } } + +aspect A { + + pointcut p(C c): receptions(* *(PR353e)) && instanceof(c) && !instanceof(E); + static before(C c): p(c) { + System.out.println("1 before A " + thisJoinPoint.methodName + " with:" + c + ":" + thisJoinPoint.className); + } + + pointcut p3(): receptions(* *(PR353e)) && !instanceof(E); + static before(): p3() { + System.out.println("3 before A " + thisJoinPoint.methodName + " with:" + thisJoinPoint.className); + } + pointcut p4(): receptions(* *(PR353e)) && !instanceof(E2); + static before(): p4() { + System.out.println("4 before A " + thisJoinPoint.methodName + " with:" + thisJoinPoint.className); + } +} + +aspect B { + + pointcut p(C c): receptions(* *(PR353e)) && instanceof(c) && !instanceof(E); + static before(C c): p(c) { + System.out.println("1 before B " + thisJoinPoint.methodName + " with:" + c + ":" + thisJoinPoint.className); + } + + pointcut p3(): receptions(* *(PR353e)) && !instanceof(E); + static before(): p3() { + System.out.println("3 before B " + thisJoinPoint.methodName + " with:" + thisJoinPoint.className); + } +} diff --git a/tests/new/PR355.java b/tests/new/PR355.java new file mode 100644 index 000000000..5c9d4fa0e --- /dev/null +++ b/tests/new/PR355.java @@ -0,0 +1,56 @@ +import org.aspectj.testing.*; +import java.io.*; + +public class PR355 { + public static void main(String[] args) { + new PR355().go(); + } + + static { + String[] types = { "static", "non", "instance" }; + String[] advice = { "before", "after", "around" }; + for (int i = 0; i < types.length; i++) { + for (int j = 0; j < advice.length; j++) { + Tester.expectEvent(types[i] + "-" + advice[j]); + } + } + Tester.expectEventsInString("C.f,C.e"); + } + + void go() { + new C().f(); + Tester.checkAllEvents(); + } +} + + +class C { + void f() { Tester.event("C.f"); e(); } + void e() { Tester.event("C.e"); } +} + +abstract aspect Cuts { + pointcut p(): within(C) && call(* C.*(..)); + static void a(String s) { Tester.event(s); } +} + +/* Static aspects have no problem */ +aspect StaticAspect extends Cuts { + before(): p() { a("static-before"); } + void around(): p() { a("static-around"); proceed(); } + after (): p() { a("static-after"); } +} + +/* Non-static aspects have a problem */ +aspect NonStaticAspect extends Cuts issingleton() { + before(): p() { a("non-before"); } + void around(): p() { a("non-around"); proceed(); } + after (): p() { a("non-after"); } +} + +/* No problem here */ +aspect InstanceOfAspect extends Cuts perthis(this(C)) { + before(): p() { a("instance-before"); } + void around(): p() { a("instance-around"); proceed(); } + after (): p() { a("instance-after"); } +} diff --git a/tests/new/PR415.java b/tests/new/PR415.java new file mode 100644 index 000000000..2d9f22737 --- /dev/null +++ b/tests/new/PR415.java @@ -0,0 +1,69 @@ +import org.aspectj.testing.*; + +public class PR415 { + public static void main(String[] args) { + ASTObject ast = new ASTObject(); + ast.f1(); + ast.f2(); + ast.f3(); + ast.g1(); + ast.g2(); + ast.g3(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("V(V),V(S),V(SS),f1,f2,f3"); + Tester.expectEventsInString("I(V),I(S),I(SS),g1,g2,g3"); + Tester.expectEventsInString("Vc,VcS,VcSS,Ic,IcS,IcSS"); + } +} + +aspect Loses { + void around(ASTObject ast): + call(void ASTObject.voidMethod()) && target(ast) { + Tester.event("Vc"); + proceed(ast); + } + void around(ASTObject ast, String msg): + call(void ASTObject.voidMethod(String)) && target(ast) && args(msg) { + Tester.event("VcS"); + proceed(ast,msg); + } + void around(ASTObject ast, String msg1, String msg2): + call(void ASTObject.voidMethod(String, String)) && target(ast) && args(msg1, msg2) { + Tester.event("VcSS"); + proceed(ast,msg1,msg2); + } + + int around(ASTObject ast): + call(int ASTObject.intMethod()) && target(ast) { + Tester.event("Ic"); + return proceed(ast); + } + int around(ASTObject ast, String msg): + call(int ASTObject.intMethod(String)) && target(ast) && args(msg) { + Tester.event("IcS"); + return proceed(ast,msg); + } + int around(ASTObject ast, String msg1, String msg2): + call(int ASTObject.intMethod(String, String)) && target(ast) && args(msg1, msg2) { + Tester.event("IcSS"); + return proceed(ast,msg1,msg2); + } +} + +class ASTObject { + void voidMethod() { Tester.event("V(V)"); } + void voidMethod(String msg) { Tester.event("V(S)"); } + void voidMethod(String msg1, String msg2) { Tester.event("V(SS)"); } + void f1() { voidMethod(); Tester.event("f1"); } + void f2() { voidMethod(null); Tester.event("f2"); } + void f3() { voidMethod(null, null); Tester.event("f3"); } + + int intMethod() { Tester.event("I(V)"); return -1; } + int intMethod(String msg) { Tester.event("I(S)"); return -1; } + int intMethod(String msg1, String msg2) { Tester.event("I(SS)"); return -1; } + void g1() { intMethod(); Tester.event("g1"); } + void g2() { intMethod(null); Tester.event("g2"); } + void g3() { intMethod(null, null); Tester.event("g3"); } +} diff --git a/tests/new/PR417a.java b/tests/new/PR417a.java new file mode 100644 index 000000000..693296430 --- /dev/null +++ b/tests/new/PR417a.java @@ -0,0 +1,48 @@ +import org.aspectj.testing.*; +public class PR417a { + + public interface Types { + public Integer INT = new Integer(3); + public int i = 0; + public byte b = (byte)1; + public long l = 2L; + public double d = (double)3; + public float f = (float)4; + public short s = (short)5; + public char c = 'c'; + } + + public static interface StaticTypes { + public Integer INT = new Integer(3); + public int i = 0; + public byte b = (byte)1; + public long l = 2L; + public double d = (double)3; + public float f = (float)4; + public short s = (short)5; + public char c = 'c'; + } + + public static void main (String[] args) { + new PR417a().run(); + } + + public void run() { + Tester.check(Types.INT.equals(new Integer(3)), "INT != 3"); + Tester.checkEqual(Types.i,0); + Tester.checkEqual((int)Types.b,1); + Tester.checkEqual((int)Types.l,2); + Tester.checkEqual((int)Types.d,3); + Tester.checkEqual((int)Types.f,4); + Tester.checkEqual((int)Types.s,5); + Tester.checkEqual(Types.c,'c'); + Tester.check(StaticTypes.INT.equals(new Integer(3)), "INT != 3"); + Tester.checkEqual(StaticTypes.i,0); + Tester.checkEqual((int)StaticTypes.b,1); + Tester.checkEqual((int)StaticTypes.l,2); + Tester.checkEqual((int)StaticTypes.d,3); + Tester.checkEqual((int)StaticTypes.f,4); + Tester.checkEqual((int)StaticTypes.s,5); + Tester.checkEqual(StaticTypes.c,'c'); + } +} diff --git a/tests/new/PR417b.java b/tests/new/PR417b.java new file mode 100644 index 000000000..6bf12afd8 --- /dev/null +++ b/tests/new/PR417b.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.*; +public class PR417b { + + public static class StaticTypes { + public static Integer INT = new Integer(3); + public static int i = 0; + public static byte b = (byte)1; + public static long l = 2L; + public static double d = (double)3; + public static float f = (float)4; + public static short s = (short)5; + public static char c = 'c'; + } + + public static void main (String[] args) { + new PR417b().run(); + } + + public void run() { + Tester.check(StaticTypes.INT.equals(new Integer(3)), "INT != 3"); + Tester.checkEqual(StaticTypes.i,0); + Tester.checkEqual((int)StaticTypes.b,1); + Tester.checkEqual((int)StaticTypes.l,2); + Tester.checkEqual((int)StaticTypes.d,3); + Tester.checkEqual((int)StaticTypes.f,4); + Tester.checkEqual((int)StaticTypes.s,5); + Tester.checkEqual(StaticTypes.c,'c'); + } +} diff --git a/tests/new/PR519.java b/tests/new/PR519.java new file mode 100644 index 000000000..7f585ae9d --- /dev/null +++ b/tests/new/PR519.java @@ -0,0 +1,111 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#519 Exception thrown when planning advice */ +public class PR519 { + private static final boolean DO_OUTPUT; + private static final String[] EXPECTED; + public static void main(String[] args) { + try { + A.main(args); + Tester.checkAllEvents(); + } catch (MyException e) { + // expecting this + log("caught expected exception " + e); + } catch (Exception e) { + e.printStackTrace(System.err); + } + } + public static void log(String s) { + if (DO_OUTPUT) System.err.println(s); + Tester.event(s); + } + + static { + DO_OUTPUT = false; + EXPECTED = new String[] + { "*** class A.foo()" + , "*** class B.foo()" + , "*** class A.bar()" + , "after(): call(void A.bar(..)) : call(void A.bar())" + , "*** class A.bar()" + , "after(): call(void A.bar(..)) : call(void A.bar())" + , "*** class B.bar()" + , "*** class A.bar(String s)" + , "after(): call(void A.bar(..)) : call(void A.bar(String))" + , "*** class A.bar(String s1, String s2)" + , "after(): call(void A.bar(..)) : call(void A.bar(String, String))" + , "*** class A.bar(int i)" + , "*** class A.bar()" + , "after(): call(void A.bar(..)) : call(void A.bar())" + , "after(): call(void A.bar(..)) : call(void A.bar(int))" + , "after(): call(void A.bar(..)) && args(problem): call(void A.bar(int))" + , "caught expected exception MyException" }; + Tester.expectEvent(EXPECTED); + } // static init +} + +class A extends B { + private int a = 0; + private int lala; + + public void bar(int i){ + PR519.log("*** " + this.getClass() + ".bar(int i)"); + bar(); + } + + public void bar(){ + PR519.log("*** " + this.getClass() + ".bar()"); + } + + public void bar(String s){ + PR519.log("*** " + this.getClass() + ".bar(String s)"); + } + public void bar(String s1, String s2){ + PR519.log("*** " + this.getClass() + ".bar(String s1, String s2)"); + } + + public static void main(String[] argv) throws Exception { + B b = new B(); + A a = new A(); + + a.foo(); + b.foo(); + + a.bar(); + a.bar(); + b.bar(); + + a.bar("lala"); + a.bar("lala", "poo"); + + a.bar(9); + throw new MyException(); + } +} +class MyException extends Exception { } + +class B { + private int b = 0; + + public void foo(){ + PR519.log("*** " + this.getClass() + ".foo()"); + } + + public void bar(){ + PR519.log("*** " + this.getClass() + ".bar()"); + } +} + + +aspect InstanceOfProblemAspect { + public static final String PREFIX = "after(): call(void A.bar(..)) "; + after(): !within(PR519) && call(void A.bar(..)){ + PR519.log(PREFIX + ": " + thisJoinPoint); + } + + after(int problem): !within(PR519) && call(void A.bar(..)) && args(problem){ + PR519.log(PREFIX + " && args(problem): " + thisJoinPoint); + } + +} diff --git a/tests/new/PR520.java b/tests/new/PR520.java new file mode 100644 index 000000000..641d00cdc --- /dev/null +++ b/tests/new/PR520.java @@ -0,0 +1,101 @@ +import org.aspectj.testing.Tester; + +/** @testcase for PR520 - NAB? */ +public class PR520 { + public static void main(String[] args) { + PR520 me = new PR520(); + me.testValidThreeArgumentCall() ; + me.testValidThreeArgumentCallTwo(); + Tester.checkAllEvents(); + } + + public void testValidThreeArgumentCall() { + for (int i = 0; i < Logger.PRIORITIES.length; i++) { + Logger.log(Logger.PRIORITIES[i], + Logger.API, "context=word_" + i); + } + } + + public void testValidThreeArgumentCallTwo() { + Logger.log( Logger.EXCEPTION, Logger.API, "context=EXCEPTION" ); + Logger.log( Logger.DEBUG, Logger.API, "context=DEBUG" ); + Logger.log( Logger.DEBUG, Logger.API, "context=DEBUG-Exception", + new Exception( "bad bad boy" ) ); + } + public static void signal(String s, String context) { + signal(context + ": " + s); + } + public static void signal(String s) { + System.err.println(s); + Tester.event(s); + } + private static final String[] EXPECTED; + static { + EXPECTED = new String[] + { "context=word_0" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=word_1" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=word_2" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=word_3" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=word_4" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=EXCEPTION" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=DEBUG" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String))" + , "context=DEBUG-Exception" + , "call(void Logger.log(Logger.ChromePriority, Unknown, String, Exception))" + }; + Tester.expectEventsInString(EXPECTED); + } +} + +class Unknown { } +class Logger { + static class ChromePriority { } + public static final ChromePriority DEBUG; + public static final ChromePriority EXCEPTION; + public static final ChromePriority FATAL; + public static final ChromePriority INFO; + public static final ChromePriority WARN; + public static final Unknown API; + public static final Logger.ChromePriority[] PRIORITIES; + + static { + API = new Unknown(); + PRIORITIES = new Logger.ChromePriority[ 5 ]; + DEBUG = new ChromePriority(); + EXCEPTION = new ChromePriority(); + FATAL = new ChromePriority(); + INFO = new ChromePriority(); + WARN = new ChromePriority(); + PRIORITIES[ 0 ] = Logger.DEBUG; + PRIORITIES[ 1 ] = Logger.EXCEPTION; + PRIORITIES[ 2 ] = Logger.FATAL; + PRIORITIES[ 3 ] = Logger.INFO; + PRIORITIES[ 4 ] = Logger.WARN; + } + public static void log(ChromePriority p, Unknown q, + String message, Exception e) { + PR520.signal(message); + } + public static void log(ChromePriority p, Unknown q, + String message) { + PR520.signal(message); + } +} + +aspect LoggerCategoryCreator { + + pointcut allLoggingCalls() + : call(public void Logger.log(..)); + + void around(): allLoggingCalls() { + // s.b. no proceed() (i.e., replace) but testing invocation + proceed(); + PR520.signal(thisJoinPointStaticPart.toString()); + } +} diff --git a/tests/new/PR527.java b/tests/new/PR527.java new file mode 100644 index 000000000..d84e4ef32 --- /dev/null +++ b/tests/new/PR527.java @@ -0,0 +1,57 @@ +import org.aspectj.testing.Tester; + +/** + * PR#527 bug in 1.0beta1 but not HEAD as of 9/24/01 + * @testcase compile error using pcd if() with advice on introduced methods. + */ +public class PR527 { + public static void main(String[] args) { + new C().run(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("run"); + Tester.expectEvent("test"); + // Tester.expectEvent("trigger"); replaced in around + Tester.expectEvent("after"); + Tester.expectEvent("callback"); + Tester.expectEvent("around"); + } +} +class C { + public void run() { + Tester.event("run"); + } +} + +aspect A { + interface I { + } + + public boolean I.test() { + Tester.event("test"); + return true; + } + + public void I.trigger() { + Tester.event("trigger"); // should not run + } + + public void I.callback() { + Tester.event("callback"); + } + + declare parents: C implements I; + + after (C c) : target(c) && execution(public void C.run()) { + Tester.event("after"); + ((I) c).trigger(); + } + void around(I i) + : target(i) + && execution(public void I.trigger()) + && if(i.test()) { + Tester.event("around"); + i.callback(); + } +} diff --git a/tests/new/PR528.java b/tests/new/PR528.java new file mode 100644 index 000000000..1f299e483 --- /dev/null +++ b/tests/new/PR528.java @@ -0,0 +1,71 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +/** + * @testcase PR#528 10rc1 error in return type (verify error if -usejavac, compile error (missing return value) otherwise) + * @testcase PR#528 10a1 unimplemented method if around advice/cflow on methods introduced by interface + * + * The !cflow(within(B)) winds up being the best test case so far for + * the ExceptionInInitializer bug with null fields for cflow state + * + */ +public class PR528 { + public static void main(String[] args) { + C c = new C(); + c.trigger(); // toggled to true, do callback + c.trigger(); // toggled to false, do trigger + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("test"); + Tester.expectEvent("test"); // called for each trigger + Tester.expectEvent("callback"); + Tester.expectEvent("trigger"); + Tester.expectEvent("around 0"); + Tester.expectEvent("around 1"); + } +} +class C { +} + +abstract aspect A { + static boolean toggle; + static int originalIndex; + static int callbackIndex; + static int aroundIndex; + interface I { + } + + public boolean I.test() { + Tester.event("test"); + return (toggle = !toggle); + } + + public void I.trigger() { + Tester.event("trigger"); + Tester.check(0==originalIndex, "trigger called again: "); + originalIndex++; + } + + public void I.callback() { + Tester.event("callback"); + Tester.check(0==callbackIndex, "callback called again: "); + callbackIndex++; + } + + declare parents: C implements I; +} + +aspect B extends A { + void around(I i) + : target(i) + && execution(public void I.trigger()) + && !cflow(within(B)) { + Tester.event("around " + aroundIndex++); + if(i.test()) { + i.callback(); + } else { + proceed(i); + } + } +} diff --git a/tests/new/PR535.java b/tests/new/PR535.java new file mode 100644 index 000000000..9bea781b6 --- /dev/null +++ b/tests/new/PR535.java @@ -0,0 +1,38 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#535 */ +public class PR535 { + public static void main(String[] args) { + Tester.expectEvent("In bar()"); + Tester.expectEvent("advice"); + Tester.expectEvent("In foo()"); + new C().foo(); + Tester.checkAllEvents(); + } +} + +class C { + + public void foo() { + Tester.event("In foo()"); + bar(); + } + + public void bar() { + Tester.event("In bar()"); + } +} + +aspect A { + pointcut outside(): !cflow(within(A)); + + void around(C c): + cflow(execution(public void C.foo())) && + target(c) && + execution(public void C.bar()) && + outside() { + Tester.event("advice"); + proceed(c); + } +} diff --git a/tests/new/PR554.java b/tests/new/PR554.java new file mode 100644 index 000000000..3f9ff8bce --- /dev/null +++ b/tests/new/PR554.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#554 second arg in formal on shared joinpoint with pcd if() causes verify error ?? */ +public class PR554 { + public static void main( String args[] ) { + String A = makeProduct( "A", new Integer(1) ); + String B = makeProduct( "B", new Integer(0) ); + Tester.check("A".equals(A), "\"A\".equals(A): " + A); + Tester.check("B".equals(B), "\"B\".equals(B): " + B); + } + static String makeProduct(String s, Integer i) { return null; } +} + +aspect a { + String around(String whatKind, Integer deleteMeToFixBug): + args(whatKind,deleteMeToFixBug) && + call(String makeProduct(String,Integer)) && + if("A".equals(whatKind)) { + return "A"; + } + String around(String whatKind, Integer deleteMeToFixBug): + args(whatKind,deleteMeToFixBug) && + call(String makeProduct(String,Integer)) && + if("B".equals(whatKind)) { + return "B"; + } +} + + diff --git a/tests/new/PR558.java b/tests/new/PR558.java new file mode 100644 index 000000000..25df05406 --- /dev/null +++ b/tests/new/PR558.java @@ -0,0 +1,7 @@ +/** @testcase PR#558 class name for identifier as String should provoke error */ +public class PR558 { + public static void main( String args[] ) { + new StringBuffer().append(PR558); // expecting compiler error that PR558 is a bad symbol + } +} + diff --git a/tests/new/PR559.java b/tests/new/PR559.java new file mode 100644 index 000000000..24a371d38 --- /dev/null +++ b/tests/new/PR559.java @@ -0,0 +1,121 @@ +import org.aspectj.testing.Tester; + +/** + * This test case shows: + * - no difference whether extending a class or aspect or interface + * - underlying "within"-based pointcut works + * - containing cflow-based pointcut does not + * - true only of inherited pointcuts - member pointcuts work fine + * + * Note that to avoid pointcut cycles, + * pointcuts exclude code within a common superinterface. + * It is not enough (now) to exclude code in the advice's super-most class subclasses. + * + * @testcase PR#559 subclass advice not run for join points selected by superclass cflow-based pointcuts + */ +public class PR559 { + public static void main( String args[] ) { + Tester.expectEvent("target aspect"); + Tester.expectEvent("inTarget class"); + Tester.expectEvent("inTarget aspect"); + Tester.expectEvent("inTargetFlow class"); + Tester.expectEvent("inTargetFlow aspect"); + Tester.expectEvent("TargetRun aspect"); + Tester.expectEvent("TargetRun class"); + Tester.expectEvent("TargetRunFlow aspect"); + Tester.expectEvent("TargetRunFlow class"); + Tester.expectEvent("TargetSubRunFlow aspect"); + Tester.expectEvent("TargetSubRunFlow class"); + new Target().run(); + Tester.checkAllEvents(); + } +} + +interface AspectMarker { + pointcut notInAspect() : ! within(AspectMarker+); + pointcut allTarget() : execution(* Target.*(..)) ; + pointcut allTargetFlow() : cflow(allTarget()); + pointcut inTarget() : notInAspect() && allTarget(); + pointcut inTargetFlow() : notInAspect() && allTargetFlow(); +} + +class Target { + public void run(){ } +} + +class Base implements AspectMarker { + pointcut TargetRun () + : within(Target) && execution(* *(..)) && !within(AspectMarker+); + ; + pointcut TargetRunFlow () + : cflow(within(Target) && execution(* *(..))) && !within(AspectMarker+) + ; +} + +/** @testcase PR#559 subaspect advice not run for superclass cflow-based pointcut */ +aspect Derived extends Base { + pointcut TargetSubRunFlow () + : cflow(within(Target) && execution(* *(..))) && !within(AspectMarker+) + ; + Object around () : inTarget() { + Tester.event("inTarget class"); + return proceed(); + } + Object around () : inTargetFlow() { + Tester.event("inTargetFlow class"); + return proceed(); + } + Object around () : TargetRun() { + Tester.event("TargetRun class"); + return proceed(); + } + Object around () : TargetRunFlow() { + Tester.event("TargetRunFlow class"); + return proceed(); + } + Object around () : TargetSubRunFlow() { + Tester.event("TargetSubRunFlow class"); + return proceed(); + } +} + +abstract aspect BaseAspect implements AspectMarker { + pointcut TargetRun () + : within(Target) && execution(* *(..)) && !within(AspectMarker+); + ; + pointcut TargetRunFlow () + : cflow(within(Target) && execution(* *(..))) && !within(AspectMarker+) + ; +} + +/** @testcase PR#559 subaspect advice not run for superaspect cflow-based pointcut */ +aspect DerivedAspect extends BaseAspect implements AspectMarker { + pointcut TargetSubRunFlow () + : cflow(within(Target) && execution(* *(..))) && !within(AspectMarker+) + ; + Object around () : TargetRun() { + Tester.event("target aspect"); + return proceed(); + } + Object around () : inTarget() { // TargetRun() { + Tester.event("inTarget aspect"); + return proceed(); + } + Object around () : inTargetFlow() { // TargetRun() { + Tester.event("inTargetFlow aspect"); + return proceed(); + } + Object around () : TargetRun() { + Tester.event("TargetRun aspect"); + return proceed(); + } + Object around () : TargetRunFlow() { + Tester.event("TargetRunFlow aspect"); + return proceed(); + } + Object around () : TargetSubRunFlow() { + Tester.event("TargetSubRunFlow aspect"); + return proceed(); + } +} + diff --git a/tests/new/PR560.java b/tests/new/PR560.java new file mode 100644 index 000000000..19df8057d --- /dev/null +++ b/tests/new/PR560.java @@ -0,0 +1,64 @@ +import org.aspectj.testing.Tester; + +/** + * @testcase PR#560 compile fails for aspect derived from percflow base aspect unless pointcut excludes base aspect and subaspects + * - works with issingleton perthis and pertarget + * - works when advice is in the same class/aspect + */ +public class PR560 { // XXX broken? + public static void main( String args[] ) { + Tester.expectEvent("Target.run()"); + Tester.expectEvent("same aspect"); + Tester.expectEvent("derived aspect"); + new Target().run(); + Tester.checkAllEventsIgnoreDups(); + } +} + +class Target { + public void run(){ + Tester.event("Target.run()"); + } +} +abstract aspect Base percflow(callcflow()) { + pointcut callcflow() + : cflow(call(public void Target.run())) + && !within(Base+) + ; + before() : within(Target) { + Tester.event("same aspect"); + } +} + +aspect Derived extends Base { + before() : within(Target) { + Tester.event("derived aspect"); + } +} + +/* + -- passing variants + - + : cflow(call(public void Target.run())) + && !within(Base+) + + -- failing variants + - + : cflow(call(public void Target.run()) && !within(Derived)) + (cflowbelow selects Derived.*) + - + : cflow(call(public void Target.run())) + && !cflow(within(Derived)) + (cflowbelow selects Base.*) + - + : cflow(call(public void Target.run()) && !within(Base+)) + (cflowbelow selects Base.*) + - + : cflow(call(public void Target.run())) + && !this(Base+) + (some join points in Base/Derived do not have Base/Derived as this) + - + : cflow(call(public void Target.run())) + && !target(Base+) + (some join points in Base/Derived do not have Base/Derived as target) +*/ diff --git a/tests/new/PR569/a/IntroAnon.java b/tests/new/PR569/a/IntroAnon.java new file mode 100644 index 000000000..0ede9e901 --- /dev/null +++ b/tests/new/PR569/a/IntroAnon.java @@ -0,0 +1,22 @@ +package a; + +import org.aspectj.testing.Tester; + +import b.Dest; + +/** @testcase PR#569 anon class written to wrong directory */ +public class IntroAnon { + private static aspect MI { + public Object MyInterface.foo () { + Tester.event("foo ran"); + return new Object(){}; + } + } + public static void main (String args []) { + Tester.expectEvent("foo ran"); + new Dest ().foo (); + Tester.checkAllEvents(); + } +} // end of class IntroAnon + + diff --git a/tests/new/PR569/a/MyInterface.java b/tests/new/PR569/a/MyInterface.java new file mode 100644 index 000000000..11ecd8d81 --- /dev/null +++ b/tests/new/PR569/a/MyInterface.java @@ -0,0 +1,7 @@ +package a; + +/** @testcase PR#569 anon class written to wrong directory */ +public interface MyInterface { + public Object foo (); +} + diff --git a/tests/new/PR569/b/Dest.java b/tests/new/PR569/b/Dest.java new file mode 100644 index 000000000..7e999979b --- /dev/null +++ b/tests/new/PR569/b/Dest.java @@ -0,0 +1,8 @@ +package b; + +import a.MyInterface; + +/** @testcase PR#569 anon class written to wrong directory */ +public class Dest implements MyInterface { } + + diff --git a/tests/new/PR573.java b/tests/new/PR573.java new file mode 100644 index 000000000..22efc6de7 --- /dev/null +++ b/tests/new/PR573.java @@ -0,0 +1,25 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +/** @testcase PR#573 pertarget stack overflow getting name of anonymous class */ +public class PR573 { + static public void main(String[] params) { + Tester.expectEvent("A.init0"); + final Object o = new Interface() { + public void m(Object oa) { + oa.toString(); + }}; + Tester.check(null != o, "null != o"); + ((Interface) o).m("hi"); // no exceptions + Tester.check(1 == A.num, "1 == A.num: " + A.num); + Tester.checkAllEvents(); + } +} +interface Interface { void m(Object o);} + +aspect A pertarget(target(Interface)) { // CW 21 will not match containing aspect + public static int num; + A(){ Tester.event("A.init" + num++); } +} + diff --git a/tests/new/PR573_1.java b/tests/new/PR573_1.java new file mode 100644 index 000000000..d9b8bf3dc --- /dev/null +++ b/tests/new/PR573_1.java @@ -0,0 +1,23 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#573 pertarget stack overflow getting name of anonymous class */ +public class PR573_1 { + static public void main(String[] params) { + final Object o1 = new Object(); + final Object o = new Object() { + public void m() { + o1.toString(); + }}; + Tester.expectEvent("A.init0"); + Tester.check(null != o, "null != o"); + o.toString(); // no exceptions + Tester.check(1 == A.num, "1 == A.num: " + A.num); + Tester.checkAllEvents(); + } +} +// different stack overflow when using Object, not Interface +aspect A pertarget(target(Object) && !target(A)) { // CW 20 will not match containing aspect + public static int num; + A(){ Tester.event("A.init" + num++); } +} diff --git a/tests/new/PR573_2.java b/tests/new/PR573_2.java new file mode 100644 index 000000000..4e3ce1878 --- /dev/null +++ b/tests/new/PR573_2.java @@ -0,0 +1,21 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +/** @testcase PR#573 pertarget stack overflow getting name of anonymous class (runtime overflow) */ +public class PR573_2 { + static public void main(String[] params) { + final Object o = new Object() { + public void m() { }}; + Tester.expectEvent("A.init0"); + Tester.check(null != o, "null != o"); + Tester.check(1 == A.num, "1 == A.num: " + A.num); + Tester.checkAllEvents(); + } +} +// different stack overflow when using Object, not Interface +//aspect A pertarget(target(Object)) { +aspect A pertarget(target(Object) && !target(A)) { + public static int num; + A(){ Tester.event("A.init" + num++); } +} diff --git a/tests/new/PR584.java b/tests/new/PR584.java new file mode 100644 index 000000000..2c4ecc03b --- /dev/null +++ b/tests/new/PR584.java @@ -0,0 +1,40 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class PR584 { + + public static void main(String[] args) { + Tester.expectEvent("foo ok"); + Tester.expectEvent("foo test2"); + Foo foo = new Foo("foo"); + /** @testcase PR#584 constructing inner classes using qualified new expression */ + Foo.Test test1 = foo.new Test(); + Foo.Test test2 = foo.new Test() { + public void foo() { + Tester.event(getFoo().baz + " test2"); + } + }; + test1.foo(); + test2.foo(); + /** @testcase PR#584 constructing static inner classes using new expression */ + Foo.StaticTest test3 = new Foo.StaticTest(); + Tester.expectEvent("static foo"); + test3.staticBaz = "static foo"; + test3.staticFoo(); + Tester.checkAllEvents(); + } +} + +class Foo { + public String baz; + public Foo(String baz) { this.baz = baz; } + public static class StaticTest { + static String staticBaz; + public void staticFoo() { Tester.event(staticBaz); } + } + public class Test { + public Foo getFoo() { return Foo.this; } + public void foo() { Tester.event(baz + " ok"); } + } +} diff --git a/tests/new/PR590.java b/tests/new/PR590.java new file mode 100644 index 000000000..04ae582d3 --- /dev/null +++ b/tests/new/PR590.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +public class PR590 { + public static void main (String args []) { + staticMethod (); + new PR590().instanceMethod("bar"); + } + + public static String staticMethod () { + return null; + } + + public String instanceMethod(String a) { + return "foo"; + } +} + +aspect A { + after () returning (String s): + execution(static String PR590.staticMethod()) && if(s == null) { } //ERR + + after () throwing (Error e): + execution(static String PR590.staticMethod()) && if(e != null) { } //ERR +} + diff --git a/tests/new/PR590a.java b/tests/new/PR590a.java new file mode 100644 index 000000000..e7e8d3a85 --- /dev/null +++ b/tests/new/PR590a.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.Tester; + +public class PR590a { + public static void main (String args []) { + staticMethod (); + new PR590a().instanceMethod("bar"); + } + + public static String staticMethod () { + return null; + } + + public String instanceMethod(String a) { + return "foo"; + } +} + +aspect A { + static Object fieldX = Boolean.TRUE; + //static Object Integer = Boolean.TRUE; // just to screw with you + + pointcut pc(Object s): call(!static String PR590a.*(..)) && args(s); + + before(): target(Byte) { } //sanity check + //before(): target(BlurghXXX) { } //sanity check, warning in -Xlint + + + + after () returning (Object s): pc(s) {} //ERR CE 29 + + after () throwing (Object e): pc(e) {} //ERR CE 31 + + // before(): target(fieldX) { } //ERR, but not handled yet + + //before(): target(Integer) { } //ERR -- finds field rather than type, but not handled yet +} + diff --git a/tests/new/PR600/A.java b/tests/new/PR600/A.java new file mode 100644 index 000000000..9f4b93d84 --- /dev/null +++ b/tests/new/PR600/A.java @@ -0,0 +1 @@ +public class A {} diff --git a/tests/new/PR600/B.java b/tests/new/PR600/B.java new file mode 100644 index 000000000..b90c4517f --- /dev/null +++ b/tests/new/PR600/B.java @@ -0,0 +1 @@ +public class B {} diff --git a/tests/new/PR600/C.java b/tests/new/PR600/C.java new file mode 100644 index 000000000..9d83983cd --- /dev/null +++ b/tests/new/PR600/C.java @@ -0,0 +1 @@ +public class C {} diff --git a/tests/new/PR600/Main.java b/tests/new/PR600/Main.java new file mode 100644 index 000000000..bf6ecc27b --- /dev/null +++ b/tests/new/PR600/Main.java @@ -0,0 +1,14 @@ + +/** @testcase PR#600 AbstractMethodError for introduced methods under some orderings of input files */ +public class Main { + public static void main(String[] args) { + A a = new A(); + B b = new B(); + C c = new C(); + + a.setNext(b); + b.setNext(c); + + a.doIt(); + } +} diff --git a/tests/new/PR600/My_error.java b/tests/new/PR600/My_error.java new file mode 100644 index 000000000..a827670ef --- /dev/null +++ b/tests/new/PR600/My_error.java @@ -0,0 +1,30 @@ +aspect My_error { + + interface Queue {} + Queue Queue.next = null; + + public void Queue.doIt() { + if (next == null) { + System.out.println("End of queue reached"); + } else { + System.out.println("\tCall received by: "+this.getClass().getName()); + System.out.println("\tCall forwarded to: "+next.getClass().getName()); + next.doIt(); + } + } + + public void Queue.setNext(Queue next) { + this.next = next; + } + + declare parents: A implements Queue; + declare parents: B implements Queue; + declare parents: C implements Queue; + + // This is the problematic declaration. If removed, the program works fine. + // If replaced by an around advice, the program also works fine. + + public void C.doIt() { + System.out.println("Hurray! The call has been received by C!"); + } +} diff --git a/tests/new/PR691.java b/tests/new/PR691.java new file mode 100644 index 000000000..b624c4839 --- /dev/null +++ b/tests/new/PR691.java @@ -0,0 +1,49 @@ + +import org.aspectj.testing.*; + +/** @testcase PR#691 around AST type XXX */ +public class PR691 { + public static void main (String[] args) { + Tester.expectEvent("around"); + new MailerTest().run(new TestResult()); + Tester.checkAllEvents(); + } + +} +class TestResult {} +class Message {} +class MailerTest { + public void run(TestResult result) { + new Mailer().sendTextMail(); + } +} +class Mailer { + public void sendTextMail(){ + new Transport().send(new Message()); + } +} +class Transport { public void send(Message m){ } } + +aspect Mail { + pointcut inThisTestCase(MailerTest testCase) : + call(* MailerTest.run(TestResult)) + && target(testCase); + + pointcut flowOfTestCase(MailerTest testCase) : + cflow(inThisTestCase(testCase)); + + pointcut sendMailCall() : call(void Mailer.sendTextMail(..)); + pointcut transportSend(Message msg) : + call(void Transport.send(Message)) && args(msg); + + // no bug if no testCase context + //void around(Message msg) : + // flowOfTestCase(MailerTest) + void around(Message msg, final MailerTest testCase) : + flowOfTestCase(testCase) + && cflow(sendMailCall()) + && transportSend(msg) { + Tester.event("around"); + proceed(msg,testCase); + } +} diff --git a/tests/new/PR852/aspect/Aspect.java b/tests/new/PR852/aspect/Aspect.java new file mode 100644 index 000000000..2e9705455 --- /dev/null +++ b/tests/new/PR852/aspect/Aspect.java @@ -0,0 +1,15 @@ +package aspect; + +import target.SuperClass; +import target.SubClass; + +/** @testcase PR#852 declaring method on superclass and subclass */ +public aspect Aspect { + void SuperClass.test() { System.out.println("SuperClass ok");} + void SubClass.test() { System.out.println("SubClass ok");} + //public void SuperClass+.callTest() { test(); } + public static void main (String[] args) { + new SuperClass().test(); + new SubClass().test(); + } +} diff --git a/tests/new/PR852/target/SubClass.java b/tests/new/PR852/target/SubClass.java new file mode 100644 index 000000000..1d2f36906 --- /dev/null +++ b/tests/new/PR852/target/SubClass.java @@ -0,0 +1,4 @@ +package target; + +public class SubClass extends SuperClass { +}
\ No newline at end of file diff --git a/tests/new/PR852/target/SuperClass.java b/tests/new/PR852/target/SuperClass.java new file mode 100644 index 000000000..da4d3ce0f --- /dev/null +++ b/tests/new/PR852/target/SuperClass.java @@ -0,0 +1,8 @@ +package target; + +public class SuperClass { + /*void test() { + System.err.println("SuperClass.test()"); + }*/ +} + diff --git a/tests/new/PR862/pack/ImportInnerFromInterfaceImplementor.java b/tests/new/PR862/pack/ImportInnerFromInterfaceImplementor.java new file mode 100644 index 000000000..10e89e569 --- /dev/null +++ b/tests/new/PR862/pack/ImportInnerFromInterfaceImplementor.java @@ -0,0 +1,17 @@ + + +package pack; + +import pack.C.*; +import java.io.Serializable; + +//import org.aspectj.testing.Tester; + +//public class ImportInnerFromInterfaceImplementor { +// public static void main(String[] args) { +// C c = new C(); +// Tester.check(c instanceof Serializable, "c: " + c); +// } +//} + +class C implements Serializable {}
\ No newline at end of file diff --git a/tests/new/Params.java b/tests/new/Params.java new file mode 100644 index 000000000..f82313344 --- /dev/null +++ b/tests/new/Params.java @@ -0,0 +1,157 @@ +import org.aspectj.testing.*; +public class Params { + public static void main(String[] args) { + new Params().go(); + } + + void go() { + A a = new A(); B b = new B(); C c = new C(); D d = new D(); + b(a); + + b(a, b); + b(b, a); + + b(a, b, c); + b(a, c, b); + b(b, a, c); + b(b, c, a); + b(c, a, b); + b(c, b, a); + + b(d, a, b, c); + b(d, a, c, b); + b(d, b, a, c); + b(d, b, c, a); + b(d, c, a, b); + b(d, c, b, a); + + b(a, d, b, c); + b(a, d, c, b); + b(b, d, a, c); + b(b, d, c, a); + b(c, d, a, b); + b(c, d, b, a); + + b(a, b, d, c); + b(a, c, d, b); + b(b, a, d, c); + b(b, c, d, a); + b(c, a, d, b); + b(c, b, d, a); + + b(a, b, c, d); + b(a, c, b, d); + b(b, a, c, d); + b(b, c, a, d); + b(c, a, b, d); + b(c, b, a, d); + + Tester.checkAllEvents(); + } + + static void m_(String str) { + Tester.expectEvent(str); + Tester.expectEvent(str + ".advice"); + } + + static { + m_("b1"); + + m_("b2.1"); + m_("b2.2"); + + m_("b3.1"); + m_("b3.2"); + m_("b3.3"); + m_("b3.4"); + m_("b3.5"); + m_("b3.6"); + + m_("b4.1.1"); + m_("b4.1.2"); + m_("b4.1.3"); + m_("b4.1.4"); + m_("b4.1.5"); + m_("b4.1.6"); + + m_("b4.2.1"); + m_("b4.2.2"); + m_("b4.2.3"); + m_("b4.2.4"); + m_("b4.2.5"); + m_("b4.2.6"); + + m_("b4.3.1"); + m_("b4.3.2"); + m_("b4.3.3"); + m_("b4.3.4"); + m_("b4.3.5"); + m_("b4.3.6"); + + m_("b4.4.1"); + m_("b4.4.2"); + m_("b4.4.3"); + m_("b4.4.4"); + m_("b4.4.5"); + m_("b4.4.6"); + } + + void b(A a) { a("b1"); } + + void b(A a, B b) { a("b2.1"); } + void b(B b, A a) { a("b2.2"); } + + void b(A a, B b, C c) { a("b3.1"); } + void b(A a, C c, B b) { a("b3.2"); } + void b(B b, A a, C c) { a("b3.3"); } + void b(B b, C c, A a) { a("b3.4"); } + void b(C c, A a, B b) { a("b3.5"); } + void b(C c, B b, A a) { a("b3.6"); } + + void b(D d, A a, B b, C c) { a("b4.1.1"); } + void b(D d, A a, C c, B b) { a("b4.1.2"); } + void b(D d, B b, A a, C c) { a("b4.1.3"); } + void b(D d, B b, C c, A a) { a("b4.1.4"); } + void b(D d, C c, A a, B b) { a("b4.1.5"); } + void b(D d, C c, B b, A a) { a("b4.1.6"); } + + void b(A a, D d, B b, C c) { a("b4.2.1"); } + void b(A a, D d, C c, B b) { a("b4.2.2"); } + void b(B b, D d, A a, C c) { a("b4.2.3"); } + void b(B b, D d, C c, A a) { a("b4.2.4"); } + void b(C c, D d, A a, B b) { a("b4.2.5"); } + void b(C c, D d, B b, A a) { a("b4.2.6"); } + + void b(A a, B b, D d, C c) { a("b4.3.1"); } + void b(A a, C c, D d, B b) { a("b4.3.2"); } + void b(B b, A a, D d, C c) { a("b4.3.3"); } + void b(B b, C c, D d, A a) { a("b4.3.4"); } + void b(C c, A a, D d, B b) { a("b4.3.5"); } + void b(C c, B b, D d, A a) { a("b4.3.6"); } + + void b(A a, B b, C c, D d) { a("b4.4.1"); } + void b(A a, C c, B b, D d) { a("b4.4.2"); } + void b(B b, A a, C c, D d) { a("b4.4.3"); } + void b(B b, C c, A a, D d) { a("b4.4.4"); } + void b(C c, A a, B b, D d) { a("b4.4.5"); } + void b(C c, B b, A a, D d) { a("b4.4.6"); } + + static String str = ""; + public static void a(Object o) { + str = o + ""; + Tester.event(str); + } + +} + +class A {} +class B {} +class C {} +class D {} + +aspect ParamsAspect { + pointcut intParams(): call(* *(..,A,..)) && target(Params); + after(): intParams() { + Tester.event(Params.str + ".advice"); + } +} diff --git a/tests/new/ParenPrimitive.java b/tests/new/ParenPrimitive.java new file mode 100644 index 000000000..99ba8e264 --- /dev/null +++ b/tests/new/ParenPrimitive.java @@ -0,0 +1,11 @@ +import org.aspectj.testing.Tester; + +public class ParenPrimitive { + public static void main(String[] args) { + Tester.checkEqual(typenameFor(null), "int"); + } + + private static String typenameFor(String type) { + return("int"); + } +} diff --git a/tests/new/ParentInterfaceUsingChildInnerInterface.java b/tests/new/ParentInterfaceUsingChildInnerInterface.java new file mode 100644 index 000000000..499c3035d --- /dev/null +++ b/tests/new/ParentInterfaceUsingChildInnerInterface.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.*; + + +/** @testcase PR#645 PUREJAVA Parent interface using public inner interface of child in same file */ +interface Child extends Parent { + public interface Inner { + public String ok(); + } +} + +/** Parent must be in same file as child and be declared AFTER */ +interface Parent { + public Child.Inner getChildInner(); +} + +public class ParentInterfaceUsingChildInnerInterface { + public static void main (String[] args) { + Example me = new Example(); + String result = me.getChildInner().ok(); + Tester.check(((result != null) && result.startsWith("ok")), + "expected ok... got " + result); + } +} + +class Example implements Parent { + public Child.Inner getChildInner() { + return new Child.Inner() { + public String ok() { + return "ok: " + getClass().getName(); + } + }; + } +} diff --git a/tests/new/ParsingFloatCE.java b/tests/new/ParsingFloatCE.java new file mode 100644 index 000000000..85106ad7d --- /dev/null +++ b/tests/new/ParsingFloatCE.java @@ -0,0 +1,8 @@ + +public class ParsingFloatCE { + /** @testcase PR#642 PUREJAVA invalid floating-point constant */ + public void notrun() { + float f = 10e-f; // expecting CE here + double d = 10ee10; // expecting CE here + } +} diff --git a/tests/new/ParsingSubtypesIntroductions.java b/tests/new/ParsingSubtypesIntroductions.java new file mode 100644 index 000000000..5bd98fd3f --- /dev/null +++ b/tests/new/ParsingSubtypesIntroductions.java @@ -0,0 +1,60 @@ +import org.aspectj.testing.Tester; +public class ParsingSubtypesIntroductions { + public static void main(String[] args) { + new ParsingSubtypesIntroductions().realMain(args); + } + public void realMain(String[] args) { + new D().f(); + new C().f(); + ((I)new C()).i(); + new E().f(); + ((I)new E()).i(); + Tester.checkAllEvents(); + } + static { + U.m(D.class, "f"); + U.m(C.class, "f"); + U.m(C.class, "i"); + U.m(E.class, "f"); + U.m(E.class, "i"); + } +} + +class U { + public static void a(Object o, Object m) { + Tester.event(m + "." + type(o)); + } + public static void m(Class t, Object m) { + Tester.expectEvent(m + "." + name(t)); + } + public static String type(Object o) { + return name(o.getClass()); + } + public static String name(Class t) { + String str = t.getName(); + int i = str.lastIndexOf('.'); + if (i != -1) str = str.substring(i+1); + return str; + } +} + +class D { + public void f() { U.a(this, "f"); } +} +class C /*extends D implements I*/ { + /*public void i() { U.a(this, "i"); }*/ +} +class E extends C {} +interface I { + public void i(); +} +aspect A { +// subtypes(C) +implements I; +// subtypes(C) +extends D; + + declare parents: C+ implements I; + declare parents: C+ extends D; + + public void I.i() { U.a(this, "i"); } +} + diff --git a/tests/new/PerTargetAndVariablesWithNumbersInTheirNames.java b/tests/new/PerTargetAndVariablesWithNumbersInTheirNames.java new file mode 100644 index 000000000..1f0ca54bf --- /dev/null +++ b/tests/new/PerTargetAndVariablesWithNumbersInTheirNames.java @@ -0,0 +1,103 @@ +import org.aspectj.testing.*; + +/** + * PR#490 + * Came from a bug from Svan Macke: + * + * Here is another problem that occured when I changed + * from aspectj0.8b3 to aspectj0.8b4. It seems that + * (under a very special condition) aspectJ has problems + * with the numbers that are appended to variable names + * inside the generated advice code. + * + * Here is the "special condition" where the error + * occured. I know the discussion about 'of eachobject' + * and I also know that in the following code it is + * absolutely unnecessary to use 'of eachobject' (don't + * ask me why I wrote such terrible code, I do not know + * it myself), but however, I think it is correct aspectj + * code and should therefore compile correctly. + * + * @since 2000.08.06 + * @author Jeff Palm + * @report 408 + */ +public class PerTargetAndVariablesWithNumbersInTheirNames { + public static void main(String[] args) { + new C(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("Hello 1"); + Tester.expectEvent("World 2"); + Tester.expectEvent("Hello World around 1"); + Tester.expectEvent("Hello World around 2"); + Tester.expectEvent("Hello World around 3"); + Tester.expectEvent("Hello World around 4"); + } +} + +class C +{ + public C() + { + doSomething("Hello", "World"); + } + public void doSomething(String arg1, String arg2) + { + Tester.event(arg1 + " 1"); + Tester.event(arg2 + " 2"); + } +} + +/* + * A pertarget aspect. + */ +aspect A1 pertarget(target(C)) { + void around(String arg1, String arg2): + target(C) && + call(public void doSomething(String,String)) && + args(arg1, arg2) { + Tester.event(arg1 + " " + arg2 + " around 1"); + proceed(arg1, arg2); + } +} + +/* + * Another pertarget aspect. + */ +aspect A2 pertarget(target(C)) { + void around(String arg1, String arg2): + target(C) && + call(public void doSomething(String,String)) && + args(arg1, arg2) { + Tester.event(arg1 + " " + arg2 + " around 2"); + proceed(arg1, arg2); + } +} + +/* + * A 'static' aspect. + */ +aspect A3 { + void around(String arg1, String arg2): + target(C) && + call(public void doSomething(String,String)) && + args(arg1, arg2) { + Tester.event(arg1 + " " + arg2 + " around 3"); + proceed(arg1, arg2); + } +} + +/* + * Another 'static' aspect. + */ +aspect A4 { + void around(String arg1, String arg2): + target(C) && + call(public void doSomething(String,String)) && + args(arg1, arg2) { + Tester.event(arg1 + " " + arg2 + " around 4"); + proceed(arg1, arg2); + } +} diff --git a/tests/new/PointcutFormals.java b/tests/new/PointcutFormals.java new file mode 100644 index 000000000..d50de023c --- /dev/null +++ b/tests/new/PointcutFormals.java @@ -0,0 +1,41 @@ +import org.aspectj.testing.*; + +public class PointcutFormals { + public static void main(String[] args) { + new PointcutFormals().call(0); + Tester.checkAllEvents(); + } + void call(int i) {} + + static { + String[] cuts = { "calls_pc", "receptions_pc", "executions_pc" }; + String[] kinds = { "before", "after", "around" }; + for (int i = 0; i < cuts.length; i++) { + for (int j = 0; j < kinds.length; j++) { + Tester.expectEvent(kinds[j] + "." + cuts[i]); + } + } + } +} + +aspect Aspect { + pointcut calls_pc (): call(void *.call(int)) && within(PointcutFormals); + pointcut receptions_pc(): call(void PointcutFormals.call(int)); + pointcut executions_pc(): execution(void *(int)); + + before(): calls_pc () { a("before.calls_pc"); } + before(): receptions_pc() { a("before.receptions_pc"); } + before(): executions_pc() { a("before.executions_pc"); } + + after(): calls_pc () { a("after.calls_pc"); } + after(): receptions_pc() { a("after.receptions_pc"); } + after(): executions_pc() { a("after.executions_pc"); } + + around() returns void: calls_pc () { a("around.calls_pc"); proceed(); } + around() returns void: receptions_pc() { a("around.receptions_pc"); proceed(); } + around() returns void: executions_pc() { a("around.executions_pc"); proceed(); } + + void a(Object msg) { + Tester.event(msg); + } +} diff --git a/tests/new/PointcutQualification.java b/tests/new/PointcutQualification.java new file mode 100644 index 000000000..446bf59f1 --- /dev/null +++ b/tests/new/PointcutQualification.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.Tester; + +public class PointcutQualification { + public static void main(String[] args) { + Tester.expectEvent("before pc_reference"); + new TargetClass().doit(); + Tester.checkAllEvents(); + } +} + +class I { + public static final void got(String s) { + Tester.event(s); + } +} + +class TargetClass{ void doit(){}} + +aspect DebugAspect { // incorrect compiler error here + before() : Aspect.pc_reference() { I.got("before pc_reference");} +} + +aspect Aspect { + + pointcut pc_notfound() + : execution(void TargetClass.doit()) ; + + pointcut someCallCflow() + : !within(Aspect) && !within(DebugAspect) && !within(I) + //&& cflow(Aspect.pc_notfound()) ; // workaround + && cflow(pc_notfound()) ; // bug: unqualified reference in DebugAspect context + + pointcut pc_reference() : someCallCflow(); +} + + diff --git a/tests/new/PointcutQualification2.java b/tests/new/PointcutQualification2.java new file mode 100644 index 000000000..63568aa3c --- /dev/null +++ b/tests/new/PointcutQualification2.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; + +public class PointcutQualification2 { + public static void main(String[] args) { + Tester.expectEvent("before pc_reference2"); + new TargetClass().doit(); + Tester.checkAllEvents(); + } +} + +class I { + public static final void got(String s) { + Tester.event(s); + } +} + +class TargetClass{ void doit(){}} + +aspect DebugAspect2 { // incorrect compiler error here + before() : Aspect2.pc_reference2() { I.got("before pc_reference2");} +} + +aspect Aspect2 { + + pointcut pc_notfound2() + : execution(void TargetClass.doit()) ; + + //pointcut anotherRef() : Aspect2.pc_notfound2(); // workaround + pointcut anotherRef() : pc_notfound2(); + + pointcut pc_reference2() : anotherRef(); +} + diff --git a/tests/new/PreInitialization.java b/tests/new/PreInitialization.java new file mode 100644 index 000000000..a4e447667 --- /dev/null +++ b/tests/new/PreInitialization.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.Tester; + +public class PreInitialization { + PreInitialization() { + this(PreInitialization.interestingCall()); + } + PreInitialization(int ignored) { + } + + public static void main(String[] args) { + new PreInitialization(); + Tester.checkEvents(new String[] {"before advice ran"}); + } + static int interestingCall() { + // do something interesting + return 3; + } +} + +aspect A { + before(): call(int PreInitialization.interestingCall()) { + Tester.checkEqual(thisEnclosingJoinPointStaticPart.getKind(), + "preinitialization"); + Tester.event("before advice ran"); + } +} diff --git a/tests/new/PrivateIntro.java b/tests/new/PrivateIntro.java new file mode 100644 index 000000000..c82474b22 --- /dev/null +++ b/tests/new/PrivateIntro.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; + +public class PrivateIntro { + public static void test() { + Tester.checkEqual(new A1().getWhere(), "A1", "from A1"); + Tester.checkEqual(new A2().getWhere(), "A2", "from A2"); + + } + + public static void main(String[] args) { + test(); + } +} + + +class A1 { + private introduction Foo { + String fromWhere() { + return "A1"; + } + } + + public String getWhere() { + return new Foo().fromWhere(); + } +} + +class A2 { + private introduction Foo { + String fromWhere() { + return "A2"; + } + } + + public String getWhere() { + return new Foo().fromWhere(); + } +} + +class Foo {} diff --git a/tests/new/PrivateMethodOnInnerInterface.java b/tests/new/PrivateMethodOnInnerInterface.java new file mode 100644 index 000000000..f6e11d732 --- /dev/null +++ b/tests/new/PrivateMethodOnInnerInterface.java @@ -0,0 +1,36 @@ + +import org.aspectj.testing.Tester; + +/** @testcase PR#823 private abstract method declared on inner interface */ +public class PrivateMethodOnInnerInterface { + + public static void main(String[] args) { + new C(); + Tester.expectEvent("method"); + Tester.checkAllEvents(); + // XXX CF test that method is not visible here + } +} + +class C { } + +abstract aspect A { + // no bug unless not member of the same aspect + interface I {} + interface J extends I{} +} +aspect B extends A { + + declare parents : C implements J; + private abstract int I.privateMethod(); + + private int C.privateMethod() { + Tester.event("method"); + return 0; + } + after(I i) returning : target(i) && initialization(I.new()) { + i.privateMethod(); + } +} + + diff --git a/tests/new/Privileged.java b/tests/new/Privileged.java new file mode 100644 index 000000000..91fb6c4b5 --- /dev/null +++ b/tests/new/Privileged.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.*; + +privileged aspect PrivilegedAspect { + public void OtherClass.foo() { + Tester.event("foo.intro"); + } +} + +class OtherClass { +} + +public class Privileged { + public static void main(String[] args) { + new Privileged().go(); + } + + static { + Tester.expectEventsInString("foo.intro,foo.done,foo.called"); + } + + void go() { + Tester.event("foo.called"); + new OtherClass().foo(); + Tester.event("foo.done"); + } +} diff --git a/tests/new/PublicClassWrongFilename.java b/tests/new/PublicClassWrongFilename.java new file mode 100644 index 000000000..85d443a5d --- /dev/null +++ b/tests/new/PublicClassWrongFilename.java @@ -0,0 +1,5 @@ + +/** no warning that file not called "TargetClass" */ +public class TargetClass { + public static void main(String[] args) { } +} diff --git a/tests/new/QualifiedSuperCall.java b/tests/new/QualifiedSuperCall.java new file mode 100644 index 000000000..c25fd3be8 --- /dev/null +++ b/tests/new/QualifiedSuperCall.java @@ -0,0 +1,93 @@ + +import org.aspectj.testing.*; + +// todo: package-qualified calls +/** PR651 PUREJAVA qualified super method calls */ +public class QualifiedSuperCall { + public static void main (String[] args) { + Super s; + s = new Super(); + Tester.check(null != s, "new Super()"); + s = new Sub(); + Tester.check(null != s, "new Sub()"); + s = new UnqualifiedSub(); + Tester.check(null != s, "new UnqualifiedSub()"); + s = new SubSub(); + Tester.check(null != s, "new SubSub()"); + s = new UnqualifiedSubSub(); + Tester.check(null != s, "new UnqualifiedSubSub()"); + s = new Mid(); + Tester.check(null != s, "new Mid()"); + s = new SubMid(); + Tester.check(null != s, "new SubMid()"); + s = new UnqualifiedSubMid(); + Tester.check(null != s, "new UnqualifiedSubMid()"); + } + static { + Tester.m("Super.duper=Sub()"); + Tester.m("Super.duper=UnqualifiedSub()"); + Tester.m("Super.duper=SubSub()"); + Tester.m("Super.duper=UnqualifiedSubSub()"); + Tester.m("Super.duper=SubMid()"); + Tester.m("Mid.duper=SubMid()"); + Tester.m("Mid.duper=UnqualifiedSubMid()"); + } + +} + +class Super { + Super() {} + void duper(String caller) { + Tester.event("Super.duper=" + caller); + } +} + +class Sub extends Super { + Sub() { + Super.super(); + Super.super.duper("Sub()"); + } +} +class UnqualifiedSub extends Super { + UnqualifiedSub() { + super(); + super.duper("UnqualifiedSub()"); + } +} + +class SubSub extends Sub { + SubSub() { + Sub.super(); + Sub.super.duper("SubSub()"); + } +} +class UnqualifiedSubSub extends UnqualifiedSub { + UnqualifiedSubSub() { + super(); + super.duper("UnqualifiedSubSub()"); + } +} + +class Mid extends Super { + Mid() { } + void duper(String caller) { + Tester.event("Mid.duper=" + caller); + } +} + +class SubMid extends Mid { + SubMid() { + Mid.super(); // XXX illegal ordering? + Super.super(); + Super.super.duper("SubMid()"); + Mid.super.duper("SubMid()"); + } +} +class UnqualifiedSubMid extends Mid { + UnqualifiedSubMid() { + super(); + super.duper("UnqualifiedSubMid()"); + } +} + + diff --git a/tests/new/RecognizeAspectCE.java b/tests/new/RecognizeAspectCE.java new file mode 100644 index 000000000..a84effb04 --- /dev/null +++ b/tests/new/RecognizeAspectCE.java @@ -0,0 +1,7 @@ +// PR#457 +class RecognizeAspectCE { + public static void main(String[] ignore) { } + pointcut mumble() // would like error here: "pointcuts not allowed in classes - use aspect" + : execution(public static void RecognizeAspectCE.main(String[])); + before(): mumble() { } // ok: get error here: constructor has the wrong name +} diff --git a/tests/new/ReferringToPointcutsInAspect_PR316.java b/tests/new/ReferringToPointcutsInAspect_PR316.java new file mode 100644 index 000000000..de1306450 --- /dev/null +++ b/tests/new/ReferringToPointcutsInAspect_PR316.java @@ -0,0 +1,20 @@ +import org.aspectj.testing.Tester; +public class ReferringToPointcutsInAspect_PR316 { + public static void main(String[] args) { + new C().f(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("void-f"); + Tester.expectEvent("before-f"); + } +} + +class C { + public void f() { Tester.event("void-f"); } +} + +aspect A /*of eachobject(i())*/ { + pointcut i(): target(C); + before(): i() && execution(* f(..)) { Tester.event("before-f"); } +} diff --git a/tests/new/RemovingFinals.java b/tests/new/RemovingFinals.java new file mode 100644 index 000000000..5a1e14b37 --- /dev/null +++ b/tests/new/RemovingFinals.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; +import java.lang.reflect.*; +public class RemovingFinals { + public static void main(String[] args) { + new RemovingFinals().realMain(args); + } + public void realMain(String[] args) { + try { + Tester.check((C.class.getField("public_i").getModifiers() + & Modifier.FINAL) != 0, "public_i is not final"); + } catch (Throwable t) { + Tester.throwable(t); + } + } +} + +class C { + public final int public_i = 1; + static int x = 2; + + private final int CONST = 0; + public void m() { + switch(x) { + case (CONST): System.out.println("no"); + } + } +} + +// make things a little difficult +aspect A { + before(): staticinitialization(C) { new StringBuffer().append(thisJoinPoint); } + before(): execution(C.new(..)) { new StringBuffer().append(thisJoinPoint); } +} diff --git a/tests/new/RestrictingVisibilityCF.java b/tests/new/RestrictingVisibilityCF.java new file mode 100644 index 000000000..429590e48 --- /dev/null +++ b/tests/new/RestrictingVisibilityCF.java @@ -0,0 +1,62 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#536 expecting compile failures with subclass narrowing scope of superclass methods or accessing private superclass variables */ +public class RestrictingVisibilityCF { + public static void main(String[] args) { + Tester.check(false, "compile should fail"); + } +} + +class Parent { + public int publicAccess; + protected int protectedAccess; + int defaultAccess; + private int privateAccess; + + public void publicAccess() {} + protected void protectedAccess() {} + void defaultAccess() {} + private void privateAccess() {} + void drivePrivateAccess() { + privateAccess(); + } +} + +class InValidChild extends Parent { + /** @testcase subclass private implementation of public method */ + private void publicAccess() { } // errLine 27 + /** @testcase subclass private implementation of method with default access */ + private void defaultAccess() { } // errLine 29 + /** @testcase subclass private implementation of protected method */ + private void protectedAccess() { } // errLine 31 + + // todo: sep package, attempt package acces + int defaultAccessSub = defaultAccess; +} + +class InValidChild2 extends Parent { + /** @testcase subclass private implementation of method with default access */ + private void defaultAccess() { } // errLine 39 + /** @testcase subclass protected implementation of public method */ + protected void publicAccess() { } // errLine 41 +} + +class InValidChild3 extends Parent { + /** @testcase subclass default implementation of method with protected access */ + void protectedAccess() { } // errLine 46 + /** @testcase subclass default implementation of public method */ + void publicAccess() { } // errLine 48 +} + +class InValidChild4 extends Parent { + /** @testcase private access members unavailable in subclass */ + private int foo = new Parent().privateAccess; // errLine 53 +} + +// /** todo: separate package test */ +// class Invalid { +// /** @testcase default access members unavailable from separate package */ +// private int bar = new Parent().defaultAccess; +// /** @testcase protected access members unavailable from separate package */ +// private int foo = new Parent().protectedAccess; +// } diff --git a/tests/new/RestrictingVisibilityCP.java b/tests/new/RestrictingVisibilityCP.java new file mode 100644 index 000000000..0b9641fac --- /dev/null +++ b/tests/new/RestrictingVisibilityCP.java @@ -0,0 +1,211 @@ +import org.aspectj.testing.Tester; + +/** @testcase PR#536 overriding subclass method may be protected when superclass method has default access */ +public class RestrictingVisibilityCP { + public static void main(String[] args) { + Tester.expectEventsInString(Const.EXPECTED); + Parent[] tests = new Parent[] + { new Parent() + , new ValidChild() + , new ValidChild2() + , new ValidChild3() + , new ValidChildTest() + , new ValidChildTest2() + , new ValidChildTest3() + }; + Parent child; + for (int i = 0; i< tests.length;i++) { + child = tests[i]; + Tester.event(child.getClass().getName()); + //System.err.println(", \"" + child.getClass().getName() + "\""); + child.publicAccess(); + child.defaultAccess(); + child.protectedAccess(); + child.drivePrivateAccess(); + } + Tester.checkAllEvents(); + } +} +/** aspect used to log progess - test case otherwise purejava */ +aspect LogAll { + before() : within(Parent+) && execution(* *(..)) { + String name = thisJoinPointStaticPart.toString(); + Tester.event(name); + // System.err.println(", \"" + name + "\""); + } +} +class Parent { + public int publicAccess = 1; + protected int protectedAccess = 1; + int defaultAccess = 1; + private int privateAccess = 1; + + public void publicAccess() {} + protected void protectedAccess() {} + void defaultAccess() {} + private void privateAccess() {} + void drivePrivateAccess() { + privateAccess(); + } +} + +class ValidChild extends Parent { + + /** @testcase subclass public implementation of public method */ + public void publicAccess() { super.publicAccess(); } + /** @testcase subclass protected implementation of protected method */ + protected void protectedAccess() { super.protectedAccess(); } + /** @testcase subclass default implementation of default method */ + void defaultAccess() { super.defaultAccess(); } + /** @testcase subclass implementation of private method - not overriding */ + private void privateAccess() { } + void drivePrivateAccess() { + privateAccess(); + super.drivePrivateAccess(); + } + + int publicAccessSub = publicAccess; + int protectedAccessSub = protectedAccess; + int defaultAccessSub = defaultAccess; +} + +class ValidChild2 extends Parent { + /** @testcase subclass public implementation of protected method */ + public void protectedAccess() { super.protectedAccess(); } + /** @testcase subclass public implementation of default method */ + public void defaultAccess() { super.defaultAccess(); } +} + +class ValidChild3 extends Parent { + /** @testcase subclass protected implementation of default method */ + // todo: restore to restore ce + protected void defaultAccess() { super.defaultAccess(); } +} + +class ValidChildTest extends ValidChild { + /** @testcase subsubclass public implementation of public method */ + public void publicAccess() { super.publicAccess(); } + /** @testcase subsubclass protected implementation of protected method */ + protected void protectedAccess() { super.protectedAccess(); } + /** @testcase subsubclass default implementation of default method */ + void defaultAccess() { super.defaultAccess(); } + /** @testcase subsubclass implementation of private method - not overriding */ + private void privateAccess() { } + void drivePrivateAccess() { + privateAccess(); + super.drivePrivateAccess(); + } +} +class ValidChildTest2 extends ValidChild { + /** @testcase subsubclass public implementation of protected method */ + public void protectedAccess() { super.protectedAccess(); } + /** @testcase subsubclass public implementation of default method */ + public void defaultAccess() { super.defaultAccess(); } +} +class ValidChildTest3 extends ValidChild { + /** @testcase PR#536 subsubclass protected implementation of default method */ + // todo protected void defaultAccess() { super.defaultAccess(); } +} +class ValidChild5 extends Parent { + int one = publicAccess; + int two = protectedAccess; + int three = defaultAccess; +} +class ValidClass { + static int[] ra; + static { + ra = new int[] + { (new Parent()).publicAccess + , (new ValidChild()).publicAccess + , (new ValidChildTest()).publicAccess + , (new Parent()).defaultAccess + , (new ValidChild()).defaultAccess + , (new ValidChildTest()).defaultAccess + , (new Parent()).protectedAccess + , (new ValidChild()).protectedAccess + , (new ValidChildTest()).protectedAccess + }; + for (int i = 0; i < ra.length; i++) { + Tester.check(1 == ra[i], + "expected 1 at " + i + " got i" + ra[i]); + } + } +} + +class Const { + public static final String[] EXPECTED = new String[] + { "Parent" + , "execution(void Parent.publicAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "ValidChild" + , "execution(void ValidChild.publicAccess())" + , "execution(void Parent.publicAccess())" + , "execution(void ValidChild.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void ValidChild.protectedAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void ValidChild.drivePrivateAccess())" + , "execution(void ValidChild.privateAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "ValidChild2" + , "execution(void Parent.publicAccess())" + , "execution(void ValidChild2.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void ValidChild2.protectedAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "ValidChild3" + , "execution(void Parent.publicAccess())" + , "execution(void ValidChild3.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "execution(void ValidChildTest.publicAccess())" + , "execution(void ValidChild.publicAccess())" + , "execution(void Parent.publicAccess())" + , "ValidChildTest" + , "execution(void ValidChildTest.defaultAccess())" + , "execution(void ValidChild.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void ValidChildTest.protectedAccess())" + , "execution(void ValidChild.protectedAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void ValidChildTest.drivePrivateAccess())" + , "execution(void ValidChildTest.privateAccess())" + , "execution(void ValidChild.drivePrivateAccess())" + , "execution(void ValidChild.privateAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "ValidChildTest2" + , "execution(void ValidChild.publicAccess())" + , "execution(void Parent.publicAccess())" + , "execution(void ValidChildTest2.defaultAccess())" + , "execution(void ValidChild.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void ValidChildTest2.protectedAccess())" + , "execution(void ValidChild.protectedAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void ValidChild.drivePrivateAccess())" + , "execution(void ValidChild.privateAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + , "ValidChildTest3" + , "execution(void ValidChild.publicAccess())" + , "execution(void Parent.publicAccess())" + , "execution(void ValidChild.defaultAccess())" + , "execution(void Parent.defaultAccess())" + , "execution(void ValidChild.protectedAccess())" + , "execution(void Parent.protectedAccess())" + , "execution(void ValidChild.drivePrivateAccess())" + , "execution(void ValidChild.privateAccess())" + , "execution(void Parent.drivePrivateAccess())" + , "execution(void Parent.privateAccess())" + + }; +} diff --git a/tests/new/ScopesAndFields_PR191.java b/tests/new/ScopesAndFields_PR191.java new file mode 100644 index 000000000..f80ececa3 --- /dev/null +++ b/tests/new/ScopesAndFields_PR191.java @@ -0,0 +1,30 @@ +import org.aspectj.testing.Tester; +public class ScopesAndFields_PR191 { + public static void main(String[] args) { + new ScopesAndFields_PR191().realMain(args); + } + public void realMain(String[] args) { + C c = new C(); + c.a(); + Tester.checkEqual(c.c(), "C"); + Tester.checkEqual(c.c, "c"); + Tester.checkEqual(c.t(), "c"); + } +} + +class C { + public String c = "c"; + public String c() { + Object c = "C"; + return c+""; + } + public String t() { + Object c = "C"; + return this.c; + } + public void a() { + String c = "C"; + Tester.checkEqual(c+"", "C"); + Tester.checkEqual(this.c, "c"); + } +} diff --git a/tests/new/SerializedOf.java b/tests/new/SerializedOf.java new file mode 100644 index 000000000..fd58d8d71 --- /dev/null +++ b/tests/new/SerializedOf.java @@ -0,0 +1,42 @@ +import org.aspectj.testing.Tester; +import java.io.*; + + +public class SerializedOf { + public static void main(String[] args) throws Exception { + C c = new C(); + + Tester.check(ASer.hasAspect(c), "ASer on original"); + Tester.check(ANoSer.hasAspect(c), "ANoSer on original"); + + + File tmp = File.createTempFile("cdata", "ser"); + FileOutputStream ostream = new FileOutputStream(tmp); + ObjectOutputStream p = new ObjectOutputStream(ostream); + p.writeObject(c); + p.flush(); + ostream.close(); + + + FileInputStream istream = new FileInputStream(tmp); + ObjectInputStream p1 = new ObjectInputStream(istream); + C newC = (C)p1.readObject(); + istream.close(); + + Tester.check(ASer.hasAspect(newC), "ASer after read"); + Tester.check(!ANoSer.hasAspect(newC), "no ANoSer after read"); + } +} + +class C implements Serializable { + int data = 42; +} + + +aspect ASer implements Serializable pertarget(target(C)) { + int serData = 20; +} + +aspect ANoSer pertarget(target(C+)) { + int noSerData = 21; +} diff --git a/tests/new/SimpleGets.java b/tests/new/SimpleGets.java new file mode 100644 index 000000000..91feda005 --- /dev/null +++ b/tests/new/SimpleGets.java @@ -0,0 +1,76 @@ +import org.aspectj.testing.Tester; +import java.util.*; +import java.io.*; + +public class SimpleGets { + public static void main(String[] args) { + Test t = new Test(); + t.go(); + + System.out.println("s: " + t.s); + + Test.ss += "hi"; + + //Tester.checkEqual(Test.calls, ", Test.go->Test, Test.foo->java.io.PrintStream"); + } +} + + +class Test { + int x = 10; + String s = "string"; + String s1 = ""; + + static String ss = ""; + + Test getT() { + return new Test(); + } + + void go() { + System.out.println(x); + s = getT().s + ":went"; + Test.ss += "static"; + getT().s += ":more"; + Test t = this; + t.s1 += "xxx"; + + x += 10; + x++; + System.out.println(x + " == " + x--); + System.out.println(x + " == " + x++); + System.out.println(x-1 + " == " + --x); + } +} + +aspect NoteGets { + + static after(Test t) returning (Object v): gets(* t.*) { + System.out.println("got it: " + v + " from " + t + " at " + thisJoinPoint); + } + + static after(String v): sets(String Test.*)[v][] { + new Test().s += "gi"; + System.out.println("set: " + v + " at " + thisJoinPoint); + } + + static around(Object old, String v) returns String: sets(String Test.*)[old][v] { + new Test().s += "gi"; + System.out.println("around set: " + old + " --> " + v + " at " + thisJoinPoint); + return proceed(old, v+"-advised"); + } + + static after(): sets(int Test.x) { + int v = 0; + System.out.println("iset: " + v + " at " + thisJoinPoint); + } + + static after(Object v, Object old): sets(* Test.*)[old][v] { + System.out.println("oset: " + old + " -> " + v + " at " + thisJoinPoint); + } + + static after(): gets(PrintStream java.lang.*.*) { + System.out.println("got System.out"); + } + +} diff --git a/tests/new/SmallComment.java b/tests/new/SmallComment.java new file mode 100644 index 000000000..6886acd7a --- /dev/null +++ b/tests/new/SmallComment.java @@ -0,0 +1,13 @@ +import org.aspectj.testing.*; + +public class SmallComment { + public static void main(String[] args) { + new SmallComment().realMain(args); + } + + public void realMain(String[] args) { + /**/ + Tester.check(true, "Compiled"); + } +} + diff --git a/tests/new/SourceLocationCall.java b/tests/new/SourceLocationCall.java new file mode 100644 index 000000000..a1ab48eff --- /dev/null +++ b/tests/new/SourceLocationCall.java @@ -0,0 +1,58 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; + +/** @testcase PR#658 simple call join point tests for JoinPoint SourceLocation context */ +public class SourceLocationCall { + public static void main(String[] args) { + new SourceLocationCall().maincall(); + } + public void maincall(){} +} + +aspect Tracing { + static void check(String label, JoinPoint jp, JoinPoint.StaticPart sp) { +// System.err.println("checking " + label + " " + jp + " " + sp +// + " - " + jp.getSourceLocation() +// + " - " + sp.getSourceLocation() ); + if (null == jp) { + Tester.check(false, "null JoinPoint@" + label); + } else { + Tester.check(null != jp.getSourceLocation(), + "null jp source location@" + label); + } + if (null == sp) { + Tester.check(false, "null JoinPoint.StaticPart@"+label); + } else { + Tester.check(null != sp.getSourceLocation(), + "null sp source location@" + label); + } + } + pointcut trace1() + : call(void SourceLocationCall.maincall(..)); + // ok + //: within(SourceLocationCall) ; + //: cflow(execution(void SourceLocationCall.main(String[]))) && !within(Tracing) ; + //: within(SourceLocationCall) && call(* *(..)); + //: execution(* SourceLocationCall.*(..)); + //: call(void SourceLocationCall.main*(..)) && within(*); + // fail + //: call(void SourceLocationCall.main*(..)); + //: call(* SourceLocationCall.*(..)); + //: call(void SourceLocationCall.*(..)); + // same result for static calls and instance calls + // same result for before and after + before() : trace1() { + check("before() : trace1()", thisJoinPoint, thisJoinPointStaticPart); + } + after() : trace1() { + check("after() : trace1()", thisJoinPoint, thisJoinPointStaticPart); + } + + before(): call(void SourceLocationCall.main(..)) { + Tester.check(thisJoinPoint.getSourceLocation() == null, "main call"); + Tester.check(thisJoinPoint.getThis() == null, "main call"); + } +} + + diff --git a/tests/new/SourceLocationToString.java b/tests/new/SourceLocationToString.java new file mode 100644 index 000000000..143dd0c70 --- /dev/null +++ b/tests/new/SourceLocationToString.java @@ -0,0 +1,29 @@ + +import org.aspectj.testing.*; +import org.aspectj.lang.*; + +/** @rfe our SourceLocation implementation should implement toString as filename:column */ +public class SourceLocationToString { + public static final String EXPECT = "SourceLocationToString.java:9"; + public static void main (String[] args) { + docall(); // line 9 + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("docall"); + } + static void docall() { + Tester.event("docall"); + } + static aspect A { + before () : call(void docall()) { + Tester.event("before"); + String sl = thisJoinPoint.getSourceLocation().toString(); + Tester.check(sl.endsWith(EXPECT), + "sl=\"" + sl + "\" did not end with \"" + + EXPECT + "\""); + } + } + +} + diff --git a/tests/new/SourceLocationWithinExpr.java b/tests/new/SourceLocationWithinExpr.java new file mode 100644 index 000000000..20352adea --- /dev/null +++ b/tests/new/SourceLocationWithinExpr.java @@ -0,0 +1,47 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +/** @testcase PR#885 call source locations within expression */ +public class SourceLocationWithinExpr { + public static void main (String[] args) { + new // 7* + C() // 8 + . // 9* + getD() // 10 + . // 11* + getE() // 12 + . // 13* + getF() // 14 + ; + Tester.expectEvent("setup"); + Tester.checkAllEvents(); + } +} +class C { D getD() { return new D(); } } +class D { E getE() { return new E(); } } +class E { F getF() { return new F(); } } +class F { } + +aspect A { + private static final String SEP = " - "; + static { + // using qualifying expr? + Tester.expectEvent("C()" + SEP + "7"); + Tester.expectEvent("getD()" + SEP + "9"); + Tester.expectEvent("getE()" + SEP + "11"); + Tester.expectEvent("getF()" + SEP + "13"); + Tester.event("setup"); + } + pointcut filter() : withincode(static void SourceLocationWithinExpr.main(String[])); + before() : filter() && call(C.new()) { signal("C()", thisJoinPoint); } + before() : filter() && call(D C.getD()) { signal("getD()", thisJoinPoint); } + before() : filter() && call(E D.getE()) { signal("getE()", thisJoinPoint); } + before() : filter() && call(F E.getF()) { signal("getF()", thisJoinPoint); } + void signal(String prefix, JoinPoint jp) { + SourceLocation sl = jp.getSourceLocation(); + System.out.println(prefix + SEP + sl.getLine()); + Tester.event(prefix + SEP + sl.getLine()); + } +} diff --git a/tests/new/StaticCalls.java b/tests/new/StaticCalls.java new file mode 100644 index 000000000..ca6c9a866 --- /dev/null +++ b/tests/new/StaticCalls.java @@ -0,0 +1,54 @@ +import org.aspectj.testing.Tester; + +public class StaticCalls { + public static void main(String args[]) { test(); } + + Object server = null; + + void run() { + Tester.checkEqual(StaticCalls.lookup("TimeService0"), + "TimeService0", + "untouched"); + Tester.checkEqual(StaticCalls.lookup("InterceptThis"), + "FromAround", + "touched"); + Tester.checkEqual(this.lookup("InterceptThis"), + "FromAround", + "this and touched"); + Tester.checkEqual(lookup("InterceptThis"), + "FromAround", + "lexical and touched"); + } + + public static void test() { + new StaticCalls().run(); + + Class c = Class.forName("java.lang.Foo"); + Tester.check(c == null, "intercepted exception and returned null"); + } + + static String lookup(String s){ + return s; + } +} + +aspect Aspect { + Object around(String s): + within(StaticCalls) && call(String StaticCalls.lookup(String)) && args(s) + { + if (s.equals("InterceptThis")) return "FromAround"; + else return proceed(s); + } + + pointcut classForName(): call(Class Class.forName(String)); + + declare soft: ClassNotFoundException: classForName(); + + Class around(): classForName() { + try { + return proceed(); + } catch (ClassNotFoundException e) { + return null; + } + } +} diff --git a/tests/new/StaticInitCE.java b/tests/new/StaticInitCE.java new file mode 100644 index 000000000..e13a9b47a --- /dev/null +++ b/tests/new/StaticInitCE.java @@ -0,0 +1,19 @@ + +public class StaticInitCE { + public static void main(String[] args) { + new C(); + } +} + +class C { C() { } } + +aspect A { + // PR#458 + void around(): staticinitialization(C) { + proceed(); + } + // PR#490 + void around(): initialization(C.new()) { + proceed(); + } +} diff --git a/tests/new/StaticInitName.java b/tests/new/StaticInitName.java new file mode 100644 index 000000000..657bd2ebb --- /dev/null +++ b/tests/new/StaticInitName.java @@ -0,0 +1,47 @@ + +import org.aspectj.testing.Tester; +import java.util.*; + +/** @testcase PR#771 static initializer member name */ +public class StaticInitName { + + public static void main(String[] args) { + Tester.expectEvent("C"); + Tester.event(""+C.class.getName()); + Tester.expectEvent("D"); + Tester.event(""+D.class.getName()); + Tester.checkAllEvents(); + } +} + +class C { + static int i = 1; +} + +class D { + static int i; + static { + i = 2; + } +} + +aspect A { + static { + Tester.expectEvent("before"); + Tester.expectEvent("before-D"); + } + + before() : within(C) && !set(* *) { + Tester.event("before"); + String memberName = thisJoinPoint.getSignature().getName(); + Tester.check("<clinit>".equals(memberName), + "\"<clinit>\".equals(\"" + memberName + "\")"); + } + + before() : within(D) && !set(* *) { + Tester.event("before-D"); + String memberName = thisJoinPoint.getSignature().getName(); + Tester.check("<clinit>".equals(memberName), + "\"<clinit>\".equals(\"" + memberName + "\")"); + } +} diff --git a/tests/new/StaticInnerAspect.java b/tests/new/StaticInnerAspect.java new file mode 100644 index 000000000..ee7e559ea --- /dev/null +++ b/tests/new/StaticInnerAspect.java @@ -0,0 +1,15 @@ +import org.aspectj.testing.*; + +public class StaticInnerAspect { + public static void main(String[] args) { + Tester.check(true, "compiled"); + } + +} + +aspect Aspect { + static class InnerClass { + static aspect InnerAspect { + } + } +} diff --git a/tests/new/StaticInnerInterfaces_PR386.java b/tests/new/StaticInnerInterfaces_PR386.java new file mode 100644 index 000000000..e7403e1a2 --- /dev/null +++ b/tests/new/StaticInnerInterfaces_PR386.java @@ -0,0 +1,36 @@ +import org.aspectj.testing.*; + +public class StaticInnerInterfaces_PR386 { + public static void main(String[] args) { + A a = new A(); + A.I ab = new C(); + C c = new C(); + D d = new D(); + a.go(); + ab.go(); + c.go(); + d.go(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("A0,C1,C2,D3"); + } +} + +class B { + static int j = 0; +} + +class A { + public static interface I { void go(); } + public void go() { Tester.event("A" + (B.j++)); } + +} + +class C extends A implements I { + public void go() { Tester.event("C" + (B.j++)); } +} + +class D implements A.I { + public void go() { Tester.event("D" + (B.j++)); } +} diff --git a/tests/new/StaticIntroducedReferences.java b/tests/new/StaticIntroducedReferences.java new file mode 100644 index 000000000..223673d23 --- /dev/null +++ b/tests/new/StaticIntroducedReferences.java @@ -0,0 +1,14 @@ +public class StaticIntroducedReferences { +} + +abstract aspect SuperA { + static void m() {} + static int i = 0; +} + +aspect A extends SuperA { + public static void StaticIntroducedReferences.main(String[] args) { + i++; + m(); + } +} diff --git a/tests/new/StaticMethodsShouldNotReceiveInstanceofAdvice.java b/tests/new/StaticMethodsShouldNotReceiveInstanceofAdvice.java new file mode 100644 index 000000000..1bc6898a9 --- /dev/null +++ b/tests/new/StaticMethodsShouldNotReceiveInstanceofAdvice.java @@ -0,0 +1,44 @@ +import org.aspectj.testing.*; +import java.util.*; + +public class StaticMethodsShouldNotReceiveInstanceofAdvice { + public static void main(String[] args) { + ClassWithStaticMethods.staticMethod(); + Tester.checkAllEvents(); + } + static { + Tester.expectEventsInString("good0"); + } +} + +class ClassWithStaticMethods { + public static void staticMethod() {} +} + + +aspect PutsAdviceOnStaticMethods { + + static void bad(Object msg) { Tester.check(false, "Shouldn't have seen: " + msg); } + static void good(String msg) { Tester.event(msg); } + + // These shouldn't run + pointcut bad0(): this(ClassWithStaticMethods) && execution(void staticMethod()); + pointcut bad1(ClassWithStaticMethods c): this(c) && execution(void staticMethod()); + pointcut bad2(): target(ClassWithStaticMethods) && call(void staticMethod()); + pointcut bad3(ClassWithStaticMethods c): target(c) && call(void staticMethod()); + pointcut bad4(): target(*) && call(void ClassWithStaticMethods.staticMethod()); + pointcut bad5(ClassWithStaticMethods c): target(c) && call(void staticMethod()); + + before(): bad0() { bad("bad0:" + thisJoinPoint); } + before(ClassWithStaticMethods c): bad1(c) { bad("bad1:" + thisJoinPoint); } + before(): bad2() { bad("bad2:" + thisJoinPoint); } + before(ClassWithStaticMethods c): bad3(c) { bad("bad3:" + thisJoinPoint); } + before(): bad4() { bad("bad4:" + thisJoinPoint); } + before(ClassWithStaticMethods c): bad5(c) { bad("bad5:" + thisJoinPoint); } + + // This should run + pointcut good0(): execution(void ClassWithStaticMethods.staticMethod()); + + before(): good0() { good("good0"); } + +} diff --git a/tests/new/StaticTypeInIf.java b/tests/new/StaticTypeInIf.java new file mode 100644 index 000000000..cc2a8087b --- /dev/null +++ b/tests/new/StaticTypeInIf.java @@ -0,0 +1,65 @@ +import org.aspectj.testing.Tester; + +// we want to be doing tests based on dynamic type in if +public class StaticTypeInIf { + public static void main(String[] args) { + D d = new D(); + C c = new C(); + + c.foo(c); + Tester.checkAndClearEvents(new String[] {}); + + A.setF(d, false); + c.foo(d); + Tester.checkAndClearEvents(new String[] {}); + A.setF(d, true); + c.foo(d); + Tester.checkAndClearEvents(new String[] {"args"}); + + A.setF(d, false); + d.foo(c); + Tester.checkAndClearEvents(new String[] {}); + A.setF(d, true); + d.foo(c); + Tester.checkAndClearEvents(new String[] {"this", "target"}); + + A.setF(d, false); + d.foo(d); + Tester.checkAndClearEvents(new String[] {}); + A.setF(d, true); + d.foo(d); + Tester.checkAndClearEvents(new String[] {"args", "this", "target"}); + + } + +} + +class C { + void foo(C c) {} +} + +class D extends C { + void foo(C c) {} +} + + +aspect A { + private boolean D.f = false; + + static void setF(D d, boolean b) { d.f = b; } + + pointcut foo(D d): call(void C.foo(C)) && target(d) && if(d.f); + + before (C c): foo(c) { + Tester.event("target"); + } + + before (D d): if(d.f) && call(void C.foo(C)) && args(d) { + Tester.event("args"); + + } + + before (D d): execution(void C.foo(C)) && this(d) && if(d.f) { + Tester.event("this"); + } +} diff --git a/tests/new/StrictFPAdvice.java b/tests/new/StrictFPAdvice.java new file mode 100644 index 000000000..af9b6bcea --- /dev/null +++ b/tests/new/StrictFPAdvice.java @@ -0,0 +1,22 @@ +import org.aspectj.testing.Tester; + +public class StrictFPAdvice { + public static void main(String[] args) { + m(2.0); + } + + static double m(double a) { return a; } +} + +aspect A { + pointcut points(double d): call(double StrictFPAdvice.m(double)) && args(d); + + strictfp before(double d): points(d) { + //XXX insert a test here that this body really is strictfp + } + + strictfp double around(double d): points(d) { + //XXX insert a test here that this body really is strictfp + return proceed(d); + } +} diff --git a/tests/new/StrictFp.java b/tests/new/StrictFp.java new file mode 100644 index 000000000..d9113a0ae --- /dev/null +++ b/tests/new/StrictFp.java @@ -0,0 +1,14 @@ +import org.aspectj.testing.*; + +public strictfp class StrictFp { + public static void main(String[] args) { + new StrictFp().go(); + Tester.check(ran, "go did not run"); + } + + static boolean ran = false; + + void go() { + ran = true; + } +} diff --git a/tests/new/StrictFpCErr1.java b/tests/new/StrictFpCErr1.java new file mode 100644 index 000000000..ff07b43be --- /dev/null +++ b/tests/new/StrictFpCErr1.java @@ -0,0 +1,4 @@ +strictfp interface StrictInterfaceBadFunction { + // Has to be error, may not generate strictfp, but has to set strictfp in bytecode + strictfp float test1(); +}; diff --git a/tests/new/StrictFpCErr2.java b/tests/new/StrictFpCErr2.java new file mode 100644 index 000000000..919069e06 --- /dev/null +++ b/tests/new/StrictFpCErr2.java @@ -0,0 +1,4 @@ +strictfp abstract class StrictClassBadField { + // Has to be an error + strictfp float f; +}; diff --git a/tests/new/StrictFpCErr3.java b/tests/new/StrictFpCErr3.java new file mode 100644 index 000000000..f4fb5acd4 --- /dev/null +++ b/tests/new/StrictFpCErr3.java @@ -0,0 +1,5 @@ +strictfp abstract class StrictClassBadConstructor { + // Has to be error, may not generate strictfp, but has to set strictfp in bytecode + strictfp StrictClassBadConstructor() {} +}; + diff --git a/tests/new/StrictFpCompile.java b/tests/new/StrictFpCompile.java new file mode 100644 index 000000000..2efe0c9d8 --- /dev/null +++ b/tests/new/StrictFpCompile.java @@ -0,0 +1,82 @@ +import org.aspectj.testing.*; + +public strictfp class StrictFpCompile { + public static void main(String[] args) { + new StrictFpCompile().go(); + Tester.check(ran, "go did not run"); + } + + static boolean ran = false; + + void go() { + ran = true; + } +} + + +// Ok, must be generated with strictfp modifier +strictfp interface StrictInterface { + // Has to be error, may not generate strictfp, but has to set strictfp in bytecode + // strictfp float test1(); + + // Ok, may not be generated with strictfp modifier + float test2(); +}; + +// Ok, must be generated with strictfp modifier +strictfp abstract class StrictClass { + // Has to be an error + // strictfp float f; + + // Ok + double d; + + // Has to be error, may not generate strictfp, but has to set strictfp in bytecode + // strictfp StrictClass() {} + + // Ok, must not generate strictfp, but has to set strictfp in bytecode + StrictClass(double _d) { d = _d; } + + // Ok, may be generated with strictfp modifier + abstract float test1(); + + // Ok, may be generated with strictfp modifier + float test2() { return 0.f; } + + // Ok, may be generated with strictfp modifier + strictfp float test3() { return 0.f; } + + // Ok, may be generated with strictfp modifier + strictfp static float test4() { return 0.f; } + +}; + +// Ok, may not be generated with strictfp modifier +class NonStrictClass { + // Ok + NonStrictClass() {} + + // Ok, may not be generated with strictfp modifier + float test2() { return 0.f; } + + // Ok, must be generated with strictfp modifier + strictfp float test3() { return 0.f; } + + // Ok, must be generated with strictfp modifier + strictfp static float test4() { return 0.f; } + +}; + +// Ok +strictfp class OuterStrictClass { + + // Ok, may be generated with strictfp modifier + class InnerStrictClass { + + // Ok, may be generated with strictfp modifier + class InnerInnerClass { + } + } + +}; + diff --git a/tests/new/StrictFpReceptions.java b/tests/new/StrictFpReceptions.java new file mode 100644 index 000000000..d3914025f --- /dev/null +++ b/tests/new/StrictFpReceptions.java @@ -0,0 +1,82 @@ +import org.aspectj.testing.*; + +public class StrictFpReceptions { + // reception counter + static int r_counter = 0; + // call counter + static int c_counter = 0; + + public static void main(String[] args) { + StrictClass s = new StrictClass(); + StrictClassAbstract sa = s; + + cleanup(); + s.test1(); + Tester.check + (r_counter==1 && c_counter==1, + "test1 method call, " + + "counters="+r_counter+","+c_counter); + + cleanup(); + sa.test2(); + Tester.check + (r_counter==0 && c_counter==0, + "test2 method call, " + + "counters="+r_counter+","+c_counter); + + cleanup(); + sa.test3(); + Tester.check + (r_counter==1 && c_counter==1, + "test3 method call, " + + "counters="+r_counter+","+c_counter); + + cleanup(); + sa.test4(); + Tester.check + (r_counter==1 && c_counter==1, + "test4 static method call, " + + "counters="+r_counter+","+c_counter); + + cleanup(); + sa.test5(); + Tester.check + (r_counter==0 && c_counter==0, + "test5 static method call, " + + "counters="+r_counter+","+c_counter); + + } + + private static void cleanup() { + r_counter = c_counter = 0; + } + +} + +aspect StrictFpWatcher { + pointcut r_strict() : execution(strictfp * *(..)); + pointcut c_strict() : call(strictfp * *.*(..)); + + before() : r_strict() { StrictFpReceptions.r_counter++; } + before() : c_strict() { StrictFpReceptions.c_counter++; } +} + + +abstract class StrictClassAbstract { + float f; + double d; + StrictClassAbstract() {} + StrictClassAbstract(double _d) { d = _d; } + public abstract float test1(); + public float test2() { return 0.f; } + public strictfp float test3() { return 0.f; } + public static strictfp float test4() { return 0.f; } + public static float test5() { return 0.f; } + +}; + +strictfp class StrictClass extends StrictClassAbstract { + public float test1() { return 0.f; } + +} + diff --git a/tests/new/SuperDisambiguatingType.java b/tests/new/SuperDisambiguatingType.java new file mode 100644 index 000000000..b94223f41 --- /dev/null +++ b/tests/new/SuperDisambiguatingType.java @@ -0,0 +1,61 @@ +import org.aspectj.testing.*; + + +/** @testcase PUREJAVA super reference used to disambiguate names of different but compatible types */ +public class SuperDisambiguatingType { + public static void main (String[] args) { + new Sub().test(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("test"); + } +} + + +interface I { } +class C { } +class IClass implements I { } +class CClass extends C { } + +class Super { + protected C fieldC; + protected I fieldI; +} + +class Sub extends Super { + // hiding super + protected CClass fieldC; + protected IClass fieldI; + protected Integer intField; + public void test() { + testC(); + testI(); + Tester.event("test"); + } + public void testC() { + super.fieldC = (C) (fieldC = new CClass()); + checkC("super.fieldC = (C) (fieldC = new CClass())"); + super.fieldC = (C) fieldC; + checkC("super.fieldC = (C) fieldC"); + super.fieldC = fieldC; + checkC("super.fieldC = fieldC"); + } + private final void checkC(String label) { + Tester.check(null != fieldC, label + "null != fieldC"); + Tester.check(super.fieldC == fieldC, label + "super.fieldC == fieldC"); + } + public void testI() { + super.fieldI = (I) (fieldI = new IClass()); + checkI("super.fieldI = (I) (fieldI = new IClass())"); + super.fieldI = (I) fieldI; + checkI("super.fieldI = (I) fieldI"); + super.fieldI = fieldI; + checkI("super.fieldI = fieldI"); + } + private final void checkI(String label) { + Tester.check(null != fieldI, label + "null != fieldI"); + Tester.check(super.fieldI == fieldI, label + "super.fieldI == fieldI"); + } +} + diff --git a/tests/new/SuperField.java b/tests/new/SuperField.java new file mode 100644 index 000000000..be80b3bd8 --- /dev/null +++ b/tests/new/SuperField.java @@ -0,0 +1,76 @@ +import org.aspectj.testing.Tester; + +public class SuperField { + public static void main(String[] args) { + Derived d = new Derived(); + Tester.checkAndClearEvents(new String[] { + "set Base on <Derived>", + "set Derived on <Derived>", + }); + d.m1(); + Tester.checkAndClearEvents(new String[] { + "get Derived on <Derived>", + "Derived", + }); + d.m2(); + Tester.checkAndClearEvents(new String[] { + "get Derived on <Derived>", + "Derived", + }); + d.m3(); + Tester.checkAndClearEvents(new String[] { + "get Base on <Derived>", + "Base", + }); + d.m4(); + Tester.checkAndClearEvents(new String[] { + "get Base on <Derived>", + "set BaseNew on <Derived>", + "get BaseNew on <Derived>", + "BaseNew", + }); + Tester.printEvents(); + } +} + +class Base { + String s = "Base"; + public String toString() { return "<Base>"; } +} + +class Derived extends Base { + String s = "Derived"; + + + void m1() { + Tester.event(s); + } + + void m2() { + Tester.event(this.s); + } + + void m3() { + Tester.event(super.s); + } + + void m4() { + super.s += "New"; + + Tester.event(super.s); + } + + public String toString() { return "<Derived>"; } +} + +aspect A { + after(Object o) returning (String v): target(o) && get(String s) { + Tester.event("get " + v + " on " + o); + } + + before(Object o, String v): target(o) && set(String s) && args(v) { + Tester.event("set " + v + " on " + o); + } + + +} diff --git a/tests/new/SuperInIntroduction.java b/tests/new/SuperInIntroduction.java new file mode 100644 index 000000000..6c101507a --- /dev/null +++ b/tests/new/SuperInIntroduction.java @@ -0,0 +1,61 @@ + +import org.aspectj.testing.Tester; + +public class SuperInIntroduction { + public static void main (String[] args) { + int result = new Sub().getInt(); + Tester.check(8==result, "new Sub().getInt() !8==" + result); + ObjectSub sb = new ObjectSub().getClone(); + Tester.check(null != sb, "null new ObjectSub().getClone()"); + sb = new ObjectSub().getSuperClone(); + Tester.check(null != sb, "null new ObjectSub().getSuperClone()"); + } +} + +class Super { + protected int protectedInt = 1; + protected int protectedIntMethod() { return protectedInt; } + int defaultInt = 1; + int defaultIntMethod() { return defaultInt; } +} + +class Sub extends Super { } +class ObjectSub { } + +aspect A { + /** @testcase accessing protected method and field of class within code the compiler controls */ + public int Sub.getInt() { + int result; + result = super.protectedInt; + result += super.protectedIntMethod(); + result += protectedInt; + result += protectedIntMethod(); + result += defaultInt; + result += defaultIntMethod(); + result += super.defaultInt; + result += super.defaultIntMethod(); + return result; + } + + /** @testcase accessing protected method of class outside code the compiler controls */ + public ObjectSub ObjectSub.getClone() { + try { + Object result = clone(); + return (ObjectSub) result; + } catch (CloneNotSupportedException e) { + return this; + } + } + + /** @testcase using super to access protected method of class outside code the compiler controls */ + public ObjectSub ObjectSub.getSuperClone() { + ObjectSub result = null; + try { + result = (ObjectSub) super.clone(); + Tester.check(false, "expecting CloneNotSupportedException"); + } catch (CloneNotSupportedException e) { + result = this; // bad programming - ok for testing + } + return result; + } +} diff --git a/tests/new/SuperInIntroductionCE.java b/tests/new/SuperInIntroductionCE.java new file mode 100644 index 000000000..fb8784156 --- /dev/null +++ b/tests/new/SuperInIntroductionCE.java @@ -0,0 +1,32 @@ + +import org.aspectj.testing.Tester; + +public class SuperInIntroductionCE { + public static void main (String[] args) { + int result = new Sub().getInt(); + Tester.check(2==result, "new Sub().getInt() !2==" + result); + } +} + +class Super { + private int privateInt = 1; + private int privateIntMethod() { return privateInt; } + int defaultedInt = 1; + int defaultIntMethod() { return privateInt; } +} + +class Sub extends Super { } + +class ObjectSub { } + +aspect A { + /** @testcase accessing private and default method and field of class within code the compiler controls */ + public int Sub.getInt() { + int result = super.privateInt; // CE 25 expected here + result += super.privateIntMethod(); // CE 26 expected here + // todo: move A and Super to separate packages + //result += defaultInt; // CE expected here + //result += defaultIntMethod(); // CE expected here + return result; + } +} diff --git a/tests/new/SuperStaticCallJoinPoint.java b/tests/new/SuperStaticCallJoinPoint.java new file mode 100644 index 000000000..5d75b8955 --- /dev/null +++ b/tests/new/SuperStaticCallJoinPoint.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +class Sup { + static void m() {} +} + +public class SuperStaticCallJoinPoint extends Sup { + static boolean ran = false; + public static void main(String[] args) { + new SuperStaticCallJoinPoint().foo(); + Tester.check(ran, "didn't run advice"); + } + void foo() { + super.m(); + } + static void m() { + throw new RuntimeException(); + } +} + +aspect A { + before(): this(SuperStaticCallJoinPoint) && call(void Sup.m()) { + SuperStaticCallJoinPoint.ran = true; + } +} diff --git a/tests/new/SupersAndInterfaces.java b/tests/new/SupersAndInterfaces.java new file mode 100644 index 000000000..8a329dc51 --- /dev/null +++ b/tests/new/SupersAndInterfaces.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; + +import java.io.IOException; + +public class SupersAndInterfaces { + public static void main(String[] args) throws IOException { + new C2().m(); + Tester.check("ran before"); + new C().toString(); + Tester.check("ran before toString"); + } +} + +class C { + public void m() throws IOException { + if (false) throw new IOException("testing"); + } + public String toString() { + return super.toString() + "C"; + } +} + +interface I { + public void m() throws IOException; +} + +class C1 extends C implements I { +} + +class C2 extends C1 { + static boolean ranBody; + public void m() throws IOException { + ranBody = true; + super.m(); + } +} + +aspect A { + before(): call(void m()) { + Tester.note("ran before"); + Tester.check(!C2.ranBody, "first entry"); + } + before(): call(String toString()) { + Tester.note("ran before toString"); + } +} diff --git a/tests/new/SynchroInterface.java b/tests/new/SynchroInterface.java new file mode 100644 index 000000000..5ec3515fe --- /dev/null +++ b/tests/new/SynchroInterface.java @@ -0,0 +1,42 @@ +import org.aspectj.testing.Tester; +import java.lang.reflect.*; + +public class SynchroInterface { + public static void main(String[] args) { + try { + new SynchroInterface().realMain(args); + } catch (Throwable t) { + Tester.check(false, "uh oh " + t); + } finally { + Tester.check(Consts.ran, "method didn't run"); + } + } + public void realMain(String[] args) throws Throwable { + Class.forName("EmptyClass").getMethod("method", new Class[]{}).invoke(new EmptyClass(), new Class[]{}); + } +} + +class Consts { + public static boolean ran = false; +} + +class EmptyClass { +} + +interface EmptyInterface { +} + +aspect IntroType { + introduction EmptyClass { + implements EmptyInterface; + } +} + +aspect IntroMethod { + introduction EmptyInterface { + public synchronized void method() { + Consts.ran = true; + } + } +} + diff --git a/tests/new/SynchronizedMethodsOnInterfaces.java b/tests/new/SynchronizedMethodsOnInterfaces.java new file mode 100644 index 000000000..4cddd77c9 --- /dev/null +++ b/tests/new/SynchronizedMethodsOnInterfaces.java @@ -0,0 +1,37 @@ +import org.aspectj.testing.*; +import java.lang.reflect.*; + +public class SynchronizedMethodsOnInterfaces { + public static void main(String[] args) { + new SynchronizedMethodsOnInterfaces().realMain(args); + } + static { + Tester.expectEventsInString("I,C"); + } + public void realMain(String[] args) { + method(new D()); + method(new C()); + Tester.checkAllEvents(); + } + void method(Object o) { + try { + o.getClass().getMethod("method", new Class[]{}).invoke(o, new Object[]{}); + } catch (Throwable t) { + Tester.check(false, t+""); + } + } + + public SynchronizedMethodsOnInterfaces() { + } +} + +interface I {} +class D implements I {} +class C {} + +aspect AspectI { + public synchronized void I.method() { Tester.event("I"); } +} +aspect AspectC { + public synchronized void C.method() { Tester.event("C"); } +} diff --git a/tests/new/TargetObjectReplacement.java b/tests/new/TargetObjectReplacement.java new file mode 100644 index 000000000..6c5e26ce9 --- /dev/null +++ b/tests/new/TargetObjectReplacement.java @@ -0,0 +1,64 @@ +import org.aspectj.testing.Tester; + +/** @testcase replacing this or target in around advice */ +public class TargetObjectReplacement { + public static void main(String[] args) { + Foo f = new Foo("orig"); + // replacing target or this in advice does not affect caller reference + f.m(); + f.n(); + f.o(); + f.p(); + Tester.checkEqual(f.idhat, "orig"); // no affect presumed + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("m: m-delegate"); + Tester.expectEvent("n: n-delegate"); + Tester.expectEvent("o: o-delegate"); + Tester.expectEvent("p: orig"); // no affect presumed + } +} + +class Foo { + String id; + String idhat; + + Foo(String id) { + this.id = id; + this.idhat = id; + } + + void m() { + Tester.event("m: " + id); + } + + void n() { + Tester.event("n: " + id); + } + + void o() { + Tester.event("o: " + id); + } + + void p() { + Tester.event("p: " + id); // before around advice on idhat get + Tester.checkEqual(idhat, "p-delegate"); // callees affected + } +} + +aspect A { + + void around(Foo foo): target(foo) && call(void m()) { + proceed(new Foo("m-delegate")); + } + void around(Foo foo): target(foo) && execution(void n()) { + proceed(new Foo("n-delegate")); + } + void around(Foo foo): this(foo) && execution(void o()) { + proceed(new Foo("o-delegate")); + } + String around(Foo foo): target(foo) && get(String Foo.idhat) && within(Foo) { + return proceed(new Foo("p-delegate")); + } +} diff --git a/tests/new/ThisJoinPointAssignments.java b/tests/new/ThisJoinPointAssignments.java new file mode 100644 index 000000000..f7b6d4971 --- /dev/null +++ b/tests/new/ThisJoinPointAssignments.java @@ -0,0 +1,20 @@ +public class ThisJoinPointAssignments { + public static void main(String[] args) { + new ThisJoinPointAssignments().realMain(args); + } + public void realMain(String[] args) { + new C().f(); + org.aspectj.testing.Tester.check(A.jp != null, "Didn't set the JoinPoint"); + } +} + +class C { + public void f() {} +} + +aspect A { + static org.aspectj.lang.JoinPoint jp; + before(): call(void C.f()) { + jp = thisJoinPoint; + } +} diff --git a/tests/new/ThrowsMatching.java b/tests/new/ThrowsMatching.java new file mode 100644 index 000000000..6f350d9d4 --- /dev/null +++ b/tests/new/ThrowsMatching.java @@ -0,0 +1,25 @@ +import org.aspectj.testing.Tester; + +public class ThrowsMatching { + public static void main(String[] args) throws Exception { + C c = new C(); + c.m1(); + c.m2(); + + Tester.checkEqual(A.buf.toString(), "before:m1:m2:"); + } +} + + +class E1 extends Exception { } + +class C { + public void m1() throws E1 { A.buf.append("m1:"); } + public void m2() { A.buf.append("m2:"); } +} + +aspect A { + static StringBuffer buf = new StringBuffer(); + + before(): call(void C.m*() throws E1) { A.buf.append("before:"); } +} diff --git a/tests/new/TopmostImplements.java b/tests/new/TopmostImplements.java new file mode 100644 index 000000000..23c466d0e --- /dev/null +++ b/tests/new/TopmostImplements.java @@ -0,0 +1,49 @@ + +import org.aspectj.testing.Tester; +import java.lang.reflect.Method; + +// PR#126 + +public class TopmostImplements { + public static void main(String[] args) { test(); } + + public static void test() { + BC1 bc1 = new BC1(); + BC2 bc2 = new BC2(); + String m1 = ""; + String m2 = ""; + try { + m1 = bc1.getClass().getMethod("m1", null).toString(); + m2 = bc2.getClass().getMethod("m1", null).toString(); + } catch ( NoSuchMethodException nsme ) { + Tester.check(false, "method not found"); + } + Tester.checkEqual(m1, "public java.lang.String B.m1()", "from extends, implements"); + Tester.checkEqual(m2, "public java.lang.String B.m1()", "from extends"); + + Tester.checkEqual(bc1.m1(), "BC1", "from extends, implements"); + Tester.checkEqual(bc2.m1(), "BC2", "from extends"); + + } +} + +aspect Introducer { + public String A.m1() { return getName(); } +} + + +interface A { + String getName(); +} + +class B implements A { + public String getName() { return "B"; } +} + +class BC1 extends B implements A { + public String getName() { return "BC1"; } +} + +class BC2 extends B { + public String getName() { return "BC2"; } +} diff --git a/tests/new/TryAndProceed.java b/tests/new/TryAndProceed.java new file mode 100644 index 000000000..42cebaeee --- /dev/null +++ b/tests/new/TryAndProceed.java @@ -0,0 +1,90 @@ +import org.aspectj.testing.Tester; + +public class TryAndProceed { + public static void main(String[] args) { + new C().mNoThrows(); + Tester.checkEqual(C.buf.toString(), "beforeAll:aroundAll:mNoThrows:"); + C.buf = new StringBuffer(); + + A.aspectOf().allowThrowingAround = true; + try { + new C().mThrowsCheckedExc(); + Tester.checkFailed("should have thrown RuntimeExc"); + } catch (CheckedExc ce) { + Tester.checkFailed("should have thrown RuntimeExc not " + ce); + } catch (RuntimeException re) { + //System.out.println("caught " + re); + } + Tester.checkEqual(C.buf.toString(), + "beforeAll:aroundCheckedNoThrow:aroundAll:aroundCheckedThrow:aroundCaughtCE:"); + C.buf = new StringBuffer(); + + A.aspectOf().allowThrowingBefore = true; + try { + new C().mThrowsCheckedExc(); + Tester.checkFailed("should have thrown CheckedExc"); + } catch (CheckedExc ce) { + //System.out.println("caught " + ce); + } catch (RuntimeException re) { + Tester.checkFailed("should have thrown CheckedExc not RuntimeExc"); + } + Tester.checkEqual(C.buf.toString(), "beforeChecked:"); + + } +} + + +class C { + public static StringBuffer buf = new StringBuffer(); + + public void mThrowsCheckedExc() throws CheckedExc { + C.buf.append("mThrowsCheckedExc:"); + } + + public void mNoThrows() { + C.buf.append("mNoThrows:"); + } +} + +aspect A { + pointcut checkedCut(): call(void C.mThrowsCheckedExc()); + pointcut uncheckedCut(): call(void C.mNoThrows()); + pointcut allCut(): checkedCut() || uncheckedCut(); + + public static boolean allowThrowingBefore = false; + public static boolean allowThrowingAround = false; + + before() throws CheckedExc: checkedCut() && if(allowThrowingBefore) { + C.buf.append("beforeChecked:"); + throw new CheckedExc("from before"); + } + + before(): allCut() { + C.buf.append("beforeAll:"); + } + + Object around(): checkedCut() { + C.buf.append("aroundCheckedNoThrow:"); + return proceed(); + } + + Object around(): allCut() { + C.buf.append("aroundAll:"); + try { + return proceed(); + } catch (CheckedExc ce) { + C.buf.append("aroundCaughtCE:"); + + throw new RuntimeException("hand-softening CheckedExc"); + } + } + + Object around() throws CheckedExc: checkedCut() && if(allowThrowingAround) { + C.buf.append("aroundCheckedThrow:"); + throw new CheckedExc("from around"); + } +} + +class CheckedExc extends Exception { + public CheckedExc(String m) { super(m); } +} diff --git a/tests/new/TryErrors.java b/tests/new/TryErrors.java new file mode 100644 index 000000000..5abe6a7af --- /dev/null +++ b/tests/new/TryErrors.java @@ -0,0 +1,33 @@ +import org.aspectj.testing.Tester; + +public class TryErrors { + public static void main(String[] args) { + test(); + } + + public static void test() { + Foo foo = new Foo(); + foo.bar(); + Tester.check(foo.memberAdvised, "member advice happened"); + Tester.check(foo.signatureAdvised, "signature advice happened"); + } +} + +class Foo { + boolean memberAdvised = false; + boolean signatureAdvised = false; + + public void bar() { + ; + } +} + +aspect A { + /*static*/ after(Foo foo): target(foo) && within(Foo) && execution(void bar()) { + foo.memberAdvised = true; + } + + /*static*/ before(Foo foo): target(foo) && call(void bar()) { + foo.signatureAdvised = true; + } +} diff --git a/tests/new/TryNoCatchCE.java b/tests/new/TryNoCatchCE.java new file mode 100644 index 000000000..9c6f0f1a2 --- /dev/null +++ b/tests/new/TryNoCatchCE.java @@ -0,0 +1,7 @@ + +public class TryNoCatchCE { + /* @testcase PR#643 PUREJAVA try without catch or finally */ + public void notRun() { + try {} // expect CE here + } +} diff --git a/tests/new/TryOffEnd.java b/tests/new/TryOffEnd.java new file mode 100644 index 000000000..c2b0c166c --- /dev/null +++ b/tests/new/TryOffEnd.java @@ -0,0 +1,25 @@ + +import org.aspectj.testing.Tester; + +/** @testcase VerifyError after around advice falls off end of tryCatch */ +public class TryOffEnd { + public static void main(String[] args) { + Tester.check(new TryOffEnd().error(), "functional failure"); + } + public boolean error() { + String s = null; + try { + s = System.getProperty("unknown Property"); + } catch (Throwable t) { // CW 13 cannot apply advice + t.printStackTrace(System.err); + } + return true; + } +} + +aspect A { + Object around() : within(TryOffEnd) && handler(Throwable) { // CW 21 cannot apply advice + Object result = proceed(); + return result; + } +} diff --git a/tests/new/TwoAnonymous.java b/tests/new/TwoAnonymous.java new file mode 100644 index 000000000..09489cef1 --- /dev/null +++ b/tests/new/TwoAnonymous.java @@ -0,0 +1,45 @@ +public class TwoAnonymous { + /**/ + Runnable i = new Runnable() { + public void run() { + System.out.println("i"); + } + private Object foo() { return null; } + }; + Runnable j = new Runnable() { + public void run() { + System.out.println(new Integer(0)); + } + }; + /**/ + public static void main(String[] args) { + Runnable k = new Runnable() { + int x = 0; + public void run() { + System.out.println("k"); + x = 4; + } + private Object foo() { return null; } + }; + + Runnable k1 = new Runnable() { public void run() { } }; + + k.run(); + + } +} + +aspect A { + + before(Runnable r): call(void Runnable.run()) && target(r) { + System.out.println("calling run: " + r + ", " + thisJoinPoint.getArgs() +", " + thisJoinPoint.getTarget()); + } + + after() returning(Runnable r): call(Runnable+.new()) { + System.out.println("new runnable: " + r); + } + + before(): set(int x) { + System.out.println("setting x"); + } +} diff --git a/tests/new/TypeBug.java b/tests/new/TypeBug.java new file mode 100644 index 000000000..76190d819 --- /dev/null +++ b/tests/new/TypeBug.java @@ -0,0 +1,73 @@ +class TypeBug { + + public static void main(String[] args) { + new TypeBug().go(); + } + + A a = new A(); + D d = new D(); + G g = new G(); + + void go(){ + g.foo(a); + g.foo(d); + bar(g); + bash(g); + } + + void bar(I i){ + i.foo(a); + } + + void bash(J j){ + j.foo(d); + } + +} + +aspect Q { + + pointcut pc1(): receptions(void I.foo(*)); + pointcut pc2(): calls(void I.foo(*)); + pointcut pc3(): callsto(pc1()); + + pointcut test():; + + static before(): pc1() { + System.out.print("(pc1) "); + } + + + static before (): pc2() { + System.out.print("(pc2) "); + } + + static before(): pc3(){ + System.out.print("(pc3) "); + } + +} + + +class A {} + + +class D {} + + +interface I { + void foo(A a); +} + +interface J { + void foo(D d); +} + +class G implements I, J { + public void foo(A a){ + System.out.println("G.foo(A)"); + } + public void foo(D d){ + System.out.println("G.foo(D)"); + } +} diff --git a/tests/new/TypeCoercions.java b/tests/new/TypeCoercions.java new file mode 100644 index 000000000..a56ab990b --- /dev/null +++ b/tests/new/TypeCoercions.java @@ -0,0 +1,9 @@ +import org.aspectj.testing.Tester; + +public class TypeCoercions { + public static void main(String[] args) { + char c1 = 'e', c2 = 'f'; + Tester.checkEqual("hello".indexOf(c1), 1); + Tester.checkEqual("hello".indexOf(c2), -1); + } +} diff --git a/tests/new/TypeDeclInAdvice.java b/tests/new/TypeDeclInAdvice.java new file mode 100644 index 000000000..e39d3421e --- /dev/null +++ b/tests/new/TypeDeclInAdvice.java @@ -0,0 +1,39 @@ +import org.aspectj.testing.Tester; + +public class TypeDeclInAdvice { + public static void main(String[] args) { test(); } + + public static void test() { + Foo foo = new Foo(); + foo.m(); + } +} + +aspect A { + void around(): this(Foo) && call(void m(..)) { + class Internal { + int val() { return 1; } + } + int i = 0; + Internal j; + + i = 1; + j = new Internal(); + + proceed(); + + //System.out.println("j: " + j); + + Tester.checkEqual(i, 1, "i"); + Tester.checkEqual(j.val(), 1, "j.val()"); + } +} + +class Foo { + Foo() { + //System.out.println("constructor Foo()"); + } + void m() { + //System.out.println("method m()"); + } +} diff --git a/tests/new/TypeNames.java b/tests/new/TypeNames.java new file mode 100644 index 000000000..e1aae7255 --- /dev/null +++ b/tests/new/TypeNames.java @@ -0,0 +1,50 @@ + +import org.aspectj.testing.Tester; + +/** @testcase package typepattern with no packages (in default package) */ +public class TypeNames { + public static void main (String[] args) { + new Suffix().run(); + new MySuffix().run(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("Suffix.run()"); + Tester.expectEvent("MySuffix.run()"); + } +} + +// classes not to be matched by TypePattern below +class Suffix { + void run() { + Tester.event("Suffix.run()"); + } +} + +class MySuffix { + void run() { + Tester.event("MySuffix.run()"); + } +} + + + +aspect A { + // BUG: This is all that's required to provoke the bug in -Xlint mode + public String (*..*Suffix).toString() { // lint: no type matched + return "ok"; + } + + // coverage cases + before() : staticinitialization(*..*Suffix) { // lint: no type matched + Tester.check(false, "no such join point"); + } + + before() : call(void *..*Suffix.run()) { // lint: no type matched + Tester.check(false, "no such join point"); + } + + before() : call(*..*Suffix.new()) { // lint: no type matched + Tester.check(false, "no such join point"); + } +} diff --git a/tests/new/TypePat.java b/tests/new/TypePat.java new file mode 100644 index 000000000..149e25741 --- /dev/null +++ b/tests/new/TypePat.java @@ -0,0 +1,82 @@ +package test; + +import org.aspectj.testing.Tester; +import java.util.*; + + +public class TypePat { + public static void main(String[] args) { + Inner o = new Inner(); + o.m(); + + Tester.checkAndClearEvents(new String[] { + "A.before1: TypePat.Inner.m()", + "InnerA.before: TypePat.Inner.m()", + "A.before2: C.foo()", + "TypePat.Inner.m", + }); + + + Map m = new HashMap(); + m.put("a", "b"); + + for (Iterator i = m.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = (Map.Entry)i.next(); + e.getKey(); + } + + Tester.checkAndClearEvents(new String[] { + "A.before3: Map.Entry.getKey()" + }); + + + + Runnable r = new Runnable() { + public void run() { + C.foo(); + Tester.event("TypePat.Runnable.run"); + } + }; + + r.run(); + Tester.checkAndClearEvents(new String[] { + "A.before2: C.foo()", + "TypePat.Runnable.run", + }); + //Tester.printEvents(); + } + static class Inner { + public void m() { + C.foo(); + Tester.event("TypePat.Inner.m"); + } + } + + static aspect InnerA { + before(): call(* Inner.*(..)) { + Tester.event("InnerA.before: " + thisJoinPoint.getSignature().toShortString()); + } + } +} + +class C { + static void foo() { + } +} + + +aspect A { + before(): call(* TypePat.*.*(..)) && within(TypePat) && !within(TypePat.*) { + Tester.event("A.before1: " + thisJoinPoint.getSignature().toShortString()); + } + + pointcut checkCall(): call(* *(..)) && !call(* Tester.*(..)); + + before(): checkCall() && within(TypePat.*) && !within(*.InnerA) { + Tester.event("A.before2: " + thisJoinPoint.getSignature().toShortString()); + } + + before(): checkCall() && target(Map.En*) { + Tester.event("A.before3: " + thisJoinPoint.getSignature().toShortString()); + } +} diff --git a/tests/new/UnambiguousClassReference3CP.java b/tests/new/UnambiguousClassReference3CP.java new file mode 100644 index 000000000..f3fc2dac8 --- /dev/null +++ b/tests/new/UnambiguousClassReference3CP.java @@ -0,0 +1,15 @@ +import java.sql.Array; + +import org.aspectj.testing.Tester; + +public class UnambiguousClassReference3CP { + + /** @testcase PR#701 PUREJAVA no CE for unambiguous reference + * see also testcase PR#631 */ + public static void main(String[] args) { + int[] gh = new int[5]; + int len = java.lang.reflect.Array.getLength(gh); // not ambiguous + Tester.check(5==len, "Array.getLength failed: " + len); + } +} + diff --git a/tests/new/UndefinedInner.java b/tests/new/UndefinedInner.java new file mode 100644 index 000000000..1ea3617ed --- /dev/null +++ b/tests/new/UndefinedInner.java @@ -0,0 +1,9 @@ + +// in 10rc2, this provokes a NPE at ConstructorDec.java:41 +class error { + class error2 { + /** @testcase PR#588 PUREJAVA Undefined inner class constructor */ + public error2(); // expecting error here + } +} + diff --git a/tests/new/UnrecognizedAspectCE.java b/tests/new/UnrecognizedAspectCE.java new file mode 100644 index 000000000..f9d9c060f --- /dev/null +++ b/tests/new/UnrecognizedAspectCE.java @@ -0,0 +1,3 @@ + +aspect UnrecognizedAspectCE + extends UnknownAspect {} diff --git a/tests/new/UnterminatedDeclareErrorCE.java b/tests/new/UnterminatedDeclareErrorCE.java new file mode 100644 index 000000000..ad4f228be --- /dev/null +++ b/tests/new/UnterminatedDeclareErrorCE.java @@ -0,0 +1,11 @@ + +/** @testcase expect CE for unterminated declare error */ +aspect UnterminatedDeclareErrorCE { + declare error : execution(void run()) : "error" // CE 7 +} + +class C { + // bug - get CE here if uncommented, but declare error unterminated + // public void run() { } +} + diff --git a/tests/new/UnwovenAdviceNotCheckedCE.java b/tests/new/UnwovenAdviceNotCheckedCE.java new file mode 100644 index 000000000..d692c2382 --- /dev/null +++ b/tests/new/UnwovenAdviceNotCheckedCE.java @@ -0,0 +1,22 @@ + +/** Currently there are no messages emitted for + * compile-time errors from advice bodies if the + * advice is not woven into the base class. + * This can lead to silent failures. + */ +class UnwovenAdviceNotCheckedCE { + public static void main(String[] args) { + System.err.println("main"); + } +} + +aspect Aspect { + void around (String[] args) + : args(args) + && call(void UnwovenAdviceNotCheckedCE.main()) { // forgot (..), so unwoven + System.err.println("before main"); + proceed() ; // CE: should get compile error here - need (args) + System.err.println("after main"); + } +} + diff --git a/tests/new/VoidAround.java b/tests/new/VoidAround.java new file mode 100644 index 000000000..6878041b1 --- /dev/null +++ b/tests/new/VoidAround.java @@ -0,0 +1,32 @@ + +import org.aspectj.testing.Tester; +import java.util.*; + +/** @testcase PR#836 void around advice without proceed */ +public class VoidAround { + + public static void main(String[] args) { + C c = new C(); + c.run(); + Object o = c.result(); + Tester.check(o == C.EXPECTED, "o: " + o); + Tester.checkAllEvents(); + } +} + +class C { + static Object EXPECTED = new Object(); + public void run() { } + public Object result() { return EXPECTED; } +} + +aspect A { + static { + Tester.expectEvent("void C.run()"); + Tester.expectEvent("Object C.result()"); + } + // no compile error expected (also note: message jp signatures are wrong?) + void around() : target(C) && call(* r*(..)) { + Tester.event(thisJoinPoint.getSignature().toString()); + } +} diff --git a/tests/new/VoidField.java b/tests/new/VoidField.java new file mode 100644 index 000000000..dfbb7eba2 --- /dev/null +++ b/tests/new/VoidField.java @@ -0,0 +1,8 @@ +public class VoidField { + void f; // ERR field is void + public static void main(String[] args) { + void var; // ERR var is void + } + void m(void x) { } // ERR formal is void +} + diff --git a/tests/new/WildNames.java b/tests/new/WildNames.java new file mode 100644 index 000000000..63260a7cd --- /dev/null +++ b/tests/new/WildNames.java @@ -0,0 +1,42 @@ +import org.aspectj.testing.Tester; + +public aspect WildNames { + public static void main(String[] args) { test(); } + + public static void test() { + C c = new C(); + + c.getFoo(); c.getBar(); + Tester.check("getFoo"); Tester.check("getBar"); + + c.fooGetter(); c.barGetter(); + Tester.check("fooGetter"); Tester.check("barGetter"); + + c.prefixFooSuffix(); c.prefixBarSuffix(); + Tester.check("prefixFooSuffix"); Tester.check("prefixBarSuffix"); + } + + /*static*/ after() returning (String s): execution(String get*()) { + Tester.checkEqual("get*", s); + Tester.note(thisJoinPoint.getSignature().getName()); + } + /*static*/ after() returning (String s): execution(String *Getter()) { + Tester.checkEqual("*Getter", s); + Tester.note(thisJoinPoint.getSignature().getName()); + } + /*static*/ after() returning (String s): execution(String prefix*Suffix()) { + Tester.checkEqual("prefix*Suffix", s); + Tester.note(thisJoinPoint.getSignature().getName()); + } +} + +class C { + public String getFoo() { return "get*"; } + public String getBar() { return "get*"; } + + public String fooGetter() { return "*Getter"; } + public String barGetter() { return "*Getter"; } + + public String prefixFooSuffix() { return "prefix*Suffix"; } + public String prefixBarSuffix() { return "prefix*Suffix"; } +} diff --git a/tests/new/WithinInners.java b/tests/new/WithinInners.java new file mode 100644 index 000000000..17a0be521 --- /dev/null +++ b/tests/new/WithinInners.java @@ -0,0 +1,66 @@ +import org.aspectj.testing.Tester; + +public class WithinInners { + public static void main(String[] args) { + C c = new C(); + + c.getRunnable().run(); + // 1.1 doesn't capture withincode and execution of local types + //(1.0 behavior)Tester.checkEqual(A.notes, "before-within:before-withincode:around-in:run:around-out:"); + Tester.checkEqual(A.notes, "before-within:around-in:run:around-out:"); + } +} + +class C { + public C() { + class Inner { + public void write( String text ) { + System.out.println( "write( String )" ); + System.out.println( text ); + } + } + + Inner i = new Inner(); + String s = "TEXT"; + i.write( s ); + } + + public Runnable getRunnable() { + return new Runnable() { + public void run() { + A.notes += "run:"; + } + }; + } +} + + +aspect A { + public static String notes = ""; + + /* These don't work because we can't give local types reasonable top-level names */ + before(String s): call(void write(String)) && args(s) { //&& withincode(C.new()) { + System.out.println(s); + } + + void around(String s): call(void write(String)) && args(s) && withincode(C.new()) { + proceed(s.toLowerCase()); + } + + /* These now work and are checked */ + //XXX not being able to do this(c) is a pain + before(Runnable runnable): execution(void Runnable.run()) && target(runnable) && within(C) { // && this(c) { + //System.out.println("about to call Runnable.run in " + c + " on " + runnable); + notes += "before-within:"; + } + before(): execution(void run()) && withincode(Runnable C.getRunnable()) { + //System.out.println("about to call Runnable.run in C"); + notes += "before-withincode:"; + } + void around(): execution(void run()) { + //System.out.println("about to call Runnable.run in C"); + notes += "around-in:"; + proceed(); + notes += "around-out:"; + } +} diff --git a/tests/new/Zeros.java b/tests/new/Zeros.java new file mode 100644 index 000000000..1fdc58cfa --- /dev/null +++ b/tests/new/Zeros.java @@ -0,0 +1,211 @@ +import org.aspectj.testing.*; + +public class Zeros { + public static void main(String[] args) { + new Zeros().realMain(args); + } + + public void realMain(String[] args) { + double d01 = 0.1; + double d02 = 00.11; + double d03 = 000.111; + double d04 = 0000.1111; + double d05 = 00000.11111; + double d06 = 000000.111111; + double d07 = 0000000.1111111; + double d08 = 00000000.11111111; + double d09 = 000000000.111111111; + double d10 = 0000000000.1111111111; + double d11 = 00000000000.11111111111; + double d12 = 000000000000.111111111111; + double d13 = 0000000000000.1111111111111; + double d14 = 00000000000000.11111111111111; + double d15 = 000000000000000.111111111111111; + double d16 = 0000000000000000.1111111111111111; + double d17 = 00000000000000000.11111111111111111; + double d18 = 000000000000000000.111111111111111111; + double d19 = 0000000000000000000.1111111111111111111; + double d20 = 00000000000000000000.11111111111111111111; + double d21 = 000000000000000000000.111111111111111111111; + double d22 = 0000000000000000000000.1111111111111111111111; + double d23 = 00000000000000000000000.11111111111111111111111; + double d24 = 000000000000000000000000.111111111111111111111111; + double d25 = 0000000000000000000000000.1111111111111111111111111; + double d26 = 00000000000000000000000000.11111111111111111111111111; + double d27 = 000000000000000000000000000.111111111111111111111111111; + double d28 = 0000000000000000000000000000.1111111111111111111111111111; + double d29 = 00000000000000000000000000000.11111111111111111111111111111; + double d30 = 000000000000000000000000000000.111111111111111111111111111111; + double d31 = 0000000000000000000000000000000.1111111111111111111111111111111; + double d32 = 00000000000000000000000000000000.11111111111111111111111111111111; + double d33 = 000000000000000000000000000000000.111111111111111111111111111111111; + double d34 = 0000000000000000000000000000000000.1111111111111111111111111111111111; + double d35 = 00000000000000000000000000000000000.11111111111111111111111111111111111; + double d36 = 000000000000000000000000000000000000.111111111111111111111111111111111111; + double d37 = 0000000000000000000000000000000000000.1111111111111111111111111111111111111; + double d38 = 00000000000000000000000000000000000000.11111111111111111111111111111111111111; + double d39 = 000000000000000000000000000000000000000.111111111111111111111111111111111111111; + double d40 = 0000000000000000000000000000000000000000.1111111111111111111111111111111111111111; + double d41 = 00000000000000000000000000000000000000000.11111111111111111111111111111111111111111; + double d42 = 000000000000000000000000000000000000000000.111111111111111111111111111111111111111111; + double d43 = 0000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111; + double d44 = 00000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111; + double d45 = 000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111; + double d46 = 0000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111; + double d47 = 00000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111; + double d48 = 000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111; + double d49 = 0000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111; + double d50 = 00000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111; + double d51 = 000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111; + double d52 = 0000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111; + double d53 = 00000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111; + double d54 = 000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111; + double d55 = 0000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111; + double d56 = 00000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111; + double d57 = 000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111; + double d58 = 0000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111; + double d59 = 00000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111; + double d60 = 000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111; + double d61 = 0000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111; + double d62 = 00000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111; + double d63 = 000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111; + double d64 = 0000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111; + double d65 = 00000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111; + double d66 = 000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111; + double d67 = 0000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111; + double d68 = 00000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111; + double d69 = 000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111; + double d70 = 0000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111; + double d71 = 00000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111; + double d72 = 000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111; + double d73 = 0000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111; + double d74 = 00000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111; + double d75 = 000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111; + double d76 = 0000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111; + double d77 = 00000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111; + double d78 = 000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d79 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d80 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d81 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d82 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d83 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d84 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d85 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d86 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d87 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d88 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d89 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d90 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d91 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d92 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d93 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d94 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d95 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d96 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d97 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d98 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d99 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d100 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d101 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d102 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d103 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d104 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d105 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d106 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d107 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d108 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d109 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d110 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d111 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d112 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d113 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d114 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d115 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d116 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d117 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d118 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d119 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d120 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d121 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d122 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d123 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d124 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d125 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d126 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d127 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d128 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d129 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d130 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d131 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d132 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d133 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d134 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d135 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d136 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d137 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d138 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d139 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d140 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d141 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d142 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d143 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d144 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d145 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d146 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d147 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d148 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d149 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d150 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d151 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d152 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d153 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d154 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d155 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d156 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d157 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d158 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d159 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d160 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d161 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d162 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d163 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d164 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d165 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d166 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d167 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d168 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d169 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d170 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d171 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d172 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d173 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d174 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d175 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d176 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d177 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d178 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d179 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d180 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d181 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d182 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d183 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d184 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d185 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d186 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d187 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d188 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d189 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d190 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d191 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d192 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d193 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d194 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d195 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d196 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d197 = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d198 = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + double d199 = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; + + Tester.check(true, "compiled!"); + } +} diff --git a/tests/new/access/Test1.java b/tests/new/access/Test1.java new file mode 100644 index 000000000..1d3b3f695 --- /dev/null +++ b/tests/new/access/Test1.java @@ -0,0 +1,16 @@ +import org.aspectj.testing.Tester; + +import pc.C; +import psub.SubC; + +public class Test1 { + public static void main(String[] args) { + C c = new C(); + SubC subc = new SubC(); + + Tester.checkEqual(c.getInternalPackage(), "pc"); + Tester.checkEqual(subc.getInternalPackage(), "pc"); + Tester.checkEqual(subc.getRealPackage(), "psub"); + + } +} diff --git a/tests/new/access/pc/C.java b/tests/new/access/pc/C.java new file mode 100644 index 000000000..412a7e7ea --- /dev/null +++ b/tests/new/access/pc/C.java @@ -0,0 +1,9 @@ +package pc; + +public class C { + public String getInternalPackage() { + return getMyPackage(); + } + + String getMyPackage() { return "pc"; } +} diff --git a/tests/new/access/psub/A.java b/tests/new/access/psub/A.java new file mode 100644 index 000000000..0b4a1a572 --- /dev/null +++ b/tests/new/access/psub/A.java @@ -0,0 +1,13 @@ +package psub; + +import org.aspectj.testing.Tester; +import pc.C; + +aspect A { + before(): call(String SubC.getMyPackage()) { + //XXXTester.checkFailed("shouldn't ever run this " + thisJoinPoint); + } + before(): call(String C.getMyPackage()) { + Tester.note("C.getMyPackage on " + thisJoinPoint.getTarget().getClass().getName()); + } +} diff --git a/tests/new/access/psub/SubC.java b/tests/new/access/psub/SubC.java new file mode 100644 index 000000000..588a2ab2c --- /dev/null +++ b/tests/new/access/psub/SubC.java @@ -0,0 +1,11 @@ +package psub; + +import pc.C; + +public class SubC extends C { + public char[] getMyPackage() { return "psub".toCharArray(); } + + public String getRealPackage() { + return new String(getMyPackage()); + } +} diff --git a/tests/new/adviceOnStaticMeth/Driver.java b/tests/new/adviceOnStaticMeth/Driver.java new file mode 100644 index 000000000..629fd776d --- /dev/null +++ b/tests/new/adviceOnStaticMeth/Driver.java @@ -0,0 +1,27 @@ + +import org.aspectj.testing.Tester; + +// PR#221 + +public class Driver { + public static String s = "s"; + + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(doIt(), s, "advice worked"); + } + + public static String doIt() { + return s; + } +} + +aspect Outer { + pointcut staticMeth(): within(Driver) && execution(String doIt()); + + /*static*/ before(): staticMeth() { + Driver.s += ":a"; + } + +} diff --git a/tests/new/ambiguousClass/AmbiguousClassReference.java b/tests/new/ambiguousClass/AmbiguousClassReference.java new file mode 100644 index 000000000..0f0087aa3 --- /dev/null +++ b/tests/new/ambiguousClass/AmbiguousClassReference.java @@ -0,0 +1,5 @@ +package ambiguousClass; + +/** @testcase PR#701 PUREJAVA CE for ambiguous type reference (two files in package) */ +public class AmbiguousClassReference { } +class AmbiguousReferent {} // CE 5 "Duplicate type name" diff --git a/tests/new/ambiguousClass/AmbiguousReferent.java b/tests/new/ambiguousClass/AmbiguousReferent.java new file mode 100644 index 000000000..39a61ecec --- /dev/null +++ b/tests/new/ambiguousClass/AmbiguousReferent.java @@ -0,0 +1,5 @@ +package ambiguousClass; + + +/** @testcase PR#701 PUREJAVA CE for ambiguous type reference (two files in package) */ +public class AmbiguousReferent {} // CE 5 "Duplicate type name" diff --git a/tests/new/anonInnerClass/Driver.java b/tests/new/anonInnerClass/Driver.java new file mode 100644 index 000000000..d2de525c4 --- /dev/null +++ b/tests/new/anonInnerClass/Driver.java @@ -0,0 +1,42 @@ + +import org.aspectj.testing.Tester; + +// PR#297 anonymous inner class with aspect + +public class Driver { + + public static String s = ""; + + public static void main(String[] args){ + new Test().go(); + Tester.checkEqual(s, "-bar-after", ""); + } + +} + +class Test { + void go(){ + seto( new I(){ + public void foo(){ bar(); } + }); + o.foo(); + } + + void bar(){ + Driver.s += "-bar"; + } + I o; + + void seto(I o){ + this.o = o; + } +} + +interface I { void foo(); } + +aspect A { + void around(): this(I) && target(Test) && within(Test) && call(* bar()){ + proceed(); + Driver.s += "-after"; + } +} diff --git a/tests/new/arndAdvRet/Driver.java b/tests/new/arndAdvRet/Driver.java new file mode 100644 index 000000000..73a492e66 --- /dev/null +++ b/tests/new/arndAdvRet/Driver.java @@ -0,0 +1,48 @@ + +import org.aspectj.testing.Tester; + +// PR#140 + +public class Driver { + public static void main(String[] args) { test(); } + public static void test() { + Tester.checkEqual(new Foo().doIt(), 5, "min of 5 and 6"); + Tester.checkEqual(new Bar().doIt(), 1, "min of 5 and 2"); + } +} + +class Foo { + public static int doIt() { + return new Foo().bar(1, 2, 3); + } + + int bar(int a, int b, int c) { + return a * b * c; + } +} + +aspect FooAspect { + pointcut cut() : target(Foo) && call(int bar(int, int, int)); + int around(): cut() { + int originalResult = proceed(); + return Math.max(0, Math.min(originalResult, 5)); + } +} + +class Bar { + public static int doIt() { + return new Bar().bar(1, 2, 1); + } + + int bar(int a, int b, int c) { + return a * b * c; + } +} + +aspect BarAspect { + pointcut cut(Bar b) : target(b) && call(int bar(int, int, int)); + int around(Bar b): cut(b) { + int originalResult = proceed(b); + return Math.max(0, Math.min(originalResult, 1)); + } +} diff --git a/tests/new/aroundinner/Common.java b/tests/new/aroundinner/Common.java new file mode 100644 index 000000000..a0ebdf476 --- /dev/null +++ b/tests/new/aroundinner/Common.java @@ -0,0 +1,42 @@ + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class Common { + public static String[] SIGNALS = new String[] { }; + public static final void expect(String[] args) { + for (int i = 0; i < args.length; i++) { + expect(args[i]); + } + } + public static final void expect(String s) { Tester.expectEvent(s); } + public static final void signal(String s) { Tester.event(s); } + public static final void fail(String s) { Tester.check(false, s); } + public static final void check() { Tester.checkAllEvents(); } + public static final void joinWith(Thread thread) { + if (null == thread) { + Common.fail("null thread"); + } + try { thread.join(); } + catch (InterruptedException e) { + Common.fail("Interrupted"); + } + } +} + +class Target { + public static void main (String[] args) { + Common.expect(Target.SIGNALS); + Common.expect(Aspect.SIGNALS); + int result = new Target().targetMethod(); + if (1 != result) Common.fail("1 != result: " + result); + Common.check(); + } + pointcut pointcutTarget() : call(int Target.targetMethod()); + public static String[] SIGNALS = new String[] + { "targetMethod()" }; + public int targetMethod() { + Common.signal(SIGNALS[0]); + return 1; + } +} diff --git a/tests/new/aroundinner/Minimal.java b/tests/new/aroundinner/Minimal.java new file mode 100644 index 000000000..80b028698 --- /dev/null +++ b/tests/new/aroundinner/Minimal.java @@ -0,0 +1,28 @@ + +public class Minimal { + public static void main (String[] args) { + Target.main(args); + } +} + +class MyObject { int result = 0; } +aspect Aspect { + static final String[] SIGNALS = new String[] + { "around - run - before proceed" + , "around - run - after proceed" + }; + + /** @testcase PR#620 around advice inner class running proceed and writing field */ + int around(): Target.pointcutTarget() { + MyObject o = new MyObject() { + void ignored() { + result = 1; // remove to avoid bug + } + }; + Common.signal(SIGNALS[0]); + int i = proceed(); + Common.signal(SIGNALS[1]); + return i; + } +} + diff --git a/tests/new/aroundinner/Proxy.java b/tests/new/aroundinner/Proxy.java new file mode 100644 index 000000000..7d4f27157 --- /dev/null +++ b/tests/new/aroundinner/Proxy.java @@ -0,0 +1,30 @@ + +public class Proxy { + public static void main (String[] args) { + Target.main(args); + } +} + +aspect Aspect { + static final String[] SIGNALS = new String[] + { "around - start" + , "around - run - before proceed" + , "around - run - after proceed" + }; + class Proxy { int result; } + + /** @testcase PR#620 around advice inner Runnable running proceed and writing method-final proxy */ + int around(): Target.pointcutTarget() { + final Proxy proxy = new Proxy(); + Runnable runner = new Runnable() { + public void run() { + Common.signal(SIGNALS[1]); + proxy.result = proceed(); + Common.signal(SIGNALS[2]); + } + }; + runner.run(); + Common.signal(SIGNALS[0]); + return proxy.result; + } +} diff --git a/tests/new/aroundinner/RunnableSub.java b/tests/new/aroundinner/RunnableSub.java new file mode 100644 index 000000000..0feef3a29 --- /dev/null +++ b/tests/new/aroundinner/RunnableSub.java @@ -0,0 +1,34 @@ + +public class RunnableSub { + public static void main (String[] args) { + Target.main(args); + } +} + +interface MyRunner extends Runnable {} + +aspect Aspect { + static final String[] SIGNALS = new String[] + { "around - start" + , "around - run - before proceed" + , "around - run - after proceed" + }; + + // introduced field on interface + int MyRunner.result; + + /** @testcase PR#620 around advice inner Runnable (subinterface) running proceed and writing field introduced on subinterface */ + int around(): Target.pointcutTarget() { + MyRunner runner = new MyRunner() { + public void run() { + Common.signal(SIGNALS[1]); + result = proceed(); // remove to avoid bug + Common.signal(SIGNALS[2]); + } + }; + runner.run(); + Common.signal(SIGNALS[0]); + return runner.result; // remove to avoid bug + } +} + diff --git a/tests/new/aroundinner/ThreadNoField.java b/tests/new/aroundinner/ThreadNoField.java new file mode 100644 index 000000000..d8ff0252b --- /dev/null +++ b/tests/new/aroundinner/ThreadNoField.java @@ -0,0 +1,28 @@ + +public class ThreadNoField { + public static void main (String[] args) { + Target.main(args); + } +} + +aspect Aspect { + static final String[] SIGNALS = new String[] + { "around - start" + , "around - run - before proceed" + , "around - run - after proceed" + }; + /** @testcase PR#620 around advice inner Thread subclass running proceed but not writing field */ + int around(): Target.pointcutTarget() { + Thread runner = new Thread() { + public void run() { + Common.signal(SIGNALS[1]); + proceed(); + Common.signal(SIGNALS[2]); + } + }; + runner.start(); + Common.joinWith(runner); + Common.signal(SIGNALS[0]); + return 1; // hard-wired since no result + } +} diff --git a/tests/new/aroundinner/ThreadSub.java b/tests/new/aroundinner/ThreadSub.java new file mode 100644 index 000000000..034f8d048 --- /dev/null +++ b/tests/new/aroundinner/ThreadSub.java @@ -0,0 +1,33 @@ + +public class ThreadSub { + public static void main (String[] args) { + Target.main(args); + } +} + +// need subclass - introduction fails on Thread as outside CCC +class ThreadSubclass extends Thread { + int result; +} + +aspect Aspect { + static final String[] SIGNALS = new String[] + { "around - start" + , "around - run - before proceed" + , "around - run - after proceed" + }; + /** @testcase PR#620 around advice inner Thread subclass running proceed and writing field */ + int around(): Target.pointcutTarget() { + ThreadSubclass runner = new ThreadSubclass() { + public void run() { + Common.signal(SIGNALS[1]); + result = proceed(); // remove to avoid bug + Common.signal(SIGNALS[2]); + } + }; + runner.start(); + Common.joinWith(runner); + Common.signal(SIGNALS[0]); + return runner.result; // remove to avoid bug + } +} diff --git a/tests/new/badCast/Driver.java b/tests/new/badCast/Driver.java new file mode 100644 index 000000000..1a6c04674 --- /dev/null +++ b/tests/new/badCast/Driver.java @@ -0,0 +1,46 @@ +import org.aspectj.testing.Tester; + +// PR#275 & 276 cast error generated by ajc when type not in signature + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new SourcePane().go(), -10); + } +} + +class SourcePane { + public int go() { + Location location = new Location(); + return location.lineNumber(); + } +} + +class Location { + public int lineNumber() { + return 10; + } +} + +aspect DriverAspect { + + pointcut locationLineNumber(Location loc): + //XXX Fails with a star + //calls(int *.lineNumber()) && within(SourcePane); + //calls(int loc.lineNumber()) && within(SourcePane); + target(loc) && call(int Location.lineNumber()) && within(SourcePane); + int around(Location loc): locationLineNumber(loc) { + int result = proceed(loc); + return result * -1; + } +// The following code won't report the cast error and will work: +/* + pointcut locationLineNumber(SourcePane s, Location loc): + calls(loc, int lineNumber()) & within(s); + static around(SourcePane s, Location loc) returns int: locationLineNumber(s, loc) { + int result = proceed(s, loc); + return result * -1; + } +*/ +} diff --git a/tests/new/beforeNotRun/Driver.java b/tests/new/beforeNotRun/Driver.java new file mode 100644 index 000000000..55162311e --- /dev/null +++ b/tests/new/beforeNotRun/Driver.java @@ -0,0 +1,38 @@ +import org.aspectj.testing.Tester; + +// PR#265 before advice not run when abstract aspect has "of" clause + +public class Driver { + + public static String result = ""; + + public static void main(String[] args) { test(); } + + public static void test() { + new Driver(); + Tester.checkEqual(result, "-before-init-after", "before and after advice run"); + } + + public Driver() { + init(); + } + + public void init() { + result += "-init"; + } +} + +// when "of" clause is removed test passes +abstract aspect AbstractAspect /*of eachobject(instanceof(Driver))*/ { + pointcut init(Driver tc): call(* init(..)) && this(tc); + + after(Driver tc): init(tc) { + Driver.result += "-after"; + } +} + +aspect BeforeAspectA extends AbstractAspect { + before(Driver tc): init(tc) { + Driver.result += "-before"; + } +} diff --git a/tests/new/cflowAdviceNoSource/Driver.java b/tests/new/cflowAdviceNoSource/Driver.java new file mode 100644 index 000000000..1fd246dd3 --- /dev/null +++ b/tests/new/cflowAdviceNoSource/Driver.java @@ -0,0 +1,29 @@ + +import org.aspectj.testing.Tester; + +// PR#285 cflow advice with no source + +public class Driver { + + public static String s = ""; + + public static void main(String[] args){ test(); } + + public static void test() { + new Driver().go(); + Tester.checkEqual(s, "-go-advised", "advice runs"); + } + + int go(){ + s += "-go"; + return Math.max(1, 3); + } +} + +aspect A of eachcflow(instanceof(Driver) && executions(* go(..))) { + + before (): calls(* Math.*(..)) && ! calls(* Driver.go()) && ! calls(* Driver.test()) { + Driver.s += "-advised"; + } +} + diff --git a/tests/new/cflowObjectCreations/Driver.java b/tests/new/cflowObjectCreations/Driver.java new file mode 100644 index 000000000..15f1d883d --- /dev/null +++ b/tests/new/cflowObjectCreations/Driver.java @@ -0,0 +1,41 @@ + +import org.aspectj.testing.Tester; + +import java.util.*; + +// PR#307 cflow and object creations + + +public class Driver { + + public static String s = ""; + + public static void main(String[] args){ + new FTPServer(); + + Tester.checkEqual(s, "-connected-after", ""); + } +} + +/* PR306 */ +class FTPServer { + public FTPServer() { + new FTPConnection().connect(); + } +} + +class FTPConnection { + public void connect() { + Driver.s += "-connected"; + } +} + +aspect FooBuilding percflow(serverIdentification(FTPServer)) { + pointcut serverIdentification(FTPServer s) : + target(s) && execution(new(..)); + + after() returning (Object ret): + target(FTPConnection) && call(* *(..)) { + Driver.s += "-after"; + } +} diff --git a/tests/new/classaccess/main/Main.java b/tests/new/classaccess/main/Main.java new file mode 100644 index 000000000..adf808ae0 --- /dev/null +++ b/tests/new/classaccess/main/Main.java @@ -0,0 +1,9 @@ + +package main; + +/** @testcase PUREJAVA package class access not enforced outside of package */ +public class Main { + public static void main(String[] args) { + pack1.Target.publicStaticMethod(); // expecting CE here - Target not public + } +} diff --git a/tests/new/classaccess/pack1/Target.java b/tests/new/classaccess/pack1/Target.java new file mode 100644 index 000000000..dbf3f7e71 --- /dev/null +++ b/tests/new/classaccess/pack1/Target.java @@ -0,0 +1,7 @@ + +package pack1; + +/** @testcase PUREJAVA package class access not enforced outside of package */ +class Target { + public static void publicStaticMethod() {} +} diff --git a/tests/new/extraThrows/Driver.java b/tests/new/extraThrows/Driver.java new file mode 100644 index 000000000..00fc340dc --- /dev/null +++ b/tests/new/extraThrows/Driver.java @@ -0,0 +1,76 @@ +import org.aspectj.testing.Tester; + +// PR#259 "throws Exception" clause is unnecessarily added to Driver.main method + +public class Driver { + + /*private*/ static String s = ""; + + public static void main(String[] args) { test(); } + + public static void test() { + Driver ts = new Driver(); + Tester.checkEqual(s, "-bound-around", "bound"); + } + + void bind() throws Exception { s += "-bound"; } + + public Driver() { bind(); } +} + +aspect Aspect { + pointcut bind(): within(Driver) && call(void Driver.bind()); + + declare soft: Exception: bind(); + + void around(): bind() { + try { + proceed(); + } catch (Exception e) { } + Driver.s += "-around"; + } +} + + +/* HERE IS THE FIXED VERSION OF MARK'S TEST (the one in the bug + database was broken): +public class Driver +{ + + Driver() throws Exception { } + + + public static void main(String[] args) { + Driver ts = new Driver(); + Driver.bind("foo",ts); + } + + static void bind(String s, Object o) + {} + + static around() returns Driver: within(Driver) && + calls(Driver, new() ){ + Driver result = null; + try { + result = proceed(); + } catch (Exception e){ } + return result; + } + + + static around(String name) returns void: + within(Driver) && + calls(Driver, * bind(name,..)) { + try { + proceed(name + "0"); + } catch (Exception e) { } + } + + static before(String[] args): + within(Driver) && executions(void main(args)){ + System.out.println("..."); + } + +} +*/ + diff --git a/tests/new/finalMemInit/Driver.java b/tests/new/finalMemInit/Driver.java new file mode 100644 index 000000000..4a253e42a --- /dev/null +++ b/tests/new/finalMemInit/Driver.java @@ -0,0 +1,21 @@ + +import org.aspectj.testing.Tester; + +// PR#162 +// works with JDK > 1.2 but not with JDK < 1.1.8 + +public aspect Driver { + public static void main(String[] args) { test(); } + public static void test() { + Tester.checkEqual(new C().fi, 1, ""); + } + pointcut install(): execution(new()) && within(C); + /*static*/ after () : install() { } +} + +class C { + public final int fi; + C() { + fi = 1; + } +} diff --git a/tests/new/foemmel/TheAspect.java b/tests/new/foemmel/TheAspect.java new file mode 100644 index 000000000..7c1b8fc15 --- /dev/null +++ b/tests/new/foemmel/TheAspect.java @@ -0,0 +1,221 @@ +import org.aspectj.testing.Tester; + +privileged aspect TheAspect perthis(this(TheObject)) { + private TheObject theObject; + private int myPrivate_int=-1, myPackage_int=-1, myProtected_int=-1, myPublic_int=-1; + + after() returning(TheObject obj): execution(new()) { // CW 7 nonmatching target + theObject = obj; + } + + after() returning(): call(* realMain(..)) { + test_eq(); + test_timeseq(); + test_diveq(); + test_modeq(); + test_pluseq(); + test_minuseq(); + test_leftShifteq(); + test_rightShifteq(); + test_xoreq(); + test_andeq(); + test_unsignedRightShifteq(); + test_postinc(); + test_postdec(); + test_preinc(); + test_predec(); + test_oreq(); + test_gets(); + test_calls(); + } + + public void test_eq() { + theObject.private_int = 1; + theObject.protected_int = 2; + theObject.package_int = 3; + theObject.public_int = 4; + Tester.checkEqual(theObject.private_int,1,"set private_int"); + Tester.checkEqual(theObject.protected_int,2,"set protected_int"); + Tester.checkEqual(theObject.package_int,3,"set package_int"); + Tester.checkEqual(theObject.public_int,4,"set public_int"); + } + + public void test_timeseq() { + theObject.private_int *= 4; + theObject.protected_int *= 4; + theObject.package_int *= 4; + theObject.public_int *= 4; + Tester.checkEqual(theObject.private_int,4,"times private_int"); + Tester.checkEqual(theObject.protected_int,8,"times protected_int"); + Tester.checkEqual(theObject.package_int,12,"times package_int"); + Tester.checkEqual(theObject.public_int,16,"times public_int"); + } + + public void test_diveq() { + theObject.private_int /= 2; + theObject.protected_int /= 2; + theObject.package_int /= 2; + theObject.public_int /= 2; + Tester.checkEqual(theObject.private_int,2,"div private_int"); + Tester.checkEqual(theObject.protected_int,4,"div protected_int"); + Tester.checkEqual(theObject.package_int,6,"div package_int"); + Tester.checkEqual(theObject.public_int,8,"div public_int"); + } + + public void test_modeq() { + theObject.private_int %= 2; + theObject.protected_int %= 3; + theObject.package_int %= 4; + theObject.public_int %= 5; + Tester.checkEqual(theObject.private_int,0,"mod private_int"); + Tester.checkEqual(theObject.protected_int,1,"mod protected_int"); + Tester.checkEqual(theObject.package_int,2,"mod package_int"); + Tester.checkEqual(theObject.public_int,3,"mod public_int"); + } + + public void test_pluseq() { + theObject.private_int += 2; + theObject.protected_int += 2; + theObject.package_int += 2; + theObject.public_int += 2; + Tester.checkEqual(theObject.private_int,2,"plus private_int"); + Tester.checkEqual(theObject.protected_int,3,"plus protected_int"); + Tester.checkEqual(theObject.package_int,4,"plus package_int"); + Tester.checkEqual(theObject.public_int,5,"plus public_int"); + } + + public void test_minuseq() { + theObject.private_int -= 1; + theObject.protected_int -= 1; + theObject.package_int -= 1; + theObject.public_int -= 1; + Tester.checkEqual(theObject.private_int,1,"minus private_int"); + Tester.checkEqual(theObject.protected_int,2,"minus protected_int"); + Tester.checkEqual(theObject.package_int,3,"minus package_int"); + Tester.checkEqual(theObject.public_int,4,"minus public_int"); + } + + public void test_leftShifteq() { + theObject.private_int <<= 1; + theObject.protected_int <<= 1; + theObject.package_int <<= 1; + theObject.public_int <<= 1; + Tester.checkEqual(theObject.private_int,2,"left shift private_int"); + Tester.checkEqual(theObject.protected_int,4,"left shift protected_int"); + Tester.checkEqual(theObject.package_int,6,"left shift package_int"); + Tester.checkEqual(theObject.public_int,8,"left shift public_int"); + } + + public void test_rightShifteq() { + theObject.private_int >>= 1; + theObject.protected_int >>= 1; + theObject.package_int >>= 1; + theObject.public_int >>= 1; + Tester.checkEqual(theObject.private_int,1,"right shift private_int"); + Tester.checkEqual(theObject.protected_int,2,"right shift protected_int"); + Tester.checkEqual(theObject.package_int,3,"right shift package_int"); + Tester.checkEqual(theObject.public_int,4,"right shift public_int"); + } + + public void test_xoreq() { + theObject.private_int ^= 0; + theObject.protected_int ^= 1; + theObject.package_int ^= 1; + theObject.public_int ^= 1; + Tester.checkEqual(theObject.private_int,1,"xor private_int"); + Tester.checkEqual(theObject.protected_int,3,"xor protected_int"); + Tester.checkEqual(theObject.package_int,2,"xor package_int"); + Tester.checkEqual(theObject.public_int,5,"xor public_int"); + } + + public void test_andeq() { + theObject.private_int &= 3; + theObject.protected_int &= 6; + theObject.package_int &= 3; + theObject.public_int &= 4; + Tester.checkEqual(theObject.private_int,1,"and private_int"); + Tester.checkEqual(theObject.protected_int,2,"and protected_int"); + Tester.checkEqual(theObject.package_int,2,"and package_int"); + Tester.checkEqual(theObject.public_int,4,"and public_int"); + } + + public void test_unsignedRightShifteq() { + theObject.private_int >>>= 0; + theObject.protected_int >>>= 1; + theObject.package_int >>>= 1; + theObject.public_int >>>= 2; + Tester.checkEqual(theObject.private_int,1,"unsigned right shift private_int"); + Tester.checkEqual(theObject.protected_int,1,"unsigned right shift protected_int"); + Tester.checkEqual(theObject.package_int,1,"unsigned right shift package_int"); + Tester.checkEqual(theObject.public_int,1,"unsigned right shift public_int"); + } + + public void test_postinc() { + theObject.private_int ++; + theObject.protected_int ++; + theObject.package_int ++; + theObject.public_int ++; + Tester.checkEqual(theObject.private_int,2,"post ++ private_int"); + Tester.checkEqual(theObject.protected_int,2,"post ++ protected_int"); + Tester.checkEqual(theObject.package_int,2,"post ++ package_int"); + Tester.checkEqual(theObject.public_int,2,"post ++ public_int"); + } + + public void test_postdec() { + theObject.private_int --; + theObject.protected_int --; + theObject.package_int --; + theObject.public_int --; + Tester.checkEqual(theObject.private_int,1,"post -- private_int"); + Tester.checkEqual(theObject.protected_int,1,"post -- protected_int"); + Tester.checkEqual(theObject.package_int,1,"post -- package_int"); + Tester.checkEqual(theObject.public_int,1,"post -- public_int"); + } + + public void test_preinc() { + ++ theObject.private_int; + ++ theObject.protected_int; + ++ theObject.package_int; + ++ theObject.public_int; + Tester.checkEqual(theObject.private_int,2,"pre ++ private_int"); + Tester.checkEqual(theObject.protected_int,2,"pre ++ protected_int"); + Tester.checkEqual(theObject.package_int,2,"pre ++ package_int"); + Tester.checkEqual(theObject.public_int,2,"pre ++ public_int"); + } + + public void test_predec() { + -- theObject.private_int; + -- theObject.protected_int; + -- theObject.package_int; + -- theObject.public_int; + Tester.checkEqual(theObject.private_int,1,"pre -- private_int"); + Tester.checkEqual(theObject.protected_int,1,"pre -- protected_int"); + Tester.checkEqual(theObject.package_int,1,"pre -- package_int"); + Tester.checkEqual(theObject.public_int,1,"pre -- public_int"); + } + + public void test_oreq() { + theObject.private_int |= 8; + theObject.protected_int |= 8; + theObject.package_int |= 8; + theObject.public_int |= 8; + Tester.checkEqual(theObject.private_int,9,"or private_int"); + Tester.checkEqual(theObject.protected_int,9,"or protected_int"); + Tester.checkEqual(theObject.package_int,9,"or package_int"); + Tester.checkEqual(theObject.public_int,9,"or public_int"); + } + + public void test_gets() { + myPrivate_int = theObject.private_int; + myProtected_int = theObject.protected_int; + myPackage_int = theObject.package_int; + myPublic_int = theObject.public_int; + } + + public void test_calls() { + theObject.private_call(); + theObject.protected_call(); + theObject.package_call(); + theObject.public_call(); + } +} diff --git a/tests/new/foemmel/TheObject.java b/tests/new/foemmel/TheObject.java new file mode 100644 index 000000000..9a23341bf --- /dev/null +++ b/tests/new/foemmel/TheObject.java @@ -0,0 +1,241 @@ +import org.aspectj.testing.Tester; + +public class TheObject { + public static void main(String[] args) { new TheObject().realMain(args); } + public void realMain(String[] args) { + new TheObject(); + } + + private int private_int; + protected int protected_int; + /*package*/ int package_int; + public int public_int; + + private int private_call() { return private_int; } + protected int protected_call() { return protected_int; } + /*package*/ int package_call() { return package_int; } + public int public_call() { return public_int; } + +} + +/* ---------------------- + privileged aspect TheAspect of eachobject(instanceof(TheObject)) { + private TheObject theObject; + private int myPrivate_int=-1, myPackage_int=-1, myProtected_int=-1, myPublic_int=-1; + + after() returning(TheObject obj): receptions(new()) { + theObject = obj; + } + + after() returning(): receptions(* realMain(..)) { + test_eq(); + test_timeseq(); + test_diveq(); + test_modeq(); + test_pluseq(); + test_minuseq(); + test_leftShifteq(); + test_rightShifteq(); + test_xoreq(); + test_andeq(); + test_unsignedRightShifteq(); + test_postinc(); + test_postdec(); + test_preinc(); + test_predec(); + test_oreq(); + test_gets(); + test_calls(); + } + + public void test_eq() { + theObject.private_int = 1; + theObject.protected_int = 2; + theObject.package_int = 3; + theObject.public_int = 4; + Tester.checkEqual(theObject.private_int,1,"set private_int"); + Tester.checkEqual(theObject.protected_int,2,"set protected_int"); + Tester.checkEqual(theObject.package_int,3,"set package_int"); + Tester.checkEqual(theObject.public_int,4,"set public_int"); + } + + public void test_timeseq() { + theObject.private_int *= 4; + theObject.protected_int *= 4; + theObject.package_int *= 4; + theObject.public_int *= 4; + Tester.checkEqual(theObject.private_int,4,"times private_int"); + Tester.checkEqual(theObject.protected_int,8,"times protected_int"); + Tester.checkEqual(theObject.package_int,12,"times package_int"); + Tester.checkEqual(theObject.public_int,16,"times public_int"); + } + + public void test_diveq() { + theObject.private_int /= 2; + theObject.protected_int /= 2; + theObject.package_int /= 2; + theObject.public_int /= 2; + Tester.checkEqual(theObject.private_int,2,"div private_int"); + Tester.checkEqual(theObject.protected_int,4,"div protected_int"); + Tester.checkEqual(theObject.package_int,6,"div package_int"); + Tester.checkEqual(theObject.public_int,8,"div public_int"); + } + + public void test_modeq() { + theObject.private_int %= 2; + theObject.protected_int %= 3; + theObject.package_int %= 4; + theObject.public_int %= 5; + Tester.checkEqual(theObject.private_int,0,"mod private_int"); + Tester.checkEqual(theObject.protected_int,1,"mod protected_int"); + Tester.checkEqual(theObject.package_int,2,"mod package_int"); + Tester.checkEqual(theObject.public_int,3,"mod public_int"); + } + + public void test_pluseq() { + theObject.private_int += 2; + theObject.protected_int += 2; + theObject.package_int += 2; + theObject.public_int += 2; + Tester.checkEqual(theObject.private_int,2,"plus private_int"); + Tester.checkEqual(theObject.protected_int,3,"plus protected_int"); + Tester.checkEqual(theObject.package_int,4,"plus package_int"); + Tester.checkEqual(theObject.public_int,5,"plus public_int"); + } + + public void test_minuseq() { + theObject.private_int -= 1; + theObject.protected_int -= 1; + theObject.package_int -= 1; + theObject.public_int -= 1; + Tester.checkEqual(theObject.private_int,1,"minus private_int"); + Tester.checkEqual(theObject.protected_int,2,"minus protected_int"); + Tester.checkEqual(theObject.package_int,3,"minus package_int"); + Tester.checkEqual(theObject.public_int,4,"minus public_int"); + } + + public void test_leftShifteq() { + theObject.private_int <<= 1; + theObject.protected_int <<= 1; + theObject.package_int <<= 1; + theObject.public_int <<= 1; + Tester.checkEqual(theObject.private_int,2,"left shift private_int"); + Tester.checkEqual(theObject.protected_int,4,"left shift protected_int"); + Tester.checkEqual(theObject.package_int,6,"left shift package_int"); + Tester.checkEqual(theObject.public_int,8,"left shift public_int"); + } + + public void test_rightShifteq() { + theObject.private_int >>= 1; + theObject.protected_int >>= 1; + theObject.package_int >>= 1; + theObject.public_int >>= 1; + Tester.checkEqual(theObject.private_int,1,"right shift private_int"); + Tester.checkEqual(theObject.protected_int,2,"right shift protected_int"); + Tester.checkEqual(theObject.package_int,3,"right shift package_int"); + Tester.checkEqual(theObject.public_int,4,"right shift public_int"); + } + + public void test_xoreq() { + theObject.private_int ^= 0; + theObject.protected_int ^= 1; + theObject.package_int ^= 1; + theObject.public_int ^= 1; + Tester.checkEqual(theObject.private_int,1,"xor private_int"); + Tester.checkEqual(theObject.protected_int,3,"xor protected_int"); + Tester.checkEqual(theObject.package_int,2,"xor package_int"); + Tester.checkEqual(theObject.public_int,5,"xor public_int"); + } + + public void test_andeq() { + theObject.private_int &= 3; + theObject.protected_int &= 6; + theObject.package_int &= 3; + theObject.public_int &= 4; + Tester.checkEqual(theObject.private_int,1,"and private_int"); + Tester.checkEqual(theObject.protected_int,2,"and protected_int"); + Tester.checkEqual(theObject.package_int,2,"and package_int"); + Tester.checkEqual(theObject.public_int,4,"and public_int"); + } + + public void test_unsignedRightShifteq() { + theObject.private_int >>>= 0; + theObject.protected_int >>>= 1; + theObject.package_int >>>= 1; + theObject.public_int >>>= 2; + Tester.checkEqual(theObject.private_int,1,"unsigned right shift private_int"); + Tester.checkEqual(theObject.protected_int,1,"unsigned right shift protected_int"); + Tester.checkEqual(theObject.package_int,1,"unsigned right shift package_int"); + Tester.checkEqual(theObject.public_int,1,"unsigned right shift public_int"); + } + + public void test_postinc() { + theObject.private_int ++; + theObject.protected_int ++; + theObject.package_int ++; + theObject.public_int ++; + Tester.checkEqual(theObject.private_int,2,"post ++ private_int"); + Tester.checkEqual(theObject.protected_int,2,"post ++ protected_int"); + Tester.checkEqual(theObject.package_int,2,"post ++ package_int"); + Tester.checkEqual(theObject.public_int,2,"post ++ public_int"); + } + + public void test_postdec() { + theObject.private_int --; + theObject.protected_int --; + theObject.package_int --; + theObject.public_int --; + Tester.checkEqual(theObject.private_int,1,"post -- private_int"); + Tester.checkEqual(theObject.protected_int,1,"post -- protected_int"); + Tester.checkEqual(theObject.package_int,1,"post -- package_int"); + Tester.checkEqual(theObject.public_int,1,"post -- public_int"); + } + + public void test_preinc() { + ++ theObject.private_int; + ++ theObject.protected_int; + ++ theObject.package_int; + ++ theObject.public_int; + Tester.checkEqual(theObject.private_int,2,"pre ++ private_int"); + Tester.checkEqual(theObject.protected_int,2,"pre ++ protected_int"); + Tester.checkEqual(theObject.package_int,2,"pre ++ package_int"); + Tester.checkEqual(theObject.public_int,2,"pre ++ public_int"); + } + + public void test_predec() { + -- theObject.private_int; + -- theObject.protected_int; + -- theObject.package_int; + -- theObject.public_int; + Tester.checkEqual(theObject.private_int,1,"pre -- private_int"); + Tester.checkEqual(theObject.protected_int,1,"pre -- protected_int"); + Tester.checkEqual(theObject.package_int,1,"pre -- package_int"); + Tester.checkEqual(theObject.public_int,1,"pre -- public_int"); + } + + public void test_oreq() { + theObject.private_int |= 8; + theObject.protected_int |= 8; + theObject.package_int |= 8; + theObject.public_int |= 8; + Tester.checkEqual(theObject.private_int,9,"or private_int"); + Tester.checkEqual(theObject.protected_int,9,"or protected_int"); + Tester.checkEqual(theObject.package_int,9,"or package_int"); + Tester.checkEqual(theObject.public_int,9,"or public_int"); + } + + public void test_gets() { + myPrivate_int = theObject.private_int; + myProtected_int = theObject.protected_int; + myPackage_int = theObject.package_int; + myPublic_int = theObject.public_int; + } + + public void test_calls() { + theObject.private_call(); + theObject.protected_call(); + theObject.package_call(); + theObject.public_call(); + } +} +-------------------- */ diff --git a/tests/new/innerAspectAccess/Driver.java b/tests/new/innerAspectAccess/Driver.java new file mode 100644 index 000000000..e77b66e2e --- /dev/null +++ b/tests/new/innerAspectAccess/Driver.java @@ -0,0 +1,40 @@ +import org.aspectj.testing.Tester; + +// PR#211 + +public class Driver { + public static String s = "s"; + + public static void main(String[] args) { test(); } + + public static void test() { + doIt(); + Tester.checkEqual(s, "s:a:b", "both advice worked"); + } + + public static String doIt() { + return s; + } +} + +aspect Outer { + static int N = 10; + + pointcut staticMeth(): within(Driver) && execution(String doIt()); + + static aspect Inner { + static void foo() { + int i = N; + } + + before(): staticMeth() { + Driver.s += ":b"; + } + + pointcut innerPoints(): within(Driver) && execution(void test()); + } + + before(): Outer.Inner.innerPoints() { + Driver.s += ":a"; + } +} diff --git a/tests/new/innerConsSyntax/Driver.java b/tests/new/innerConsSyntax/Driver.java new file mode 100644 index 000000000..b432f5f9a --- /dev/null +++ b/tests/new/innerConsSyntax/Driver.java @@ -0,0 +1,22 @@ + +import org.aspectj.testing.Tester; + +// PR#192 + +public class Driver { + private static java.util.Vector v = new java.util.Vector(); + + public static void main(String[] args) { test(); } + + public static void test() { + Driver temp = new Driver(); + + Inner inner = temp.new Inner(); + + Tester.check(inner.isInst, "Inner instance flag"); + } + + class Inner { + public boolean isInst = true; + } +}
\ No newline at end of file diff --git a/tests/new/innerInterfaces/other/Test.java b/tests/new/innerInterfaces/other/Test.java new file mode 100644 index 000000000..4e4190c05 --- /dev/null +++ b/tests/new/innerInterfaces/other/Test.java @@ -0,0 +1,5 @@ +package other; + +public class Test { + public void foo() { } +} diff --git a/tests/new/innerInterfaces/p/Driver.java b/tests/new/innerInterfaces/p/Driver.java new file mode 100644 index 000000000..5f5e7d72a --- /dev/null +++ b/tests/new/innerInterfaces/p/Driver.java @@ -0,0 +1,14 @@ +package p; + +import org.aspectj.testing.Tester; +import other.Test; + +public class Driver { + public static void main(String[] args) { + Test t = new Test(); + t.foo(); + Tester.checkEqual(InnerTest.getCallCount(t), 1); + t.foo(); + Tester.checkEqual(InnerTest.getCallCount(t), 2); + } +} diff --git a/tests/new/innerInterfaces/p/InnerTest.java b/tests/new/innerInterfaces/p/InnerTest.java new file mode 100644 index 000000000..adc25be1f --- /dev/null +++ b/tests/new/innerInterfaces/p/InnerTest.java @@ -0,0 +1,17 @@ +package p; + +aspect InnerTest { + private interface Inner {} + declare parents: other.Test implements Inner; + + private int Inner.count = 0; + + before(Inner i): target(i) && call(* *(..)) { + i.count++; + } + + public static int getCallCount(Object o) { + if (o instanceof Inner) return ((Inner)o).count; + else return -1; + } +} diff --git a/tests/new/introTypeMissing/AspectInIntroducedMethod.java b/tests/new/introTypeMissing/AspectInIntroducedMethod.java new file mode 100644 index 000000000..17de800e9 --- /dev/null +++ b/tests/new/introTypeMissing/AspectInIntroducedMethod.java @@ -0,0 +1,32 @@ + +import org.aspectj.testing.Tester; + +public class AspectInIntroducedMethod { + public static void main(String[] args) { + String result = new TargetClass().addMethod(); + Tester.check("inner".equals(result), + "\"inner\".equals(\"" + result + "\")"); + } +} +aspect A { + class inner { + public String name() { return "inner"; } + } + /** shows A usable in non-introductions */ + public String getName() { + new inner(); + A a = this; + return a.new inner().name(); + } + + // NPE at NewInstanceExpr.java:287 + /** @testcase qualified new expression using aspect type in method introduction body */ + public String TargetClass.addMethod() { + String result = null; + A a = A.aspectOf(); + result = a.getName(); + result = a.new inner().name(); // bug: remove this to avoid NPE + return result; + } +} +class TargetClass {} diff --git a/tests/new/introTypeMissing/Cast.java b/tests/new/introTypeMissing/Cast.java new file mode 100644 index 000000000..f262b938b --- /dev/null +++ b/tests/new/introTypeMissing/Cast.java @@ -0,0 +1,46 @@ + + +import org.aspectj.testing.Tester; + +public class Cast { + public static void main(String[] args) { + Tester.expectEvent("cast"); + new TargetClass().introducedCast(); + Tester.checkAllEvents(); + } +} + +aspect CastAspect { + /** @testcase Introduced type unavailable to cast expressions in introduced methods */ + public void TargetClass.introducedCast() { + boolean boolean_1 = getboolean(); + boolean boolean_2 = (boolean) getboolean(); + boolean boolean_3 = (boolean) this.getboolean(); + byte byte_1 = getbyte(); + byte byte_2 = (byte) getbyte(); + byte byte_3 = (byte) this.getbyte(); + char char_1 = getchar(); + char char_2 = (char) getchar(); + char char_3 = (char) this.getchar(); + short short_1 = getshort(); + short short_2 = (short) getshort(); + short short_3 = (short) this.getshort(); + int int_1 = getint(); + int int_2 = (int) getint(); + int int_3 = (int) this.getint(); + long long_1 = getlong(); + long long_2 = (long) getlong(); + long long_3 = (long) this.getlong(); + float float_1 = getfloat(); + float float_2 = (float) getfloat(); + float float_3 = (float) this.getfloat(); + double double_1 = getdouble(); + double double_2 = (double) getdouble(); + double double_3 = (double) this.getdouble(); + //X X_1 = getX(); + //X X_2 = (X) getX(); + //X X_3 = (X) this.getX(); + Util.signal("cast"); + } +} + diff --git a/tests/new/introTypeMissing/CastInFieldInit.java b/tests/new/introTypeMissing/CastInFieldInit.java new file mode 100644 index 000000000..ed0e6b5a3 --- /dev/null +++ b/tests/new/introTypeMissing/CastInFieldInit.java @@ -0,0 +1,54 @@ + + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class CastInFieldInit { + public static void main(String[] args) { + Tester.expectEvent("castfield"); + TargetClass me = new TargetClass(); + Tester.check(me.result, "me.result"); + Tester.checkAllEvents(); + } +} + +interface Valid { public boolean valid();} + +aspect CastInFieldInitAspect { + /** @testcase Introduced type unavailable to cast expressions in introduced field initializers */ + public boolean TargetClass.result = + new Valid() { + public boolean valid() { + boolean boolean_1 = getboolean(); + boolean boolean_2 = (boolean) getboolean(); + //boolean boolean_3 = (boolean) TargetClass.this.getboolean(); + byte byte_1 = getbyte(); + byte byte_2 = (byte) getbyte(); + //byte byte_3 = (byte) TargetClass.this.getbyte(); + char char_1 = getchar(); + char char_2 = (char) getchar(); + //char char_3 = (char) TargetClass.this.getchar(); + short short_1 = getshort(); + short short_2 = (short) getshort(); + //short short_3 = (short) TargetClass.this.getshort(); + int int_1 = getint(); + int int_2 = (int) getint(); + //int int_3 = (int) TargetClass.this.getint(); + long long_1 = getlong(); + long long_2 = (long) getlong(); + //long long_3 = (long) TargetClass.this.getlong(); + float float_1 = getfloat(); + float float_2 = (float) getfloat(); + //float float_3 = (float) TargetClass.this.getfloat(); + double double_1 = getdouble(); + double double_2 = (double) getdouble(); + //double double_3 = (double) TargetClass.this.getdouble(); + //X X_1 = getX(); + //X X_2 = (X) getX(); + //X X_3 = (X) this.getX(); + Util.signal("castfield"); + return (boolean_1 && boolean_2 ); + } + }.valid(); +} + diff --git a/tests/new/introTypeMissing/Inner.java b/tests/new/introTypeMissing/Inner.java new file mode 100644 index 000000000..ee3b8f52b --- /dev/null +++ b/tests/new/introTypeMissing/Inner.java @@ -0,0 +1,21 @@ +import org.aspectj.testing.Tester; + +public class Inner { + public static void main(String[] args) { + Tester.expectEvent("inner"); + new TargetClass().inner(); + Tester.checkAllEvents(); + } +} + +aspect InstanceOfAspect { + /** @testcase Introduced type unavailable to qualified new expressions in introduced methods */ + public void TargetClass.inner() { + InnerClass i = this.new InnerClass(); + if (!i.valid()) Util.fail("this.new InnerClass()"); + InnerClass j = getThis().new InnerClass(); + if (!j.valid()) Util.fail("getThis().new InnerClass()"); + Util.signal("inner"); + } +} + diff --git a/tests/new/introTypeMissing/InnerInFieldInit.java b/tests/new/introTypeMissing/InnerInFieldInit.java new file mode 100644 index 000000000..3269fce3f --- /dev/null +++ b/tests/new/introTypeMissing/InnerInFieldInit.java @@ -0,0 +1,29 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class InnerInFieldInit { + public static void main(String[] args) { + Tester.expectEvent("innerfield"); + TargetClass me = new TargetClass(); + Tester.check(me.result, "me.result"); + Tester.checkAllEvents(); + } +} + +interface Valid { public boolean valid();} + +aspect InnerInFieldInitAspect { + /** @testcase Introduced type unavailable to qualified new expressions in introduced field initializers */ + public boolean TargetClass.result = + new Valid() { + public boolean valid() { + InnerClass i = TargetClass.this.new InnerClass(); + if (!i.valid()) Util.fail("this.new InnerClass()"); + InnerClass j = getThis().new InnerClass(); + if (!j.valid()) Util.fail("getThis().new InnerClass()"); + Util.signal("innerfield"); + return i.valid() && j.valid(); + } + }.valid(); +} + diff --git a/tests/new/introTypeMissing/InstanceOf.java b/tests/new/introTypeMissing/InstanceOf.java new file mode 100644 index 000000000..f78bda28e --- /dev/null +++ b/tests/new/introTypeMissing/InstanceOf.java @@ -0,0 +1,32 @@ +import org.aspectj.testing.Tester; + +public class InstanceOf { + public static void main(String[] args) { + Tester.expectEvent("instanceOf"); + new TargetClass().instanceOf(); + Tester.checkAllEvents(); + } +} + +aspect InstanceOfAspect { + /** @testcase Introduced type unavailable to instanceof expressions in introduced methods */ + public void TargetClass.instanceOf() { + /* expecting compiler error, + but only getting compiler warnings and generated class? + -> needs work + */ + // -------- RuntimeException: "Unsupported emit on NotFoundType" Type.java:460 + if (!((getboolean()) instanceof boolean)) { Util.fail("boolean"); } + if (!((getchar()) instanceof char)) { Util.fail("char"); } + if (!((getbyte()) instanceof byte)) { Util.fail("byte"); } + if (!((getshort()) instanceof short)) { Util.fail("short"); } + if (!((getint()) instanceof int)) { Util.fail("int"); } + if (!((getlong()) instanceof long)) { Util.fail("long"); } + if (!((getfloat()) instanceof float)) { Util.fail("float"); } + if (!((getdouble()) instanceof double)) { Util.fail("double"); } + // ------ todo: expecting error, get RuntimeException + //if (!((doVoid()) instanceof Void)) { Tester.check(false,"void"); } + Util.signal("instanceOf"); + } +} + diff --git a/tests/new/introTypeMissing/TargetClass.java b/tests/new/introTypeMissing/TargetClass.java new file mode 100644 index 000000000..8883035ba --- /dev/null +++ b/tests/new/introTypeMissing/TargetClass.java @@ -0,0 +1,189 @@ +/* + @testcase definitions for introduced type test cases + --- initial variants + // -------- error "can't emit cast for NotFoundType() to PrimitiveType(int) + //double i = (double) i2() - i1(); + //int i = (int) this.someInt(); + + // -------- compiler RuntimeException: "Unsupported emit on NotFoundType" Type.java:460 + //double j = (double) (d2() - d1()); + //if ((d2() - d1()) instanceof float) { doTrue(); } + //if ((d2() - d1()) instanceof int) { doTrue(); } + //if ((d2() - d1()) instanceof short) { doTrue(); } + //if ((d2() - d1()) instanceof double) { doTrue(); } + //if ((i2() - i1()) instanceof int) { doTrue(); } + //if (!((getBoolean()) instanceof boolean)) { Tester.check(false,"boolean"); } + //if (!((getChar()) instanceof char)) { Tester.check(false,"char"); } + //if (!((getByte()) instanceof byte)) { Tester.check(false,"byte"); } + if (d2 instanceof double) { doTrue(); } + + // ------ expecting error, get compiler RuntimeException + if (!((doVoid()) instanceof Void)) { Tester.check(false,"void"); } + + // -------- NPE NewInstanceExpr.java:287 + //InnerClass i = this.new InnerClass(); + //InnerClass i = getThis().new InnerClass(); + +--- generalization of initial variants + primitive type not found: + either the introduced-on type or the method type of it + + --- possibly-relevant variants + [failingTypeExpressions: instanceof, cast, qualified-new] + x [introduced|normal|subclass] + x [static|{default}] + x [methods|field initializers] + x [types=[String|Object|Type]|primitiveTypes=[boolean|...]] + + --- actual variants + [failingTypeExpressions] + x [introduced|subclass] + x [methods|field initializers] + x [primitiveTypes] + except cast expression only for introduced methods - uncertain here + +*/ + + +class Type {} +public class TargetClass { + TargetClass getThis() { return this ; } + boolean getboolean() { return (this != null); } + byte getbyte() { return '\1'; } + char getchar() { return '\1'; } + short getshort() { return 0; } + int getint() { return 0; } + long getlong() { return 1l; } + float getfloat() { return 1f; } + double getdouble() { return 1d; } + String getstring() { return ""; } + + void doVoid() { } + Type getType() { return null; } + + /** run PUREJAVA variant of the tests */ + public static void main(String[] args) { + PureJava me = new PureJava(); + me.run(); + if (!me.result_cast) Util.fail("me.result_cast"); + if (!me.result_inner) Util.fail("me.result_inner"); + } + public class InnerClass { + public boolean valid() { + return (null != this); + } + } +} + +/** PUREJAVA variant of the tests */ +class PureJava extends TargetClass { + public void run() { + instanceOf(); + cast(); + newInner(); + } + + public void newInner() { + InnerClass i = this.new InnerClass(); + if (!i.valid()) Util.fail("this.new InnerClass()"); + InnerClass j = getThis().new InnerClass(); + if (!j.valid()) Util.fail("getThis().new InnerClass()"); + Util.signal("inner"); + } + + public void cast() { + boolean boolean_1 = getboolean(); + boolean boolean_2 = (boolean) getboolean(); + boolean boolean_3 = (boolean) this.getboolean(); + byte byte_1 = getbyte(); + byte byte_2 = (byte) getbyte(); + byte byte_3 = (byte) this.getbyte(); + char char_1 = getchar(); + char char_2 = (char) getchar(); + char char_3 = (char) this.getchar(); + short short_1 = getshort(); + short short_2 = (short) getshort(); + short short_3 = (short) this.getshort(); + int int_1 = getint(); + int int_2 = (int) getint(); + int int_3 = (int) this.getint(); + long long_1 = getlong(); + long long_2 = (long) getlong(); + long long_3 = (long) this.getlong(); + float float_1 = getfloat(); + float float_2 = (float) getfloat(); + float float_3 = (float) this.getfloat(); + double double_1 = getdouble(); + double double_2 = (double) getdouble(); + double double_3 = (double) this.getdouble(); + //X X_1 = getX(); + //X X_2 = (X) getX(); + //X X_3 = (X) this.getX(); + Util.signal("cast"); + } + public void instanceOf() { + // -------- RuntimeException: "Unsupported emit on NotFoundType" Type.java:460 + /* + if (!((getBoolean()) instanceof Boolean)) { Util.fail("boolean"); } + if (!((getChar()) instanceof char)) { Util.fail("char"); } + if (!((getByte()) instanceof byte)) { Util.fail("byte"); } + if (!((getShort()) instanceof short)) { Util.fail("short"); } + if (!((getInt()) instanceof int)) { Util.fail("int"); } + if (!((getLong()) instanceof long)) { Util.fail("long"); } + if (!((getFloat()) instanceof float)) { Util.fail("float"); } + if (!((getDouble()) instanceof double)) { Util.fail("double"); } + */ + // ------ todo: expecting error, get RuntimeException + //if (!((doVoid()) instanceof Void)) { Tester.check(false,"void"); } + Util.signal("instanceOf"); + } + // ---------- field initializer + interface Result { public boolean run();} + boolean result_inner = + new Result() { + public boolean run() { + TargetClass.InnerClass i = ((TargetClass) PureJava.this).new InnerClass(); + if (!i.valid()) Util.fail("this.new InnerClass()"); + TargetClass.InnerClass j = ((TargetClass) getThis()).new InnerClass(); + if (!j.valid()) Util.fail("getThis().new InnerClass()"); + Util.signal("innerfield"); + return i.valid() && j.valid(); + } + }.run(); + boolean result_cast = + new Result() { + public boolean run() { + boolean boolean_1 = getboolean(); + boolean boolean_2 = (boolean) getboolean(); + boolean boolean_3 = (boolean) PureJava.this.getboolean(); + byte byte_1 = getbyte(); + byte byte_2 = (byte) getbyte(); + byte byte_3 = (byte) PureJava.this.getbyte(); + char char_1 = getchar(); + char char_2 = (char) getchar(); + char char_3 = (char) PureJava.this.getchar(); + short short_1 = getshort(); + short short_2 = (short) getshort(); + short short_3 = (short) PureJava.this.getshort(); + int int_1 = getint(); + int int_2 = (int) getint(); + int int_3 = (int) PureJava.this.getint(); + long long_1 = getlong(); + long long_2 = (long) getlong(); + long long_3 = (long) PureJava.this.getlong(); + float float_1 = getfloat(); + float float_2 = (float) getfloat(); + float float_3 = (float) PureJava.this.getfloat(); + double double_1 = getdouble(); + double double_2 = (double) getdouble(); + double double_3 = (double) PureJava.this.getdouble(); + //X X_1 = getX(); + //X X_2 = (X) getX(); + //X X_3 = (X) this.getX(); + Util.signal("castfield"); + return (boolean_1 && boolean_2 && boolean_3); + } + }.run(); + +} + diff --git a/tests/new/introTypeMissing/TargetClassCF.java b/tests/new/introTypeMissing/TargetClassCF.java new file mode 100644 index 000000000..e3e3aae49 --- /dev/null +++ b/tests/new/introTypeMissing/TargetClassCF.java @@ -0,0 +1,30 @@ + +public class TargetClassCF { + /** run PUREJAVA variant of the tests */ + public static void main(String[] args) { + throw new Error("expecting compile failure"); + } +} + +class TargetClass { + boolean getboolean() { return (this != null); } + public class InnerClass { + public boolean valid() { + return (null != this); + } + } +} + +/** @testcase superclass n/a as this qualifier in inner classes */ +class PureJava extends TargetClass { + public class inner { + public void run() { + InnerClass j = TargetClass.this.new InnerClass(); // s.b. PureJava + boolean boolean_4 = TargetClass.this.getboolean(); // s.b. PureJava + } + } + + boolean result_cast = TargetClass.this.getboolean(); // s.b. PureJava + InnerClass f = TargetClass.this.new InnerClass(); // s.b. PureJava +} + diff --git a/tests/new/introTypeMissing/TargetClassCP.java b/tests/new/introTypeMissing/TargetClassCP.java new file mode 100644 index 000000000..2247f8c7b --- /dev/null +++ b/tests/new/introTypeMissing/TargetClassCP.java @@ -0,0 +1,38 @@ +import org.aspectj.testing.Tester; + +public class TargetClassCP { + /** run PUREJAVA variant of the tests */ + public static void main(String[] args) { + SubClass me = new SubClass(); + Tester.check(me.field, "me.field"); + Tester.check(me.f.valid(), "me.f.valid()"); + Tester.check(me.new inner().run(), "me.new inner().run() "); + Tester.check(me.result_cast, "me.result_cast"); + } +} + +class TargetClass { + boolean ok = true; + boolean getboolean() { return (this != null); } + public class InnerClass { + public boolean valid() { + return (null != this); + } + } +} + +/** @testcase enclosing class available as this qualifier in inner classes */ +class SubClass extends TargetClass { + public class inner { + public boolean run() { + InnerClass j = SubClass.this.new InnerClass(); + boolean boolean_4 = SubClass.this.getboolean(); + return (boolean_4 && j.valid()); + } + } + + boolean result_cast = SubClass.this.getboolean(); + InnerClass f = SubClass.this.new InnerClass(); + boolean field = SubClass.this.ok; +} + diff --git a/tests/new/introTypeMissing/ThisInIntroFieldInit.java b/tests/new/introTypeMissing/ThisInIntroFieldInit.java new file mode 100644 index 000000000..4517ac1ac --- /dev/null +++ b/tests/new/introTypeMissing/ThisInIntroFieldInit.java @@ -0,0 +1,93 @@ +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class ThisInIntroFieldInit { + public static void main(String[] args) { + Tester.expectEvent("result init"); + Tester.expectEvent("internalResult init"); + TargetClass me = new TargetClass(); + + // pure-java - field references + Tester.check(me.t_result_ref, "me.t_result_ref"); + Tester.check(me.t_result_ref_this, "me.t_result_ref_this"); + Tester.check(me.t_result_ref_qualified, "me.t_result_ref_qualified"); + + // pure-java - method references + Tester.check(me.t_result, "me.t_result"); + Tester.check(me.t_result_this, "me.t_result_this"); + Tester.check(me.t_result_qualified, "me.t_result_qualified"); + Tester.check(me.t_result_anon, "me.t_result_anon"); + + // introduction - field references + // local initializers are run after introduced initializers in 1.1 + Tester.check(!me.result_ref, "me.result_ref"); + Tester.check(!me.result_ref_this, "me.result_ref_this"); + Tester.check(!me.result_ref_qualified, "me.result_ref_qualified"); + + // introduction - method references + Tester.check(me.result, "me.result"); + Tester.check(me.result_this, "me.result_this"); + Tester.check(me.result_qualified, "me.result_qualified"); + Tester.check(me.result_anon, "me.result_anon"); + + Tester.checkAllEvents(); + } +} + +class TargetClass { + boolean targTest() { return (null != this); } + public boolean ok = (this != null); + /** @testcase field reference in field initializer */ + public boolean t_result_ref = ok; + /** @testcase this field reference in field initializer */ + public boolean t_result_ref_this = this.ok; + /** @testcase qualified this field reference in field initializer */ + public boolean t_result_ref_qualified = TargetClass.this.ok; + /** @testcase method reference in field initializer */ + public boolean t_result = targTest(); + /** @testcase this method in field initializer */ + public boolean t_result_this = this.targTest(); + /** @testcase qualified this method in field initializer */ + public boolean t_result_qualified = TargetClass.this.targTest(); + /** @testcase qualified this method in field initializer anon class definition */ + boolean t_result_anon + = new Validator() { + public boolean valid() { + boolean one = targTest(); + boolean two = TargetClass.this.targTest(); + boolean three = ok; + boolean four = TargetClass.this.ok; + Tester.event("internalResult init"); + return (one && two && three && four); + }}.valid(); +} +interface Validator { + public boolean valid(); +} + +aspect A { + /** @testcase field reference in field initializer */ + public boolean TargetClass.result_ref = ok; + /** @testcase this field reference in field initializer */ + public boolean TargetClass.result_ref_this = this.ok; + /** @testcase qualified this field reference in field initializer */ + public boolean TargetClass.result_ref_qualified = TargetClass.this.ok; + + /** @testcase method reference in introduced field initializer */ + public boolean TargetClass.result = targTest(); + /** @testcase this method in introduced field initializer */ + public boolean TargetClass.result_this = this.targTest(); + /** @testcase qualified this method in introduced field initializer */ + public boolean TargetClass.result_qualified = TargetClass.this.targTest(); + /** @testcase qualified this method in introduced field initializer anon class definition */ + public boolean TargetClass.result_anon + = new Validator() { + public boolean valid() { + boolean one = targTest(); + boolean two = TargetClass.this.targTest(); + boolean three = !ok; + boolean four = !TargetClass.this.ok; + Tester.event("result init"); + return (one && two && three && four); + }}.valid(); +} diff --git a/tests/new/introTypeMissing/Util.java b/tests/new/introTypeMissing/Util.java new file mode 100644 index 000000000..22e33eff2 --- /dev/null +++ b/tests/new/introTypeMissing/Util.java @@ -0,0 +1,14 @@ + + +import org.aspectj.testing.Tester; + +public class Util { + public static void fail(String s) { + //System.err.println("fail: " + s); + Tester.check(false,s); + } + public static void signal(String s) { + //System.err.println("signal: " + s); + Tester.event(s); + } +} diff --git a/tests/new/introductionPackage/one/Aspect.java b/tests/new/introductionPackage/one/Aspect.java new file mode 100644 index 000000000..43ce36c20 --- /dev/null +++ b/tests/new/introductionPackage/one/Aspect.java @@ -0,0 +1,25 @@ +package one; + +/** @testcase PR#548 introduced methods have incorrect package */ +public aspect Aspect { + public void C.foo() { // workaround: add qualification: one.C.foo + /** @testcase PR#548 introduction method casting this to introduction type */ + ((C) this).protectedMethod(); // bad CE: Can't convert from two.C to one.C + /** @testcase PR#548 introduction method accessing protected method */ + protectedMethod(); // bad CE: can't find any method with name: protectedMethod + /** @testcase PR#548 introduction method accessing public method */ + publicMethod(); // bad CE: can't find any method with name: publicMethod + /** @testcase PR#548 introduction method accessing default method */ + defaultMethod(); // bad CE: can't find any method with name: defaultMethod + + /** @testcase PR#548 introduction method accessing protected field */ + int i = protectedInt; // bad CE: can't bind name: protectedInt + /** @testcase PR#548 introduction method accessing private field */ + int j = publicInt; // bad CE: can't bind name: publicInt + /** @testcase PR#548 introduction method accessing default field */ + int k = defaultInt; // bad CE: can't bind name: defaultInt + int l = i * j * k; + //privateMethod(); // todo error case + //int p = privateInt; // todo error case + } +} diff --git a/tests/new/introductionPackage/one/C.java b/tests/new/introductionPackage/one/C.java new file mode 100644 index 000000000..47fa2a078 --- /dev/null +++ b/tests/new/introductionPackage/one/C.java @@ -0,0 +1,13 @@ +package one; + +/** @testcase PR#548 */ +public class C { + public void publicMethod(){ } + protected void protectedMethod(){} + void defaultMethod(){ } + private void privateMethod(){ } + public int publicInt = 1; + protected int protectedInt = 1; + int defaultInt = 1; + private int privateInt = 1; +} diff --git a/tests/new/introductionPackage/one/TestAspect.java b/tests/new/introductionPackage/one/TestAspect.java new file mode 100644 index 000000000..11e4188b3 --- /dev/null +++ b/tests/new/introductionPackage/one/TestAspect.java @@ -0,0 +1,28 @@ +package one; + +import org.aspectj.testing.*; +public aspect TestAspect { + public static void main(String[] args) { + C me = new C(); + me.foo(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("execution(void one.C.publicMethod())"); + Tester.expectEvent("execution(void one.C.protectedMethod())"); + Tester.expectEvent("execution(void one.C.defaultMethod())"); + Tester.expectEvent("get(int one.C.protectedInt)"); + Tester.expectEvent("get(int one.C.publicInt)"); + Tester.expectEvent("get(int one.C.defaultInt)"); + + // XXX added - correct? + Tester.expectEvent("execution(void one.C.foo())"); + Tester.expectEvent("execution(void one.C.protectedMethod())"); + } + + before () : execution(* C.*(..)) || get(int C.*) + { + Tester.event("" + thisJoinPointStaticPart); + //System.out.println("" + thisJoinPointStaticPart); + } +} diff --git a/tests/new/introductionPackage/two/C.java b/tests/new/introductionPackage/two/C.java new file mode 100644 index 000000000..1db9e2b99 --- /dev/null +++ b/tests/new/introductionPackage/two/C.java @@ -0,0 +1,5 @@ +package two; + +/** @testcase PR#548 */ +public class C { } + diff --git a/tests/new/nolang/java/lang/Object.java b/tests/new/nolang/java/lang/Object.java new file mode 100644 index 000000000..c660f39f4 --- /dev/null +++ b/tests/new/nolang/java/lang/Object.java @@ -0,0 +1,6 @@ + +package java.lang; + +/** @testcase PR#762 Compiling java.lang.Object with ajc yields non-verifying bytecode */ +public class Object { // CE 5 here? +}
\ No newline at end of file diff --git a/tests/new/nolang/java/lang/String.java b/tests/new/nolang/java/lang/String.java new file mode 100644 index 000000000..1e6f99d3d --- /dev/null +++ b/tests/new/nolang/java/lang/String.java @@ -0,0 +1,8 @@ + +package java.lang; + + + +/** @testcase PR#762 Compiling java.lang.Object with ajc yields non-verifying bytecode */ +public class String { // CE 7 here? +}
\ No newline at end of file diff --git a/tests/new/options11/Aspect.java b/tests/new/options11/Aspect.java new file mode 100644 index 000000000..e0c56f519 --- /dev/null +++ b/tests/new/options11/Aspect.java @@ -0,0 +1,43 @@ + + +import org.aspectj.testing.Tester; +import org.aspectj.lang.JoinPoint; + +import library1.Library1; +import library2.Library2; + +/** extend abstract, and implement needed */ +aspect AnotherAspect extends Library2 { + + pointcut targetJoinPoints() : + execution(public static void Main.main(..)); + + protected String renderId(JoinPoint jp) { + String result = super.renderId(jp); + return result + " - ok"; + } +} + +class Testing { + static aspect Init { + + declare dominates : Init, Library1, AnotherAspect; + + before() : AnotherAspect.targetJoinPoints() { + Main.i = 1; + Tester.expectEvent("before main"); + Tester.expectEvent("after main"); + Tester.expectEvent("after 2 main - ok"); + Tester.expectEvent("before 2 main - ok"); + Tester.expectEvent("before run"); + } + after () returning : AnotherAspect.targetJoinPoints() { + Tester.checkAllEvents(); + } + + before() : call(void run()) { + Tester.event("before run"); + } + } + +}
\ No newline at end of file diff --git a/tests/new/options11/Main.java b/tests/new/options11/Main.java new file mode 100644 index 000000000..cfefc7b90 --- /dev/null +++ b/tests/new/options11/Main.java @@ -0,0 +1,11 @@ + + +import org.aspectj.testing.Tester; + +public class Main { + static int i = 0; + public static void main(String[] args) { + new injar.Injar().run(); + Tester.check(i != 0, "aspect failed"); + } +}
\ No newline at end of file diff --git a/tests/new/options11/aspectlib1.jar b/tests/new/options11/aspectlib1.jar Binary files differnew file mode 100644 index 000000000..31e101889 --- /dev/null +++ b/tests/new/options11/aspectlib1.jar diff --git a/tests/new/options11/aspectlib2.jar b/tests/new/options11/aspectlib2.jar Binary files differnew file mode 100644 index 000000000..20a22aa46 --- /dev/null +++ b/tests/new/options11/aspectlib2.jar diff --git a/tests/new/options11/injar.jar b/tests/new/options11/injar.jar Binary files differnew file mode 100644 index 000000000..2003bdc86 --- /dev/null +++ b/tests/new/options11/injar.jar diff --git a/tests/new/options11/injar/Injar.java b/tests/new/options11/injar/Injar.java new file mode 100644 index 000000000..02123001d --- /dev/null +++ b/tests/new/options11/injar/Injar.java @@ -0,0 +1,6 @@ + +package injar; + +public class Injar { + public void run() {} +}
\ No newline at end of file diff --git a/tests/new/options11/library1/Library1.java b/tests/new/options11/library1/Library1.java new file mode 100644 index 000000000..ce2a13067 --- /dev/null +++ b/tests/new/options11/library1/Library1.java @@ -0,0 +1,23 @@ + +package library1; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.testing.Tester; + +public aspect Library1 { + pointcut targetJoinPoints() : + //execution(public static void main(String[])); + execution(public static void main(..)); + + before() : targetJoinPoints() { + Tester.event("before " + renderId(thisJoinPoint)); + } + + before() : targetJoinPoints() { + Tester.event("after " + renderId(thisJoinPoint)); + } + + protected String renderId(JoinPoint jp) { + return jp.getSignature().getName(); + } +}
\ No newline at end of file diff --git a/tests/new/options11/library2/Library2.java b/tests/new/options11/library2/Library2.java new file mode 100644 index 000000000..989dafb3c --- /dev/null +++ b/tests/new/options11/library2/Library2.java @@ -0,0 +1,20 @@ + +package library2; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.testing.Tester; + +public abstract aspect Library2 { + abstract pointcut targetJoinPoints(); + + before() : targetJoinPoints() { + Tester.event("before 2 " + renderId(thisJoinPoint)); + } + + before() : targetJoinPoints() { + Tester.event("after 2 " + renderId(thisJoinPoint)); + } + protected String renderId(JoinPoint jp) { + return jp.getSignature().getName(); + } +}
\ No newline at end of file diff --git a/tests/new/pack/PackageWildcards.java b/tests/new/pack/PackageWildcards.java new file mode 100644 index 000000000..649392072 --- /dev/null +++ b/tests/new/pack/PackageWildcards.java @@ -0,0 +1,33 @@ +package pack; + +import org.aspectj.testing.Tester; + +public aspect PackageWildcards { + pointcut fooCut(): call(String foo()); + + String around(): fooCut() && within(*) { + String result = proceed(); + return result + ":fooCut"; + } + + pointcut allMethodsCut(): target(Foo) && call(!abstract String *(..)); + + String around(): allMethodsCut() { + String result = proceed(); + return result + ":allMethodsCut"; + } + + public static void test() { + String message = new Foo().foo(); + //System.out.println(message); + Tester.checkEqual(message, "foo:allMethodsCut:fooCut", "all advice active"); + } + + public static void main(String[] args) { + test(); + } +} + +class Foo { + String foo() { return "foo"; } +} diff --git a/tests/new/packageAccessPR556/base1/p/C1.java b/tests/new/packageAccessPR556/base1/p/C1.java new file mode 100644 index 000000000..03b6c3c18 --- /dev/null +++ b/tests/new/packageAccessPR556/base1/p/C1.java @@ -0,0 +1,29 @@ +package p; + +import p.*; +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public aspect C1 { + private static int privateOne = 1 ; //C2.privateOne + /** @testcase PR#556 aspects get package access to variables in other aspects */ + /** @testcase PR#556 aspects get package access to variables in other classes */ + public static void main(String[] args) { + int i = C2.defaultOne + C2.protectedOne + C2.publicOne + + A2.defaultOne + A2.protectedOne + A2.publicOne; + Tester.expectEvent("C2"); + Tester.expectEvent("A2"); + Tester.check(i==6, "initialization failed: " + i); + try { System.getProperty("ignore" + i); } + catch (Exception e) {} + Tester.checkAllEvents(); + } + /** @testcase class pointcuts visible via package-access from another aspect */ + before () : C2.p() && execution(static void C1.main(String[])) { + Tester.event("C2"); + } + /** @testcase aspect pointcuts visible via package-access from another aspect */ + before () : A2.p() && execution(static void C1.main(String[])) { + Tester.event("A2"); + } +} diff --git a/tests/new/packageAccessPR556/base2/p/C2.java b/tests/new/packageAccessPR556/base2/p/C2.java new file mode 100644 index 000000000..a16dd1fe7 --- /dev/null +++ b/tests/new/packageAccessPR556/base2/p/C2.java @@ -0,0 +1,17 @@ +package p; + +aspect A2 { + private static int privateOne = 1; + static int defaultOne = 1; + protected static int protectedOne = 1; + public static int publicOne = 1; + pointcut p() : within (p..*) ; +} + +class C2 { + private static int privateOne = 1; + static int defaultOne = 1; + protected static int protectedOne = 1; + public static int publicOne = 1; + pointcut p() : within (p..*) ; +} diff --git a/tests/new/packageNameClash/Driver.java b/tests/new/packageNameClash/Driver.java new file mode 100644 index 000000000..5c7f55b8c --- /dev/null +++ b/tests/new/packageNameClash/Driver.java @@ -0,0 +1,9 @@ +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + new pkg.Class1().doIt(); + } +} diff --git a/tests/new/packageNameClash/otherpkg/Driver.java b/tests/new/packageNameClash/otherpkg/Driver.java new file mode 100644 index 000000000..f2c07aa4f --- /dev/null +++ b/tests/new/packageNameClash/otherpkg/Driver.java @@ -0,0 +1,10 @@ +package otherpkg; +import org.aspectj.testing.Tester; + +public class Driver { + public static void main(String[] args) { test(); } + + public static void test() { + new pkg.Class1().doIt(); + } +} diff --git a/tests/new/packageNameClash/pkg/Aspect1.java b/tests/new/packageNameClash/pkg/Aspect1.java new file mode 100644 index 000000000..e967dbbba --- /dev/null +++ b/tests/new/packageNameClash/pkg/Aspect1.java @@ -0,0 +1,4 @@ +package pkg; + +aspect Aspect1 /*of eachobject(instanceof(Class1))*/ { +} diff --git a/tests/new/packageNameClash/pkg/Class1.java b/tests/new/packageNameClash/pkg/Class1.java new file mode 100644 index 000000000..feafcc8ef --- /dev/null +++ b/tests/new/packageNameClash/pkg/Class1.java @@ -0,0 +1,16 @@ +package pkg; + +public class Class1 { + public String doIt() { + // I guess it's gone now ??? + //Aspect1 pkg = Aspect1.aspectOf(this); + Aspect1 pkg = null; + try { + java.lang.reflect.Constructor c = + Aspect1.class.getDeclaredConstructors()[0]; + c.setAccessible(true); + pkg = (Aspect1)c.newInstance(new Object[]{}); + } catch (Exception e) { throw new Error(e+""); } + return pkg.getClass().getName(); + } +} diff --git a/tests/new/packagePrefix/p/prefix.java b/tests/new/packagePrefix/p/prefix.java new file mode 100644 index 000000000..72865af32 --- /dev/null +++ b/tests/new/packagePrefix/p/prefix.java @@ -0,0 +1,3 @@ +package p; +/** @testcase PUREJAVA PR#574 compile problems loading classes whose package names are suffixes of class names */ +public class prefix{} diff --git a/tests/new/packagePrefix/p/prefix/SomeClass.java b/tests/new/packagePrefix/p/prefix/SomeClass.java new file mode 100644 index 000000000..4f6a6031f --- /dev/null +++ b/tests/new/packagePrefix/p/prefix/SomeClass.java @@ -0,0 +1,12 @@ + +package p.prefix; + +import org.aspectj.testing.Tester; + +/** @testcase PUREJAVA PR#574 compile problems loading classes whose package names are suffixes of class names */ +public class SomeClass { + public static void main(String[] args) { + int i = new p.prefix().hashCode(); + Tester.check(i!=0, "int i = new p.prefix().hashCode()"); + } +} diff --git a/tests/new/packagevisibility/PackagesAndAdvice.java b/tests/new/packagevisibility/PackagesAndAdvice.java new file mode 100644 index 000000000..ca17f0da7 --- /dev/null +++ b/tests/new/packagevisibility/PackagesAndAdvice.java @@ -0,0 +1,39 @@ +package packagevisibility; +import org.aspectj.testing.Tester; + +import packagevisibility.testPackage.*; + +public class PackagesAndAdvice +{ + public static void main(String[] args) { test(); } + + public static void test() { + packagevisibility.testPackage.Class1 c1 = + new packagevisibility.testPackage.Class1(); + Tester.checkEqual(c1.doIt("-1"), + "-1-advised-advised1-1-class1", + "publically visible"); + Tester.checkEqual(c1.doItToClass2("-2"), + "-2-advised-advised1-2-class2", + "package visible"); + } + +} + +aspect A { + static String message = "-advised"; + + String around(String s): + call(String doIt(String)) && args(s) && + (target(packagevisibility.testPackage.Class1) || + target(packagevisibility.testPackage.Class2)) { + String result = s + message; + result += A1.message; + return result + proceed(s); + } + +} + +class A1 { + static String message = "-advised1"; +} diff --git a/tests/new/packagevisibility/testPackage/Class1.java b/tests/new/packagevisibility/testPackage/Class1.java new file mode 100644 index 000000000..d53733d34 --- /dev/null +++ b/tests/new/packagevisibility/testPackage/Class1.java @@ -0,0 +1,11 @@ +package packagevisibility.testPackage; + +public class Class1 { + public String doIt(String s) { + return s + "-class1"; + } + + public String doItToClass2(String s) { + return (new packagevisibility.testPackage.Class2()).doIt(s); + } +} diff --git a/tests/new/packagevisibility/testPackage/Class2.java b/tests/new/packagevisibility/testPackage/Class2.java new file mode 100644 index 000000000..d32e84683 --- /dev/null +++ b/tests/new/packagevisibility/testPackage/Class2.java @@ -0,0 +1,13 @@ +package packagevisibility.testPackage; + +class Class2 { + String doIt(String s) { + new Runnable() { + public void run() { + System.out.println("running"); + } + }.run(); + + return s + "-class2"; + } +} diff --git a/tests/new/paramWidening/Driver.java b/tests/new/paramWidening/Driver.java new file mode 100644 index 000000000..bacd6bde4 --- /dev/null +++ b/tests/new/paramWidening/Driver.java @@ -0,0 +1,24 @@ + +import org.aspectj.testing.Tester; + +// PR#195 + +public class Driver { + private static java.util.Vector v = new java.util.Vector(); + + public static void main(String[] args) { test(); } + + public static void test() { + long l = foo(42); + + Tester.check(l == 42, "foo(42) == 42"); + } + + private static float foo(float f) { + return f; + } + + private static long foo(long l) { + return l; + } +}
\ No newline at end of file diff --git a/tests/new/pointcutParameter/Driver.java b/tests/new/pointcutParameter/Driver.java new file mode 100644 index 000000000..7dc1c6194 --- /dev/null +++ b/tests/new/pointcutParameter/Driver.java @@ -0,0 +1,31 @@ + +import org.aspectj.testing.Tester; + +// PR#290 compiler crashes with eachobject and named pointcuts with parameters + +public class Driver { + + public static String s = ""; + + public static void main(String[] args){ + new C().go(); + Tester.checkEqual(s, "-before-go", ""); + } + +} + +class C { + int x; + + public void go() { + Driver.s += "-go"; + } +} + +aspect A /*of eachobject(A.testPointcut(C))*/ { + pointcut testPointcut(C c): target(c); + + before(C c): target(c) && call(* *(..)) { + Driver.s += "-before"; + } +} diff --git a/tests/new/pr456/AroundVarBug.java b/tests/new/pr456/AroundVarBug.java new file mode 100644 index 000000000..e0ef18ed9 --- /dev/null +++ b/tests/new/pr456/AroundVarBug.java @@ -0,0 +1,38 @@ +import java.util.*; +import org.aspectj.testing.Tester; + +/** @testcase PR#456 advice on advice in usejavac mode */ +public aspect AroundVarBug { + static { + Tester.expectEvent("Meta-advice reached"); + Tester.expectEvent("advice reached"); + } + + protected pointcut iterator () : + call (public Iterator Collection.iterator ()); + + Iterator around () : iterator () { + return handleIterator (thisJoinPoint, proceed ()); + } + + private Iterator handleIterator (Object join, Iterator iter) { + Tester.event("advice reached"); + return iter; + } + + // ------------- + // Meta-advice + // ------------- + + private pointcut adviceHandlers (): + call (private * AroundVarBug.handle*(..)); + + // Advice on this aspect! + Object around () : adviceHandlers () { + Tester.event("Meta-advice reached"); + return proceed(); + } + +} // end of aspect AroundVarBug + + diff --git a/tests/new/pr456/Test_AroundVarBug.java b/tests/new/pr456/Test_AroundVarBug.java new file mode 100644 index 000000000..ed394fbca --- /dev/null +++ b/tests/new/pr456/Test_AroundVarBug.java @@ -0,0 +1,16 @@ +import java.util.ArrayList; + +import org.aspectj.testing.Tester; + +/** @testcase PR#456 advice on advice in usejavac mode */ +public class Test_AroundVarBug { + { + new ArrayList ().iterator (); + } + public static void main (String[] args) { + new Test_AroundVarBug(); + Tester.checkAllEvents(); + } + +} + diff --git a/tests/new/pr626/a/Outer.java b/tests/new/pr626/a/Outer.java new file mode 100644 index 000000000..413b36ba9 --- /dev/null +++ b/tests/new/pr626/a/Outer.java @@ -0,0 +1,27 @@ +package a; + +import org.aspectj.testing.Tester; + +/** @testcase PR#626 declared parent not defined in scope of target class declaration (CE in -usejavac only) */ +public abstract aspect Outer { + public static void main (String[] args) { + b.Foo foo = new b.Foo() { + public void run() { + Tester.event("run"); + } + }; + Inner i = (Inner) foo; + i.run(); + Tester.checkAllEvents(); + } + + static { + Tester.expectEvent("run"); + } + + protected interface Inner { + public void run(); + } + +} + diff --git a/tests/new/pr626/b/Foo.java b/tests/new/pr626/b/Foo.java new file mode 100644 index 000000000..3b40c6c74 --- /dev/null +++ b/tests/new/pr626/b/Foo.java @@ -0,0 +1,11 @@ +package b; + +import a.Outer; + +/** @testcase PR#626 declared parent not defined in scope of target class declaration (CE in -usejavac only) */ +public interface Foo { + public static aspect Specific extends Outer { + declare parents: Foo extends Inner; + } +} + diff --git a/tests/new/pr728/AnotherClass.java b/tests/new/pr728/AnotherClass.java new file mode 100644 index 000000000..c48be7089 --- /dev/null +++ b/tests/new/pr728/AnotherClass.java @@ -0,0 +1,13 @@ + +import org.aspectj.testing.*; + +/** @testcase PR#728 file order in type searching */ +public class AnotherClass implements Interface { + public static class InnerClass { } + public static void main (String[] args) { + String s = new AnotherClass.InnerClass().toString(); + Tester.expectEvent(s); + Tester.checkAllEvents(); + } +} + diff --git a/tests/new/pr728/Interface.java b/tests/new/pr728/Interface.java new file mode 100644 index 000000000..1b1119578 --- /dev/null +++ b/tests/new/pr728/Interface.java @@ -0,0 +1,17 @@ +import org.aspectj.testing.*; + +/** @testcase PR#728 file order in type searching */ +public interface Interface { + static aspect Aspect { + void aspectMethod( AnotherClass.InnerClass targ ) { + Tester.event( targ.toString()); + } + before(AnotherClass.InnerClass targ) : target(targ) + && !withincode(void Aspect.aspectMethod(AnotherClass.InnerClass)) + && call(public String toString()) { + aspectMethod(targ); + } + } +} + + diff --git a/tests/new/privilegedAspects/driver/PR555.java b/tests/new/privilegedAspects/driver/PR555.java new file mode 100644 index 000000000..92e1ef86e --- /dev/null +++ b/tests/new/privilegedAspects/driver/PR555.java @@ -0,0 +1,65 @@ + +package driver; + +//package pack; // check test passing +// import pack.DefaultTarget; // not expected to work +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class PR555 { + public static void main(String[] args) { + Tester.expectEvent("runner"); + int i ; + i = PA.readPrivateStaticInt(); + Tester.check(1==i,"PA.readPrivateStaticInt()"); + i = PA.readPrivateStaticIntFromInner(); + Tester.check(1==i,"PA.readPrivateStaticIntFromInner()"); + i = PA.runIntroducedAnonymousInnerClass(); + Tester.check(1==i,"PA.runIntroducedAnonymousInnerClass()"); + Tester.checkAllEvents(); + } + +} + +/* test access to private target variables */ +privileged aspect PA { + + public static int readPrivateStaticInt() { + return pack.DefaultTarget.privateStaticInt; + } + + public static int readPrivateStaticIntFromInner() { + return new Inner().readPrivateIntFromInner(); + } + + public static int runIntroducedAnonymousInnerClass() { + pack.DefaultTarget dtarget = new pack.DefaultTarget(); + dtarget.runner.run(); + return dtarget.privateInt; + //return dtarget.publicInt; + } + + static class Inner { + public static final int i = pack.DefaultTarget.privateStaticInt; + //public static final int i = pack.DefaultTarget.publicStaticInt; + public int readPrivateIntFromInner() { + pack.DefaultTarget defaultTarget + = new pack.DefaultTarget(); + return defaultTarget.privateInt; + //return defaultTarget.publicInt; + } + } + + // todo: bug used unprivileged aspect to introduce + // todo: inner class of aspect or of DefaultTarget? + Runnable pack.DefaultTarget.runner = new Runnable() { + public void run() { + Tester.event("runner"); + //if (1 != publicInt) { + if (1 != privateInt) { + throw new Error("1 != privateInt"); + } + } + }; +} + diff --git a/tests/new/privilegedAspects/driver/PrivilegedAspect.java b/tests/new/privilegedAspects/driver/PrivilegedAspect.java new file mode 100644 index 000000000..e29dffc17 --- /dev/null +++ b/tests/new/privilegedAspects/driver/PrivilegedAspect.java @@ -0,0 +1,119 @@ + +package driver; + +// import pack.DefaultTarget; // does not work - ok +import pack.PublicTarget; + +/** + * This aspect attempts to bind class references + * and read members of all access types + * from public- and default-access classes and inner classes + * from public static methods in the aspect. Usage: + * <pre>PrivilegedAspect.main(null);</pre> + * - or - + * <pre>PrivilegedAspect.readPublicTarget(); + * PrivilegedAspect.readPublicInnerTarget(); + * PrivilegedAspect.readDefaultTarget(); + * PrivilegedAspect.readDefaultInnerTarget();</pre> + */ +public privileged aspect PrivilegedAspect { + /** run all other static methods + * @param args ignored */ + public static void main(String[] args) { + readPublicTarget(); + readPublicInnerTarget(); + readDefaultTarget(); + readDefaultInnerTarget(); + } + + /** in public class + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readPublicTarget() { + Class c = PublicTarget.class; + int i = 0; + i += PublicTarget.publicStaticInt; + i += PublicTarget.protectedStaticInt; + i += PublicTarget.defaultStaticInt; + i += PublicTarget.privateStaticInt; + PublicTarget publicTarget = new PublicTarget(); + i += publicTarget.publicInt; + i += publicTarget.protectedInt; + i += publicTarget.defaultInt; + i += publicTarget. privateInt; + publicTarget.publicMethod(); + publicTarget.protectedMethod(); + publicTarget.defaultMethod(); + publicTarget.privateMethod(); + } + + /** in public inner class + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readPublicInnerTarget() { + Class c = PublicTarget.PublicInner.class; + int i = 0; + i += PublicTarget.PublicInner.publicStaticPublicInnerInt; + i += PublicTarget.PublicInner.protectedStaticPublicInnerInt; + i += PublicTarget.PublicInner.defaultStaticPublicInnerInt; + i += PublicTarget.PublicInner.privateStaticPublicInnerInt; + PublicTarget.PublicInner publicInnerTarget + = new PublicTarget().new PublicInner(); + i += publicInnerTarget.publicPublicInnerInt; + i += publicInnerTarget.protectedPublicInnerInt; + i += publicInnerTarget.defaultPublicInnerInt; + i += publicInnerTarget. privatePublicInnerInt; + publicInnerTarget.publicPublicInnerMethod(); + publicInnerTarget.protectedPublicInnerMethod(); + publicInnerTarget.defaultPublicInnerMethod(); + publicInnerTarget.privatePublicInnerMethod(); + } + + + /** in class with default access + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readDefaultTarget() { + Class c = pack.DefaultTarget.class; + int i = 0; + i += pack.DefaultTarget.publicStaticInt; + i += pack.DefaultTarget.protectedStaticInt; + i += pack.DefaultTarget.defaultStaticInt; + i += pack.DefaultTarget.privateStaticInt; + pack.DefaultTarget defaultTarget = new pack.DefaultTarget(); + i += defaultTarget.publicInt; + i += defaultTarget.protectedInt; + i += defaultTarget.defaultInt; + i += defaultTarget. privateInt; + defaultTarget.publicMethod(); + defaultTarget.protectedMethod(); + defaultTarget.defaultMethod(); + defaultTarget.privateMethod(); + } + + /** in inner class with default access + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readDefaultInnerTarget() { + Class c = pack.DefaultTarget.DefaultInner.class; + int i = 0; + i += pack.DefaultTarget.DefaultInner.publicStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.protectedStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.defaultStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.privateStaticDefaultInnerInt; + pack.DefaultTarget.DefaultInner defaultInnerTarget + = new pack.DefaultTarget().new DefaultInner(); + i += defaultInnerTarget.publicDefaultInnerInt; + i += defaultInnerTarget.protectedDefaultInnerInt; + i += defaultInnerTarget.defaultDefaultInnerInt; + i += defaultInnerTarget.privateDefaultInnerInt; + defaultInnerTarget.publicDefaultInnerMethod(); + defaultInnerTarget.protectedDefaultInnerMethod(); + defaultInnerTarget.defaultDefaultInnerMethod(); + defaultInnerTarget.privateDefaultInnerMethod(); + } +} diff --git a/tests/new/privilegedAspects/driver/UnprivilegedAspect.java b/tests/new/privilegedAspects/driver/UnprivilegedAspect.java new file mode 100644 index 000000000..7a2c1283f --- /dev/null +++ b/tests/new/privilegedAspects/driver/UnprivilegedAspect.java @@ -0,0 +1,113 @@ + +package driver; + +// import pack.DefaultTarget; // does not work - ok +import pack.PublicTarget; + +/** + * This is a copy of PrivilegedAspect, but without the privilege. + * It is an error test for unprivileged access to target classes + * esp. when compiled at the same time as PrivilegedAspect. + * todo: remove this case or render manageable. + */ +// Keep in sync with PrivilegedAspect +public aspect UnprivilegedAspect { + /** run all other static methods + * @param args ignored */ + public static void main(String[] args) { + readPublicTarget(); + readPublicInnerTarget(); + readDefaultTarget(); + readDefaultInnerTarget(); + } + + /** in public class + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readPublicTarget() { + Class c = PublicTarget.class; + int i = 0; + i += PublicTarget.publicStaticInt; + i += PublicTarget.protectedStaticInt; + i += PublicTarget.defaultStaticInt; + i += PublicTarget.privateStaticInt; + PublicTarget publicTarget = new PublicTarget(); + i += publicTarget.publicInt; + i += publicTarget.protectedInt; + i += publicTarget.defaultInt; + i += publicTarget. privateInt; + publicTarget.publicMethod(); + publicTarget.protectedMethod(); + publicTarget.defaultMethod(); + publicTarget.privateMethod(); + } + + /** in public inner class + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readPublicInnerTarget() { + Class c = PublicTarget.PublicInner.class; + int i = 0; + i += PublicTarget.PublicInner.publicStaticPublicInnerInt; + i += PublicTarget.PublicInner.protectedStaticPublicInnerInt; + i += PublicTarget.PublicInner.defaultStaticPublicInnerInt; + i += PublicTarget.PublicInner.privateStaticPublicInnerInt; + PublicTarget.PublicInner publicInnerTarget + = new PublicTarget().new PublicInner(); + i += publicInnerTarget.publicPublicInnerInt; + i += publicInnerTarget.protectedPublicInnerInt; + i += publicInnerTarget.defaultPublicInnerInt; + i += publicInnerTarget. privatePublicInnerInt; + publicInnerTarget.publicPublicInnerMethod(); + publicInnerTarget.protectedPublicInnerMethod(); + publicInnerTarget.defaultPublicInnerMethod(); + publicInnerTarget.privatePublicInnerMethod(); + } + + /** in class with default access + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readDefaultTarget() { + Class c = pack.DefaultTarget.class; + int i = 0; + i += pack.DefaultTarget.publicStaticInt; + i += pack.DefaultTarget.protectedStaticInt; + i += pack.DefaultTarget.defaultStaticInt; + i += pack.DefaultTarget.privateStaticInt; + pack.DefaultTarget defaultTarget = new pack.DefaultTarget(); + i += defaultTarget.publicInt; + i += defaultTarget.protectedInt; + i += defaultTarget.defaultInt; + i += defaultTarget. privateInt; + defaultTarget.publicMethod(); + defaultTarget.protectedMethod(); + defaultTarget.defaultMethod(); + defaultTarget.privateMethod(); + } + + /** in inner class with default access + * read static and instance fields and + * invoke methods, both of all access types + */ + public static void readDefaultInnerTarget() { + Class c = pack.DefaultTarget.DefaultInner.class; + int i = 0; + i += pack.DefaultTarget.DefaultInner.publicStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.protectedStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.defaultStaticDefaultInnerInt; + i += pack.DefaultTarget.DefaultInner.privateStaticDefaultInnerInt; + pack.DefaultTarget.DefaultInner defaultInnerTarget + = new pack.DefaultTarget().new DefaultInner(); + i += defaultInnerTarget.publicDefaultInnerInt; + i += defaultInnerTarget.protectedDefaultInnerInt; + i += defaultInnerTarget.defaultDefaultInnerInt; + i += defaultInnerTarget.privateDefaultInnerInt; + defaultInnerTarget.publicDefaultInnerMethod(); + defaultInnerTarget.protectedDefaultInnerMethod(); + defaultInnerTarget.defaultDefaultInnerMethod(); + defaultInnerTarget.privateDefaultInnerMethod(); + } +} diff --git a/tests/new/privilegedAspects/fish/B.java b/tests/new/privilegedAspects/fish/B.java new file mode 100644 index 000000000..d56aef758 --- /dev/null +++ b/tests/new/privilegedAspects/fish/B.java @@ -0,0 +1,27 @@ +package fish; +import main.Main; + +privileged aspect B { + private static String privateStatic = "B's private"; + + //introduction PrivateClass { + public void PrivateClass.fooB() { + b--; + Main.doThang("B: " + b); + Main.doThang("B: " + b()); + + System.out.println(privateStatic + "::" + FooC.privateStatic); + } + //} + + + before(PrivateClass obj): call(void PrivateClass.goo()) && target(obj) { + obj.b--; + Main.doThang("B: " + obj.b); + Main.doThang("B: " + obj.b()); + } +} + +class FooC { + private static int privateStatic = 2; +} diff --git a/tests/new/privilegedAspects/fish/PrivateClass.java b/tests/new/privilegedAspects/fish/PrivateClass.java new file mode 100644 index 000000000..f02941036 --- /dev/null +++ b/tests/new/privilegedAspects/fish/PrivateClass.java @@ -0,0 +1,32 @@ +package fish; +import main.Main; + +public class PrivateClass { + private int a = 999; + private int a() { return 888; } + private int b = 777; + private int b() { return 666; } + private int c = 555; + private int c() { return 444; } + private int d = 333; + private int d() { return 222; } + + public void goo() {} +} + +privileged aspect A { + + public void PrivateClass.fooA() { + a--; + Main.doThang("A: " + a); + Main.doThang("A: " + a()); + } + + before(PrivateClass obj): call(void PrivateClass.goo()) && target(obj) { + obj.a--; + Main.doThang("A: " + obj.a); + Main.doThang("A: " + obj.a()); + } +} + + diff --git a/tests/new/privilegedAspects/fowl/C.java b/tests/new/privilegedAspects/fowl/C.java new file mode 100644 index 000000000..bc227f85f --- /dev/null +++ b/tests/new/privilegedAspects/fowl/C.java @@ -0,0 +1,18 @@ +package fowl; +import fish.PrivateClass; +import main.Main; + +privileged aspect C { + + public void PrivateClass.fooC() { + c--; + Main.doThang("C: " + c); + Main.doThang("C: " + c()); + } + + before(PrivateClass obj): call(void PrivateClass.goo()) && target(obj) { + obj.c--; + Main.doThang("C: " + obj.c); + Main.doThang("C: " + obj.c()); + } +} diff --git a/tests/new/privilegedAspects/fowl/D.java b/tests/new/privilegedAspects/fowl/D.java new file mode 100644 index 000000000..4b36d2fe8 --- /dev/null +++ b/tests/new/privilegedAspects/fowl/D.java @@ -0,0 +1,17 @@ +package fowl; +import main.Main; + +privileged aspect D { + + public void fish.PrivateClass.fooD() { + d--; + Main.doThang("D: " + d); + Main.doThang("D: " + d()); + } + + before(fish.PrivateClass obj): call(void fish.PrivateClass.goo()) && target(obj) { + obj.d--; + Main.doThang("D: " + obj.d); + Main.doThang("D: " + obj.d()); + } +} diff --git a/tests/new/privilegedAspects/main/Main.java b/tests/new/privilegedAspects/main/Main.java new file mode 100644 index 000000000..89b0877b7 --- /dev/null +++ b/tests/new/privilegedAspects/main/Main.java @@ -0,0 +1,14 @@ +package main; + +class Main { + public static void main(String[] args) { + fish.PrivateClass obj = new fish.PrivateClass(); + obj.fooA(); + obj.fooB(); + obj.fooC(); + obj.fooD(); + obj.goo(); + } + + public static void doThang(String arg) {} +} diff --git a/tests/new/privilegedAspects/notes.txt b/tests/new/privilegedAspects/notes.txt new file mode 100644 index 000000000..01eda6263 --- /dev/null +++ b/tests/new/privilegedAspects/notes.txt @@ -0,0 +1,89 @@ + +testing privileged aspects +These notes apply to subdirectories util, pack, and driver. + +---- privileged aspects +- A privileged aspect ignores Java's accessibility rules and can access + any members anywhere in the world regardless of access restrictions. +- The privilege extends to anything in the lexical scope of the + privileged aspect, including inner classes and aspects + - the privilege does not extend to members introduced + onto the privileged aspect + - the privilege does not extend to subaspects +- a privileged aspect can be public +- a privileged aspect can be an inner aspect + even a static inner aspect of a class +- In some cases, providing this private access changes the access + permissions in the generated (byte)code, visible to other + classes compiled or running with the target class. + However, in the scope of the AspectJ compilation process, + only the privileged aspect should enjoy enhanced permissions +- type names from external packages must be fully qualified in the + privileged aspect. the visibility of import statements in the + file of the privileged aspect is unchanged. + - as a result, if {static} inner aspects are permitted, they will + be unable to bind some names that their enclosing class/aspect + can bind unless they fully qualify the names. + +---- testing privileged aspects +- binding: testing binding involves ensuring the class or aspect + can (or cannot) bind a name to a type or member at compile time + and can actually use that reference at runtime without an + IllegalAccessException + +testable statements: +1 any aspect may be privileged, including abstract and inner aspects, + including static inner aspects of classes +2 privileged aspects can bind any members of targets + - targets: classes, inner classes; aspects, inner aspects; + in the same package, a different package, and the default package + - sources in the privileged aspect: + - constructors, static and instance methods and initializers + - bodies for introduced methods and member initializers + - pointcut declarations + - pointcut pcd if() bodies + - advice bodies + - the same for inner classes and aspects +3 when privileged aspects get this access, access does not change for + other classes in the same set of files compiled +4 2 is not true of non-privileged subaspects of a privileged aspect +5 AspectJ will open up the target class to the minimal extent possible, + subject to these rules: + - the access permissions for the privileged access will not change + - the class hierarchy of the privileged aspect or the target class + will not be modified to gain protected access + - if protected access is available, AspectJ will not convert + to default/package access or to public access + - if default/package access is available, AspectJ will not convert + to public access +6 code in privileged aspects has no enhanced runtime permissions for + reflective access to (target classes or) non-target classes + +test plan: +1 compile-time binding test: + - public and default access classes in one package + each with a corresponding inner class (public/default) + each class has static and instance members of all access types + -> pack.PublicTarget, pack.DefaultTarget + - privileged aspect in another package + accesses all target methods/members from static methods + -> driver.PrivilegedAspect +2 test 1 with the aspect as an inner aspect + - unprivileged inner aspect of a privileged aspect + - privileged inner aspect of an unprivileged aspect + - static privileged inner aspect of a class +3 test 1 with errors expected for protected/private/default access + for a non-privileged subaspect + -> driver.UnPrivilegedAspect + +----- Priority 3 tests +4 test 1 with errors expected for private/default access + for a non-privileged subaspect inner class of a target subclass +5 test 1 with errors expected for private access + for a non-privileged aspect in the same package + +---- current status +Aggregate versions of tests 1 and 3 done; 2 is close. See -> above. +Error tests are brittle since it is undefined how many errors the +compiler will find in a file before giving up. The error test +cases should be broken out into separate test cases/files. diff --git a/tests/new/privilegedAspects/pack/DefaultTarget.java b/tests/new/privilegedAspects/pack/DefaultTarget.java new file mode 100644 index 000000000..3c2231db4 --- /dev/null +++ b/tests/new/privilegedAspects/pack/DefaultTarget.java @@ -0,0 +1,70 @@ + +package pack; + +import util.Util; + +/* copy/paste of PublicTarget with mods to default */ +class DefaultTarget { + public static int publicStaticInt = 1; + protected static int protectedStaticInt = 1; + static int defaultStaticInt = 1; + private static int privateStaticInt = 1; + public int publicInt = 1; + protected int protectedInt = 1; + int defaultInt = 1; + private int privateInt = 1; + public void publicMethod() { Util.signal(Util.defPublic); } + protected void protectedMethod() { Util.signal(Util.defProtected); } + void defaultMethod() { Util.signal(Util.defDefault); } + private void privateMethod() { Util.signal(Util.defPrivate); } + + public static void readDefaultTarget() { + int i = 0; + i += DefaultTarget.publicStaticInt; + i += DefaultTarget.protectedStaticInt; + i += DefaultTarget.defaultStaticInt; + i += DefaultTarget.privateStaticInt; + DefaultTarget defaultTarget = new DefaultTarget(); + i += defaultTarget.publicInt; + i += defaultTarget.protectedInt; + i += defaultTarget.defaultInt; + i += defaultTarget. privateInt; + defaultTarget.publicMethod(); + defaultTarget.protectedMethod(); + defaultTarget.defaultMethod(); + defaultTarget.privateMethod(); + } + + class DefaultInner { + public static final int publicStaticDefaultInnerInt = 1; + protected static final int protectedStaticDefaultInnerInt = 1; + /* def */ static final int defaultStaticDefaultInnerInt = 1; + private static final int privateStaticDefaultInnerInt = 1; + public int publicDefaultInnerInt = 1; + protected int protectedDefaultInnerInt = 1; + /* default */ int defaultDefaultInnerInt = 1; + private int privateDefaultInnerInt = 1; + public void publicDefaultInnerMethod() { Util.signal(Util.defInnerPublic); } + protected void protectedDefaultInnerMethod() { Util.signal(Util.defInnerProtected); } + /* default */ void defaultDefaultInnerMethod() { Util.signal(Util.defInnerDefault); } + private void privateDefaultInnerMethod() { Util.signal(Util.defInnerPrivate); } + + public void readDefaultInnerTarget() { + int i = 0; + i += DefaultTarget.DefaultInner.publicStaticDefaultInnerInt; + i += DefaultTarget.DefaultInner.protectedStaticDefaultInnerInt; + i += DefaultTarget.DefaultInner.defaultStaticDefaultInnerInt; + i += DefaultTarget.DefaultInner.privateStaticDefaultInnerInt; + DefaultTarget.DefaultInner defaultInnerTarget + = new DefaultTarget().new DefaultInner(); + i += defaultInnerTarget.publicDefaultInnerInt; + i += defaultInnerTarget.protectedDefaultInnerInt; + i += defaultInnerTarget.defaultDefaultInnerInt; + i += defaultInnerTarget.privateDefaultInnerInt; + defaultInnerTarget.publicDefaultInnerMethod(); + defaultInnerTarget.protectedDefaultInnerMethod(); + defaultInnerTarget.defaultDefaultInnerMethod(); + defaultInnerTarget.privateDefaultInnerMethod(); + } + } +} diff --git a/tests/new/privilegedAspects/pack/PublicTarget.java b/tests/new/privilegedAspects/pack/PublicTarget.java new file mode 100644 index 000000000..f32a5468a --- /dev/null +++ b/tests/new/privilegedAspects/pack/PublicTarget.java @@ -0,0 +1,69 @@ + +package pack; + +import util.Util; + +public class PublicTarget { + public static int publicStaticInt = 1; + protected static int protectedStaticInt = 1; + static int defaultStaticInt = 1; + private static int privateStaticInt = 1; + public int publicInt = 1; + protected int protectedInt = 1; + int defaultInt = 1; + private int privateInt = 1; + public void publicMethod() { Util.signal(Util.pubPublic); } + protected void protectedMethod() { Util.signal(Util.pubProtected); } + void defaultMethod() { Util.signal(Util.pubDefault); } + private void privateMethod() { Util.signal(Util.pubPrivate); } + + public static void readPublicTarget() { + int i = 0; + i += PublicTarget.publicStaticInt; + i += PublicTarget.protectedStaticInt; + i += PublicTarget.defaultStaticInt; + i += PublicTarget.privateStaticInt; + PublicTarget publicTarget = new PublicTarget(); + i += publicTarget.publicInt; + i += publicTarget.protectedInt; + i += publicTarget.defaultInt; + i += publicTarget. privateInt; + publicTarget.publicMethod(); + publicTarget.protectedMethod(); + publicTarget.defaultMethod(); + publicTarget.privateMethod(); + } + + public class PublicInner { + public static final int publicStaticPublicInnerInt = 1; + protected static final int protectedStaticPublicInnerInt = 1; + /* def */ static final int defaultStaticPublicInnerInt = 1; + private static final int privateStaticPublicInnerInt = 1; + public int publicPublicInnerInt = 1; + protected int protectedPublicInnerInt = 1; + /* default */ int defaultPublicInnerInt = 1; + private int privatePublicInnerInt = 1; + public void publicPublicInnerMethod() { Util.signal(Util.pubInnerPublic); } + protected void protectedPublicInnerMethod() { Util.signal(Util.pubInnerProtected); } + /* default */ void defaultPublicInnerMethod() { Util.signal(Util.pubInnerDefault); } + private void privatePublicInnerMethod() { Util.signal(Util.pubInnerPrivate); } + + public void readPublicInnerTarget() { + int i = 0; + i += PublicTarget.PublicInner.publicStaticPublicInnerInt; + i += PublicTarget.PublicInner.protectedStaticPublicInnerInt; + i += PublicTarget.PublicInner.defaultStaticPublicInnerInt; + i += PublicTarget.PublicInner.privateStaticPublicInnerInt; + PublicTarget.PublicInner publicInnerTarget + = new PublicTarget().new PublicInner(); + i += publicInnerTarget.publicPublicInnerInt; + i += publicInnerTarget.protectedPublicInnerInt; + i += publicInnerTarget.defaultPublicInnerInt; + i += publicInnerTarget. privatePublicInnerInt; + publicInnerTarget.publicPublicInnerMethod(); + publicInnerTarget.protectedPublicInnerMethod(); + publicInnerTarget.defaultPublicInnerMethod(); + publicInnerTarget.privatePublicInnerMethod(); + } + } +} diff --git a/tests/new/privilegedAspects/util/Util.java b/tests/new/privilegedAspects/util/Util.java new file mode 100644 index 000000000..7b9d70f22 --- /dev/null +++ b/tests/new/privilegedAspects/util/Util.java @@ -0,0 +1,35 @@ + +package util; + +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +public class Util { + public static boolean PRINT = false; + public static final String pubPublic = "PublicTarget.publicPublicMethod"; + public static final String pubProtected = "PublicTarget.protectedPublicMethod"; + public static final String pubDefault = "PublicTarget.defaultPublicMethod"; + public static final String pubPrivate = "PublicTarget.privatePublicMethod"; + public static final String pubInnerPublic = "PublicTarget.publicPublicInnerMethod"; + public static final String pubInnerProtected = "PublicTarget.protectedPublicInnerMethod"; + public static final String pubInnerDefault = "PublicTarget.defaultPublicInnerMethod"; + public static final String pubInnerPrivate = "PublicTarget.privatePublicInnerMethod"; + public static final String defPublic = "DefaultTarget.publicDefaultMethod"; + public static final String defProtected = "DefaultTarget.protectedDefaultMethod"; + public static final String defDefault = "DefaultTarget.defaultDefaultMethod"; + public static final String defPrivate = "DefaultTarget.privateDefaultMethod"; + public static final String defInnerPublic = "DefaultTarget.publicDefaultInnerMethod"; + public static final String defInnerProtected = "DefaultTarget.protectedDefaultInnerMethod"; + public static final String defInnerDefault = "DefaultTarget.defaultDefaultInnerMethod"; + public static final String defInnerPrivate = "DefaultTarget.privateDefaultInnerMethod"; + + /** signal some test event for later validation + * if PRINT, also outputs to System.err + */ + public static void signal(String s) { + if (PRINT) { + System.err.println(" Util.signal: " + s); + } + Tester.event(s); + } +} diff --git a/tests/new/protectedStatic/SubClass.java b/tests/new/protectedStatic/SubClass.java new file mode 100644 index 000000000..d2caf89eb --- /dev/null +++ b/tests/new/protectedStatic/SubClass.java @@ -0,0 +1,32 @@ +import pack.SuperClass; +import org.aspectj.testing.Tester; + +/** @testcase PR#585 PUREJAVA subclass unable to access protected static methods using type-qualified references */ +public class SubClass extends SuperClass { + private static int i; + static { + while (i<6) { + Tester.expectEvent(label() + SuperClass.SUPERCLASS); + } + i = 0; + } + static void register(Object o) { + Tester.event(""+o); + } + + public static String label() { return "label() " + i++; } + public static void main(String[] args) { + Object o = protectedStaticObject; + register(""+protectedStatic(label() + o)); + register(""+SuperClass.protectedStatic(label() + o)); + register(""+pack.SuperClass.protectedStatic(label() + o)); + new SubClass().run(); + Tester.checkAllEvents(); + } + public void run() { + Object o = protectedObject; + register(label() + protectedObject); + register(""+protectedMethod(label()+o)); + register(""+this.protectedMethod(label()+o)); + } +} diff --git a/tests/new/protectedStatic/pack/SuperClass.java b/tests/new/protectedStatic/pack/SuperClass.java new file mode 100644 index 000000000..ac301a3ee --- /dev/null +++ b/tests/new/protectedStatic/pack/SuperClass.java @@ -0,0 +1,19 @@ + +package pack; + +public class SuperClass { + public static final String SUPERCLASS = "SuperClass"; + private static String superClass() { return SUPERCLASS; } + + /** @testcase PR#585 subclass access to protected static field */ + protected static Object protectedStaticObject = superClass(); + /** @testcase PR#585 subclass access to protected static method */ + protected static Object protectedStatic(String s) { return s; } + + /** @testcase PR#585 subclass access to protected field */ + protected Object protectedObject = superClass(); + /** @testcase PR#585 subclass access to protected method */ + protected Object protectedMethod(String s) { return s; } + + public String toString() { return superClass(); } +} diff --git a/tests/new/runtime/AllRuntime.java b/tests/new/runtime/AllRuntime.java new file mode 100644 index 000000000..6d817699c --- /dev/null +++ b/tests/new/runtime/AllRuntime.java @@ -0,0 +1,489 @@ + +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +/** + * Run via main or driveTest. + * If you want the verbose output, + * use "-p{rint}" to print when invoking via main, + * or set resultCache with your result sink before running: + * <pre>StringBuffer sb = new StringBuffer(); + * AllRuntime.resultCache(sb); + * int errors = AllRuntime.driveTest(); + * System.err.println(sb.toString()); + * System.err.println("Errors: " + errors);</pre> + * <p> + * This was written to run in a 1.1 VM, + * outside the Tester or Collections or... + * + * @testcase PR#474 rt.java uses 1.2-only variant of Class.forName + */ +public class AllRuntime { + public static void resultCache(StringBuffer cache) { + A.resultCache(cache); + } + + public static void main(String[] args) { + StringBuffer result = null; + if ((null != args) && (0 < args.length) + && (args[0].startsWith("-p"))) { + result = new StringBuffer(); + resultCache(result); + } + int errors = driveTest(); + A.log("Errors: " + errors); + if (null != result) { + System.err.println(result.toString()); + } + } + + /** @return number of errors detected */ + public static int driveTest() { + int result = 0; + boolean ok = testNoAspectBoundException(); + if (!ok) result++; + A.log("testNoAspectBoundException: " + ok); + ok = testMultipleAspectsBoundException(); + if (!ok) result++; + A.log("testMultipleAspectsBoundException: " + ok); + + TargetClass me = new TargetClass(); + + ok = me.catchThrows(); + if (!ok) result++; + + int temp = me.publicIntMethod(2); + if (temp != 12) result++; + + StringBuffer sb = new StringBuffer(); + sb.append("" + me); // callee-side join point + if (sb.length() < 1) result++; + A.log("Callee-side join point " + sb.toString()); + + try { + ok = false; + me.throwException = true; + me.run(); + } catch (SoftException e) { + ok = true; + } + if (!ok) result++; + A.log("SoftException: " + ok); + A a = A.aspectOf(); + if (null != a) { + ok = a.report(); + if (!ok) result++; + A.log(" => all advice was run: " + ok); + } + return result; + } + + /** todo: need test case for multiple aspects */ + public static boolean testMultipleAspectsBoundException() { + return true; + } + + public static boolean testNoAspectBoundException() { + boolean result = false; + try { + B a = B.aspectOf(new Object()); + } catch (NoAspectBoundException e) { + result = true; + } + return result; + } +} + + +/** This has all relevant join points */ +class TargetClass { + private static int INDEX; + static { + INDEX = 10; + } + private int index = INDEX; + private int shadow = index; + + public int publicIntMethod(int input) { + return privateIntMethod(input); + } + + public boolean catchThrows() { + try { + throw new Exception("hello"); + } catch (Exception e) { + if (null != e) return true; + } + return false; + } + + /** print in VM-independent fashion */ + public String toString() { + return "TargetClass " + shadow; + } + + private int privateIntMethod(int input) { + return shadow = index += input; + } +} + +/** used only for NoAspectBoundException test */ +aspect B perthis(target(TargetClass)) { } + +aspect A { + /** log goes here if defined */ + private static StringBuffer CACHE; + /** count number of join points hit */ + private static int jpIndex = 0; + /** count number of A created */ + private static int INDEX = 0; + /** index of this A */ + private int index; + /** count for each advice of how many times invoked */ + private final int[] adviceHits; + A() { + index = INDEX++; + adviceHits = new int[21]; + } + + public static void resultCache(StringBuffer cache) { + if (CACHE != cache) CACHE = cache; + } + + public static void log(String s) { + StringBuffer cache = CACHE; + if (null != cache) { + cache.append(s); + cache.append("\n"); + } + } + + private void log(int i) { adviceHits[i]++; } + + /** report how many times each advice was run + * logging report. + * @return false if any advice was not hit + */ + public boolean report() { + StringBuffer sb = new StringBuffer(); + boolean result = report(this, sb); + log(sb.toString()); + return result; + } + + /** report how many times each advice was run + * @return false if any advice was not hit + */ + public static boolean report(A a, StringBuffer sb) { + boolean result = true; + if (null == a.adviceHits) { + sb.append("[]"); + } else { + sb.append("["); + int[] adviceHits = a.adviceHits; + for (int i = 0; i < adviceHits.length; i++) { + if (i > 0) sb.append(", "); + sb.append(i+"="+adviceHits[i]); + if (result && (0 == adviceHits[i])) { + result = false; + } + } + sb.append("]"); + } + return result; + } + + public static void throwsException() throws Exception { + throw new Exception("exception"); + } + public String toString() { return "A " + index; } + + //-------------------------------------- pointcuts + pointcut safety() + : !within(A) + && !cflow(execution(String TargetClass.toString())) + && !call(String TargetClass.toString()) + ; + pointcut intMethod() : call(int TargetClass.publicIntMethod(int)); + + + //-------------------------------------- declare, introductions + declare parents : TargetClass implements Runnable; + declare soft : Exception : execution(void TargetClass.run()); + + /** unused - enable to throw exception from run() */ + public boolean TargetClass.throwException; + public void TargetClass.run() { + if (throwException) throwsException(); + } + + //-------------------------------------- advice + /** callee-side call join point */ // todo: not being invoked, though TargetClass.toString is??? + before() : call(public String toString()) + && target(TargetClass) { + /* comment out test to avoid StackOverflow + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : call(String TargetClass.toString())"); + */ + log(1); + } + + /** caller-side call join point */ + before() : call(int TargetClass.privateIntMethod(int)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : call(int TargetClass.privateIntMethod()) "); + log(2); + } + /** call join point */ + before() : intMethod() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : pc() "); + log(3); + } + + /** execution join point */ + before() : execution(int TargetClass.privateIntMethod(int)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : execution(int TargetClass.privateIntMethod()) "); + log(4); + } + + /** execution join point for constructor */ + before() : execution(TargetClass.new(..)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : execution(TargetClass.new(..)) "); + log(5); + } + + /** initialization join point */ + before() : initialization(TargetClass+.new(..)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : initialization(TargetClass+.new(..)) "); + log(6); + } + + /** static initialization join point */ + before() : initialization(TargetClass+.new(..)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : initialization(TargetClass+.new(..)) "); + log(7); + } + + /** cflow join point */ + before() : cflow(execution(int TargetClass.publicIntMethod(int))) + && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : cflow(execution(int TargetClass.publicIntMethod(int)))"); + log(8); + } + + /** cflowbelow join point */ + before() : cflowbelow(execution(int TargetClass.publicIntMethod(int))) + && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : cflowbelow(execution(int TargetClass.publicIntMethod(int)))"); + log(9); + } + + /** initialization join point */ + before() : initialization(TargetClass+.new(..)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : initialization(TargetClass+.new(..)) "); + log(10); + } + + /** field set join point */ + before() : set(int TargetClass.index) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : set(int TargetClass.index) "); + log(11); + } + + /** field get join point */ + before() : get(int TargetClass.index) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : get(int TargetClass.index) "); + log(12); + } + + /** within join point (static) */ + before() : within(TargetClass+) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : within(TargetClass+) "); + log(13); + } + + /** withincode join point (static) */ + before() : withincode(int TargetClass+.publicIntMethod(int)) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : withincode(int TargetClass+.publicIntMethod(int)) "); + log(14); + } + + /** this join point */ + before(TargetClass t) : this(t) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before(TargetClass t) : this(t) && safety() This t: " + t + " this: " + this); + log(15); + } + + /** target join point */ + before(TargetClass t) : target(t) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before(TargetClass t) : target(t) && safety() target t: " + t + " this: " + this); + log(16); + } + + /** args join point */ + before(int i) : args(i) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before(int i) : args(i) && safety() args i: " + i); + log(17); + } + + /** handler join point */ + before() : handler(Exception) { // && args(e) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before(Throwable e) : handler(Throwable) && args(e) && within(TargetClass+) args e: " ); + log(18); + } + + /** if pcd join point */ + before(int i) : args(i) && if(i > 0) && safety() { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before(int i) : args(i) && if(i > 0) && safety() args i: " + i); + log(19); + } + + /** call join point for constructor */ + before() : call(TargetClass.new(..)) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "before() : call(TargetClass.new(..)) "); + log(20); + } + + /** everything join point */ + before(TargetClass t) + : (target(t) ) + && (call(int TargetClass.privateIntMethod(int)) + || execution(int TargetClass.privateIntMethod(int)) + || initialization(TargetClass.new()) + || (cflow(call(int TargetClass.privateIntMethod(int))) + && !cflowbelow(call(int TargetClass.privateIntMethod(int)))) + ) + && (!cflow(call(void TargetClass.catchThrows()))) + && (!call(void TargetClass.run())) + && (!set(int TargetClass.index)) + && (!get(int TargetClass.index)) + && safety() + && if(null != t) { + test(thisJoinPoint, thisJoinPointStaticPart, this, + "everything"); // todo: add args + log(0); + } + + private void test(JoinPoint jp, JoinPoint.StaticPart jpsp, Object tis, + String context) { + StringBuffer sb = new StringBuffer(); + sb.append("\n join pt: " + jpIndex++); + sb.append("\n jp: " + jp); + render(jp, sb); + sb.append("\n jpsp: " + jpsp); + sb.append("\n tis: " + tis); + sb.append("\n this: " + this); + sb.append("\n context: " + context); + log(sb.toString()); + } + + private void render(JoinPoint jp, StringBuffer sb) { + if (null == jp) { + sb.append("null"); + } else { + //sb.append("\n args: " + jp.getArgs()); + sb.append("\n args: "); + render(jp.getArgs(), sb); + sb.append("\n kind: " + jp.getKind()); + sb.append("\n sig: " ); + render(jp.getSignature(), sb); + sb.append("\n loc: " ); + render(jp.getSourceLocation(), sb); + sb.append("\n targ: " + jp.getTarget()); + sb.append("\n this: " + jp.getThis()); + } + } + + /** render to check subtype of Signature, print in VM-independent fashion */ + private void render(Signature sig, StringBuffer sb) { + if (null == sig) { + sb.append("null"); + } else { + if (sig instanceof AdviceSignature) { + sb.append("AdviceSignature "); + sb.append(sig.getName() + " " ); + sb.append(""+((AdviceSignature ) sig).getReturnType()); + } else if (sig instanceof CatchClauseSignature) { + sb.append("CatchClauseSignature "); + sb.append(sig.getName() + " " ); + sb.append(""+((CatchClauseSignature ) sig).getParameterType()); + } else if (sig instanceof ConstructorSignature) { + sb.append("ConstructorSignature "); + sb.append(sig.getName() + " " ); + sb.append(""+((ConstructorSignature) sig).getName()); + } else if (sig instanceof FieldSignature) { + sb.append("FieldSignature "); + sb.append(sig.getName() + " " ); + sb.append(""+((FieldSignature ) sig).getFieldType()); + } else if (sig instanceof InitializerSignature) { + sb.append("InitializerSignature "); + sb.append(sig.getName() + " " ); + } else if (sig instanceof MethodSignature) { + sb.append("MethodSignature "); + sb.append(sig.getName() + " " ); + sb.append(""+((MethodSignature) sig).getReturnType()); + } else if (sig instanceof MemberSignature) { + sb.append("MemberSignature?? "); + sb.append(sig.getName() + " " ); + } else if (sig instanceof CodeSignature) { + sb.append("CodeSignature ??"); + sb.append(sig.getName() + " " ); + } else { + sb.append("Unknown ??"); + sb.append(sig.getName() + " " ); + } + } + } + private void render(SourceLocation sl, StringBuffer sb) { + if (null == sl) { + sb.append("null"); + } else { + String path = sl.getFileName(); + int loc = path.lastIndexOf("/"); + if (-1 != loc) { + path = path.substring(loc+1); + } else { + // todo: not portable to other machines + loc = path.lastIndexOf("\\"); + if (-1 != loc) { + path = path.substring(loc+1); + } + } + sb.append(path); + sb.append(":" + sl.getLine()); + sb.append(":" + sl.getColumn()); + } + } + + private void render(Object[] args, StringBuffer sb) { + if (null == args) { + sb.append("null"); + } else { + sb.append("Object[" + args.length + "] = {"); + for (int i = 0; i < args.length; i++) { + if (i > 0) sb.append(", "); + sb.append("" + args[i]); + } + sb.append("}"); + } + } +} + diff --git a/tests/new/runtime/TesterDriver.java b/tests/new/runtime/TesterDriver.java new file mode 100644 index 000000000..56b1349eb --- /dev/null +++ b/tests/new/runtime/TesterDriver.java @@ -0,0 +1,15 @@ + +import org.aspectj.testing.Tester; + +/** Drive AllRuntime in a tester environment */ +public class TesterDriver { + public static void main(String[] args) { + StringBuffer sb = new StringBuffer(); + AllRuntime.resultCache(sb); + int errors = AllRuntime.driveTest(); + if (0 != errors) { + Tester.check(0 == errors, "AllRuntime errors: " + errors); + System.err.println(sb.toString()); + } + } +} diff --git a/tests/new/scopeTypingBug/Driver.java b/tests/new/scopeTypingBug/Driver.java new file mode 100644 index 000000000..845789b09 --- /dev/null +++ b/tests/new/scopeTypingBug/Driver.java @@ -0,0 +1,16 @@ + +import org.aspectj.testing.Tester; + +public class Driver { + private static java.util.Vector v = new java.util.Vector(); + + public static void main(String[] args) { test(); } + + public static void test() { + v.addElement("foo"); + boolean containsFoo = v.contains("foo"); + Object v = new Object(); + + Tester.check(containsFoo, "Vector contains element added"); + } +} diff --git a/tests/new/staticMethAdv/Driver.java b/tests/new/staticMethAdv/Driver.java new file mode 100644 index 000000000..9946c0f07 --- /dev/null +++ b/tests/new/staticMethAdv/Driver.java @@ -0,0 +1,29 @@ + +import org.aspectj.testing.Tester; + +// PR#151 + +public class Driver { + public static void main(String[] args) { test(); } + public static void test() { + Tester.checkEqual(C.set(), "C-advised-set", ""); + } + + static advice(C c): c && * *(..) { + before { + if (c != null) + Tester.check(false, "c == null"); + else + c.s += "-advised"; + } + } +} + +class C { + static String s = "C"; + + static String set() { + s += "-set"; + return s; + } +} diff --git a/tests/new/subaspects/AbstractAspectUsedStatically.java b/tests/new/subaspects/AbstractAspectUsedStatically.java new file mode 100644 index 000000000..272e9279b --- /dev/null +++ b/tests/new/subaspects/AbstractAspectUsedStatically.java @@ -0,0 +1,20 @@ + +import org.aspectj.testing.*; + +/** @testcase PR#647 abstract aspect used statically should not cause instantiation of advice or pointcut */ +public abstract aspect AbstractAspectUsedStatically { + public static void main (String[] args) { + Tester.event("main"); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("main"); + } + + before() : definePrivate() { + Tester.check(false, "definePrivate"); + } + + /** private must be implemented in defining class */ + private pointcut definePrivate() : execution(void main(..)); +} diff --git a/tests/new/subaspects/PrivatePointcutCE.java b/tests/new/subaspects/PrivatePointcutCE.java new file mode 100644 index 000000000..283dded32 --- /dev/null +++ b/tests/new/subaspects/PrivatePointcutCE.java @@ -0,0 +1,6 @@ + +/** @testcase PR#647 aspect with private abstract pointcut */ +abstract aspect PrivatePointcutCE { + /** @testcase abstract private pointcut */ + abstract private pointcut defined(); // CE expected here +} diff --git a/tests/new/subaspects/child/ChildCE.java b/tests/new/subaspects/child/ChildCE.java new file mode 100644 index 000000000..4a0b8377c --- /dev/null +++ b/tests/new/subaspects/child/ChildCE.java @@ -0,0 +1,31 @@ + + +package child; + +import parent.ParentCE; + +import org.aspectj.testing.*; + +public class ChildCE { + public static void main (String[] args) { + new Target().run(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("define"); + Tester.expectEvent("run"); + } +} + +class Target { + public void run(){ + Tester.event("run"); + } +} + +/** @testcase PR#647 concrete aspect unable to access abstract package-private pointcut in parent for overriding */ +aspect ParentChild extends ParentCE {// expect CE here: child does not define "define()" b/c inaccessible + protected pointcut define() + : call(public void Target.run()); +} + diff --git a/tests/new/subaspects/child/ChildMethodCE.java b/tests/new/subaspects/child/ChildMethodCE.java new file mode 100644 index 000000000..61bbb8024 --- /dev/null +++ b/tests/new/subaspects/child/ChildMethodCE.java @@ -0,0 +1,30 @@ + + +package child; + +import parent.ParentMethodCE; + +import org.aspectj.testing.*; + +public class ChildMethodCE { + public static void main (String[] args) { + new Target().run(); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("define"); + Tester.expectEvent("run"); + } +} + +class Target { + public void run(){ + Tester.event("run"); + } +} + +/** @testcase PR#647 attempt to concretize abstract aspect without access to abstract member method */ +class ParentChild extends ParentMethodCE { // expect CE here: child does not define "defineMethod()" b/c inaccessible + protected void defineMethod() {} +} + diff --git a/tests/new/subaspects/child/ForeignChildAspect.java b/tests/new/subaspects/child/ForeignChildAspect.java new file mode 100644 index 000000000..4c65a01ff --- /dev/null +++ b/tests/new/subaspects/child/ForeignChildAspect.java @@ -0,0 +1,29 @@ + +package child; + +import parent.SubAspectVisibility; +import parent.ForeignChildHelper; + +import org.aspectj.testing.*; + +/** @testcase PR#647 inner, outer, and outside-package subaspects of an aspect with abstract protected-, public-, and default-access pointcuts */ +public aspect ForeignChildAspect extends ForeignChildHelper { + public static void main (String[] args) { + Tester.event("ForeignChildAspect.main"); + } + + before() : defineProtected() { + Tester.event("ForeignChildAspect.defineProtected"); + } + + before() : definePublic() { + Tester.event("ForeignChildAspect.definePublic"); + } + + /** can be implemented */ + public pointcut definePublic() : execution(void ForeignChildAspect.main(..)); + + /** can be implemented */ + protected pointcut defineProtected() : execution(void ForeignChildAspect.main(..)); + +} diff --git a/tests/new/subaspects/parent/ForeignChildHelper.java b/tests/new/subaspects/parent/ForeignChildHelper.java new file mode 100644 index 000000000..31b929eb1 --- /dev/null +++ b/tests/new/subaspects/parent/ForeignChildHelper.java @@ -0,0 +1,16 @@ + +package parent; + +import child.ForeignChildAspect; +import parent.SubAspectVisibility; + +import org.aspectj.testing.*; + +/** @testcase PR#647 inner, outer, and outside-package subaspects of an aspect with abstract protected-, public-, and default-access pointcuts */ +public abstract aspect ForeignChildHelper extends SubAspectVisibility { + /** @testCase override package-private pointcut in outer class */ + pointcut definePackagePrivate() : execution(void ForeignChildAspect.main(..)); + before() : definePackagePrivate() { + Tester.event("ForeignChildHelper.definePackagePrivate"); + } +} diff --git a/tests/new/subaspects/parent/ParentCE.java b/tests/new/subaspects/parent/ParentCE.java new file mode 100644 index 000000000..a28dd83d7 --- /dev/null +++ b/tests/new/subaspects/parent/ParentCE.java @@ -0,0 +1,15 @@ + +package parent; + +import org.aspectj.testing.*; + +/** @testcase PR#647 concrete aspect unable to access abstract package-private pointcut in parent for overriding */ +public abstract aspect ParentCE { + abstract pointcut define(); + before() : define() { + Tester.event("define"); + } +} +aspect Child extends ParentCE { + pointcut define() : call(public void Target.run()); +} diff --git a/tests/new/subaspects/parent/ParentMethodCE.java b/tests/new/subaspects/parent/ParentMethodCE.java new file mode 100644 index 000000000..0f25fe2d5 --- /dev/null +++ b/tests/new/subaspects/parent/ParentMethodCE.java @@ -0,0 +1,10 @@ + +package parent; + +import org.aspectj.testing.*; + +/** @testcase PR#647 concrete aspect unable to access abstract package-private method in parent for overriding */ +public abstract class ParentMethodCE { + /** cannot be implemented outside this class */ + abstract void defineMethod(); +} diff --git a/tests/new/subaspects/parent/PrivatePointcut.java b/tests/new/subaspects/parent/PrivatePointcut.java new file mode 100644 index 000000000..1c09fb040 --- /dev/null +++ b/tests/new/subaspects/parent/PrivatePointcut.java @@ -0,0 +1,26 @@ + +package parent; + +import org.aspectj.testing.*; + +/** @testcase PR#647 inner subaspects of an aspect with private pointcut */ +public abstract aspect PrivatePointcut { + public static void main (String[] args) { + Tester.event("main"); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("main"); + Tester.expectEvent("definePrivate"); + } + + before() : definePrivate() { + Tester.event("definePrivate"); + } + + /** private must be implemented in defining class */ + private pointcut definePrivate() : execution(void PrivatePointcut.main(..)); +} +aspect InnerChild extends PrivatePointcut { +} + diff --git a/tests/new/subaspects/parent/PrivatePointcutOuterClass.java b/tests/new/subaspects/parent/PrivatePointcutOuterClass.java new file mode 100644 index 000000000..7ae3752c0 --- /dev/null +++ b/tests/new/subaspects/parent/PrivatePointcutOuterClass.java @@ -0,0 +1,26 @@ + +package parent; + +import org.aspectj.testing.*; + +/** PR#647 outer subaspects of an aspect with private pointcut */ +public abstract aspect PrivatePointcutOuterClass { + public static void main (String[] args) { + Tester.event("main"); + Tester.checkAllEvents(); + } + static { + Tester.expectEvent("main"); + Tester.expectEvent("definePrivate"); + } + + before() : definePrivate() { + Tester.event("definePrivate"); + } + + /** private must be implemented in defining class */ + private pointcut definePrivate() + : execution(void PrivatePointcutOuterClass.main(..)); +} +aspect InnerChild extends PrivatePointcutOuterClass { } + diff --git a/tests/new/subaspects/parent/SubAspectVisibility.java b/tests/new/subaspects/parent/SubAspectVisibility.java new file mode 100644 index 000000000..e7af8c345 --- /dev/null +++ b/tests/new/subaspects/parent/SubAspectVisibility.java @@ -0,0 +1,95 @@ + +package parent; + +import child.ForeignChildAspect; + +import org.aspectj.testing.*; + +/** @testcase PR#647 inner, outer, and outside-package subaspects of an aspect with abstract protected-, public-, and default-access pointcuts */ +public abstract aspect SubAspectVisibility { + public static void main (String[] args) { + Tester.event("main"); + OuterChild.main(args); + ForeignChildAspect.main(args); + Tester.checkAllEventsIgnoreDups(); + } + static { + Tester.expectEvent("main"); + Tester.expectEvent("definePrivate"); + Tester.expectEvent("definePackagePrivate"); + Tester.expectEvent("defineProtected"); + Tester.expectEvent("definePublic"); + + Tester.expectEvent("Outer.main"); + Tester.expectEvent("Outer.definePackagePrivate"); + Tester.expectEvent("Outer.defineProtected"); + Tester.expectEvent("Outer.definePublic"); + + Tester.expectEvent("ForeignChildAspect.main"); + Tester.expectEvent("ForeignChildHelper.definePackagePrivate"); + Tester.expectEvent("ForeignChildAspect.defineProtected"); + Tester.expectEvent("ForeignChildAspect.definePublic"); + } + + before() : definePrivate() { + Tester.event("definePrivate"); + } + + before() : definePackagePrivate() { + Tester.event("definePackagePrivate"); + } + + before() : defineProtected() { + Tester.event("defineProtected"); + } + + before() : definePublic() { + Tester.event("definePublic"); + } + + /** public can be implemented in outer or inner child class */ + abstract public pointcut definePublic(); + + /** protected can be can be implemented in outer or inner child class */ + abstract protected pointcut defineProtected(); + + /** package-private can be can be implemented in outer or inner child class */ + abstract pointcut definePackagePrivate(); + + /** private must be implemented in defining class */ + private pointcut definePrivate() : execution(void SubAspectVisibility.main(..)); + + // bug? says definePrivate() is not defined in InnerChild + static aspect InnerChild extends SubAspectVisibility { + /** @testCase override protected pointcut in inner class */ + protected pointcut defineProtected() : execution(void SubAspectVisibility.main(..)); + /** @testCase override package-private pointcut in inner class */ + pointcut definePackagePrivate() : execution(void SubAspectVisibility.main(..)); + /** @testCase override public pointcut in inner class */ + public pointcut definePublic() : execution(void SubAspectVisibility.main(..)); + } +} + +aspect OuterChild extends SubAspectVisibility { + public static void main (String[] args) { + Tester.event("Outer.main"); + } + + /** @testCase override package-private pointcut in outer class */ + pointcut definePackagePrivate() : execution(void OuterChild.main(..)); + /** @testCase override protected pointcut in outer class */ + protected pointcut defineProtected() : execution(void OuterChild.main(..)); + /** @testCase override public pointcut in outer class */ + public pointcut definePublic() : execution(void OuterChild.main(..)); + + before() : definePackagePrivate() { + Tester.event("Outer.definePackagePrivate"); + } + before() : defineProtected() { + Tester.event("Outer.defineProtected"); + } + before() : definePublic() { + Tester.event("Outer.definePublic"); + } +} + diff --git a/tests/new/test/Test.java b/tests/new/test/Test.java new file mode 100644 index 000000000..efe358e26 --- /dev/null +++ b/tests/new/test/Test.java @@ -0,0 +1,16 @@ +package test; + +import org.aspectj.testing.*; + +public class Test { + public static void main(String[] args) { + new Test().run(); + Tester.checkAllEvents(); + } + public void run() { + Tester.event("run"); + } + static { + Tester.expectEventsInString("before,after,run"); + } +} diff --git a/tests/new/test/TraceAspect.java b/tests/new/test/TraceAspect.java new file mode 100644 index 000000000..d79c1d69c --- /dev/null +++ b/tests/new/test/TraceAspect.java @@ -0,0 +1,15 @@ +package test; + +import org.aspectj.testing.*; + +aspect Trace pertarget(target(test.Test)) { + + pointcut runs(): call(void run()); + + before(): runs() { + Tester.event("before"); + } + after(): runs() { + Tester.event("after"); + } +} diff --git a/tests/new/testPackage/Class1.java b/tests/new/testPackage/Class1.java new file mode 100644 index 000000000..d53733d34 --- /dev/null +++ b/tests/new/testPackage/Class1.java @@ -0,0 +1,11 @@ +package packagevisibility.testPackage; + +public class Class1 { + public String doIt(String s) { + return s + "-class1"; + } + + public String doItToClass2(String s) { + return (new packagevisibility.testPackage.Class2()).doIt(s); + } +} diff --git a/tests/new/testPackage/Class2.java b/tests/new/testPackage/Class2.java new file mode 100644 index 000000000..697a8c86e --- /dev/null +++ b/tests/new/testPackage/Class2.java @@ -0,0 +1,7 @@ +package packagevisibility.testPackage; + +class Class2 { + String doIt(String s) { + return s + "-class2"; + } +} diff --git a/tests/new/testPackage/Import.java b/tests/new/testPackage/Import.java new file mode 100644 index 000000000..b546ad89f --- /dev/null +++ b/tests/new/testPackage/Import.java @@ -0,0 +1,9 @@ +package testPackage; + +import testPackage.subPackage.Class1; + +public class Import extends Class1 { + public static void main( String[] args ) { + print( "here" ); + } +} diff --git a/tests/new/testPackage/subPackage/Class1.java b/tests/new/testPackage/subPackage/Class1.java new file mode 100644 index 000000000..432285125 --- /dev/null +++ b/tests/new/testPackage/subPackage/Class1.java @@ -0,0 +1,7 @@ +package testPackage.subPackage; + +public class Class1 { + static public void print( String s ) { + System.out.println( ">> " + s ); + } +} diff --git a/tests/new/thisUsedInMain/Driver.java b/tests/new/thisUsedInMain/Driver.java new file mode 100644 index 000000000..efb7cc338 --- /dev/null +++ b/tests/new/thisUsedInMain/Driver.java @@ -0,0 +1,24 @@ +import org.aspectj.testing.Tester; + +// PR#262 + +import org.aspectj.testing.Tester; + +public aspect Driver /*of eachobject(instanceof(CallsTo))*/ { + + public static void test() { main(null); } + + public static void main(String[] args) { + CallsTo ct = new CallsTo(); + Tester.checkEqual(ct.a(), "s", "after calls"); + } + + pointcut call1(): call(* CallsFrom.b(..)) && within(CallsTo); + before(): call1() { + //System.out.println("before-call1"); + } +} + +class CallsTo { public String a() { return new CallsFrom().b("s"); } } + +class CallsFrom { public String b(String s) { return s; } } diff --git a/tests/new/twofiles/TheAspect.java b/tests/new/twofiles/TheAspect.java new file mode 100644 index 000000000..72416eab9 --- /dev/null +++ b/tests/new/twofiles/TheAspect.java @@ -0,0 +1,3 @@ +privileged aspect TheAspect pertarget(target(TheObject)) { + +} diff --git a/tests/new/twofiles/TheObject.java b/tests/new/twofiles/TheObject.java new file mode 100644 index 000000000..378841dd4 --- /dev/null +++ b/tests/new/twofiles/TheObject.java @@ -0,0 +1,6 @@ +import org.aspectj.testing.Tester; +public class TheObject { + public static void main(String[] args) { + Tester.check(true, "compiled!"); + } +} diff --git a/tests/new/typeNameConflicts/Driver.java b/tests/new/typeNameConflicts/Driver.java new file mode 100644 index 000000000..95e403cb9 --- /dev/null +++ b/tests/new/typeNameConflicts/Driver.java @@ -0,0 +1,30 @@ +package typeNameConflicts; + +public class Driver { + static int x; + + public Entry getEntry() { + return new Integer(); + } + + public static void main(String[] args) { + x = 2; + Runnable r = new Runnable() { public void run() { System.out.println("running"); } }; + r.run(); + + //java.lang.Integer i = new java.lang.Integer(2); + } + + abstract class Entry { + } + + class Integer extends Entry { + int value; + + public void m() { + value = 3; + //java.lang.Integer i = new java.lang.Integer(2); + } + } +} + diff --git a/tests/new/typeNameConflicts/aspects/A.java b/tests/new/typeNameConflicts/aspects/A.java new file mode 100644 index 000000000..a00046cce --- /dev/null +++ b/tests/new/typeNameConflicts/aspects/A.java @@ -0,0 +1,27 @@ +package typeNameConflicts.aspects; + +aspect A { + /* + before(): set(int value) { //&& args(o) { + System.out.println(thisJoinPointStaticPart); + } + */ + + after() returning(Object o): set(int value) { + System.out.println(o); + } + + + before(): call(void Runnable.run()) { + System.out.println("about to run"); + } + + /* + after(): set(int value) { + System.out.println("set"); + } + after() throwing: set(int value) { + System.out.println("throwing"); + } + */ +} diff --git a/tests/new/typeNameConflicts/p1/C.java b/tests/new/typeNameConflicts/p1/C.java new file mode 100644 index 000000000..6928b2e81 --- /dev/null +++ b/tests/new/typeNameConflicts/p1/C.java @@ -0,0 +1,11 @@ +package typeNameConflicts.p1; + +public class C { + static class Inner { + public Runnable makeRunnable() { + return new Runnable() { + public void run() { System.out.println("running"); } + }; + } + } +} diff --git a/tests/new/typepatternmatch/pack1/IntroErrorLocation.java b/tests/new/typepatternmatch/pack1/IntroErrorLocation.java new file mode 100644 index 000000000..3b5b397db --- /dev/null +++ b/tests/new/typepatternmatch/pack1/IntroErrorLocation.java @@ -0,0 +1,41 @@ + +package typepatternmatch.pack1; +import org.aspectj.testing.Tester; +import org.aspectj.testing.Tester; + +/** + * FYI the compiler will not warn when a TypePattern matches no type/class. + * From an email to user from Stefan + */ +public class IntroErrorLocation { + /** change to true if the compiler ever should weave in by finding type? */ + public static volatile boolean EXPECT_INIT = false; + /** signifies that the initialization advice was run */ + public static final String INIT_SIGNAL = "init"; + static { + if (EXPECT_INIT) Tester.event(INIT_SIGNAL); + } + public static void main(String[] args) { + typepatternmatch.pack2.TargetClass target + = new typepatternmatch.pack2.TargetClass(); + Tester.checkAllEvents(); + } +} + +aspect MyIntroductionAspect { + + /** @testTarget typepattern.nonmatching.introduction.method */ + public String TargetClass.introMethod(String s) { // fails to match typepattern in other package + return s; + } + /** @testTarget signature.nonmatching.advice.initialization */ + after (typepatternmatch.pack2.TargetClass c) + : initialization(TargetClass.new()) && this(c) { // fails to match signature in other package + final String test = IntroErrorLocation.INIT_SIGNAL; + if (IntroErrorLocation.EXPECT_INIT) { + //Tester.event(c.introMethod(test)); // todo add positive: passed + } + // compiler error here is correct: no such method; no introMethod b/c TargetClass not matched + Tester.checkEqual(test, c.introMethod(test), "Round trip failed"); // correct compiler error + } +} diff --git a/tests/new/typepatternmatch/pack2/TargetClass.java b/tests/new/typepatternmatch/pack2/TargetClass.java new file mode 100644 index 000000000..afb567423 --- /dev/null +++ b/tests/new/typepatternmatch/pack2/TargetClass.java @@ -0,0 +1,8 @@ + +package typepatternmatch.pack2; + +/** + */ +// PR#TODO +public class TargetClass { +} diff --git a/tests/new/unqualifiedPointcutName/Driver.java b/tests/new/unqualifiedPointcutName/Driver.java new file mode 100644 index 000000000..1989cbcdb --- /dev/null +++ b/tests/new/unqualifiedPointcutName/Driver.java @@ -0,0 +1,40 @@ + +import org.aspectj.testing.Tester; + +import java.util.*; + +// PR#304 lookup rules for unqualified pointcut names + + +public class Driver { + + public static String s = ""; + + public static void main(String[] args){ + new MyObject().go(); + Tester.checkEqual(s, "-before-new", ""); + } + +} + +aspect MyPointCuts { + pointcut excludes(): + (call(* equals(..))) || + (call(* toString(..))) || + (call(* hashCode(..))) || + (call(* clone(..))) + ; + pointcut allCalls(): call(* *(..)) && !excludes(); +} + +aspect MyAspect /*of eachobject(instanceof(MyObject))*/ { + before(): MyPointCuts.allCalls() && target(MyObject) { + Driver.s += "-before"; + } +} + +class MyObject { + public void go() { + Driver.s += "-new"; + } +} diff --git a/tests/new/volatileKeyword/Driver.java b/tests/new/volatileKeyword/Driver.java new file mode 100644 index 000000000..acac776d1 --- /dev/null +++ b/tests/new/volatileKeyword/Driver.java @@ -0,0 +1,15 @@ + +import org.aspectj.testing.Tester; + +public class Driver { + volatile static boolean completed = true; + public static void main(String[] args) { test(); } + public static void test() { + Tester.check(completed, "static volatile filed"); + Tester.check(new C().completed, "instance of volatile filed"); + } +} + +class C { + volatile boolean completed = true; +}
\ No newline at end of file |