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.

AdviceSignatureImpl.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.reflect;
  14. import java.lang.reflect.Method;
  15. import java.util.StringTokenizer;
  16. import org.aspectj.lang.reflect.AdviceSignature;
  17. class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
  18. Class<?> returnType;
  19. private Method adviceMethod = null;
  20. AdviceSignatureImpl(int modifiers, String name, Class<?> declaringType,
  21. Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
  22. Class<?> returnType)
  23. {
  24. super(modifiers, name, declaringType, parameterTypes, parameterNames,
  25. exceptionTypes);
  26. this.returnType = returnType;
  27. }
  28. AdviceSignatureImpl(String stringRep) {
  29. super(stringRep);
  30. }
  31. /* name is consistent with reflection API
  32. before and after always return Void.TYPE
  33. (some around also return Void.Type) */
  34. public Class getReturnType() {
  35. if (returnType == null) returnType = extractType(6);
  36. return returnType;
  37. }
  38. protected String createToString(StringMaker sm) {
  39. StringBuffer buf = new StringBuffer();
  40. // buf.append(sm.makeModifiersString(getModifiers()));
  41. if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType()));
  42. if (sm.includeArgs) buf.append(" ");
  43. buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
  44. buf.append(".");
  45. buf.append(toAdviceName(getName()));
  46. sm.addSignature(buf, getParameterTypes());
  47. sm.addThrows(buf, getExceptionTypes());
  48. return buf.toString();
  49. }
  50. private String toAdviceName(String methodName) {
  51. if (methodName.indexOf('$') == -1) return methodName;
  52. StringTokenizer strTok = new StringTokenizer(methodName,"$");
  53. while (strTok.hasMoreTokens()) {
  54. String token = strTok.nextToken();
  55. if ( token.startsWith("before") ||
  56. token.startsWith("after") ||
  57. token.startsWith("around") ) return token;
  58. }
  59. return methodName;
  60. }
  61. /* (non-Javadoc)
  62. * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
  63. */
  64. public Method getAdvice() {
  65. if (adviceMethod == null) {
  66. try {
  67. adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes());
  68. } catch (Exception ex) {
  69. ; // nothing we can do, caller will see null
  70. }
  71. }
  72. return adviceMethod;
  73. }
  74. }