final Context context,
final ClassGen cg,
final ConstantPoolGen cpg,
final InstructionFactory factory,
final AddImplementationTransformer transformer) {
AspectWerkzDefinitionImpl def = (AspectWerkzDefinitionImpl)definition;
boolean isClassAdvised = false;
ClassMetaData metaData = new ClassMetaData();
metaData.setName(cg.getClassName());
for (Iterator it = def.getIntroductionNames(metaData).iterator(); it.hasNext();) {
String introductionName = (String)it.next();
String introductionImplName = def.getIntroductionImplName(introductionName);
if (introductionImplName == null) {
continue;
}
int introductionIndex = 0;
List methodMetaDataList = Collections.synchronizedList(new ArrayList());
try {
introductionIndex = def.getIntroductionIndex(introductionName);
// get the method meta-data for the class
boolean match = false;
Map metaDataRepository = context.getMetaDataRepository();
for (Iterator it2 = metaDataRepository.values().iterator(); it2.hasNext();) {
if (match) break;
Set metaDataSet = (Set)it2.next();
for (Iterator it3 = metaDataSet.iterator(); it3.hasNext();) {
ClassMetaData classMetaData = (ClassMetaData)it3.next();
if (classMetaData.getName().equals(introductionImplName)) {
methodMetaDataList = classMetaData.getMethods();
match = true;
break;
}
}
}
if (methodMetaDataList == null) {
throw new RuntimeException("no meta-data for introduction " + introductionImplName + " could be found in repository");
}
}
catch (Exception e) {
throw new DefinitionException("trying to weave introduction with null or empty string as name to class " + cg.getClassName() + ": definition file is not consistent");
}
if (methodMetaDataList == null) {
continue; // interface introduction
}
// the iterator is on a list and the loop body does list.remove
// which is forbidden
List methodMetaDataListFiltered = new ArrayList();
for (Iterator it2 = methodMetaDataList.iterator(); it2.hasNext();) {
MethodMetaData methodMetaData = (MethodMetaData)it2.next();
// remove the ___AW_getUuid, ___AW_getMetaData, ___AW_addMetaData and class$ methods
// as well as some other methods before sorting the method list
if (!(
methodMetaData.getName().equals("equals") ||
methodMetaData.getName().equals("hashCode") ||
methodMetaData.getName().equals("getClass") ||
methodMetaData.getName().equals("toString") ||
methodMetaData.getName().equals("wait") ||
methodMetaData.getName().equals("notify") ||
methodMetaData.getName().equals("notifyAll") ||
methodMetaData.getName().equals(
TransformationUtil.GET_UUID_METHOD) ||
methodMetaData.getName().equals(
TransformationUtil.GET_UUID_METHOD) ||
methodMetaData.getName().equals(
TransformationUtil.GET_META_DATA_METHOD) ||
methodMetaData.getName().equals(
TransformationUtil.SET_META_DATA_METHOD) ||
methodMetaData.getName().equals(
TransformationUtil.CLASS_LOOKUP_METHOD) ||
methodMetaData.getName().startsWith(
TransformationUtil.ORIGINAL_METHOD_PREFIX))) {
methodMetaDataListFiltered.add(methodMetaData);
}
}
// sort the list so that we can enshure that the indexes are in synch
// see AbstractIntroductionContainerStrategy#AbstractIntroductionContainerStrategy
Collections.sort(methodMetaDataListFiltered, MethodComparator.
getInstance(MethodComparator.METHOD_META_DATA));
int methodIndex = -1; // start with -1 since the method array is 0 indexed
for (Iterator it2 = methodMetaDataListFiltered.iterator(); it2.hasNext();) {
MethodMetaData methodMetaData = (MethodMetaData)it2.next();
if (methodMetaData.getReturnType() == null || methodMetaData.getName().equals("<init>")) {
continue;
}
methodIndex++;
transformer.createProxyMethod(
cg, cpg, factory,
methodMetaData,
introductionIndex,
methodIndex,
def.getUuid()
);
isClassAdvised = true;
}
}