1 13 14 15 package org.aspectj.runtime.reflect; 16 17 import java.lang.reflect.Method ; 18 import java.util.StringTokenizer ; 19 20 import org.aspectj.lang.reflect.AdviceSignature; 21 22 class AdviceSignatureImpl extends CodeSignatureImpl implements AdviceSignature { 23 Class returnType; 24 private Method adviceMethod = null; 25 26 AdviceSignatureImpl(int modifiers, String name, Class declaringType, 27 Class [] parameterTypes, String [] parameterNames, Class [] exceptionTypes, 28 Class returnType) 29 { 30 super(modifiers, name, declaringType, parameterTypes, parameterNames, 31 exceptionTypes); 32 this.returnType = returnType; 33 } 34 35 AdviceSignatureImpl(String stringRep) { 36 super(stringRep); 37 } 38 41 public Class getReturnType() { 42 if (returnType == null) returnType = extractType(6); 43 return returnType; 44 } 45 46 protected String createToString(StringMaker sm) { 47 StringBuffer buf = new StringBuffer (); 48 if (sm.includeArgs) buf.append(sm.makeTypeName(getReturnType())); 50 if (sm.includeArgs) buf.append(" "); 51 buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName())); 52 buf.append("."); 53 buf.append(toAdviceName(getName())); 54 sm.addSignature(buf, getParameterTypes()); 55 sm.addThrows(buf, getExceptionTypes()); 56 return buf.toString(); 57 } 58 59 private String toAdviceName(String methodName) { 60 if (methodName.indexOf('$') == -1) return methodName; 61 StringTokenizer strTok = new StringTokenizer (methodName,"$"); 62 while (strTok.hasMoreTokens()) { 63 String token = strTok.nextToken(); 64 if ( token.startsWith("before") || 65 token.startsWith("after") || 66 token.startsWith("around") ) return token; 67 } 68 return methodName; 69 } 70 71 74 public Method getAdvice() { 75 if (adviceMethod == null) { 76 try { 77 adviceMethod = getDeclaringType().getDeclaredMethod(getName(),getParameterTypes()); 78 } catch (Exception ex) { 79 ; } 81 } 82 return adviceMethod; 83 } 84 } 85 | Popular Tags |