// build and sort the method lookup list
final List methodLookupList = new ArrayList();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(methods[i]);
if (methodFilter(definition, classMetaData, methodMetaData, method)) {
continue;
}
methodLookupList.add(methods[i]);
// TODO: does not work, needs to be thought through more
// if advised swap add the prefixed one as well to enable second-round instrumentation
// String originalPrefixedName =
// TransformationUtil.ORIGINAL_METHOD_PREFIX +
// methods[i].getName();
// Method[] declaredMethods = cg.getMethods();
// for (int j = 0; j < declaredMethods.length; j++) {
// Method declaredMethod = declaredMethods[j];
// if (declaredMethod.getName().startsWith(originalPrefixedName)) {
// methodLookupList.add(declaredMethod);
// }
// }
}
Collections.sort(methodLookupList, BCELMethodComparator.getInstance());
final Map methodSequences = new HashMap();
final List newMethods = new ArrayList();
Method clInitMethod = null;
boolean isClassAdvised = false;
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(method);
if (methodFilter(definition, classMetaData, methodMetaData, method)
|| !method.isStatic()) {
continue;
}
isClassAdvised = true;
// TODO: does not work, needs to be thought through more
// if advised swap the method to the prefixed one
// String originalPrefixedName =
// TransformationUtil.ORIGINAL_METHOD_PREFIX +
// methods[i].getName();
// Method[] declaredMethods = cg.getMethods();
// for (int j = 0; j < declaredMethods.length; j++) {
// Method declaredMethod = declaredMethods[j];
// if (declaredMethod.getName().startsWith(originalPrefixedName)) {
// method = declaredMethod;
// }
// }
final MethodGen mg = new MethodGen(method, cg.getClassName(), cpg);
// take care of identification of overloaded methods by
// inserting a sequence number
if (methodSequences.containsKey(method.getName())) {
int sequence = ((Integer)methodSequences.get(methods[i].getName())).intValue();
methodSequences.remove(method.getName());
sequence++;
methodSequences.put(method.getName(), new Integer(sequence));
}
else {
methodSequences.put(method.getName(), new Integer(1));
}
final int methodLookupId = methodLookupList.indexOf(method);
final int methodSequence = ((Integer)methodSequences.get(method.getName())).intValue();
addStaticJoinPointField(cpg, cg, mg, methodSequence);
// get the join point controller
final String controllerClassName = definition.getJoinPointController(
classMetaData, methodMetaData
);
if (noClinitMethod) {
// no <clinit> method exists
if (clInitMethod == null) {
clInitMethod = createClInitMethodWithStaticJoinPointField(
cpg, cg,
method,
factory,
methodSequence
);
}
else {
clInitMethod = createStaticJoinPointField(
cpg, cg, clInitMethod,
method,
factory,
methodSequence
);
}
}
else {
// we have a <clinit> method
methods[indexClinit] = createStaticJoinPointField(
cpg, cg, methods[indexClinit],
method,
factory,
methodSequence
);
}
// create a proxy method for the original method
newMethods.add(createProxyMethod(
cpg, cg,
methodMetaData.getName(),
mg, factory,
methodLookupId,
methodSequence,
method.getAccessFlags(),
definition.getUuid(),