Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

21 роки тому
21 роки тому
21 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. */
  10. package tjp;
  11. import org.aspectj.lang.JoinPoint;
  12. import org.aspectj.lang.reflect.CodeSignature;
  13. aspect GetInfo {
  14. static final void println(String s){ System.out.println(s); }
  15. pointcut goCut(): cflow(this(Demo) && execution(void go()));
  16. pointcut demoExecs(): within(Demo) && execution(* *(..));
  17. Object around(): demoExecs() && !execution(* go()) && goCut() {
  18. println("Intercepted message: " +
  19. thisJoinPointStaticPart.getSignature().getName());
  20. println("in class: " +
  21. thisJoinPointStaticPart.getSignature().getDeclaringType().getName());
  22. printParameters(thisJoinPoint);
  23. println("Running original method: \n" );
  24. Object result = proceed();
  25. println(" result: " + result );
  26. return result;
  27. }
  28. static private void printParameters(JoinPoint jp) {
  29. println("Arguments: " );
  30. Object[] args = jp.getArgs();
  31. String[] names = ((CodeSignature)jp.getSignature()).getParameterNames();
  32. Class[] types = ((CodeSignature)jp.getSignature()).getParameterTypes();
  33. for (int i = 0; i < args.length; i++) {
  34. println(" " + i + ". " + names[i] +
  35. " : " + types[i].getName() +
  36. " = " + args[i]);
  37. }
  38. }
  39. }