1 12 package org.aspectj.internal.lang.reflect; 13 14 import java.lang.reflect.Method ; 15 import java.lang.reflect.Type ; 16 import java.lang.reflect.TypeVariable ; 17 18 import org.aspectj.lang.reflect.AjType; 19 import org.aspectj.lang.reflect.AjTypeSystem; 20 import org.aspectj.lang.reflect.InterTypeMethodDeclaration; 21 22 26 public class InterTypeMethodDeclarationImpl extends InterTypeDeclarationImpl 27 implements InterTypeMethodDeclaration { 28 29 private String name; 30 private Method baseMethod; 31 private int parameterAdjustmentFactor = 1; private AjType<?>[] parameterTypes; 33 private Type [] genericParameterTypes; 34 private AjType<?> returnType; 35 private Type genericReturnType; 36 private AjType<?>[] exceptionTypes; 37 38 43 public InterTypeMethodDeclarationImpl(AjType<?> decType, String target, 44 int mods, String name, Method itdInterMethod) { 45 super(decType, target, mods); 46 this.name = name; 47 this.baseMethod = itdInterMethod; 48 } 49 50 public InterTypeMethodDeclarationImpl(AjType<?> decType, AjType<?> targetType, Method base, int modifiers) { 51 super(decType,targetType,modifiers); 52 this.parameterAdjustmentFactor = 0; 53 this.name = base.getName(); 54 this.baseMethod = base; 55 } 56 57 60 public String getName() { 61 return this.name; 62 } 63 64 67 public AjType<?> getReturnType() { 68 return AjTypeSystem.getAjType(baseMethod.getReturnType()); 69 } 70 71 74 public Type getGenericReturnType() { 75 Type gRet = baseMethod.getGenericReturnType(); 76 if (gRet instanceof Class ) { 77 return AjTypeSystem.getAjType((Class <?>)gRet); 78 } 79 return gRet; 80 } 81 82 85 public AjType<?>[] getParameterTypes() { 86 Class <?>[] baseTypes = baseMethod.getParameterTypes(); 87 AjType<?>[] ret = new AjType<?>[baseTypes.length -parameterAdjustmentFactor]; 88 for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) { 89 ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType(baseTypes[i]); 90 } 91 return ret; 92 } 93 94 97 public Type [] getGenericParameterTypes() { 98 Type [] baseTypes = baseMethod.getGenericParameterTypes(); 99 Type [] ret = new AjType<?>[baseTypes.length-parameterAdjustmentFactor]; 100 for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) { 101 if (baseTypes[i] instanceof Class ) { 102 ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType((Class <?>)baseTypes[i]); 103 } else { 104 ret[i-parameterAdjustmentFactor] = baseTypes[i]; 105 } 106 } 107 return ret; 108 } 109 110 113 public TypeVariable <Method >[] getTypeParameters() { 114 return baseMethod.getTypeParameters(); 115 } 116 117 public AjType<?>[] getExceptionTypes() { 118 Class <?>[] baseTypes = baseMethod.getExceptionTypes(); 119 AjType<?>[] ret = new AjType<?>[baseTypes.length]; 120 for (int i = 0; i < baseTypes.length; i++) { 121 ret[i] = AjTypeSystem.getAjType(baseTypes[i]); 122 } 123 return ret; 124 } 125 126 public String toString() { 127 StringBuffer sb = new StringBuffer (); 128 sb.append(java.lang.reflect.Modifier.toString(getModifiers())); 129 sb.append(" "); 130 sb.append(getReturnType().toString()); 131 sb.append(" "); 132 sb.append(this.targetTypeName); 133 sb.append("."); 134 sb.append(getName()); 135 sb.append("("); 136 AjType<?>[] pTypes = getParameterTypes(); 137 for(int i = 0; i < (pTypes.length - 1); i++) { 138 sb.append(pTypes[i].toString()); 139 sb.append(", "); 140 } 141 if (pTypes.length > 0) { 142 sb.append(pTypes[pTypes.length -1].toString()); 143 } 144 sb.append(")"); 145 return sb.toString(); 146 } 147 148 } 149 | Popular Tags |