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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Common Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/cpl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.reflect;
  14. import java.lang.reflect.Method;
  15. import org.aspectj.lang.reflect.AdviceSignature;
  16. class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature {
  17. Class returnType;
  18. private Method adviceMethod = null;
  19. AdviceSignatureImpl(int modifiers, String name, Class declaringType,
  20. Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
  21. Class returnType)
  22. {
  23. super(modifiers, name, declaringType, parameterTypes, parameterNames,
  24. exceptionTypes);
  25. this.returnType = returnType;
  26. }
  27. AdviceSignatureImpl(String stringRep) {
  28. super(stringRep);
  29. }
  30. /* name is consistent with reflection API
  31. before and after always return Void.TYPE
  32. (some around also return Void.Type) */
  33. public Class getReturnType() {
  34. if (returnType == null) returnType = extractType(6);
  35. return returnType;
  36. }
  37. protected String createToString(StringMaker sm) {
  38. //XXX this signature needs a lot of work
  39. StringBuffer buf = new StringBuffer("ADVICE: ");
  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(getName());
  46. sm.addSignature(buf, getParameterTypes());
  47. sm.addThrows(buf, getExceptionTypes());
  48. return buf.toString();
  49. }
  50. /* (non-Javadoc)
  51. * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
  52. */
  53. public Method getAdvice() {
  54. if (adviceMethod == null) {
  55. try {
  56. adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes());
  57. } catch (Exception ex) {
  58. ; // nothing we can do, caller will see null
  59. }
  60. }
  61. return adviceMethod;
  62. }
  63. }