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.
|
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||||
HunkActionFilter hunkFilter = new HunkActionFilter();
|
HunkActionFilter hunkFilter = new HunkActionFilter();
|
||||||
List<DiffEntryHunk> selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets, revFile, prevFile);
|
List<DiffEntryHunk> selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets);
|
||||||
|
|
||||||
for (DiffEntryHunk patchHunk : selectedPatchHunks) {
|
for (DiffEntryHunk patchHunk : selectedPatchHunks) {
|
||||||
List<HierarchicalActionSet> hunkActionSets = patchHunk.getActionSets();
|
List<HierarchicalActionSet> hunkActionSets = patchHunk.getActionSets();
|
||||||
@@ -69,8 +69,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
int bugEndPosition = 0;
|
int bugEndPosition = 0;
|
||||||
int fixEndPosition = 0;
|
int fixEndPosition = 0;
|
||||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||||
|
|
||||||
|
|
||||||
//TODO FIX ME
|
//TODO FIX ME
|
||||||
int actionBugStart = hunkActionSet.getBugStartLineNum();
|
int actionBugStart = hunkActionSet.getBugStartLineNum();
|
||||||
int actionBugEnd = hunkActionSet.getBugEndLineNum();
|
int actionBugEnd = hunkActionSet.getBugEndLineNum();
|
||||||
@@ -102,11 +100,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
continue;
|
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;
|
boolean isPureInsert = false;
|
||||||
if (bugStartLine == 0 && patchHunk.getBugLineStartNum() > 0) {
|
if (bugStartLine == 0 && patchHunk.getBugLineStartNum() > 0) {
|
||||||
bugStartLine = patchHunk.getBugLineStartNum();
|
bugStartLine = patchHunk.getBugLineStartNum();
|
||||||
@@ -141,10 +134,6 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
|
|
||||||
String patchPosition = "\n" + revFile.getName() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\n";
|
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";
|
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.patchesSourceCode += info;
|
||||||
this.sizes += size + "\n";
|
this.sizes += size + "\n";
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ public class HierarchicalRegrouperForC {
|
|||||||
|
|
||||||
List<HierarchicalActionSet> actionSets = new ArrayList<>();
|
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.
|
* First, sort actions by their positions.
|
||||||
*/
|
*/
|
||||||
List<Action> actions = new ListSorter<Action>(actionsArgu).sortAscending();
|
// List<Action> actions = new ListSorter<Action>(actionsArgu).sortAscending();
|
||||||
if (actions == null) {
|
// if (actions == null) {
|
||||||
actions = actionsArgu;
|
// actions = actionsArgu;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Second, group actions by their positions.
|
* Second, group actions by their positions.
|
||||||
@@ -82,10 +82,42 @@ public class HierarchicalRegrouperForC {
|
|||||||
private HierarchicalActionSet createActionSet(Action act, Action parentAct, HierarchicalActionSet parent) {
|
private HierarchicalActionSet createActionSet(Action act, Action parentAct, HierarchicalActionSet parent) {
|
||||||
HierarchicalActionSet actionSet = new HierarchicalActionSet();
|
HierarchicalActionSet actionSet = new HierarchicalActionSet();
|
||||||
actionSet.setAction(act);
|
actionSet.setAction(act);
|
||||||
actionSet.setActionString(parseAction(act.toString()));
|
String actStr = parseAction(act.toString());
|
||||||
|
actionSet.setActionString(actStr);
|
||||||
actionSet.setParentAction(parentAct);
|
actionSet.setParentAction(parentAct);
|
||||||
actionSet.setNode(act.getNode());
|
actionSet.setNode(act.getNode());
|
||||||
actionSet.setParent(parent);
|
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;
|
return actionSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +164,7 @@ public class HierarchicalRegrouperForC {
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (isPossibileSubAction(action, act)) {
|
if (isPossibileSubAction(action, act)) {
|
||||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2
|
// SubAction range: startPosition2 <= startPosition && length <= length2
|
||||||
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +180,7 @@ public class HierarchicalRegrouperForC {
|
|||||||
int startPosition2 = parent.getPosition();
|
int startPosition2 = parent.getPosition();
|
||||||
int length2 = parent.getLength();
|
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.
|
// when act is not the sub-set of action.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -177,7 +209,7 @@ public class HierarchicalRegrouperForC {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (isPossibileSubAction(action, act)) {
|
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();
|
List<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
|
||||||
if (subActionSets.size() > 0) {
|
if (subActionSets.size() > 0) {
|
||||||
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
||||||
|
|||||||
@@ -361,8 +361,7 @@ public class HunkActionFilter {
|
|||||||
* @param prevFile
|
* @param prevFile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<DiffEntryHunk> matchActionsByDiffEntryForC(List<DiffEntryHunk> diffentryHunks,
|
public List<DiffEntryHunk> matchActionsByDiffEntryForC(List<DiffEntryHunk> diffentryHunks, List<HierarchicalActionSet> actionSets) {
|
||||||
List<HierarchicalActionSet> actionSets, File revFile, File prevFile) {
|
|
||||||
|
|
||||||
List<DiffEntryHunk> selectedViolations = new ArrayList<>();
|
List<DiffEntryHunk> selectedViolations = new ArrayList<>();
|
||||||
|
|
||||||
@@ -375,22 +374,21 @@ public class HunkActionFilter {
|
|||||||
for (HierarchicalActionSet actionSet : actionSets) {
|
for (HierarchicalActionSet actionSet : actionSets) {
|
||||||
String actionStr = actionSet.getActionString();
|
String actionStr = actionSet.getActionString();
|
||||||
if (actionStr.startsWith("INS")) {
|
if (actionStr.startsWith("INS")) {
|
||||||
int actionFixStartLine = actionSet.getStartPosition();
|
int actionFixStartLine = actionSet.getFixStartLineNum();
|
||||||
int actionFixEndLine = actionSet.getLength();
|
int actionFixEndLine = actionSet.getFixEndLineNum();
|
||||||
if (fixHunkStartLine <= actionFixEndLine && fixHunkEndLine >= actionFixStartLine ) {
|
if (fixHunkStartLine <= actionFixEndLine && actionFixStartLine <= fixHunkEndLine ) {
|
||||||
diffentryHunk.getActionSets().add(actionSet);
|
diffentryHunk.getActionSets().add(actionSet);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int actionBugStartLine = actionSet.getStartPosition();
|
int actionBugStartLine = actionSet.getBugStartLineNum();
|
||||||
int actionBugEndLine = actionSet.getLength();
|
int actionBugEndLine = actionSet.getBugEndLineNum();
|
||||||
|
|
||||||
if (bugHunkStartLine <= actionBugEndLine && bugHunkEndLine >= actionBugStartLine) {
|
if (bugHunkStartLine <= actionBugEndLine && actionBugStartLine <= bugHunkEndLine) {
|
||||||
diffentryHunk.getActionSets().add(actionSet);
|
diffentryHunk.getActionSets().add(actionSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (diffentryHunk.getActionSets().size() > 0) {
|
if (diffentryHunk.getActionSets().size() > 0) {
|
||||||
selectedViolations.add(diffentryHunk);
|
selectedViolations.add(diffentryHunk);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user