Skip to content

Commit

Permalink
Fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kimseokjin committed Jun 13, 2020
1 parent e127e12 commit 267e158
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 118 deletions.
10 changes: 4 additions & 6 deletions src/main/java/hgu/csee/isel/alinew/szz/AGSZZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ public void run() throws IOException {
AnnotationGraphModel agm = agb.buildAnnotationGraph(repo, revsWithPath, debug);

final long endBuildingTime = System.currentTimeMillis();
System.out.println(
"\nBuilding Annotation Graph takes " + (endBuildingTime - startBuildingTime) / 1000.0 + "s\n");
System.out.println("\nBuilding Annotation Graph takes " + (endBuildingTime - startBuildingTime) / 1000.0 + "s\n");

// Phase 2 : Trace and collect BIC candidates and filter out format changes,
// comments, etc among candidates
// Phase 2 : Trace and collect BIC candidates and filter out format changes, comments, etc among candidates
final long startTracingTime = System.currentTimeMillis();

Tracer tracer = new Tracer(analysis);
List<BICInfo> BILines = tracer.collectBILines(repo, bfcList, agm, revsWithPath, debug);
Tracer tracer = new Tracer(analysis,debug);
List<BICInfo> BILines = tracer.collectBILines(repo, bfcList, agm, revsWithPath);

final long endTracingTime = System.currentTimeMillis();
System.out.println("\nCollecting BICs takes " + (endTracingTime - startTracingTime) / 1000.0 + "s\n");
Expand Down
42 changes: 28 additions & 14 deletions src/main/java/hgu/csee/isel/alinew/szz/AGSZZRunner.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package hgu.csee.isel.alinew.szz;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -35,17 +32,34 @@ public static void main(String[] args) {
private Options createOptions() {
Options options = new Options();

options.addOption(Option.builder("u").longOpt("url").desc("Git URL (ex. https://github.com/SukJinKim/AG-SZZ)")
.hasArg().required(true).build());

options.addOption(Option.builder("b").longOpt("bugFix").desc("Path of file that has bug fix issue keys")
.hasArg().required(true).build());

options.addOption(Option.builder("d").longOpt("debug").desc("Debug Mode").build());

options.addOption(Option.builder("a").longOpt("analysis").desc("Analysis Mode").build());

options.addOption(Option.builder("h").longOpt("help").desc("Help").build());
options.addOption(Option.builder("u")
.longOpt("url")
.desc("Git URL (ex. https://github.com/SukJinKim/AG-SZZ)")
.hasArg()
.required(true)
.build());

options.addOption(Option.builder("b")
.longOpt("bugFix")
.desc("Path of file that has bug fix issue keys")
.hasArg()
.required(true)
.build());

options.addOption(Option.builder("d")
.longOpt("debug")
.desc("Debug Mode")
.build());

options.addOption(Option.builder("a")
.longOpt("analysis")
.desc("Analysis Mode")
.build());

options.addOption(Option.builder("h")
.longOpt("help")
.desc("Help")
.build());

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AnnotationGraphModel buildAnnotationGraph(Repository repo, RevsWithPath r
executor.shutdown(); // no new tasks will be accepted.

while (!executor.isTerminated()) {

}

AnnotationGraphModel annotationGraph = new AnnotationGraphModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void run() {
} catch (IndexOutOfBoundsException e) {
// TODO Logging


}
}

Expand All @@ -69,14 +68,12 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
while (paths.hasNext()) {

String path = paths.next();

// For Debugging
debug = path.equals("zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java");

List<RevCommit> revs = revsWithPath.get(path);

// Skip building AG when the number of paths is 1 as it's not appropriate
if(revs.size() == 1) continue;
if(revs.size() == 1)
continue;

// Generate subAnnotationGraph
HashMap<RevCommit, ArrayList<Line>> subAnnotationGraph = new HashMap<RevCommit, ArrayList<Line>>();
Expand All @@ -90,8 +87,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re

for (RevCommit childRev : revs) {
// Escape from the loop when there is no parent rev anymore
if (revs.indexOf(childRev) == revs.size() - 1)
break;
if (revs.indexOf(childRev) == revs.size() - 1) break;

RevCommit parentRev = revs.get(revs.indexOf(childRev) + 1);

Expand Down Expand Up @@ -131,7 +127,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
offset = 0;

while (childIdx < childLineList.size()) {

boolean isIgnorable = false;
childLine = childLineList.get(childIdx);

if (debug) {
Expand All @@ -143,8 +139,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
// Case 1 - when there is no hunk anymore
if (hunkList.size() <= hunkIdx) {
if (debug) {
System.out.println("Connected parent index : " + (childIdx + offset) + " / "
+ (parentLineList.size() - 1));
System.out.println("Connected parent index : " + (childIdx + offset) + " / " + (parentLineList.size() - 1));
System.out.println("No Hunk anymore\n");
}
childLine.setLineType(LineType.CONTEXT);
Expand All @@ -171,8 +166,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
// Case 2 - child index is out of hunk range
if (childIdx < beginOfChild) {
if (debug) {
System.out.println("Connected parent index : " + (childIdx + offset) + " / "
+ (parentLineList.size() - 1));
System.out.println("Connected parent index : " + (childIdx + offset) + " / " + (parentLineList.size() - 1));
System.out.println("Out of Hunk range\n");

}
Expand All @@ -189,7 +183,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
}

// When childIdx is the last index in hunk, increment hunk index
if (childIdx == endOfChild - 1)
if (childIdx == endOfChild - 1)
hunkIdx++;

childLine.setLineType(LineType.INSERT);
Expand All @@ -215,7 +209,7 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
String mergedParentContent = Utils.mergeLineList(parentLineList.subList(hunk.getBeginOfParent(), hunk.getEndOfParent()));
String mergedChildContent = Utils.mergeLineList(childLineList.subList(hunk.getBeginOfChild(), hunk.getEndOfChild()));

if (mergedParentContent.equals(mergedChildContent))
if (mergedParentContent.equals(mergedChildContent))
childLine.setFormatChange(true);

childLine.setLineType(LineType.REPLACE);
Expand All @@ -226,52 +220,29 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re

case "DELETE":
// If the last child line is in DELETE, it maps with nothing
if (childIdx == childLineList.size() - 1) break;

// If the begin of child belongs to both DELETE and INSERT
if (belongsToBothDELETEAndINSERT(hunkList, hunkIdx, beginOfChild)) {
offset += hunk.getRangeOfParent() - 1;
if (childIdx == childLineList.size() - 1)
break;

// If the begin of child belongs to both DELETE and INSERT or both DELETE and REPALCE
if (belongsToBothDELETEAndINSERT(hunkList, hunkIdx, beginOfChild) || belongsToBothDELETEAndREPLACE(hunkList, hunkIdx, beginOfChild)) {
offset += hunk.getRangeOfParent();

childLine.setLineType(LineType.INSERT);
childLine.setWithinHunk(true);
hunkIdx++;

if (debug) {
System.out.println("INSERT\n");
}

isIgnorable = true; // Iteration can be ignored in this situation.

break;
}

// If the begin of child belongs to both DELETE and REPLACE
// if (belongsToBothDELETEAndREPLACE(hunkList, hunkIdx, beginOfChild)) {
// // TODO implement setting offset
//
//
// childLine.setLineType(LineType.REPLACE);
// childLine.setWithinHunk(true);
// mapChildLineWithAncestors(hunk, parentLineList, childLine);
//
// hunkIdx++;
//
// if (debug) {
// System.out.println("REPLACE\n");
// }
//
// break;
// }

offset += hunk.getRangeOfParent();

childLine.setLineType(LineType.CONTEXT);
// childLine.setWithinHunk(true);
mapChildLineWithAncestor(childIdx, offset, parentLineList, childLine);

hunkIdx++;

if (debug) {
System.out.println("Connected parent index : " + (childIdx + offset) + " / "
+ (parentLineList.size() - 1));
System.out.println("Connected parent index : " + (childIdx + offset) + " / " + (parentLineList.size() - 1));
System.out.println("DELETE\n");
}

Expand All @@ -281,8 +252,9 @@ private AnnotationGraphModel buildPartitionedAnnotationGraph(Repository repo, Re
throw new EmptyHunkTypeException();
}
}

childIdx++;
if(!isIgnorable) {
childIdx++;
}
}

// put lists of line corresponding to commit into subAG
Expand Down Expand Up @@ -351,30 +323,26 @@ private ArrayList<Hunk> configureHunkList(EditList editList) {
ArrayList<Hunk> hunkList = new ArrayList<>();

for (Edit edit : editList) {
Hunk hunk = new Hunk(edit.getType().toString(), edit.getBeginA(), edit.getEndA(), edit.getBeginB(),
edit.getEndB());

Hunk hunk = new Hunk(edit.getType().toString(), edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB());

hunkList.add(hunk);
}

return hunkList;
}

private void mapChildLineWithAncestor(int childIdx, int offset, List<Line> parentLineList, Line childLine) {
Line ancestor;
List<Line> ancestorsOfChild;

ancestor = parentLineList.get(childIdx + offset);
ancestorsOfChild = childLine.getAncestors();
Line ancestor = parentLineList.get(childIdx + offset);
List<Line> ancestorsOfChild = childLine.getAncestors();

ancestorsOfChild.add(ancestor);
childLine.setAncestors(ancestorsOfChild);
}

private void mapChildLineWithAncestors(Hunk hunk, List<Line> parentLineList, Line childLine) {

List<Line> ancestorsOfChild = parentLineList.subList(hunk.getBeginOfParent(), hunk.getEndOfParent());

childLine.setAncestors(ancestorsOfChild);

}

}
Loading

0 comments on commit 267e158

Please sign in to comment.