1 12 package org.aspectj.internal.lang.reflect; 13 14 import java.lang.reflect.Method ; 15 import java.util.StringTokenizer ; 16 17 import org.aspectj.lang.reflect.AjType; 18 import org.aspectj.lang.reflect.AjTypeSystem; 19 import org.aspectj.lang.reflect.Pointcut; 20 import org.aspectj.lang.reflect.PointcutExpression; 21 22 26 public class PointcutImpl implements Pointcut { 27 28 private final String name; 29 private final PointcutExpression pc; 30 private final Method baseMethod; 31 private final AjType declaringType; 32 private String [] parameterNames = new String [0]; 33 34 protected PointcutImpl(String name, String pc, Method method, AjType declaringType, String pNames) { 35 this.name = name; 36 this.pc = new PointcutExpressionImpl(pc); 37 this.baseMethod = method; 38 this.declaringType = declaringType; 39 this.parameterNames = splitOnComma(pNames); 40 } 41 42 45 public PointcutExpression getPointcutExpression() { 46 return pc; 47 } 48 49 public String getName() { 50 return name; 51 } 52 53 public int getModifiers() { 54 return baseMethod.getModifiers(); 55 } 56 57 public AjType<?>[] getParameterTypes() { 58 Class <?>[] baseParamTypes = baseMethod.getParameterTypes(); 59 AjType<?>[] ajParamTypes = new AjType<?>[baseParamTypes.length]; 60 for (int i = 0; i < ajParamTypes.length; i++) { 61 ajParamTypes[i] = AjTypeSystem.getAjType(baseParamTypes[i]); 62 } 63 return ajParamTypes; 64 } 65 66 public AjType getDeclaringType() { 67 return declaringType; 68 } 69 70 public String [] getParameterNames() { 71 return parameterNames; 72 } 73 74 private String [] splitOnComma(String s) { 75 StringTokenizer strTok = new StringTokenizer (s,","); 76 String [] ret = new String [strTok.countTokens()]; 77 for (int i = 0; i < ret.length; i++) { 78 ret[i] = strTok.nextToken().trim(); 79 } 80 return ret; 81 } 82 83 public String toString() { 84 StringBuffer sb = new StringBuffer (); 85 sb.append(getName()); 86 sb.append("("); 87 AjType<?>[] ptypes = getParameterTypes(); 88 for (int i = 0; i < ptypes.length; i++) { 89 sb.append(ptypes[i].getName()); 90 if (this.parameterNames != null && this.parameterNames[i] != null) { 91 sb.append(" "); 92 sb.append(this.parameterNames[i]); 93 } 94 if (i+1 < ptypes.length) sb.append(","); 95 } 96 sb.append(") : "); 97 sb.append(getPointcutExpression().asString()); 98 return sb.toString(); 99 } 100 } 101 | Popular Tags |