/**
* Removes the wrapper from all the target calls within this method.
*/
private void unpatchMethod() {
InstructionSearcher aFinder =
new InstructionSearcher( constPoolGen, iList );
CallWrapperVariableHandler vHandler =
new CallWrapperVariableHandler(
mGen, iList,
factory, constPoolGen,
joinpointPattern );
// the index of the wrapper to be deinstalled
int callWrapperIdx = vHandler.getCallWrapperVariableIndex();
// get the loads of this wrapper variable
aFinder.setCallWrapperLoads( callWrapperIdx, targets );
Iterator<CallMatch> cmIter = targets.iterator();
// loop over the target calls
while( cmIter.hasNext() ) {
// REMOVE before()-call
// get the argumentList variable
int curArgListVarIdx =
vHandler.getNextArgumentListVariableIndex();
InstructionHandle curArgListInit =
aFinder.lookUpArgumentListInit( curArgListVarIdx );
CallMatch curCallMatch = cmIter.next();
InstructionHandle beforeLoad =
curCallMatch.getBeforeLoad();
try {
iList.delete( curArgListInit,
vHandler.getLastReloadInstruction(
beforeLoad.getNext().getNext(),
curCallMatch.getCallInfo() ) );
}
catch( TargetLostException tle ) {
Logger.debug( "removing before()-calls: %s", tle.toString() );
}
// REMOVE after-call
InstructionHandle afterLoad =
curCallMatch.getAfterLoad();
try {
iList.delete( afterLoad,
getLastAfterInstruction(
afterLoad, curCallMatch.getCallInfo() ) );
}
catch( TargetLostException tle ) {
Logger.debug( "removing after()-calls: %s", tle.toString() );
}
// REMOVE Exception-handler
InstructionHandle afterExceptionLoad =
curCallMatch.getAfterExceptionLoad();
removeExceptionHandler( afterExceptionLoad );
try {
iList.delete( afterExceptionLoad.getPrev(),
afterExceptionLoad.getNext().getNext().
getNext().getNext().getNext() );
}
catch( TargetLostException tle ) {
Logger.debug(
"removing afterException()-calls: %s", tle.toString() );
}
}
// remove the creation of the wrapper variable
List<InstructionHandle> callWrapperStores =
aFinder.lookUpCallWrapperStores( callWrapperIdx );
try {
iList.delete(
callWrapperStores.get(0).getPrev(),
callWrapperStores.get(1) );