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.

JoinPoint.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.lang;
  14. import org.aspectj.lang.reflect.SourceLocation;
  15. /**
  16. * <p>Provides reflective access to both the state available at a join point and
  17. * static information about it. This information is available from the body
  18. * of advice using the special form <code>thisJoinPoint</code>. The primary
  19. * use of this reflective information is for tracing and logging applications.
  20. * </p>
  21. *
  22. * <pre>
  23. * aspect Logging {
  24. * before(): within(com.bigboxco..*) && execution(public * *(..)) {
  25. * System.err.println("entering: " + thisJoinPoint);
  26. * System.err.println(" w/args: " + thisJoinPoint.getArgs());
  27. * System.err.println(" at: " + thisJoinPoint.getSourceLocation());
  28. * }
  29. * }
  30. * </pre>
  31. */
  32. public interface JoinPoint {
  33. String toString();
  34. /**
  35. * Returns an abbreviated string representation of the join point.
  36. */
  37. String toShortString();
  38. /**
  39. * Returns an extended string representation of the join point.
  40. */
  41. String toLongString();
  42. /**
  43. * <p> Returns the currently executing object. This will always be
  44. * the same object as that matched by the <code>this</code> pointcut
  45. * designator. Unless you specifically need this reflective access,
  46. * you should use the <code>this</code> pointcut designator to
  47. * get at this object for better static typing and performance.</p>
  48. *
  49. * <p> Returns null when there is no currently executing object available.
  50. * This includes all join points that occur in a static context.</p>
  51. */
  52. Object getThis();
  53. /**
  54. * <p> Returns the target object. This will always be
  55. * the same object as that matched by the <code>target</code> pointcut
  56. * designator. Unless you specifically need this reflective access,
  57. * you should use the <code>target</code> pointcut designator to
  58. * get at this object for better static typing and performance.</p>
  59. *
  60. * <p> Returns null when there is no target object.</p>
  61. */
  62. Object getTarget();
  63. /**
  64. * <p>Returns the arguments at this join point.</p>
  65. */
  66. Object[] getArgs();
  67. /** Returns the signature at the join point.
  68. *
  69. * <code>getStaticPart().getSignature()</code> returns the same object
  70. */
  71. Signature getSignature();
  72. /** <p>Returns the source location corresponding to the join point.</p>
  73. *
  74. * <p>If there is no source location available, returns null.</p>
  75. *
  76. * <p>Returns the SourceLocation of the defining class for default constructors.</p>
  77. *
  78. * <p> <code>getStaticPart().getSourceLocation()</code> returns the same object. </p>
  79. */
  80. SourceLocation getSourceLocation();
  81. /** Returns a String representing the kind of join point. This
  82. * String is guaranteed to be
  83. * interned. <code>getStaticPart().getKind()</code> returns
  84. * the same object.
  85. */
  86. String getKind();
  87. /**
  88. * <p>This helper object contains only the static information about a join point.
  89. * It is available from the <code>JoinPoint.getStaticPart()</code> method, and
  90. * can be accessed separately within advice using the special form
  91. * <code>thisJoinPointStaticPart</code>.</p>
  92. *
  93. * <p>If you are only interested in the static information about a join point,
  94. * you should access it through this type for the best performance. This
  95. * is particularly useful for library methods that want to do serious
  96. * manipulations of this information, i.e.</p>
  97. *
  98. * <pre>
  99. * public class LoggingUtils {
  100. * public static void prettyPrint(JoinPoint.StaticPart jp) {
  101. * ...
  102. * }
  103. * }
  104. *
  105. * aspect Logging {
  106. * before(): ... { LoggingUtils.prettyPrint(thisJoinPointStaticPart); }
  107. * }
  108. * </pre>
  109. *
  110. * @see JoinPoint#getStaticPart()
  111. */
  112. public interface StaticPart {
  113. /** Returns the signature at the join point. */
  114. Signature getSignature();
  115. /** <p>Returns the source location corresponding to the join point.</p>
  116. *
  117. * <p>If there is no source location available, returns null.</p>
  118. *
  119. * <p>Returns the SourceLocation of the defining class for default constructors.</p>
  120. */
  121. SourceLocation getSourceLocation();
  122. /** <p> Returns a String representing the kind of join point. This String
  123. * is guaranteed to be interned</p>
  124. */
  125. String getKind();
  126. /**
  127. * Return the id for this JoinPoint.StaticPart. All JoinPoint.StaticPart
  128. * instances are assigned an id number upon creation. For each advised type
  129. * the id numbers start at 0.
  130. * <br>
  131. * The id is guaranteed to remain constant across repeated executions
  132. * of a program but may change if the code is recompiled.
  133. * <br>
  134. * The benefit of having an id is that it can be used for array index
  135. * purposes which can be quicker than using the JoinPoint.StaticPart
  136. * object itself in a map lookup.
  137. * <br>
  138. * Since two JoinPoint.StaticPart instances in different advised types may have
  139. * the same id, then if the id is being used to index some joinpoint specific
  140. * state then that state must be maintained on a pertype basis - either by
  141. * using pertypewithin() or an ITD.
  142. *
  143. * @return the id of this joinpoint
  144. */
  145. int getId();
  146. String toString();
  147. /**
  148. * Returns an abbreviated string representation of the join point
  149. */
  150. String toShortString();
  151. /**
  152. * Returns an extended string representation of the join point
  153. */
  154. String toLongString();
  155. }
  156. public interface EnclosingStaticPart extends StaticPart {}
  157. /**
  158. * Returns an object that encapsulates the static parts of this join point.
  159. */
  160. StaticPart getStaticPart();
  161. /**
  162. * The legal return values from getKind()
  163. */
  164. static String METHOD_EXECUTION = "method-execution";
  165. static String METHOD_CALL = "method-call";
  166. static String CONSTRUCTOR_EXECUTION = "constructor-execution";
  167. static String CONSTRUCTOR_CALL = "constructor-call";
  168. static String FIELD_GET = "field-get";
  169. static String FIELD_SET = "field-set";
  170. static String STATICINITIALIZATION = "staticinitialization";
  171. static String PREINITIALIZATION = "preinitialization";
  172. static String INITIALIZATION = "initialization";
  173. static String EXCEPTION_HANDLER = "exception-handler";
  174. static String SYNCHRONIZATION_LOCK = "lock";
  175. static String SYNCHRONIZATION_UNLOCK = "unlock";
  176. static String ADVICE_EXECUTION = "adviceexecution";
  177. }