Update
This commit is contained in:
+150
-11
@@ -1,13 +1,20 @@
|
||||
package edu.lu.uni.serval.FixPatternParser.violations;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
|
||||
import edu.lu.uni.serval.FixPatternParser.Tokenizer;
|
||||
import edu.lu.uni.serval.config.Configuration;
|
||||
import edu.lu.uni.serval.diffentry.DiffEntryHunk;
|
||||
import edu.lu.uni.serval.diffentry.DiffEntryReader;
|
||||
import edu.lu.uni.serval.gumtree.GumTreeGenerator;
|
||||
import edu.lu.uni.serval.gumtree.GumTreeGenerator.GumTreeType;
|
||||
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
||||
import edu.lu.uni.serval.gumtree.regroup.HunkActionFilter;
|
||||
import edu.lu.uni.serval.gumtree.regroup.SimpleTree;
|
||||
@@ -21,7 +28,15 @@ import edu.lu.uni.serval.utils.ListSorter;
|
||||
*
|
||||
*/
|
||||
public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
int counter;
|
||||
public String testingInfo = "";
|
||||
/*
|
||||
* ResultType:
|
||||
* 0: normal GumTree results.
|
||||
* 1: null GumTree result.
|
||||
*/
|
||||
public int resultType = 0;
|
||||
public int nullMappingGumTreeResult = 0;
|
||||
public int pureDeletions = 0;
|
||||
|
||||
public FixedViolationHunkParser() {
|
||||
}
|
||||
@@ -68,7 +83,10 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||
HunkActionFilter hunkFilter = new HunkActionFilter();
|
||||
List<Violation> selectedViolations = hunkFilter.filterActionsByModifiedRange2(violations, actionSets, revFile, prevFile);
|
||||
|
||||
|
||||
violations.removeAll(selectedViolations);
|
||||
this.nullMappingGumTreeResult += violations.size();
|
||||
|
||||
for (Violation violation : selectedViolations) {
|
||||
List<HierarchicalActionSet> hunkActionSets = violation.getActionSets();
|
||||
// // Remove overlapped UPD and INS, MOV
|
||||
@@ -153,7 +171,11 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (fixStartLine == 0) continue;
|
||||
if (fixStartLine == 0) {
|
||||
// pure delete actions.
|
||||
this.pureDeletions ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||
SimplifyTree abstractIdentifier = new SimplifyTree();
|
||||
@@ -171,6 +193,7 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
bugStartLine = violation.getStartLineNum();
|
||||
bugEndLine = violation.getEndLineNum();
|
||||
isInsert = true;
|
||||
// continue;
|
||||
}
|
||||
if (bugEndLine - bugStartLine >= Configuration.HUNK_SIZE || fixEndLine - fixStartLine >= Configuration.HUNK_SIZE) continue;
|
||||
|
||||
@@ -179,7 +202,10 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
|
||||
// Source Code of patches.
|
||||
String patchSourceCode = getPatchSourceCode(prevFile, revFile, bugStartLine, bugEndLine, fixStartLine, fixEndLine, isInsert);
|
||||
if ("".equals(patchSourceCode)) continue;
|
||||
if ("".equals(patchSourceCode)) {
|
||||
this.nullMappingGumTreeResult ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select edit scripts for deep learning.
|
||||
@@ -190,22 +216,135 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
||||
// 2. source code: raw tokens
|
||||
// 3. abstract identifiers:
|
||||
// 4. semi-source code:
|
||||
int size = astEditScripts.split(" ").length;
|
||||
if (size == 1) continue;
|
||||
String[] editScriptTokens = astEditScripts.split(" ");
|
||||
int size = editScriptTokens.length;
|
||||
if (size == 1) {
|
||||
this.nullMappingGumTreeResult ++;
|
||||
continue;
|
||||
}
|
||||
String alarmType = violation.getAlarmType();
|
||||
|
||||
counter ++;
|
||||
String patchPosition = "###:" + counter + "\n" + revFile.getName() + "Position: " + violation.getStartLineNum() + " --> " + violation.getEndLineNum() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\n";
|
||||
this.patchesSourceCode += Configuration.PATCH_SIGNAL + "\nAlarm Type :" + violation.getAlarmType() + "\n" + patchPosition + patchSourceCode + "\nAST Diff###:\n" + getAstEditScripts(hunkActionSets, bugEndPosition, fixEndPosition) + "\n";
|
||||
// String patchPosition = "\n" + revFile.getName() + "Position: " + violation.getStartLineNum() + " --> " + violation.getEndLineNum() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\n";
|
||||
String patchPosition = "\n" + "Position: " + violation.getStartLineNum() + " --> " + violation.getEndLineNum() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\n";
|
||||
String info = Configuration.PATCH_SIGNAL + "\nAlarm Type :" + violation.getAlarmType() + "\n" + patchPosition + patchSourceCode + "\nAST Diff###:\n" + getAstEditScripts(hunkActionSets, bugEndPosition, fixEndPosition) + "\n";
|
||||
if (noUpdate(editScriptTokens)) {
|
||||
// System.err.println(info);
|
||||
this.testingInfo += info;
|
||||
|
||||
if (!"SE_NO_SERIALVERSIONID".equals(alarmType)) {
|
||||
if (containsFiledDeclaration(hunkActionSets)) {
|
||||
this.nullMappingGumTreeResult ++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ("UL_UNRELEASED_LOCK".equals(alarmType) ||
|
||||
"SF_SWITCH_NO_DEFAULT".equals(alarmType) ||
|
||||
"SF_SWITCH_FALLTHROUGH".equals(alarmType) ||
|
||||
"SE_NO_SERIALVERSIONID".equals(alarmType) ||
|
||||
"REC_CATCH_EXCEPTION".equals(alarmType) ||
|
||||
"OS_OPEN_STREAM".equals(alarmType) ||
|
||||
"NP_ALWAYS_NULL".equals(alarmType) ||
|
||||
"IS2_INCONSISTENT_SYNC".equals(alarmType) ||
|
||||
"EI_EXPOSE_REP".equals(alarmType) ) {
|
||||
|
||||
} else if (containSpecialStmt(hunkActionSets, bugEndPosition, fixEndPosition)) {
|
||||
|
||||
} else {
|
||||
this.nullMappingGumTreeResult ++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
this.patchesSourceCode += info;
|
||||
this.sizes += size + "\n";
|
||||
this.astEditScripts += astEditScripts + "\n";
|
||||
this.alarmTypes += violation.getAlarmType() + "\n";
|
||||
this.alarmTypes += alarmType + "\n";
|
||||
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n";
|
||||
this.tokensOfSourceCode += Tokenizer.getTokensDeepFirst(simpleTree).trim() + "\n";
|
||||
String tokens = Tokenizer.getTokensDeepFirst(simpleTree).trim();
|
||||
if ("Block Block".equals(tokens)) {
|
||||
tokens = getContextTokens(patchSourceCode);
|
||||
}
|
||||
this.tokensOfSourceCode += tokens + "\n";
|
||||
// this.actionSets += Configuration.BUGGY_TREE_TOKEN + "\n" + readActionSet(actionSet, "") + "\n";
|
||||
// this.originalTree += Configuration.BUGGY_TREE_TOKEN + "\n" + actionSet.getOriginalTree().toString() + "\n";
|
||||
|
||||
}
|
||||
} else {
|
||||
this.resultType = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsFiledDeclaration(List<HierarchicalActionSet> hunkActionSets) {
|
||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||
if (hunkActionSet.getAstNodeType().equals("FieldDeclaration")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean containSpecialStmt(List<HierarchicalActionSet> hunkActionSets, int bugEndPosition, int fixEndPosition) {
|
||||
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
|
||||
if (hunkActionSet.getActionString().startsWith("INS")) {
|
||||
if (hunkActionSet.getAstNodeType().equals("IfStatement")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hunkActionSet.getAstNodeType().equals("ThrowStatement")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hunkActionSet.getAstNodeType().equals("ReturnStatement")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getContextTokens(String patchSourceCode) {
|
||||
BufferedReader reader = new BufferedReader(new StringReader(patchSourceCode));
|
||||
String line = null;
|
||||
String context = "";
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("+") || line.startsWith("-")) {
|
||||
continue;
|
||||
}
|
||||
context += line + "\n";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if ("".equals(context)) {
|
||||
return "Block Block";
|
||||
} else {
|
||||
ITree tree = new GumTreeGenerator().generateITreeForCodeBlock(context, GumTreeType.EXP_JDT);
|
||||
if (tree == null) {
|
||||
return "Block Block";
|
||||
}
|
||||
SimpleTree simpleTree = new SimplifyTree().canonicalizeSourceCodeTree(tree, null);
|
||||
String tokens = Tokenizer.getTokensDeepFirst(simpleTree).trim();
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean noUpdate(String[] tokens) {
|
||||
for (String token : tokens) {
|
||||
if (token.startsWith("UPD") || token.startsWith("MOV")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ public class TestHunkParser {
|
||||
int counter = 0;
|
||||
for (MessageFile msgFile : msgFiles) {
|
||||
FixedViolationHunkParser parser = new FixedViolationHunkParser();
|
||||
parser.counter = counter;
|
||||
parser.setPositionFile(msgFile.getPositionFile());
|
||||
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
@@ -71,7 +70,6 @@ public class TestHunkParser {
|
||||
sizes.append(parser.getSizes());
|
||||
patches.append(parser.getPatchesSourceCode());
|
||||
alarmTypes.append(parser.getAlarmTypes());
|
||||
counter = parser.counter;
|
||||
|
||||
a ++;
|
||||
if (a % 100 == 0) {
|
||||
|
||||
@@ -2,7 +2,10 @@ package edu.lu.uni.serval.MultipleThreadsParser;
|
||||
|
||||
import static java.lang.System.err;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -70,22 +73,30 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
|
||||
int id = msg.getId();
|
||||
int counter = 0;
|
||||
boolean containsAlarmTypes = false;
|
||||
|
||||
int testAlarms = 0;
|
||||
int nullGumTreeResults = 0;
|
||||
int nullMappingGumTreeResults = 0;
|
||||
int pureDeletion = 0;
|
||||
int expNums = 0;
|
||||
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
Parser parser = null;
|
||||
if (containsAlarmTypes || positionFile != null) {
|
||||
parser = new FixedViolationHunkParser(positionFile);
|
||||
containsAlarmTypes = true;
|
||||
} else {
|
||||
parser = new CommitPatchSingleStatementParser();
|
||||
}
|
||||
// Parser parser = null;
|
||||
// if (containsAlarmTypes || positionFile != null) {
|
||||
// parser = new FixedViolationHunkParser(positionFile);
|
||||
// containsAlarmTypes = true;
|
||||
// } else {
|
||||
// parser = new CommitPatchSingleStatementParser();
|
||||
// }
|
||||
FixedViolationHunkParser parser = new FixedViolationHunkParser(positionFile);
|
||||
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
// schedule the work
|
||||
@@ -94,15 +105,22 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
// wait for task to complete
|
||||
future.get(Configuration.SECONDS_TO_WAIT, TimeUnit.SECONDS);
|
||||
|
||||
nullMappingGumTreeResults += parser.nullMappingGumTreeResult;
|
||||
pureDeletion += parser.pureDeletions;
|
||||
|
||||
String editScript = parser.getAstEditScripts();
|
||||
if (!"".equals(editScript)) {
|
||||
if ("".equals(editScript)) {
|
||||
if (parser.resultType == 1) {
|
||||
nullGumTreeResults += countAlarms(positionFile);
|
||||
}
|
||||
} else {
|
||||
editScripts.append(editScript);
|
||||
patchesSourceCode.append(parser.getPatchesSourceCode());
|
||||
sizes.append(parser.getSizes());
|
||||
// tokens.append(parser.getTokensOfSourceCode());
|
||||
alarmTypes.append(parser.getAlarmTypes());
|
||||
tokens.append(parser.getTokensOfSourceCode());
|
||||
if (containsAlarmTypes) {
|
||||
alarmTypes.append(((FixedViolationHunkParser) parser).getAlarmTypes());
|
||||
}
|
||||
|
||||
counter ++;
|
||||
if (counter % 100 == 0) {
|
||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||
@@ -113,19 +131,20 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
patchesSourceCode.setLength(0);
|
||||
sizes.setLength(0);
|
||||
tokens.setLength(0);
|
||||
if (containsAlarmTypes) {
|
||||
FileHelper.outputToFile(alarmTypesFilePath + "alarmTypes_" + id + ".list", alarmTypes, true);
|
||||
alarmTypes.setLength(0);
|
||||
}
|
||||
FileHelper.outputToFile(alarmTypesFilePath + "alarmTypes_" + id + ".list", alarmTypes, true);
|
||||
alarmTypes.setLength(0);
|
||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
||||
}
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
err.println("task timed out");
|
||||
future.cancel(true);
|
||||
expNums ++;
|
||||
} catch (InterruptedException e) {
|
||||
expNums ++;
|
||||
err.println("task interrupted");
|
||||
} catch (ExecutionException e) {
|
||||
expNums ++;
|
||||
err.println("task aborted");
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
@@ -141,11 +160,12 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
patchesSourceCode.setLength(0);
|
||||
sizes.setLength(0);
|
||||
tokens.setLength(0);
|
||||
if (containsAlarmTypes) {
|
||||
FileHelper.outputToFile(alarmTypesFilePath + "alarmTypes_" + id + ".list", alarmTypes, true);
|
||||
alarmTypes.setLength(0);
|
||||
}
|
||||
|
||||
FileHelper.outputToFile(alarmTypesFilePath + "alarmTypes_" + id + ".list", alarmTypes, true);
|
||||
alarmTypes.setLength(0);
|
||||
}
|
||||
String statistic = "testAlarms: " + testAlarms + "\nnullGumTreeResults: " + nullGumTreeResults + "\nnullMappingGumTreeResults: " + nullMappingGumTreeResults + "\npureDeletion: " + pureDeletion + "\nTimeout: " + expNums;
|
||||
FileHelper.outputToFile("OUTPUT/statistic_" + id + ".list", statistic, false);
|
||||
|
||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
||||
log.info("Worker #" + id + " finished the work...");
|
||||
@@ -154,4 +174,24 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
private int countAlarms(File positionFile) {
|
||||
int counter = 0;
|
||||
String content = FileHelper.readFile(positionFile);
|
||||
BufferedReader reader = new BufferedReader(new StringReader(content));
|
||||
try {
|
||||
while (reader.readLine() != null) {
|
||||
counter ++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package edu.lu.uni.serval.bugLocalization;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
|
||||
import edu.lu.uni.serval.gumtree.GumTreeGenerator;
|
||||
import edu.lu.uni.serval.gumtree.GumTreeGenerator.GumTreeType;
|
||||
|
||||
public class BuggyCodeParser {
|
||||
|
||||
public void parseBuggyCode(String buggyCode) {
|
||||
ITree tree = new GumTreeGenerator().generateITreeForCodeBlock(buggyCode, GumTreeType.EXP_JDT);
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,28 @@ import edu.lu.uni.serval.utils.FileHelper;
|
||||
public class Step8 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String outputLocalizeFile = Configuration.TEST_POSITION_FILE;
|
||||
String outputTokensFile = Configuration.TEST_DATA_FILE;
|
||||
FileHelper.deleteDirectory(outputLocalizeFile);
|
||||
FileHelper.deleteDirectory(outputTokensFile);
|
||||
|
||||
int limitationOfTestingInstances = Integer.parseInt(FileHelper.readFile(Configuration.NUMBER_OF_TRAINING_DATA).trim()) / 10;
|
||||
|
||||
File testProjects = new File(Configuration.TEST_INPUT);
|
||||
File[] projects = testProjects.listFiles();
|
||||
ProjectScanner scanner = new ProjectScanner();
|
||||
scanner.scanJavaProject(projects, outputLocalizeFile, outputTokensFile, limitationOfTestingInstances);
|
||||
// String outputLocalizeFile = Configuration.TEST_POSITION_FILE;
|
||||
// String outputTokensFile = Configuration.TEST_DATA_FILE;
|
||||
// FileHelper.deleteDirectory(outputLocalizeFile);
|
||||
// FileHelper.deleteDirectory(outputTokensFile);
|
||||
//
|
||||
// int limitationOfTestingInstances = Integer.parseInt(FileHelper.readFile(Configuration.NUMBER_OF_TRAINING_DATA).trim()) / 10;
|
||||
//
|
||||
// File testProjects = new File(Configuration.TEST_INPUT);
|
||||
// File[] projects = testProjects.listFiles();
|
||||
// ProjectScanner scanner = new ProjectScanner();
|
||||
// scanner.scanJavaProject(projects, outputLocalizeFile, outputTokensFile, limitationOfTestingInstances);
|
||||
for (int i = 1; i <= 106; i ++) {
|
||||
System.out.println("cd ../../" + i + "/buggy");
|
||||
System.out.println("mvn package -DskipTests=true");
|
||||
System.out.println("mv target/commons-math3-3.3-SNAPSHOT.jar ../../Math" + i + ".jar");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
cd ../../4/buggy
|
||||
mvn package -Dmaven.test.skip=true
|
||||
|
||||
mv target/commons-lang3-3.2-SNAPSHOT.jar ../../Lang
|
||||
*/
|
||||
@@ -0,0 +1,108 @@
|
||||
package edu.lu.uni.serval.bugLocalization;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import edu.lu.uni.serval.utils.FileHelper;
|
||||
import edu.lu.uni.serval.utils.ListSorter;
|
||||
|
||||
public class test {
|
||||
/*
|
||||
Alarm Type :UPM_UNCALLED_PRIVATE_METHOD : 13
|
||||
Alarm Type :SS_SHOULD_BE_STATIC : 2
|
||||
Alarm Type :FE_FLOATING_POINT_EQUALITY : 1
|
||||
Alarm Type :UWF_UNWRITTEN_FIELD : 2
|
||||
Alarm Type :CN_IDIOM_NO_SUPER_CALL : 1
|
||||
Alarm Type :SBSC_USE_STRINGBUFFER_CONCATENATION : 2
|
||||
Alarm Type :RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT : 2
|
||||
Alarm Type :URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD : 15
|
||||
Alarm Type :SF_SWITCH_FALLTHROUGH : 1
|
||||
Alarm Type :EI_EXPOSE_REP2 : 7
|
||||
Alarm Type :REC_CATCH_EXCEPTION : 1
|
||||
Alarm Type :MS_MUTABLE_ARRAY : 1
|
||||
Alarm Type :FI_MISSING_SUPER_CALL : 1
|
||||
Alarm Type :RI_REDUNDANT_INTERFACES : 1
|
||||
Alarm Type :RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE : 5
|
||||
Alarm Type :DB_DUPLICATE_SWITCH_CLAUSES : 1
|
||||
Alarm Type :UCF_USELESS_CONTROL_FLOW : 6
|
||||
Alarm Type :NP_DEREFERENCE_OF_READLINE_VALUE : 1
|
||||
Alarm Type :RV_RETURN_VALUE_IGNORED_BAD_PRACTICE : 4
|
||||
Alarm Type :DLS_DEAD_LOCAL_STORE : 41
|
||||
Alarm Type :EI_EXPOSE_REP : 1
|
||||
Alarm Type :URF_UNREAD_FIELD : 19
|
||||
Alarm Type :ODR_OPEN_DATABASE_RESOURCE : 1
|
||||
Alarm Type :DMI_RANDOM_USED_ONLY_ONCE : 1
|
||||
Alarm Type :NP_LOAD_OF_KNOWN_NULL_VALUE : 1
|
||||
Alarm Type :OBL_UNSATISFIED_OBLIGATION : 1
|
||||
Alarm Type :WA_NOT_IN_LOOP : 1
|
||||
Alarm Type :MS_SHOULD_BE_FINAL : 3
|
||||
Alarm Type :RV_CHECK_FOR_POSITIVE_INDEXOF : 1
|
||||
Alarm Type :DM_DEFAULT_ENCODING : 13
|
||||
Alarm Type :ODR_OPEN_DATABASE_RESOURCE_EXCEPTION_PATH : 1
|
||||
Alarm Type :DM_GC : 1
|
||||
Alarm Type :SIC_INNER_SHOULD_BE_STATIC : 3
|
||||
Alarm Type :ES_COMPARING_STRINGS_WITH_EQ : 3
|
||||
Alarm Type :ICAST_INTEGER_MULTIPLY_CAST_TO_LONG : 1
|
||||
Alarm Type :ES_COMPARING_PARAMETER_STRING_WITH_EQ : 3
|
||||
Alarm Type :UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR : 3
|
||||
Alarm Type :WMI_WRONG_MAP_ITERATOR : 1
|
||||
Alarm Type :BC_UNCONFIRMED_CAST : 1
|
||||
Alarm Type :MS_PKGPROTECT : 2
|
||||
Alarm Type :SIC_INNER_SHOULD_BE_STATIC_ANON : 3
|
||||
Alarm Type :PZLA_PREFER_ZERO_LENGTH_ARRAYS : 2
|
||||
Alarm Type :SC_START_IN_CTOR : 1
|
||||
Alarm Type :RR_NOT_CHECKED : 4
|
||||
Alarm Type :RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE : 2
|
||||
Alarm Type :DM_CONVERT_CASE : 10
|
||||
Alarm Type :DE_MIGHT_IGNORE : 1
|
||||
Alarm Type :SW_SWING_METHODS_INVOKED_IN_SWING_THREAD : 1
|
||||
Alarm Type :ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD : 14
|
||||
*/
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String content = FileHelper.readFile("OUTPUT/DEL_INS.list");
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(content));
|
||||
String line = null;
|
||||
StringBuilder singleAlarm = new StringBuilder();
|
||||
List<String> alarms = new ArrayList<>();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("Alarm")) {
|
||||
if (singleAlarm.length() > 0) {
|
||||
alarms.add(singleAlarm.toString());
|
||||
singleAlarm = new StringBuilder();
|
||||
}
|
||||
}
|
||||
singleAlarm.append(line + "\n");
|
||||
// String type = line.trim();
|
||||
//
|
||||
// if (map.containsKey(type)) {
|
||||
// map.put(type, map.get(type) + 1);
|
||||
// } else {
|
||||
// map.put(type, 1);
|
||||
// }
|
||||
}
|
||||
reader.close();
|
||||
alarms.add(singleAlarm.toString());
|
||||
|
||||
ListSorter<String> sorter = new ListSorter<String>(alarms);
|
||||
alarms = sorter.sortAscending();
|
||||
|
||||
StringBuilder alarmsBuilder = new StringBuilder();
|
||||
for (String a : alarms) {
|
||||
alarmsBuilder.append(a);
|
||||
}
|
||||
FileHelper.outputToFile("OUTPUT/DEL.list", alarmsBuilder, false);
|
||||
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
System.out.println(entry.getKey() + " : " + entry.getValue());
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package edu.lu.uni.serval.config;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
public static final long SECONDS_TO_WAIT = 30L;
|
||||
public static final long SECONDS_TO_WAIT = 60L;
|
||||
|
||||
private static final String ROOT_PATH = "../FPM_Violations/"; // The root path of all output data.
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Configuration {
|
||||
|
||||
|
||||
// the output path of GumTree results.
|
||||
private static final String GUM_TREE_OUTPUT = ROOT_PATH + "GumTreeResults_2/";
|
||||
private static final String GUM_TREE_OUTPUT = ROOT_PATH + "GumTreeResults/";
|
||||
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 BUGGYTREE_FILE_PATH = GUM_TREE_OUTPUT + "buggyTrees/";
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package edu.lu.uni.serval.findbugs;
|
||||
|
||||
public class FindBugsAanalyser {
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import edu.lu.uni.serval.violation.Violation;
|
||||
|
||||
public class AlarmsReader {
|
||||
|
||||
int counter = 0;
|
||||
|
||||
public Map<String, Violation> readAlarmsList(String fileName) {
|
||||
Map<String, Violation> violationsMap = new HashMap<>();
|
||||
FileInputStream fis = null;
|
||||
@@ -61,6 +63,7 @@ public class AlarmsReader {
|
||||
} else {
|
||||
positions.put(startLine, endLine);
|
||||
tempAlarm.getAlarmTypes().put(startLine, alarmType);
|
||||
counter ++;
|
||||
}
|
||||
} else {
|
||||
Map<Integer, String> alarmTypes = new HashMap<>();
|
||||
@@ -70,6 +73,7 @@ public class AlarmsReader {
|
||||
positions.put(startLine, endLine);
|
||||
alarm.setPositions(positions);
|
||||
alarms.add(alarm);
|
||||
counter ++;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
@@ -82,6 +86,8 @@ public class AlarmsReader {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(counter);
|
||||
return violationsMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class TestViolationParser {
|
||||
List<File> repositoriesList = new ArrayList<>();
|
||||
File repositories = new File(REPO_PATH);
|
||||
File[] subFiles = repositories.listFiles();
|
||||
for (File subFile : subFiles) { // repos-a to u
|
||||
for (File subFile : subFiles) {
|
||||
if (subFile.isDirectory()) {
|
||||
File[] repos = subFile.listFiles();
|
||||
for (File repo : repos) {
|
||||
@@ -25,8 +25,19 @@ public class TestViolationParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
String fixedAlarmFile = "Dataset/fixed-alarms-v0.2.list";
|
||||
String fixedAlarmFile = "Dataset/fixed-alarms-v0.3.list.txt";
|
||||
|
||||
/**
|
||||
* 544 projects.
|
||||
* 84103 alarms.
|
||||
*
|
||||
* cd ../../7/buggy/
|
||||
* mvn compile
|
||||
* mvn package -Dmaven.test.skip=true
|
||||
*
|
||||
* Lang 54, 56-65
|
||||
* Math 105 and 106
|
||||
*/
|
||||
|
||||
final String previousFilesPath = Configuration.GUM_TREE_INPUT + "prevFiles/";
|
||||
final String revisedFilesPath = Configuration.GUM_TREE_INPUT + "revFiles/";
|
||||
|
||||
@@ -3,15 +3,19 @@ package edu.lu.uni.serval.violation.parse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jgit.errors.RevisionSyntaxException;
|
||||
|
||||
import edu.lu.uni.serval.config.Configuration;
|
||||
import edu.lu.uni.serval.git.exception.GitRepositoryNotFoundException;
|
||||
import edu.lu.uni.serval.git.exception.NotValidGitRepositoryException;
|
||||
import edu.lu.uni.serval.git.travel.GitRepository;
|
||||
import edu.lu.uni.serval.utils.Exporter;
|
||||
import edu.lu.uni.serval.utils.FileHelper;
|
||||
import edu.lu.uni.serval.utils.MapSorter;
|
||||
import edu.lu.uni.serval.violation.Alarm;
|
||||
import edu.lu.uni.serval.violation.Violation;
|
||||
|
||||
@@ -22,12 +26,16 @@ import edu.lu.uni.serval.violation.Violation;
|
||||
*/
|
||||
public class ViolationParser {
|
||||
|
||||
Map<String, Integer> alarmTypesCounter = new HashMap<>();
|
||||
|
||||
public void parseViolations(String fixedAlarmFile, List<File> repos, String previousFilesPath, String revisedFilesPath, String positionsFilePath, String diffentryFilePath) {
|
||||
AlarmsReader reader = new AlarmsReader();
|
||||
Map<String, Violation> violations = reader.readAlarmsList(fixedAlarmFile);
|
||||
List<String> throwExpProjs = new ArrayList<>();
|
||||
int a = 0;
|
||||
int exceptionsCounter = 0;
|
||||
int violationsAmount = 0;
|
||||
System.out.println(violations.size());
|
||||
for (Map.Entry<String , Violation> entry : violations.entrySet()) {
|
||||
String projectName = entry.getKey();
|
||||
String repoName = "";
|
||||
@@ -94,6 +102,8 @@ public class ViolationParser {
|
||||
FileHelper.outputToFile(fixedFile, fixedFileContent, false);
|
||||
FileHelper.outputToFile(positionFile, readPosition(alarm.getPositions(), alarm.getAlarmTypes()), false);
|
||||
FileHelper.outputToFile(diffentryFile, diffentry, false);
|
||||
|
||||
violationsAmount += counter(alarm);
|
||||
}
|
||||
} catch (GitRepositoryNotFoundException e) {
|
||||
System.out.println("Exception: " + projectName);
|
||||
@@ -120,8 +130,29 @@ public class ViolationParser {
|
||||
System.out.println(throwExpProjs.size());
|
||||
System.out.println(throwExpProjs);
|
||||
|
||||
System.out.println("### Violations amount: " + violationsAmount);
|
||||
|
||||
MapSorter<String, Integer> sorter = new MapSorter<String, Integer>();
|
||||
alarmTypesCounter = sorter.sortByKeyAscending(alarmTypesCounter);
|
||||
String[] columns = { "Alarm Type", "amount" };
|
||||
Exporter.exportOutliers(alarmTypesCounter, new File(Configuration.GUM_TREE_INPUT + "AlarmTypes.xls"), 1, columns);
|
||||
}
|
||||
|
||||
private int counter(Alarm alarm) {
|
||||
int counter = 0;
|
||||
Map<Integer, String> alarmTypes = alarm.getAlarmTypes();
|
||||
counter += alarmTypes.size();
|
||||
for (Map.Entry<Integer, String> entry : alarmTypes.entrySet()) {
|
||||
String type = entry.getValue();
|
||||
if (this.alarmTypesCounter.containsKey(entry.getValue())) {
|
||||
this.alarmTypesCounter.put(type, this.alarmTypesCounter.get(type) + 1);
|
||||
} else {
|
||||
this.alarmTypesCounter.put(type, 1);
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output data in terms of alarm types.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user