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.

TraceMyClasses.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 tracing.version1;
  11. /**
  12. *
  13. * This class connects the tracing functions in the Trace class with
  14. * the constructors and methods in the application classes.
  15. *
  16. */
  17. import tracing.TwoDShape;
  18. import tracing.Circle;
  19. import tracing.Square;
  20. import tracing.ExampleMain;
  21. aspect TraceMyClasses {
  22. /**
  23. * Application classes.
  24. */
  25. pointcut myClass(): within(TwoDShape) || within(Circle) || within(Square);
  26. /**
  27. * The constructors in those classes.
  28. */
  29. pointcut myConstructor(): myClass() && execution(new(..));
  30. /**
  31. * The methods of those classes.
  32. */
  33. pointcut myMethod(): myClass() && execution(* *(..));
  34. /**
  35. * Prints trace messages before and after executing constructors.
  36. */
  37. before (): myConstructor() {
  38. Trace.traceEntry("" + thisJoinPointStaticPart.getSignature());
  39. }
  40. after(): myConstructor() {
  41. Trace.traceExit("" + thisJoinPointStaticPart.getSignature());
  42. }
  43. /**
  44. * Prints trace messages before and after executing methods.
  45. */
  46. before (): myMethod() {
  47. Trace.traceEntry("" + thisJoinPointStaticPart.getSignature());
  48. }
  49. after(): myMethod() {
  50. Trace.traceExit("" + thisJoinPointStaticPart.getSignature());
  51. }
  52. /**
  53. * A main function for testing the trace aspect.
  54. */
  55. public static void main(String[] args) {
  56. Trace.TRACELEVEL = 2;
  57. Trace.initStream(System.err);
  58. ExampleMain.main(args);
  59. }
  60. }