You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NewSiteAdvice.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import org.aspectj.testing.Tester;
  2. import java.rmi.*;
  3. import java.rmi.server.UnicastRemoteObject;
  4. public class NewSiteAdvice {
  5. public static void main(String[] args) { test(); }
  6. NewSiteAdvice() throws RemoteException { }
  7. /* here's another comment */
  8. public static void test() {
  9. Tester.checkEqual(new NewSiteAdvice().go(), "ran", "rmi exception intercepted");
  10. Tester.check(new Integer(42) == A.cached42, "caching new 42");
  11. Tester.check("around NewSiteAdvice");
  12. }
  13. /** this is the way to make things go **/
  14. String go() {
  15. return "ran"; // and an eol commment
  16. }
  17. }
  18. aspect A {
  19. pointcut makeNewSiteAdvice():
  20. within(NewSiteAdvice) && call(NewSiteAdvice.new());
  21. declare soft: RemoteException: makeNewSiteAdvice();
  22. NewSiteAdvice around(): makeNewSiteAdvice() {
  23. NewSiteAdvice result = null;
  24. try {
  25. result = proceed();
  26. } catch (RemoteException e){
  27. }
  28. Tester.note("around NewSiteAdvice");
  29. return result;
  30. }
  31. Integer around(int i):
  32. args(i) && call(Integer.new(int)) && !within(A) {
  33. if (i == 42) return cached42;
  34. return proceed(i);
  35. }
  36. static Integer cached42 = new Integer(42);
  37. }