* @param klass the class set.
*/
public void transform(final Context context, final Klass klass) throws NotFoundException, CannotCompileException {
m_joinPointIndex = TransformationUtil.getJoinPointIndex(klass.getCtClass());
for (Iterator it = m_definitions.iterator(); it.hasNext();) {
final SystemDefinition definition = (SystemDefinition)it.next();
final CtClass ctClass = klass.getCtClass();
ClassMetaData classMetaData = JavassistMetaDataMaker.createClassMetaData(ctClass);
if (classFilter(definition, classMetaData, ctClass)) {
return;
}
ctClass.instrument(
new ExprEditor() {
public void edit(NewExpr newExpr) throws CannotCompileException {
try {
CtBehavior where = null;
try {
where = newExpr.where();
}
catch (RuntimeException e) {
// <clinit> access leads to a bug in Javassist
where = ctClass.getClassInitializer();
}
// filter caller methods
if (methodFilterCaller(where)) {
return;
}
CtConstructor ctConstructor = newExpr.getConstructor();
String calleeClassName = newExpr.getClassName();
// filter callee classes
if (!definition.inIncludePackage(calleeClassName)) {
return;
}
// filter the constructors
if (constructorFilter(ctConstructor)) {
return;
}
// create the class meta-data
ClassMetaData calleeSideClassMetaData;
try {
calleeSideClassMetaData =
JavassistMetaDataMaker.createClassMetaData(
context.getClassPool().get(calleeClassName)
);
}
catch (NotFoundException e) {
throw new WrappedRuntimeException(e);
}
// create the method meta-data
ConstructorMetaData constructorMetaData =
JavassistMetaDataMaker.createConstructorMetaData(newExpr.getConstructor());
// is this a caller side method pointcut?
if (definition.isPickedOutByCallPointcut(calleeSideClassMetaData, constructorMetaData)) {
// check the callee class is not the same as target class, if that is the case
// then we have have class loaded and set in the ___AW_clazz already
String declaringClassMethodName = TransformationUtil.STATIC_CLASS_FIELD;