This commit is contained in:
Kui LIU
2017-09-14 23:11:09 +02:00
parent 6a03af9fea
commit 72116994e4
5 changed files with 45 additions and 35 deletions
@@ -68,9 +68,8 @@ public class FixedViolationHunkParser extends FixedViolationParser {
for (Violation v : violations) {
System.err.println(type + revFile.getName().replace("#", "/") + ":" + v.getStartLineNum() + ":" + v.getEndLineNum() + ":" + v.getAlarmType());
}
return;
} else {
// }
// if (actionSets != null && actionSets.size() != 0) {
if (violations.size() == 0) {
this.resultType = 4;
return;
@@ -197,7 +196,7 @@ public class FixedViolationHunkParser extends FixedViolationParser {
if (fixStartLine == 0) {
// pure delete actions.
this.pureDeletions ++;
System.err.println("#PureDeletion: " + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
System.err.println("#PureDeletion:" + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
+ ":" + violation.getEndLineNum() + ":" + violation.getAlarmType());
// continue;
}
@@ -221,8 +220,8 @@ public class FixedViolationHunkParser extends FixedViolationParser {
// continue;
}
if (bugEndLine - bugStartLine > Configuration.HUNK_SIZE || fixEndLine - fixStartLine > Configuration.HUNK_SIZE) {
this.largeHunk ++;
if (fixStartLine != 0) {
this.largeHunk ++;
System.err.println("#LargeHunk:" + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
+ ":" + violation.getEndLineNum() + ":" + violation.getAlarmType());
}
@@ -235,8 +234,8 @@ public class FixedViolationHunkParser extends FixedViolationParser {
// Source Code of patches.
String patchSourceCode = getPatchSourceCode(prevFile, revFile, bugStartLine, bugEndLine, fixStartLine, fixEndLine, isInsert);
if ("".equals(patchSourceCode)) {
this.nullSourceCode ++;
if (fixStartLine != 0) {
this.nullSourceCode ++;
System.err.println("#NullSourceCode:" + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
+ ":" + violation.getEndLineNum() + ":" + violation.getAlarmType());
}
@@ -270,8 +269,8 @@ public class FixedViolationHunkParser extends FixedViolationParser {
if (!"SE_NO_SERIALVERSIONID".equals(alarmType)) {
if (containsFiledDeclaration(hunkActionSets)) {
// this.nullMappingGumTreeResult ++; //TODO
this.testingInfo += info + revFile.getName() + "\n";
if (fixStartLine != 0) {
this.testingInfo += info + revFile.getName() + "\n";
this.testingInfo += "#TestingInfo: " + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
+ ":" + violation.getEndLineNum() + ":" + violation.getAlarmType();
}
@@ -293,8 +292,8 @@ public class FixedViolationHunkParser extends FixedViolationParser {
} else {
// this.nullMappingGumTreeResult ++; // TODO
this.testingInfo += info + revFile.getName() + "\n";
if (fixStartLine != 0) {
this.testingInfo += info + revFile.getName() + "\n";
this.testingInfo += "#TestingInfo: " + revFile.getName().replace("#", "/") + ":" + violation.getStartLineNum()
+ ":" + violation.getEndLineNum() + ":" + violation.getAlarmType();
}
@@ -7,9 +7,6 @@ import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.gumtreediff.actions.model.Action;
import edu.lu.uni.serval.FixPatternParser.Parser;
@@ -27,8 +24,6 @@ import edu.lu.uni.serval.utils.ListSorter;
*/
public class FixedViolationParser extends Parser {
private static Logger log = LoggerFactory.getLogger(FixedViolationParser.class);
/*
* ResultType:
* 0: normal GumTree results.
@@ -83,15 +83,18 @@ public class ParseFixPatternWorker extends UntypedActor {
int largeHunk = 0;
int nullSourceCode = 0;
int illegalV = 0;
// Read violations with Null_Violation_Hunk or Illegal_Line_Position
List<Violation> uselessViolations = readUselessViolations("logs/FixedViolationCodeParseResults.log");
for (MessageFile msgFile : files) {
File revFile = msgFile.getRevFile();
File prevFile = msgFile.getPrevFile();
File diffentryFile = msgFile.getDiffEntryFile();
File positionFile = msgFile.getPositionFile();
if (revFile.getName().toLowerCase().contains("test")) {
testAlarms += countAlarms(positionFile, "#TestViolation:");
// continue;
if (revFile.getName().toLowerCase().contains("/test/")) {
testAlarms += countAlarms(positionFile, "#TestViolation:", uselessViolations);
continue;
}
// Parser parser = null;
// if (containsAlarmTypes || positionFile != null) {
@@ -101,8 +104,6 @@ public class ParseFixPatternWorker extends UntypedActor {
// parser = new CommitPatchSingleStatementParser();
// }
FixedViolationHunkParser parser = new FixedViolationHunkParser(positionFile);
// Read violations with Null_Violation_Hunk or Illegal_Line_Position
List<Violation> uselessViolations = readUselessViolations("logs/FixedViolationCodeParseResults.log");
parser.setUselessViolations(uselessViolations);
final ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -121,14 +122,14 @@ public class ParseFixPatternWorker extends UntypedActor {
String editScript = parser.getAstEditScripts();
if ("".equals(editScript)) {
if (parser.resultType == 1) {
nullGumTreeResults += countAlarms(positionFile, "");
nullGumTreeResults += countAlarms(positionFile, "", uselessViolations);
// System.err.println("#NullGumTreeResult:" + revFile.getName());
} else if (parser.resultType == 2) {
noSourceCodeChanges += countAlarms(positionFile, "");
noSourceCodeChanges += countAlarms(positionFile, "", uselessViolations);
} else if (parser.resultType == 3) {
noStatementChanges += countAlarms(positionFile, "");
noStatementChanges += countAlarms(positionFile, "", uselessViolations);
} else if (parser.resultType == 4) {
illegalV += countAlarms(positionFile, "");
// illegalV += countAlarms(positionFile, "", uselessViolations);
}
} else {
editScripts.append(editScript);
@@ -158,14 +159,14 @@ public class ParseFixPatternWorker extends UntypedActor {
} catch (TimeoutException e) {
// err.println("task timed out");
future.cancel(true);
expNums += countAlarms(positionFile, "#Timeout:");
expNums += countAlarms(positionFile, "#Timeout:", uselessViolations);
// System.err.println("#Timeout: " + revFile.getName());
} catch (InterruptedException e) {
expNums += countAlarms(positionFile, "#TimeInterrupted:");
expNums += countAlarms(positionFile, "#TimeInterrupted:", uselessViolations);
// err.println("task interrupted");
// System.err.println("#TimeInterrupted: " + revFile.getName());
} catch (ExecutionException e) {
expNums += countAlarms(positionFile, "#TimeAborted:");
expNums += countAlarms(positionFile, "#TimeAborted:", uselessViolations);
// err.println("task aborted");
// System.err.println("#TimeAborted: " + revFile.getName());
} finally {
@@ -233,17 +234,25 @@ public class ParseFixPatternWorker extends UntypedActor {
return uselessViolations;
}
private int countAlarms(File positionFile, String type) {
private int countAlarms(File positionFile, String type, List<Violation> uselessViolations) {
int counter = 0;
String content = FileHelper.readFile(positionFile);
BufferedReader reader = new BufferedReader(new StringReader(content));
String line = null;
try {
while ((line = reader.readLine()) != null) {
counter ++;
if (!"".equals(type)) {
String[] elements = line.split(":");
System.err.println(type + positionFile.getName().replaceAll("#", "/").replace(".txt", ".java") + ":" + elements[1] + ":" + elements[2] + ":" + elements[0]);
String[] elements = line.split(":");
Violation v = new Violation(Integer.parseInt(elements[1]), Integer.parseInt(elements[2]), elements[0]);
String fileName = positionFile.getName().replaceAll("#", "/").replace(".txt", ".java");
v.setFileName(fileName);
if (!uselessViolations.contains(v)) {
counter ++;
if (!"".equals(type)) {
if (!uselessViolations.contains(v)) {
System.err.println(type + fileName + ":" + elements[1] + ":" + elements[2] + ":" + elements[0]);
}
}
}
}
} catch (IOException e) {
@@ -2,7 +2,7 @@ package edu.lu.uni.serval.config;
public class Configuration {
public static final long SECONDS_TO_WAIT = 60L;
public static final long SECONDS_TO_WAIT = 120L;
public static final String ROOT_PATH = "../FPM_Violations/"; // The root path of all output data.
@@ -64,7 +64,9 @@ public class Statistic {
int largeHunk = 0;
int nullSourceCode = 0;
int noStatementChanges = 0;
int IllegalV = 0;
for (File file : files) {
if (file.getName().startsWith("test")) continue;
String content = FileHelper.readFile(file);
BufferedReader reader = new BufferedReader(new StringReader(content));
String line = null;
@@ -88,6 +90,8 @@ public class Statistic {
nullSourceCode += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("noStatementChanges")) {
noStatementChanges += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("IllegalV")) {
IllegalV +=Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
}
}
} catch (IOException e) {
@@ -110,12 +114,14 @@ public class Statistic {
// Statistics:
// TestAlarms: 5696
// nullGumTreeResults: 0
// nullMappingGumTreeResults: 26366
// pureDeletion: 38158
// Timeout: 6090
// noSourceCodeChange: 14442
// largeHunk: 232
// nullMappingGumTreeResults: 29056 29078
// pureDeletion: 40728
// Timeout: 135
// noSourceCodeChange: 7496
// largeHunk: 2584
// nullSourceCode: 0
// noStatementChanges: 7567
// IllegalV: 1194
System.out.println("\n\nStatistics:\nTestAlarms: " + testAlarms);
System.out.println("nullGumTreeResults: " + nullGumTreeResults);
System.out.println("nullMappingGumTreeResults: " + nullMappingGumTreeResults);
@@ -125,6 +131,7 @@ public class Statistic {
System.out.println("largeHunk: " + largeHunk);
System.out.println("nullSourceCode: " + nullSourceCode);
System.out.println("noStatementChanges: " + noStatementChanges);
System.out.println("IllegalV: " + IllegalV);
}
public static void statistics(String fileName, String type) throws IOException {