1 8 package org.codehaus.aspectwerkz.transform; 9 10 import java.lang.reflect.Modifier ; 11 12 import org.codehaus.aspectwerkz.joinpoint.management.JoinPointType; 13 14 19 public final class TransformationUtil { 20 21 27 public static String getPrefixedOriginalClinitName(final String className) { 28 return getPrefixedOriginalMethodName( 29 TransformationConstants.STATICINITIALIZER_WRAPPER_METHOD_KEY, className 31 ); 32 } 33 34 41 public static String getPrefixedOriginalMethodName(final String methodName, 42 final String className) { 43 final StringBuffer buf = new StringBuffer (); 44 buf.append(TransformationConstants.ORIGINAL_METHOD_PREFIX); 45 buf.append(methodName); 46 buf.append(TransformationConstants.DELIMITER); 47 buf.append(className.replace('.', '_').replace('/', '_')); 48 return buf.toString(); 49 } 50 51 59 public static String getWrapperMethodName(final String methodName, 60 final String methodDesc, 61 final String className, 62 final String prefix) { 63 final StringBuffer buf = new StringBuffer (); 64 buf.append(TransformationConstants.WRAPPER_METHOD_PREFIX); 69 buf.append(prefix); 70 buf.append(methodName); 71 buf.append(methodDesc.hashCode()); buf.append(className.replace('.', '_').replace('/', '_')); 73 return buf.toString().replace('-', '_'); 74 } 75 76 86 public static String getInvokeSignatureForCodeJoinPoints(final int codeModifiers, 87 final String codeDesc, 88 final String callerTypeName, 89 final String calleeTypeName) { 90 StringBuffer sig = new StringBuffer ("("); 91 if (!Modifier.isStatic(codeModifiers)) { 92 sig.append('L'); 95 sig.append(calleeTypeName); 96 sig.append(';'); 97 } 98 int index = codeDesc.lastIndexOf(')'); 99 sig.append(codeDesc.substring(1, index)); 100 sig.append('L'); 101 sig.append(callerTypeName); 102 sig.append(';'); 103 sig.append(codeDesc.substring(index, codeDesc.length())); 104 return sig.toString(); 105 } 106 107 117 public static String getInvokeSignatureForFieldJoinPoints(final int fieldModifiers, 118 final String fieldDesc, 119 final String callerTypeName, 120 final String calleeTypeName) { 121 StringBuffer sig = new StringBuffer ("("); 122 if (!Modifier.isStatic(fieldModifiers)) { 123 sig.append('L'); 126 sig.append(calleeTypeName); 127 sig.append(';'); 128 } 129 sig.append(fieldDesc); 130 sig.append('L'); 131 sig.append(callerTypeName); 132 sig.append(';'); 133 sig.append(')'); 134 sig.append(fieldDesc); 135 return sig.toString(); 136 } 137 138 146 public static String getInvokeSignatureForHandlerJoinPoints(final String withinTypeName, 147 final String exceptionTypeName) { 148 StringBuffer sig = new StringBuffer ("("); 149 sig.append('L'); 150 sig.append(exceptionTypeName); 151 sig.append(';'); 152 sig.append('L'); sig.append(exceptionTypeName); 154 sig.append(';'); 155 sig.append('L'); 156 sig.append(withinTypeName); 157 sig.append(';'); 158 sig.append(')'); 159 sig.append('L'); 160 sig.append(exceptionTypeName); 161 sig.append(';'); 162 return sig.toString(); 163 } 164 165 173 public static String getInvokeSignatureForConstructorCallJoinPoints(final String calleeConstructorDesc, 174 final String callerTypeName, 175 final String calleeTypeName) { 176 StringBuffer sig = new StringBuffer ("("); 177 int index = calleeConstructorDesc.lastIndexOf(')'); 178 sig.append(calleeConstructorDesc.substring(1, index)); 180 sig.append('L'); 182 sig.append(callerTypeName); 183 sig.append(';'); 184 sig.append(")L"); 185 sig.append(calleeTypeName); 186 sig.append(';'); 187 return sig.toString(); 188 } 189 190 196 public static String getConstructorBodyMethodName(final String calleeTypeName) { 197 final StringBuffer buf = new StringBuffer (); 198 buf.append(TransformationConstants.ORIGINAL_METHOD_PREFIX); 199 buf.append("init"); 200 buf.append(TransformationConstants.DELIMITER); 201 buf.append(calleeTypeName.replace('.', '_').replace('/', '_')); 202 return buf.toString(); 203 } 204 205 213 public static String getConstructorBodyMethodSignature(final String ctorDesc, final String calleeTypeName) { 214 StringBuffer sig = new StringBuffer ("(L"); 215 sig.append(calleeTypeName); 216 sig.append(";"); 217 sig.append(ctorDesc.substring(1)); 218 return sig.toString(); 219 } 220 221 233 public static String getJoinPointClassName(final String thisClassName, 234 final String thisMemberName, 235 final String thisMemberDesc, 236 final String targetClassName, 237 final int joinPointType, 238 final int joinPointHash) { 239 StringBuffer classNameBuf = new StringBuffer (thisClassName); 240 classNameBuf.append('_'); 243 classNameBuf.append(joinPointType); 244 classNameBuf.append('_'); 245 classNameBuf.append((thisMemberName+thisMemberDesc).hashCode()); 247 classNameBuf.append('_'); 248 classNameBuf.append(joinPointHash); 249 if (joinPointType == JoinPointType.CONSTRUCTOR_CALL_INT || joinPointType == JoinPointType.METHOD_CALL_INT 251 || joinPointType == JoinPointType.FIELD_GET_INT 252 || joinPointType == JoinPointType.FIELD_SET_INT 253 ) { 254 classNameBuf.append('_').append(targetClassName.hashCode()); 255 } 256 classNameBuf.append(TransformationConstants.JOIN_POINT_CLASS_SUFFIX); 257 258 return classNameBuf.toString().replace('-', '_').replace('.', '/'); 260 } 261 262 } | Popular Tags |