Skip to content

Commit b4efdb0

Browse files
committed
Moving logic about debugging further inner blocks into new method
1 parent 58a7eaa commit b4efdb0

1 file changed

Lines changed: 77 additions & 10 deletions

File tree

src/main/java/edu/illinois/cs/dt/tools/fixer/CleanerFixerPlugin.java

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -871,16 +871,9 @@ private PatchResult applyFix(final List<String> failingOrder,
871871
currentInterCleanerStmts = NodeList.nodeList(interCleanerStmts);
872872
interCleanerStmts = NodeList.nodeList();
873873
interCleanerStmts.addAll(finalDebugger.deltaDebug(currentInterCleanerStmts, 2));
874-
// Try to go through each statement and look to see if can delta debug a try statement more
875-
for (int i = 0; i < interCleanerStmts.size(); i++) {
876-
if (interCleanerStmts.get(i) instanceof TryStmt) {
877-
TryStmt tryStmt = (TryStmt)interCleanerStmts.get(i);
878-
CleanerFixerBlockDeltaDebugger internalDebugger = new CleanerFixerBlockDeltaDebugger(this.project, this.runner, finalHelperMethod, failingOrder, finalPrepend, tryStmt.getTryBlock(), interCleanerStmts);
879-
NodeList<Statement> stmts = NodeList.nodeList();
880-
stmts.addAll(internalDebugger.deltaDebug(tryStmt.getTryBlock().getStatements(), 2));
881-
tryStmt.getTryBlock().setStatements(stmts);
882-
}
883-
}
874+
875+
// Debug each statement further if they contain blocks, so debug within statements in that block(s)
876+
interCleanerStmts = debugFurther(interCleanerStmts, finalHelperMethod, failingOrder, finalPrepend, interCleanerStmts);
884877

885878
// "Unravel" any blocks and potentially debug some more
886879
NodeList<Statement> unraveledCleanerStmts = NodeList.nodeList();
@@ -999,6 +992,80 @@ private PatchResult applyFix(final List<String> failingOrder,
999992
return new PatchResult(elapsedTime.get(0), fixStatus, victimMethod.methodName(), polluterMethod != null ? polluterMethod.methodName() : "N/A", cleanerMethod.methodName(), iterations, patchFile.toString());
1000993
}
1001994

995+
// Debug list of statements even further, if any statement contains blocks
996+
private NodeList<Statement> debugFurther(NodeList<Statement> stmts, JavaMethod helperMethod,
997+
List<String> failingOrder, boolean prepend, NodeList<Statement> stmtsToRun) {
998+
CleanerFixerBlockDeltaDebugger debugger;
999+
1000+
// Iterate through all statements and try to debug further if contain block
1001+
for (int i = 0; i < stmts.size(); i++) {
1002+
Statement stmt = stmts.get(i);
1003+
1004+
if (stmt instanceof BlockStmt) {
1005+
BlockStmt blockStmt = (BlockStmt)stmt;
1006+
1007+
debugger = new CleanerFixerBlockDeltaDebugger(this.project, this.runner, helperMethod, failingOrder, prepend, blockStmt, stmtsToRun);
1008+
NodeList<Statement> minimalBlockStmts = NodeList.nodeList();
1009+
minimalBlockStmts.addAll(debugger.deltaDebug(blockStmt.getStatements(), 2));
1010+
blockStmt.setStatements(minimalBlockStmts);
1011+
1012+
// Debug further nested blocks
1013+
minimalBlockStmts = debugFurther(minimalBlockStmts, helperMethod, failingOrder, prepend, stmtsToRun);
1014+
blockStmt.setStatements(minimalBlockStmts);
1015+
} else if (stmt instanceof TryStmt) {
1016+
TryStmt tryStmt = (TryStmt)stmt;
1017+
1018+
// Do the try block part
1019+
debugger = new CleanerFixerBlockDeltaDebugger(this.project, this.runner, helperMethod, failingOrder, prepend, tryStmt.getTryBlock(), stmtsToRun);
1020+
NodeList<Statement> minimalBlockStmts = NodeList.nodeList();
1021+
minimalBlockStmts.addAll(debugger.deltaDebug(tryStmt.getTryBlock().getStatements(), 2));
1022+
tryStmt.setTryBlock(new BlockStmt(minimalBlockStmts));
1023+
1024+
// Debug further nested blocks
1025+
minimalBlockStmts = debugFurther(minimalBlockStmts, helperMethod, failingOrder, prepend, stmtsToRun);
1026+
tryStmt.setTryBlock(new BlockStmt(minimalBlockStmts));
1027+
1028+
// If has finally block, do that
1029+
if (tryStmt.getFinallyBlock().isPresent()) {
1030+
debugger = new CleanerFixerBlockDeltaDebugger(this.project, this.runner, helperMethod, failingOrder, prepend, tryStmt.getFinallyBlock().get(), stmtsToRun);
1031+
minimalBlockStmts = NodeList.nodeList();
1032+
minimalBlockStmts.addAll(debugger.deltaDebug(tryStmt.getFinallyBlock().get().getStatements(), 2));
1033+
tryStmt.setFinallyBlock(new BlockStmt(minimalBlockStmts));
1034+
1035+
// Debug further nested blocks
1036+
minimalBlockStmts = debugFurther(minimalBlockStmts, helperMethod, failingOrder, prepend, stmtsToRun);
1037+
tryStmt.setFinallyBlock(new BlockStmt(minimalBlockStmts));
1038+
1039+
// If the finally block is empty, remove
1040+
if (minimalBlockStmts.isEmpty()) {
1041+
tryStmt.removeFinallyBlock();
1042+
}
1043+
}
1044+
1045+
// Special case for try: see if we can remove the try and change just to a normal block
1046+
// This can happen if minimized enough statements as to remove the ones that actually throw exceptions
1047+
if (!tryStmt.getFinallyBlock().isPresent()) { // For now, only do if finally block is not there
1048+
BlockStmt blockStmt = new BlockStmt();
1049+
blockStmt.setStatements(tryStmt.getTryBlock().getStatements());
1050+
1051+
// Manipulate list to add this block at that location and remove the try that got shifted next
1052+
stmts.add(i, blockStmt);
1053+
stmts.remove(i + 1);
1054+
1055+
// Use debugger to just check if things work with this block instead of try
1056+
debugger = new CleanerFixerBlockDeltaDebugger(this.project, this.runner, helperMethod, failingOrder, prepend, blockStmt, stmtsToRun);
1057+
if (!debugger.checkValid(blockStmt.getStatements())) {
1058+
// If invalid, we should set the try statement back in
1059+
stmts.add(i, tryStmt);
1060+
stmts.remove(i + 1);
1061+
}
1062+
}
1063+
}
1064+
}
1065+
1066+
return stmts;
1067+
}
1068+
10021069
// Helper method to create a patch file adding in the passed in block
10031070
// Includes a bunch of extra information that may be useful
10041071
private Path writePatch(JavaMethod victimMethod, int begin, BlockStmt blockStmt, int originalsize,

0 commit comments

Comments
 (0)