* @param klass the class set.
*/
public void transformCode(final Context context, final Klass klass) {
final ClassGen cg = klass.getClassGen();
ClassMetaData classMetaData = BcelMetaDataMaker.
createClassMetaData(context.getJavaClass(cg));
// filter caller classes
if (classFilter(classMetaData, cg)) {
return;
}
final Method[] methods = cg.getMethods();
// get the index for the <clinit> method (if there is one)
boolean hasClInitMethod = false;
int clinitIndex = -1;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals("<clinit>")) {
clinitIndex = i;
hasClInitMethod = true;
break;
}
}
final ConstantPoolGen cpg = cg.getConstantPool();
final String className = cg.getClassName();
final InstructionFactory factory = new InstructionFactory(cg);
final Set callerSideJoinPoints = new HashSet();
Method clInitMethod = null;
final Map methodSequences = new HashMap();
final List newMethods = new ArrayList();
boolean isClassAdvised = false;
boolean isMethodChanged = false;
for (int i = 0; i < methods.length; i++) {
// filter caller methods
if (methodFilterCaller(methods[i])) {
continue;
}
final MethodGen mg = new MethodGen(methods[i], className, cpg);
final InstructionList il = mg.getInstructionList();
if (il == null) {
continue;
}
InstructionHandle ih = il.getStart();
isMethodChanged = false;
// search for all InvokeInstruction instructions and
// inserts the call side pointcuts
while (ih != null) {
final Instruction ins = ih.getInstruction();
if (ins instanceof INVOKESPECIAL ||
ins instanceof INVOKESTATIC ||
ins instanceof INVOKEVIRTUAL) {
final InvokeInstruction invokeInstruction = (InvokeInstruction)ins;
// get the callee method name, signature and class name
final String calleeMethodName = invokeInstruction.getName(cpg);
final String calleeClassName = invokeInstruction.getClassName(cpg);
final String calleeMethodSignature = invokeInstruction.getSignature(cpg);
// filter callee classes
if (!m_definition.inTransformationScope(calleeClassName)) {
ih = ih.getNext();
continue;
}
// filter callee methods
if (methodFilterCallee(calleeMethodName)) {
ih = ih.getNext();
continue;
}
// create the class meta-data
ClassMetaData calleeSideClassMetaData;
try {
JavaClass javaClass = context.getRepository().loadClass(calleeClassName);
calleeSideClassMetaData = BcelMetaDataMaker.createClassMetaData(javaClass);
}
catch (ClassNotFoundException e) {