1 4 package com.tc.aspectwerkz.transform; 5 6 import java.lang.reflect.Modifier ; 7 8 import com.tc.aspectwerkz.joinpoint.management.JoinPointType; 9 10 15 public final class TransformationUtil { 16 17 23 public static String getPrefixedOriginalClinitName(final String className) { 24 return getPrefixedOriginalMethodName( 25 TransformationConstants.STATICINITIALIZER_WRAPPER_METHOD_KEY, className 27 ); 28 } 29 30 37 public static String getPrefixedOriginalMethodName(final String methodName, 38 final String className) { 39 final StringBuffer buf = new StringBuffer (); 40 buf.append(TransformationConstants.ORIGINAL_METHOD_PREFIX); 41 buf.append(methodName); 42 buf.append(TransformationConstants.DELIMITER); 43 buf.append(className.replace('.', '_').replace('/', '_')); 44 return buf.toString(); 45 } 46 47 55 public static String getWrapperMethodName(final String methodName, 56 final String methodDesc, 57 final String className, 58 final String prefix) { 59 final StringBuffer buf = new StringBuffer (); 60 buf.append(TransformationConstants.WRAPPER_METHOD_PREFIX); 65 buf.append(prefix); 66 buf.append(methodName.replace('<', '$').replace('>', '$')); buf.append(methodDesc.hashCode()); buf.append(className.replace('.', '_').replace('/', '_')); 69 return buf.toString().replace('-', '_'); 70 } 71 72 82 public static String getInvokeSignatureForCodeJoinPoints(final int codeModifiers, 83 final String codeDesc, 84 final String callerTypeName, 85 final String calleeTypeName) { 86 StringBuffer sig = new StringBuffer ("("); 87 if (!Modifier.isStatic(codeModifiers)) { 88 sig.append('L'); 91 sig.append(calleeTypeName); 92 sig.append(';'); 93 } 94 int index = codeDesc.lastIndexOf(')'); 95 sig.append(codeDesc.substring(1, index)); 96 sig.append('L'); 97 sig.append(callerTypeName); 98 sig.append(';'); 99 sig.append(codeDesc.substring(index, codeDesc.length())); 100 return sig.toString(); 101 } 102 103 113 public static String getInvokeSignatureForFieldJoinPoints(final int fieldModifiers, 114 final String fieldDesc, 115 final String callerTypeName, 116 final String calleeTypeName) { 117 StringBuffer sig = new StringBuffer ("("); 118 if (!Modifier.isStatic(fieldModifiers)) { 119 sig.append('L'); 122 sig.append(calleeTypeName); 123 sig.append(';'); 124 } 125 sig.append(fieldDesc); 126 sig.append('L'); 127 sig.append(callerTypeName); 128 sig.append(';'); 129 sig.append(')'); 130 sig.append(fieldDesc); 131 return sig.toString(); 132 } 133 134 142 public static String getInvokeSignatureForHandlerJoinPoints(final String withinTypeName, 143 final String exceptionTypeName) { 144 StringBuffer sig = new StringBuffer ("("); 145 sig.append('L'); 146 sig.append(exceptionTypeName); 147 sig.append(';'); 148 sig.append('L'); sig.append(exceptionTypeName); 150 sig.append(';'); 151 sig.append('L'); 152 sig.append(withinTypeName); 153 sig.append(';'); 154 sig.append(')'); 155 sig.append('L'); 156 sig.append(exceptionTypeName); 157 sig.append(';'); 158 return sig.toString(); 159 } 160 161 169 public static String getInvokeSignatureForConstructorCallJoinPoints(final String calleeConstructorDesc, 170 final String callerTypeName, 171 final String calleeTypeName) { 172 StringBuffer sig = new StringBuffer ("("); 173 int index = calleeConstructorDesc.lastIndexOf(')'); 174 sig.append(calleeConstructorDesc.substring(1, index)); 176 sig.append('L'); 178 sig.append(callerTypeName); 179 sig.append(';'); 180 sig.append(")L"); 181 sig.append(calleeTypeName); 182 sig.append(';'); 183 return sig.toString(); 184 } 185 186 192 public static String getConstructorBodyMethodName(final String calleeTypeName) { 193 final StringBuffer buf = new StringBuffer (); 194 buf.append(TransformationConstants.ORIGINAL_METHOD_PREFIX); 195 buf.append("init"); 196 buf.append(TransformationConstants.DELIMITER); 197 buf.append(calleeTypeName.replace('.', '_').replace('/', '_')); 198 return buf.toString(); 199 } 200 201 209 public static String getConstructorBodyMethodSignature(final String ctorDesc, final String calleeTypeName) { 210 StringBuffer sig = new StringBuffer ("(L"); 211 sig.append(calleeTypeName); 212 sig.append(";"); 213 sig.append(ctorDesc.substring(1)); 214 return sig.toString(); 215 } 216 217 229 public static String getJoinPointClassName(final String thisClassName, 230 final String thisMemberName, 231 final String thisMemberDesc, 232 final String targetClassName, 233 final int joinPointType, 234 final int joinPointHash) { 235 StringBuffer classNameBuf = new StringBuffer (thisClassName); 236 classNameBuf.append('_'); 239 classNameBuf.append(joinPointType); 240 classNameBuf.append('_'); 241 classNameBuf.append((thisMemberName + thisMemberDesc).hashCode()); 243 classNameBuf.append('_'); 244 classNameBuf.append(joinPointHash); 245 if (joinPointType == JoinPointType.CONSTRUCTOR_CALL_INT || joinPointType == JoinPointType.METHOD_CALL_INT 247 || joinPointType == JoinPointType.FIELD_GET_INT 248 || joinPointType == JoinPointType.FIELD_SET_INT 249 ) { 250 classNameBuf.append('_').append(targetClassName.hashCode()); 251 } 252 classNameBuf.append(TransformationConstants.JOIN_POINT_CLASS_SUFFIX); 253 254 return classNameBuf.toString().replace('-', '_').replace('.', '/'); 256 } 257 258 } | Popular Tags |