diff --git a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/FixedViolationHunkParser.java b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/FixedViolationHunkParser.java index 392b10b..78bbc01 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/FixedViolationHunkParser.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternParser/violations/FixedViolationHunkParser.java @@ -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 selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets, revFile, prevFile); + List selectedPatchHunks = hunkFilter.matchActionsByDiffEntryForC(diffentryHunks, actionSets); for (DiffEntryHunk patchHunk : selectedPatchHunks) { List 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"; diff --git a/src/main/java/edu/lu/uni/serval/gumtree/regroup/HierarchicalRegrouperForC.java b/src/main/java/edu/lu/uni/serval/gumtree/regroup/HierarchicalRegrouperForC.java index 34db1c8..d98ef8f 100644 --- a/src/main/java/edu/lu/uni/serval/gumtree/regroup/HierarchicalRegrouperForC.java +++ b/src/main/java/edu/lu/uni/serval/gumtree/regroup/HierarchicalRegrouperForC.java @@ -29,14 +29,14 @@ public class HierarchicalRegrouperForC { List actionSets = new ArrayList<>(); - public List regroupGumTreeResults(List actionsArgu) { + public List regroupGumTreeResults(List actions) { /* * First, sort actions by their positions. */ - List actions = new ListSorter(actionsArgu).sortAscending(); - if (actions == null) { - actions = actionsArgu; - } +// List actions = new ListSorter(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 subActionSets = actionSet.getSubActions(); if (subActionSets.size() > 0) { boolean added = addToAactionSet(act, parentAct, subActionSets); diff --git a/src/main/java/edu/lu/uni/serval/gumtree/regroup/HunkActionFilter.java b/src/main/java/edu/lu/uni/serval/gumtree/regroup/HunkActionFilter.java index a9ac36b..f986f33 100644 --- a/src/main/java/edu/lu/uni/serval/gumtree/regroup/HunkActionFilter.java +++ b/src/main/java/edu/lu/uni/serval/gumtree/regroup/HunkActionFilter.java @@ -361,8 +361,7 @@ public class HunkActionFilter { * @param prevFile * @return */ - public List matchActionsByDiffEntryForC(List diffentryHunks, - List actionSets, File revFile, File prevFile) { + public List matchActionsByDiffEntryForC(List diffentryHunks, List actionSets) { List 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); }