Match change actions for diffs of C code.
This commit is contained in:
+1
-12
@@ -53,7 +53,7 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
|
||||
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||
HunkActionFilter hunkFilter = new HunkActionFilter();
|
||||
List<DiffEntryHunk> selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets, revFile, prevFile);
|
||||
List<DiffEntryHunk> selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets);
|
||||
|
||||
for (DiffEntryHunk patchHunk : selectedPatchHunks) {
|
||||
List<HierarchicalActionSet> hunkActionSets = patchHunk.getActionSets();
|
||||
@@ -69,8 +69,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
int bugEndPosition = 0;
|
||||
int fixEndPosition = 0;
|
||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||
|
||||
|
||||
//TODO FIX ME
|
||||
int actionBugStart = hunkActionSet.getBugStartLineNum();
|
||||
int actionBugEnd = hunkActionSet.getBugEndLineNum();
|
||||
@@ -102,11 +100,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fixStartLine == 0 && bugStartLine != 0) {// pure delete actions.
|
||||
// get the exact buggy code by violation's position. TODO later
|
||||
}
|
||||
|
||||
// if (children.size() == 0) continue;
|
||||
boolean isPureInsert = false;
|
||||
if (bugStartLine == 0 && patchHunk.getBugLineStartNum() > 0) {
|
||||
bugStartLine = patchHunk.getBugLineStartNum();
|
||||
@@ -141,10 +134,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
|
||||
String patchPosition = "\n" + revFile.getName() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\n";
|
||||
String info = Configuration.PATCH_SIGNAL + "\n" + patchPosition + patchHunk.getHunk() + "\nAST Diff###:\n" + getAstEditScripts(hunkActionSets, bugEndPosition, fixEndPosition) + "\n";
|
||||
//TODO uncomment the line below for more detailed gumtree input
|
||||
// String info = Configuration.PATCH_SIGNAL + "\n" + patchPosition + patchHunk.getHunk() + "\nAST Diff###:\n" + getAstEditScripts(hunkActionSets) + "\n";
|
||||
// if (noUpdate(editScriptTokens)) {
|
||||
// }
|
||||
|
||||
this.patchesSourceCode += info;
|
||||
this.sizes += size + "\n";
|
||||
|
||||
@@ -29,14 +29,14 @@ public class HierarchicalRegrouperForC {
|
||||
|
||||
List<HierarchicalActionSet> actionSets = new ArrayList<>();
|
||||
|
||||
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actionsArgu) {
|
||||
public List<HierarchicalActionSet> regroupGumTreeResults(List<Action> actions) {
|
||||
/*
|
||||
* First, sort actions by their positions.
|
||||
*/
|
||||
List<Action> actions = new ListSorter<Action>(actionsArgu).sortAscending();
|
||||
if (actions == null) {
|
||||
actions = actionsArgu;
|
||||
}
|
||||
// List<Action> actions = new ListSorter<Action>(actionsArgu).sortAscending();
|
||||
// if (actions == null) {
|
||||
// actions = actionsArgu;
|
||||
// }
|
||||
|
||||
/*
|
||||
* Second, group actions by their positions.
|
||||
@@ -82,10 +82,42 @@ public class HierarchicalRegrouperForC {
|
||||
private HierarchicalActionSet createActionSet(Action act, Action parentAct, HierarchicalActionSet parent) {
|
||||
HierarchicalActionSet actionSet = new HierarchicalActionSet();
|
||||
actionSet.setAction(act);
|
||||
actionSet.setActionString(parseAction(act.toString()));
|
||||
String actStr = parseAction(act.toString());
|
||||
actionSet.setActionString(actStr);
|
||||
actionSet.setParentAction(parentAct);
|
||||
actionSet.setNode(act.getNode());
|
||||
actionSet.setParent(parent);
|
||||
|
||||
int bugStartLineNum = 0;
|
||||
int bugEndLineNum = 0;
|
||||
int fixStartLineNum = 0;
|
||||
int fixEndLineNum = 0;
|
||||
if (actStr.startsWith("INS")) {
|
||||
Insert insert = (Insert) act;
|
||||
// int pos = insert.getPos();//index position of the new node in the children array list of its corresponding old parent node.
|
||||
ITree newTree = insert.getNode();
|
||||
fixStartLineNum = newTree.getPos();
|
||||
fixEndLineNum = newTree.getLength();
|
||||
} else {
|
||||
ITree tree = act.getNode();
|
||||
bugStartLineNum = tree.getPos();
|
||||
bugEndLineNum = tree.getLength();
|
||||
if (actStr.startsWith("UPD")) {
|
||||
Update update = (Update) act;
|
||||
ITree newTree = update.getNewNode();
|
||||
fixStartLineNum = newTree.getPos();
|
||||
fixEndLineNum = newTree.getLength();
|
||||
} else if (actStr.startsWith("MOV")) {
|
||||
Move update = (Move) act;
|
||||
ITree newTree = update.getNewNode();
|
||||
fixStartLineNum = newTree.getPos();
|
||||
fixEndLineNum = newTree.getLength();
|
||||
}
|
||||
}
|
||||
actionSet.setBugStartLineNum(bugStartLineNum);
|
||||
actionSet.setBugEndLineNum(bugEndLineNum);
|
||||
actionSet.setFixStartLineNum(fixStartLineNum);
|
||||
actionSet.setFixEndLineNum(fixEndLineNum);
|
||||
return actionSet;
|
||||
}
|
||||
|
||||
@@ -132,7 +164,7 @@ public class HierarchicalRegrouperForC {
|
||||
break;
|
||||
} else {
|
||||
if (isPossibileSubAction(action, act)) {
|
||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2
|
||||
// SubAction range: startPosition2 <= startPosition && length <= length2
|
||||
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
||||
}
|
||||
}
|
||||
@@ -148,7 +180,7 @@ public class HierarchicalRegrouperForC {
|
||||
int startPosition2 = parent.getPosition();
|
||||
int length2 = parent.getLength();
|
||||
|
||||
if (!(startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2)) {
|
||||
if (!(startPosition2 <= startPosition && length <= length2)) {
|
||||
// when act is not the sub-set of action.
|
||||
return false;
|
||||
}
|
||||
@@ -177,7 +209,7 @@ public class HierarchicalRegrouperForC {
|
||||
return true;
|
||||
} else {
|
||||
if (isPossibileSubAction(action, act)) {
|
||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2
|
||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2
|
||||
List<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
|
||||
if (subActionSets.size() > 0) {
|
||||
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
||||
|
||||
@@ -361,8 +361,7 @@ public class HunkActionFilter {
|
||||
* @param prevFile
|
||||
* @return
|
||||
*/
|
||||
public List<DiffEntryHunk> matchActionsByDiffEntryForC(List<DiffEntryHunk> diffentryHunks,
|
||||
List<HierarchicalActionSet> actionSets, File revFile, File prevFile) {
|
||||
public List<DiffEntryHunk> matchActionsByDiffEntryForC(List<DiffEntryHunk> diffentryHunks, List<HierarchicalActionSet> actionSets) {
|
||||
|
||||
List<DiffEntryHunk> selectedViolations = new ArrayList<>();
|
||||
|
||||
@@ -375,22 +374,21 @@ public class HunkActionFilter {
|
||||
for (HierarchicalActionSet actionSet : actionSets) {
|
||||
String actionStr = actionSet.getActionString();
|
||||
if (actionStr.startsWith("INS")) {
|
||||
int actionFixStartLine = actionSet.getStartPosition();
|
||||
int actionFixEndLine = actionSet.getLength();
|
||||
if (fixHunkStartLine <= actionFixEndLine && fixHunkEndLine >= actionFixStartLine ) {
|
||||
int actionFixStartLine = actionSet.getFixStartLineNum();
|
||||
int actionFixEndLine = actionSet.getFixEndLineNum();
|
||||
if (fixHunkStartLine <= actionFixEndLine && actionFixStartLine <= fixHunkEndLine ) {
|
||||
diffentryHunk.getActionSets().add(actionSet);
|
||||
}
|
||||
} else {
|
||||
int actionBugStartLine = actionSet.getStartPosition();
|
||||
int actionBugEndLine = actionSet.getLength();
|
||||
int actionBugStartLine = actionSet.getBugStartLineNum();
|
||||
int actionBugEndLine = actionSet.getBugEndLineNum();
|
||||
|
||||
if (bugHunkStartLine <= actionBugEndLine && bugHunkEndLine >= actionBugStartLine) {
|
||||
if (bugHunkStartLine <= actionBugEndLine && actionBugStartLine <= bugHunkEndLine) {
|
||||
diffentryHunk.getActionSets().add(actionSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (diffentryHunk.getActionSets().size() > 0) {
|
||||
selectedViolations.add(diffentryHunk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user