treedumps
This commit is contained in:
@@ -87,7 +87,7 @@
|
|||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>
|
<mainClass>
|
||||||
edu.lu.uni.serval.FixPatternParser.violations.TestHunkParser
|
edu.lu.uni.serval.FixPatternParser.violations.MultiThreadTreeLoader
|
||||||
</mainClass>
|
</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
|
|||||||
+169
-111
@@ -1,11 +1,12 @@
|
|||||||
package edu.lu.uni.serval.FixPatternParser.violations;
|
package edu.lu.uni.serval.FixPatternParser.violations;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.github.gumtreediff.actions.model.Update;
|
||||||
import com.github.gumtreediff.tree.ITree;
|
import com.github.gumtreediff.tree.ITree;
|
||||||
|
|
||||||
import edu.lu.uni.serval.FixPatternParser.Tokenizer;
|
import edu.lu.uni.serval.FixPatternParser.Tokenizer;
|
||||||
@@ -38,124 +39,181 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
||||||
// GumTree results
|
|
||||||
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile);
|
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile);
|
||||||
if (this.resultType != 0) {
|
|
||||||
// String type = "";
|
|
||||||
// if (this.resultType == 1) {
|
|
||||||
// type = "#NullGumTreeResult:";
|
|
||||||
// } else if (this.resultType == 2) {
|
|
||||||
// type = "#NoSourceCodeChange:";
|
|
||||||
// } else if (this.resultType == 3) {
|
|
||||||
// type = "#NoStatementChange:";
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks3(diffentryFile);
|
|
||||||
|
|
||||||
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
boolean isUpdate =
|
||||||
HunkActionFilter hunkFilter = new HunkActionFilter();
|
actionSets.stream().allMatch(p -> p.getAction() instanceof Update);
|
||||||
List<DiffEntryHunk> selectedPatchHunks = hunkFilter.filterActionsByModifiedRange2(diffentryHunks, actionSets, revFile, prevFile);
|
int hunkSet = 0;
|
||||||
|
if(isUpdate){
|
||||||
|
for (HierarchicalActionSet actionSet : actionSets) {
|
||||||
|
|
||||||
for (DiffEntryHunk patchHunk : selectedPatchHunks) {
|
|
||||||
List<HierarchicalActionSet> hunkActionSets = patchHunk.getActionSets();
|
|
||||||
// multiple UPD, and some UPD contain other UPD.
|
|
||||||
removeOverlapperdUPD(hunkActionSets);
|
|
||||||
|
|
||||||
// Range of buggy source code
|
FileOutputStream f = null;
|
||||||
int bugStartLine = 0;
|
try {
|
||||||
int bugEndLine = 0;
|
String pj = diffentryFile.getParent().split("GumTreeInputBug4")[1];
|
||||||
// Range of fixing source code
|
String root = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2";
|
||||||
int fixStartLine = 0;
|
String hunkTreeFileName = root+pj.replace("DiffEntries","ASTDumps/") + diffentryFile.getName() + "_" + String.valueOf(hunkSet);
|
||||||
int fixEndLine = 0;
|
f = new FileOutputStream(new File(hunkTreeFileName));
|
||||||
int bugEndPosition = 0;
|
ObjectOutputStream o = new ObjectOutputStream(f);
|
||||||
int fixEndPosition = 0;
|
o.writeObject(actionSet.getNode());
|
||||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
|
||||||
int actionBugStart = hunkActionSet.getBugStartLineNum();
|
o.close();
|
||||||
int actionBugEnd = hunkActionSet.getBugEndLineNum();
|
f.close();
|
||||||
int actionFixStart = hunkActionSet.getFixStartLineNum();
|
} catch (FileNotFoundException e) {
|
||||||
int actionFixEnd = hunkActionSet.getFixEndLineNum();
|
e.printStackTrace();
|
||||||
if (bugStartLine == 0) {
|
} catch (IOException e) {
|
||||||
bugStartLine = actionBugStart;
|
e.printStackTrace();
|
||||||
} else if (actionBugStart != 0 && actionBugStart < bugStartLine) {
|
|
||||||
bugStartLine = actionBugStart;
|
|
||||||
}
|
|
||||||
if (fixStartLine == 0) {
|
|
||||||
fixStartLine = actionFixStart;
|
|
||||||
} else if (actionFixStart != 0 && actionFixStart < fixStartLine) {
|
|
||||||
fixStartLine = actionFixStart;
|
|
||||||
}
|
|
||||||
if (bugEndLine < actionBugEnd) {
|
|
||||||
bugEndLine = actionBugEnd;
|
|
||||||
bugEndPosition = hunkActionSet.getBugEndPosition();
|
|
||||||
}
|
|
||||||
if (fixEndLine < actionFixEnd) {
|
|
||||||
fixEndLine = actionFixEnd;
|
|
||||||
fixEndPosition = hunkActionSet.getFixEndPosition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
hunkSet++;
|
||||||
if (fixStartLine == 0 && bugStartLine == 0) {
|
|
||||||
this.unfixedViolations += "#WRONG: " + revFile.getName() + ":" + patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize() + "\n";
|
|
||||||
this.nullMappingGumTreeResult ++;
|
|
||||||
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();
|
|
||||||
bugEndLine = bugStartLine + patchHunk.getBuggyHunkSize() - 1;
|
|
||||||
isPureInsert = true;
|
|
||||||
// continue;
|
|
||||||
}
|
|
||||||
// if ((bugEndLine - bugStartLine > Configuration.HUNK_SIZE ) || fixEndLine - fixStartLine > Configuration.HUNK_SIZE) {
|
|
||||||
// continue; //TODO hunk size
|
|
||||||
// }
|
|
||||||
if(patchHunk.getBuggyHunkSize() > Configuration.HUNK_SIZE || patchHunk.getFixedHunkSize() > Configuration.HUNK_SIZE){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Select edit scripts for deep learning.
|
|
||||||
* Edit scripts will be used to mine common fix patterns.
|
|
||||||
*/
|
|
||||||
// 1. First level: AST node type.
|
|
||||||
String astEditScripts = getASTEditScriptsDeepFirst(hunkActionSets, bugEndPosition, fixEndPosition);
|
|
||||||
if (astEditScripts.contains("\n") || astEditScripts.split(" ").length % 3 != 0) {
|
|
||||||
System.err.println("===+++===: " + revFile.getName() + ":" +patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize());
|
|
||||||
}
|
|
||||||
// 2. source code: raw tokens
|
|
||||||
// 3. abstract identifiers:
|
|
||||||
// 4. semi-source code:
|
|
||||||
String[] editScriptTokens = astEditScripts.split(" ");
|
|
||||||
int size = editScriptTokens.length;
|
|
||||||
if (size == 1) {
|
|
||||||
this.nullMappingGumTreeResult ++;
|
|
||||||
this.unfixedViolations += "#NullMatchedGumTreeResult1:" + revFile.getName() + ":" + patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize() + "\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
String canonicalVariableNames = getBuggyCodeTree(patchHunk, prevFile, revFile);
|
|
||||||
this.patchesSourceCode += info;
|
|
||||||
this.patchesSourceCode += "\nRenamed_Variables###:\n" + canonicalVariableNames;
|
|
||||||
this.sizes += size + "\n";
|
|
||||||
this.astEditScripts += astEditScripts + "\n";
|
|
||||||
// String tokens = Tokenizer.getTokensDeepFirst(simpleTree).trim();
|
|
||||||
// this.tokensOfSourceCode += tokens + "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
||||||
|
// // GumTree results
|
||||||
|
// List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (this.resultType != 0) {
|
||||||
|
//// String type = "";
|
||||||
|
//// if (this.resultType == 1) {
|
||||||
|
//// type = "#NullGumTreeResult:";
|
||||||
|
//// } else if (this.resultType == 2) {
|
||||||
|
//// type = "#NoSourceCodeChange:";
|
||||||
|
//// } else if (this.resultType == 3) {
|
||||||
|
//// type = "#NoStatementChange:";
|
||||||
|
//// }
|
||||||
|
// } else {
|
||||||
|
// List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks3(diffentryFile);
|
||||||
|
//
|
||||||
|
// //Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||||
|
// HunkActionFilter hunkFilter = new HunkActionFilter();
|
||||||
|
// List<DiffEntryHunk> selectedPatchHunks = hunkFilter.filterActionsByModifiedRange2(diffentryHunks, actionSets, revFile, prevFile);
|
||||||
|
//
|
||||||
|
// for (DiffEntryHunk patchHunk : selectedPatchHunks) {
|
||||||
|
// List<HierarchicalActionSet> hunkActionSets = patchHunk.getActionSets();
|
||||||
|
// // multiple UPD, and some UPD contain other UPD.
|
||||||
|
// removeOverlapperdUPD(hunkActionSets);
|
||||||
|
//
|
||||||
|
// // Range of buggy source code
|
||||||
|
// int bugStartLine = 0;
|
||||||
|
// int bugEndLine = 0;
|
||||||
|
// // Range of fixing source code
|
||||||
|
// int fixStartLine = 0;
|
||||||
|
// int fixEndLine = 0;
|
||||||
|
// int bugEndPosition = 0;
|
||||||
|
// int fixEndPosition = 0;
|
||||||
|
// int hunkSet = 0;
|
||||||
|
// for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// FileOutputStream f = null;
|
||||||
|
// try {
|
||||||
|
// String pj = diffentryFile.getParent().split("GumTreeInputBug4")[1];
|
||||||
|
// String root = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2";
|
||||||
|
// String hunkTreeFileName = root+pj.replace("DiffEntries","ASTDumps/") + diffentryFile.getName() + "_" + String.valueOf(hunkSet);
|
||||||
|
// f = new FileOutputStream(new File(hunkTreeFileName));
|
||||||
|
// ObjectOutputStream o = new ObjectOutputStream(f);
|
||||||
|
// o.writeObject(hunkActionSet.getNode());
|
||||||
|
//
|
||||||
|
// o.close();
|
||||||
|
// f.close();
|
||||||
|
// } catch (FileNotFoundException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// hunkSet++;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// int actionBugStart = hunkActionSet.getBugStartLineNum();
|
||||||
|
// int actionBugEnd = hunkActionSet.getBugEndLineNum();
|
||||||
|
// int actionFixStart = hunkActionSet.getFixStartLineNum();
|
||||||
|
// int actionFixEnd = hunkActionSet.getFixEndLineNum();
|
||||||
|
// if (bugStartLine == 0) {
|
||||||
|
// bugStartLine = actionBugStart;
|
||||||
|
// } else if (actionBugStart != 0 && actionBugStart < bugStartLine) {
|
||||||
|
// bugStartLine = actionBugStart;
|
||||||
|
// }
|
||||||
|
// if (fixStartLine == 0) {
|
||||||
|
// fixStartLine = actionFixStart;
|
||||||
|
// } else if (actionFixStart != 0 && actionFixStart < fixStartLine) {
|
||||||
|
// fixStartLine = actionFixStart;
|
||||||
|
// }
|
||||||
|
// if (bugEndLine < actionBugEnd) {
|
||||||
|
// bugEndLine = actionBugEnd;
|
||||||
|
// bugEndPosition = hunkActionSet.getBugEndPosition();
|
||||||
|
// }
|
||||||
|
// if (fixEndLine < actionFixEnd) {
|
||||||
|
// fixEndLine = actionFixEnd;
|
||||||
|
// fixEndPosition = hunkActionSet.getFixEndPosition();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (fixStartLine == 0 && bugStartLine == 0) {
|
||||||
|
// this.unfixedViolations += "#WRONG: " + revFile.getName() + ":" + patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize() + "\n";
|
||||||
|
// this.nullMappingGumTreeResult ++;
|
||||||
|
// 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();
|
||||||
|
// bugEndLine = bugStartLine + patchHunk.getBuggyHunkSize() - 1;
|
||||||
|
// isPureInsert = true;
|
||||||
|
//// continue;
|
||||||
|
// }
|
||||||
|
//// if ((bugEndLine - bugStartLine > Configuration.HUNK_SIZE ) || fixEndLine - fixStartLine > Configuration.HUNK_SIZE) {
|
||||||
|
//// continue; //TODO hunk size
|
||||||
|
//// }
|
||||||
|
// if(patchHunk.getBuggyHunkSize() > Configuration.HUNK_SIZE || patchHunk.getFixedHunkSize() > Configuration.HUNK_SIZE){
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Select edit scripts for deep learning.
|
||||||
|
// * Edit scripts will be used to mine common fix patterns.
|
||||||
|
// */
|
||||||
|
// // 1. First level: AST node type.
|
||||||
|
// String astEditScripts = getASTEditScriptsDeepFirst(hunkActionSets, bugEndPosition, fixEndPosition);
|
||||||
|
// if (astEditScripts.contains("\n") || astEditScripts.split(" ").length % 3 != 0) {
|
||||||
|
// System.err.println("===+++===: " + revFile.getName() + ":" +patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize());
|
||||||
|
// }
|
||||||
|
// // 2. source code: raw tokens
|
||||||
|
// // 3. abstract identifiers:
|
||||||
|
// // 4. semi-source code:
|
||||||
|
// String[] editScriptTokens = astEditScripts.split(" ");
|
||||||
|
// int size = editScriptTokens.length;
|
||||||
|
// if (size == 1) {
|
||||||
|
// this.nullMappingGumTreeResult ++;
|
||||||
|
// this.unfixedViolations += "#NullMatchedGumTreeResult1:" + revFile.getName() + ":" + patchHunk.getBugLineStartNum() + ", " + patchHunk.getBuggyHunkSize() + "\n";
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// 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)) {
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// String canonicalVariableNames = getBuggyCodeTree(patchHunk, prevFile, revFile);
|
||||||
|
// this.patchesSourceCode += info;
|
||||||
|
// this.patchesSourceCode += "\nRenamed_Variables###:\n" + canonicalVariableNames;
|
||||||
|
// this.sizes += size + "\n";
|
||||||
|
// this.astEditScripts += astEditScripts + "\n";
|
||||||
|
//// String tokens = Tokenizer.getTokensDeepFirst(simpleTree).trim();
|
||||||
|
//// this.tokensOfSourceCode += tokens + "\n";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private String getAstEditScripts(List<HierarchicalActionSet> hunkActionSets) {
|
private String getAstEditScripts(List<HierarchicalActionSet> hunkActionSets) {
|
||||||
String scripts = "";
|
String scripts = "";
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package edu.lu.uni.serval.FixPatternParser.violations;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.util.Pair;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by anilkoyuncu on 19/03/2018.
|
||||||
|
*/
|
||||||
|
public class Message implements Serializable{
|
||||||
|
Pair<Integer, String> first;
|
||||||
|
Pair<Integer, String> second;
|
||||||
|
Pair<Pair,Pair> p;
|
||||||
|
|
||||||
|
public Pair<Pair, Pair> getPair() {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPair(Pair<Pair, Pair> p) {
|
||||||
|
this.p = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Message(Integer keyFirst, String valueFirst, Integer keySecond, String valueSecond ){
|
||||||
|
first = new Pair<>(keyFirst,valueFirst);
|
||||||
|
second = new Pair<>(keySecond,valueSecond);
|
||||||
|
p = new Pair<>(first,second);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+168
@@ -0,0 +1,168 @@
|
|||||||
|
package edu.lu.uni.serval.FixPatternParser.violations;
|
||||||
|
|
||||||
|
import akka.actor.ActorRef;
|
||||||
|
import akka.actor.ActorSystem;
|
||||||
|
import com.github.gumtreediff.actions.ActionGenerator;
|
||||||
|
import com.github.gumtreediff.actions.model.Action;
|
||||||
|
import com.github.gumtreediff.matchers.Matcher;
|
||||||
|
import com.github.gumtreediff.matchers.Matchers;
|
||||||
|
import com.github.gumtreediff.tree.ITree;
|
||||||
|
import edu.lu.uni.serval.MultipleThreadsParser.MessageFile;
|
||||||
|
import edu.lu.uni.serval.MultipleThreadsParser.WorkMessage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by anilkoyuncu on 19/03/2018.
|
||||||
|
*/
|
||||||
|
public class MultiThreadTreeLoader {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(MultiThreadTreeLoader.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
String inputPath;
|
||||||
|
String outputPath;
|
||||||
|
if(args.length > 0){
|
||||||
|
inputPath = args[0];
|
||||||
|
outputPath = args[1];
|
||||||
|
}else{
|
||||||
|
inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2/";
|
||||||
|
outputPath = "/Users/anilkoyuncu/bugStudy/dataset/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// String inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2/";
|
||||||
|
File folder = new File(inputPath);
|
||||||
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
Stream<File> stream = Arrays.stream(listOfFiles);
|
||||||
|
List<File> pjs = stream
|
||||||
|
.filter(x -> !x.getName().startsWith("."))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<File> fileToCompare = new ArrayList<>();
|
||||||
|
for (File pj : pjs) {
|
||||||
|
File[] files = pj.listFiles(new FilenameFilter() {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.startsWith("ASTDumps");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Collections.addAll(fileToCompare, files[0].listFiles());
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println("a");
|
||||||
|
// compareAll(fileToCompare);
|
||||||
|
final List<Message> msgFiles = readMessageFiles(fileToCompare);
|
||||||
|
|
||||||
|
FileOutputStream f = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
f = new FileOutputStream(new File(outputPath + "messageFile"));
|
||||||
|
ObjectOutputStream o = new ObjectOutputStream(f);
|
||||||
|
o.writeObject(msgFiles);
|
||||||
|
|
||||||
|
o.close();
|
||||||
|
f.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
List<Message> loaded = null;
|
||||||
|
try {
|
||||||
|
FileInputStream fi = new FileInputStream(new File(outputPath + "messageFile"));
|
||||||
|
ObjectInputStream oi = new ObjectInputStream(fi);
|
||||||
|
loaded = (List<Message>) oi.readObject();
|
||||||
|
oi.close();
|
||||||
|
fi.close();
|
||||||
|
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error initializing stream");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log.info(String.valueOf(msgFiles.size()));
|
||||||
|
log.info(String.valueOf(loaded.size()));
|
||||||
|
// msgFiles.parallelStream()
|
||||||
|
// .forEach(m -> m.dosomething()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// private static coreLoop(){
|
||||||
|
// try {
|
||||||
|
// BufferedWriter writer = new BufferedWriter(new FileWriter("output2.txt", true));
|
||||||
|
// ITree oldTree = getSimpliedTree(treesFileNames.get(i));
|
||||||
|
//
|
||||||
|
// ITree newTree = getSimpliedTree(treesFileNames.get(j));
|
||||||
|
//
|
||||||
|
// Matcher m = Matchers.getInstance().getMatcher(oldTree, newTree);
|
||||||
|
// m.match();
|
||||||
|
//
|
||||||
|
// ActionGenerator ag = new ActionGenerator(oldTree, newTree, m.getMappings());
|
||||||
|
// ag.generate();
|
||||||
|
// List<Action> actions = ag.getActions();
|
||||||
|
// writer.write(String.valueOf(i));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(String.valueOf(j));
|
||||||
|
// writer.write("\t");
|
||||||
|
//
|
||||||
|
// writer.write(String.format("%1.2f", m.chawatheSimilarity(oldTree, newTree)));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(String.format("%1.2f", m.diceSimilarity(oldTree, newTree)));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(String.format("%1.2f", m.jaccardSimilarity(oldTree, newTree)));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(String.valueOf(actions.size()));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(treesFileNames.get(i));
|
||||||
|
// writer.write("\t");
|
||||||
|
// writer.write(treesFileNames.get(j));
|
||||||
|
// writer.write("\n");
|
||||||
|
//
|
||||||
|
// writer.close();
|
||||||
|
// } catch (FileNotFoundException e) {
|
||||||
|
// System.out.println("File not found");
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// System.out.println("Error initializing stream");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private static List<Message> readMessageFiles(List<File> folders) {
|
||||||
|
|
||||||
|
List<String> treesFileNames = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Message> msgFiles = new ArrayList<>();
|
||||||
|
for (File target : folders) {
|
||||||
|
|
||||||
|
treesFileNames.add(target.toString());
|
||||||
|
}
|
||||||
|
log.info("Calculating pairs");
|
||||||
|
|
||||||
|
for (int i = 0; i < treesFileNames.size(); i++) {
|
||||||
|
for (int j = i + 1; j < treesFileNames.size(); j++) {
|
||||||
|
Message msgFile = new Message(i, treesFileNames.get(i), j, treesFileNames.get(j));
|
||||||
|
msgFiles.add(msgFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return msgFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,8 +35,10 @@ public class TestHunkParser {
|
|||||||
inputPath = args[1];
|
inputPath = args[1];
|
||||||
outputPath = args[0] + "/GumTreeOutputBug/";
|
outputPath = args[0] + "/GumTreeOutputBug/";
|
||||||
}else{
|
}else{
|
||||||
inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeInputBug";
|
// inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeInputBug4";
|
||||||
outputPath = "/Users/anilkoyuncu/bugStudy/dataset" + "/GumTreeOutputBug2/";
|
inputPath = "/Volumes/data/bugStudy_backup/dataset/GumTreeInputBug4";
|
||||||
|
// outputPath = "/Users/anilkoyuncu/bugStudy/code/python/GumTreeOutput2/";
|
||||||
|
outputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -57,14 +59,20 @@ public class TestHunkParser {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// List<String> pjList = Arrays.asList("DATAJPA","ZXing","PDE","SWS","SWT", "SWF", "COLLECTIONS", "JDT");
|
||||||
|
|
||||||
for (File target : folders) {
|
for (File target : folders) {
|
||||||
|
String pjName = target.getName();
|
||||||
|
// if (!pjList.contains(pjName)){
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
final List<MessageFile> msgFiles = getMessageFiles(target.toString() + "/"); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/"
|
final List<MessageFile> msgFiles = getMessageFiles(target.toString() + "/"); //"/Users/anilkoyuncu/bugStudy/code/python/GumTreeInput/Apache/CAMEL/"
|
||||||
System.out.println(msgFiles.size());
|
System.out.println(msgFiles.size());
|
||||||
if(msgFiles.size() == 0)
|
if(msgFiles.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
String pjName = target.getName();
|
|
||||||
// output path
|
String GUM_TREE_OUTPUT = outputPath + "/"+ pjName + "/";
|
||||||
String GUM_TREE_OUTPUT = outputPath + pjName + "/";
|
|
||||||
final String editScriptsFilePath = GUM_TREE_OUTPUT + "editScripts.list";
|
final String editScriptsFilePath = GUM_TREE_OUTPUT + "editScripts.list";
|
||||||
final String patchesSourceCodeFilePath =GUM_TREE_OUTPUT + "patchSourceCode.list";
|
final String patchesSourceCodeFilePath =GUM_TREE_OUTPUT + "patchSourceCode.list";
|
||||||
final String buggyTokensFilePath = GUM_TREE_OUTPUT + "tokens.list";
|
final String buggyTokensFilePath = GUM_TREE_OUTPUT + "tokens.list";
|
||||||
@@ -72,7 +80,7 @@ public class TestHunkParser {
|
|||||||
final String alarmTypesFilePath = GUM_TREE_OUTPUT + "alarmTypes.list";
|
final String alarmTypesFilePath = GUM_TREE_OUTPUT + "alarmTypes.list";
|
||||||
|
|
||||||
|
|
||||||
|
FileHelper.createDirectory(GUM_TREE_OUTPUT + "/ASTDumps");
|
||||||
FileHelper.deleteDirectory(editScriptsFilePath);
|
FileHelper.deleteDirectory(editScriptsFilePath);
|
||||||
FileHelper.deleteDirectory(patchesSourceCodeFilePath);
|
FileHelper.deleteDirectory(patchesSourceCodeFilePath);
|
||||||
FileHelper.deleteDirectory(buggyTokensFilePath);
|
FileHelper.deleteDirectory(buggyTokensFilePath);
|
||||||
@@ -106,7 +114,7 @@ public class TestHunkParser {
|
|||||||
alarmTypes.append(parser.getAlarmTypes());
|
alarmTypes.append(parser.getAlarmTypes());
|
||||||
|
|
||||||
a++;
|
a++;
|
||||||
if (a % 10 == 0) {
|
if (a % 100 == 0) {
|
||||||
FileHelper.outputToFile(editScriptsFilePath, astEditScripts, true);
|
FileHelper.outputToFile(editScriptsFilePath, astEditScripts, true);
|
||||||
FileHelper.outputToFile(buggyTokensFilePath, tokens, true);
|
FileHelper.outputToFile(buggyTokensFilePath, tokens, true);
|
||||||
FileHelper.outputToFile(editScriptSizesFilePath, sizes, true);
|
FileHelper.outputToFile(editScriptSizesFilePath, sizes, true);
|
||||||
|
|||||||
@@ -0,0 +1,229 @@
|
|||||||
|
package edu.lu.uni.serval.FixPatternParser.violations;
|
||||||
|
|
||||||
|
import com.github.gumtreediff.actions.ActionGenerator;
|
||||||
|
import com.github.gumtreediff.actions.model.Action;
|
||||||
|
import com.github.gumtreediff.matchers.Mapping;
|
||||||
|
import com.github.gumtreediff.matchers.Matcher;
|
||||||
|
import com.github.gumtreediff.matchers.Matchers;
|
||||||
|
import com.github.gumtreediff.tree.ITree;
|
||||||
|
import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by anilkoyuncu on 17/03/2018.
|
||||||
|
*/
|
||||||
|
public class TestTreeLoader {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
// String inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput/ENTESB/ASTDumps";
|
||||||
|
String inputPath = "/Users/anilkoyuncu/bugStudy/dataset/GumTreeOutput2/";
|
||||||
|
File folder = new File(inputPath);
|
||||||
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
Stream<File> stream = Arrays.stream(listOfFiles);
|
||||||
|
List<File> pjs = stream
|
||||||
|
.filter(x -> !x.getName().startsWith("."))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<File> fileToCompare = new ArrayList<>();
|
||||||
|
for(File pj:pjs){
|
||||||
|
File[] files = pj.listFiles(new FilenameFilter() {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.startsWith("ASTDumps");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Collections.addAll(fileToCompare, files[0].listFiles());
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println("a");
|
||||||
|
// compareAll(fileToCompare);
|
||||||
|
memoryFriendlyCompare(fileToCompare);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ITree getSimpliedTree(String fn) {
|
||||||
|
ITree tree = null;
|
||||||
|
try {
|
||||||
|
FileInputStream fi = new FileInputStream(new File(fn));
|
||||||
|
ObjectInputStream oi = new ObjectInputStream(fi);
|
||||||
|
tree = (ITree) oi.readObject();
|
||||||
|
oi.close();
|
||||||
|
fi.close();
|
||||||
|
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error initializing stream");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
tree.setLabel("");
|
||||||
|
tree.setParent(null);
|
||||||
|
List<ITree> descendants = tree.getDescendants();
|
||||||
|
for (ITree descendant : descendants) {
|
||||||
|
descendant.setLabel("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree;
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void memoryFriendlyCompare(List<File> folders){
|
||||||
|
List<String> treesFileNames = new ArrayList<>();
|
||||||
|
// HashMap<Integer, String> hmap = new HashMap<Integer, String>();
|
||||||
|
|
||||||
|
for (File target : folders) {
|
||||||
|
// hmap.put(folders.indexOf(target), target.toString());
|
||||||
|
treesFileNames.add(target.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < treesFileNames.size(); i++) {
|
||||||
|
for (int j = i + 1; j < treesFileNames.size(); j++) {
|
||||||
|
// compare list.get(i) and list.get(j)
|
||||||
|
try {
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter("output2.txt", true));
|
||||||
|
ITree oldTree = getSimpliedTree(treesFileNames.get(i));
|
||||||
|
|
||||||
|
ITree newTree = getSimpliedTree(treesFileNames.get(j));
|
||||||
|
|
||||||
|
Matcher m = Matchers.getInstance().getMatcher(oldTree, newTree);
|
||||||
|
m.match();
|
||||||
|
|
||||||
|
ActionGenerator ag = new ActionGenerator(oldTree, newTree, m.getMappings());
|
||||||
|
ag.generate();
|
||||||
|
List<Action> actions = ag.getActions();
|
||||||
|
writer.write(String.valueOf(i));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.valueOf(j));
|
||||||
|
writer.write("\t");
|
||||||
|
|
||||||
|
writer.write(String.format("%1.2f", m.chawatheSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.format("%1.2f", m.diceSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.format("%1.2f", m.jaccardSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.valueOf(actions.size()));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(treesFileNames.get(i));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(treesFileNames.get(j));
|
||||||
|
writer.write("\n");
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error initializing stream");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void compareAll(List<File> folders){
|
||||||
|
List<ITree> trees = new ArrayList<>();
|
||||||
|
HashMap<Integer, String> hmap = new HashMap<Integer, String>();
|
||||||
|
for (File target : folders) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileInputStream fi = new FileInputStream(new File(target.toString()));
|
||||||
|
ObjectInputStream oi = new ObjectInputStream(fi);
|
||||||
|
ITree pr1 = (ITree) oi.readObject();
|
||||||
|
oi.close();
|
||||||
|
fi.close();
|
||||||
|
trees.add(pr1);
|
||||||
|
hmap.put(folders.indexOf(target), target.toString());
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error initializing stream");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ITree tree : trees) {
|
||||||
|
// SimplifyTree simplifyTree = new SimplifyTree();
|
||||||
|
// simplifyTree.canonicalizeSourceCodeTree(tree);
|
||||||
|
tree.setLabel("");
|
||||||
|
tree.setParent(null);
|
||||||
|
List<ITree> descendants = tree.getDescendants();
|
||||||
|
for (ITree descendant : descendants) {
|
||||||
|
descendant.setLabel("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println("a");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < trees.size(); i++) {
|
||||||
|
for (int j = i + 1; j < trees.size(); j++) {
|
||||||
|
// compare list.get(i) and list.get(j)
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt",true));
|
||||||
|
ITree oldTree = trees.get(i);
|
||||||
|
|
||||||
|
ITree newTree = trees.get(j);
|
||||||
|
|
||||||
|
Matcher m = Matchers.getInstance().getMatcher(oldTree, newTree);
|
||||||
|
m.match();
|
||||||
|
|
||||||
|
ActionGenerator ag = new ActionGenerator(oldTree, newTree, m.getMappings());
|
||||||
|
ag.generate();
|
||||||
|
List<Action> actions = ag.getActions();
|
||||||
|
writer.write(String.valueOf(i));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.valueOf(j));
|
||||||
|
writer.write("\t");
|
||||||
|
|
||||||
|
writer.write(String.format("%1.2f", m.chawatheSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.format("%1.2f", m.diceSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.format("%1.2f", m.jaccardSimilarity(oldTree, newTree)));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(String.valueOf(actions.size()));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(hmap.get(i));
|
||||||
|
writer.write("\t");
|
||||||
|
writer.write(hmap.get(j));
|
||||||
|
writer.write("\n");
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error initializing stream");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (actions.size() > 1) {
|
||||||
|
// Matcher m1 = Matchers.getInstance().getMatcher(actions.get(0).getNode(), actions.get(0).getNode());
|
||||||
|
// m1.match();
|
||||||
|
// Set<Mapping> mappingSet1 = m1.getMappingSet();
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ public class Configuration {
|
|||||||
|
|
||||||
|
|
||||||
// the output path of GumTree results.
|
// the output path of GumTree results.
|
||||||
private static final String GUM_TREE_OUTPUT = ROOT_PATH + "GumTreeResults/";
|
public static final String GUM_TREE_OUTPUT = ROOT_PATH + "GumTreeResults/";
|
||||||
public static final String EDITSCRIPTS_FILE_PATH = GUM_TREE_OUTPUT + "editScripts/";
|
public static final String EDITSCRIPTS_FILE_PATH = GUM_TREE_OUTPUT + "editScripts/";
|
||||||
public static final String PATCH_SOURCECODE_FILE_PATH = GUM_TREE_OUTPUT + "sourceCode/";
|
public static final String PATCH_SOURCECODE_FILE_PATH = GUM_TREE_OUTPUT + "sourceCode/";
|
||||||
public static final String BUGGYTREE_FILE_PATH = GUM_TREE_OUTPUT + "buggyTrees/";
|
public static final String BUGGYTREE_FILE_PATH = GUM_TREE_OUTPUT + "buggyTrees/";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package edu.lu.uni.serval.gumtree.regroup;
|
package edu.lu.uni.serval.gumtree.regroup;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ import com.github.gumtreediff.tree.ITree;
|
|||||||
* @author kui.liu
|
* @author kui.liu
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HierarchicalActionSet implements Comparable<HierarchicalActionSet> {
|
public class HierarchicalActionSet implements Comparable<HierarchicalActionSet>,Serializable {
|
||||||
|
|
||||||
private String astNodeType;
|
private String astNodeType;
|
||||||
private Action action;
|
private Action action;
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class HierarchicalRegrouper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return reActionSets;
|
return reActionSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user