Update parser of fixed violations.
This commit is contained in:
+43
-29
@@ -7,12 +7,13 @@ import java.io.StringReader;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
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;
|
||||||
import edu.lu.uni.serval.config.Configuration;
|
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;
|
||||||
import edu.lu.uni.serval.gumtree.GumTreeGenerator.GumTreeType;
|
import edu.lu.uni.serval.gumtree.GumTreeGenerator.GumTreeType;
|
||||||
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
||||||
@@ -27,18 +28,23 @@ import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FixedViolationHunkParser extends FixedViolationParser {
|
public class FixedViolationHunkParser extends FixedViolationParser {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static Logger log = LoggerFactory.getLogger(FixedViolationHunkParser.class);
|
||||||
public String testingInfo = "";
|
public String testingInfo = "";
|
||||||
/*
|
/*
|
||||||
* ResultType:
|
* ResultType:
|
||||||
* 0: normal GumTree results.
|
* 0: normal GumTree results.
|
||||||
* 1: null GumTree result.
|
* 1: null GumTree result.
|
||||||
* 2: No source code changes.
|
* 2: No source code changes.
|
||||||
|
* 3: useless violations
|
||||||
*/
|
*/
|
||||||
public int resultType = 0;
|
public int resultType = 0;
|
||||||
public int nullMappingGumTreeResult = 0;
|
public int nullMappingGumTreeResult = 0;
|
||||||
public int pureDeletions = 0;
|
public int pureDeletions = 0;
|
||||||
public int largeHunk = 0;
|
public int largeHunk = 0;
|
||||||
public int nullSourceCode = 0;
|
public int nullSourceCode = 0;
|
||||||
|
public int nullMatchedDiffEntry = 0;
|
||||||
|
|
||||||
public FixedViolationHunkParser() {
|
public FixedViolationHunkParser() {
|
||||||
}
|
}
|
||||||
@@ -50,7 +56,7 @@ 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
|
// GumTree results
|
||||||
// TODO remove the modification of variable names or not?
|
// TODO remove the modification of variable names or not? FIXME
|
||||||
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile); // only remove non-statement source code, eg. method declaration
|
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree2(prevFile, revFile); // only remove non-statement source code, eg. method declaration
|
||||||
|
|
||||||
if (actionSets == null) {
|
if (actionSets == null) {
|
||||||
@@ -58,32 +64,38 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
} else if (actionSets.size() == 0) {
|
} else if (actionSets.size() == 0) {
|
||||||
this.resultType = 2;
|
this.resultType = 2;
|
||||||
} else {
|
} else {
|
||||||
List<Violation> violations = readPositionsAndAlarmTypes();
|
List<Violation> violations = readViolations(revFile.getName());
|
||||||
|
if (violations.size() == 0) {
|
||||||
List<DiffEntryHunk> diffentryHunks1 = new DiffEntryReader().readHunks2(diffentryFile);
|
this.resultType = 3;
|
||||||
// Select hunks by positions of violations.
|
return;
|
||||||
for (Violation violation : violations) {
|
|
||||||
int violationStartLineNum = violation.getStartLineNum();
|
|
||||||
int violationEndLineNum = violation.getEndLineNum();
|
|
||||||
for (int index = 0, hunkListSize = diffentryHunks1.size(); index < hunkListSize; index ++) {
|
|
||||||
DiffEntryHunk hunk = diffentryHunks1.get(index);
|
|
||||||
int startLine = hunk.getBugLineStartNum();
|
|
||||||
int range = hunk.getBugRange();
|
|
||||||
if (violationStartLineNum > startLine + range - 1) continue;
|
|
||||||
if (violationEndLineNum < startLine) break;
|
|
||||||
|
|
||||||
if (violation.getBugStartLineNum() == 0) {
|
|
||||||
violation.setBugStartLineNum(startLine);
|
|
||||||
violation.setFixStartLineNum(hunk.getFixLineStartNum());
|
|
||||||
}
|
|
||||||
violation.setBugEndLineNum(startLine + range - 1);
|
|
||||||
violation.setFixEndLineNum(hunk.getFixLineStartNum() + hunk.getFixRange() - 1);
|
|
||||||
violation.getHunks().add(hunk);
|
|
||||||
}
|
|
||||||
if (violation.getBugStartLineNum() == 0 && violation.getBugEndLineNum() == 0) {
|
|
||||||
System.err.println("WRONG");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// List<DiffEntryHunk> diffentryHunks1 = new DiffEntryReader().readHunks2(diffentryFile);
|
||||||
|
// // Select hunks by positions of violations.
|
||||||
|
// for (Violation violation : violations) {
|
||||||
|
// int violationStartLineNum = violation.getStartLineNum();
|
||||||
|
// int violationEndLineNum = violation.getEndLineNum();
|
||||||
|
// for (int index = 0, hunkListSize = diffentryHunks1.size(); index < hunkListSize; index ++) {
|
||||||
|
// DiffEntryHunk hunk = diffentryHunks1.get(index);
|
||||||
|
// int startLine = hunk.getBugLineStartNum();
|
||||||
|
// int range = hunk.getBugRange();
|
||||||
|
// if (violationStartLineNum > startLine + range - 1) continue;
|
||||||
|
// if (violationEndLineNum < startLine) break;
|
||||||
|
//
|
||||||
|
// if (violation.getBugStartLineNum() == 0) {
|
||||||
|
// violation.setBugStartLineNum(startLine);
|
||||||
|
// violation.setFixStartLineNum(hunk.getFixLineStartNum());
|
||||||
|
// }
|
||||||
|
// violation.setBugEndLineNum(startLine + range - 1);
|
||||||
|
// violation.setFixEndLineNum(hunk.getFixLineStartNum() + hunk.getFixRange() - 1);
|
||||||
|
// violation.getHunks().add(hunk);
|
||||||
|
// }
|
||||||
|
// if (violation.getBugStartLineNum() == 0 && violation.getBugEndLineNum() == 0) {
|
||||||
|
// // This fixed violation cannot be matched with a DiffEntry, it is difficult to identify related source code change for it.
|
||||||
|
// nullMatchedDiffEntry ++;
|
||||||
|
// log.warn("#Null-DiffEntry: " + revFile.getName().replace("#", "/") + " : " +violation.getStartLineNum() + " : " +
|
||||||
|
// violation.getBugEndLineNum() + " : " + violation.getAlarmType());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
//Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||||
HunkActionFilter hunkFilter = new HunkActionFilter();
|
HunkActionFilter hunkFilter = new HunkActionFilter();
|
||||||
@@ -233,8 +245,10 @@ public class FixedViolationHunkParser extends FixedViolationParser {
|
|||||||
String alarmType = violation.getAlarmType();
|
String alarmType = violation.getAlarmType();
|
||||||
|
|
||||||
// String patchPosition = "\n" + revFile.getName() + "Position: " + violation.getStartLineNum() + " --> " + violation.getEndLineNum() + "\n@@ -" + bugStartLine + ", " + bugEndLine + " +" + fixStartLine + ", " + fixEndLine + "@@\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";
|
||||||
String patchPosition = "\n" + "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";
|
String info = Configuration.PATCH_SIGNAL + "\nAlarm Type :" + violation.getAlarmType() + "\n" + patchSourceCode + "\n" + patchPosition + revFile.getName() + "\n";
|
||||||
if (noUpdate(editScriptTokens)) {
|
if (noUpdate(editScriptTokens)) {
|
||||||
|
|
||||||
if (!"SE_NO_SERIALVERSIONID".equals(alarmType)) {
|
if (!"SE_NO_SERIALVERSIONID".equals(alarmType)) {
|
||||||
|
|||||||
+17
-1
@@ -14,6 +14,7 @@ import edu.lu.uni.serval.gumtree.GumTreeComparer;
|
|||||||
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
||||||
import edu.lu.uni.serval.gumtree.regroup.HierarchicalRegrouper;
|
import edu.lu.uni.serval.gumtree.regroup.HierarchicalRegrouper;
|
||||||
import edu.lu.uni.serval.utils.FileHelper;
|
import edu.lu.uni.serval.utils.FileHelper;
|
||||||
|
import edu.lu.uni.serval.utils.ListSorter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse fix patterns with GumTree.
|
* Parse fix patterns with GumTree.
|
||||||
@@ -25,6 +26,7 @@ public class FixedViolationParser extends Parser {
|
|||||||
|
|
||||||
private File positionFile = null;
|
private File positionFile = null;
|
||||||
protected String alarmTypes = "";
|
protected String alarmTypes = "";
|
||||||
|
protected List<Violation> uselessViolations;
|
||||||
|
|
||||||
public void setPositionFile(File positionFile) {
|
public void setPositionFile(File positionFile) {
|
||||||
this.positionFile = positionFile;
|
this.positionFile = positionFile;
|
||||||
@@ -59,11 +61,18 @@ public class FixedViolationParser extends Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter out modified actions of changing method names, method parameters, variable names and field names in declaration part.
|
||||||
|
// TODO: variable effects range, sub-actions are these kinds of modification?
|
||||||
|
// actionSets.addAll(new ActionFilter().filterOutUselessActions(allActionSets));
|
||||||
|
|
||||||
|
ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(actionSets);
|
||||||
|
actionSets = sorter.sortAscending();
|
||||||
|
|
||||||
return actionSets;
|
return actionSets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Violation> readPositionsAndAlarmTypes() {
|
protected List<Violation> readViolations(String fileName) {
|
||||||
List<Violation> violations = new ArrayList<>();
|
List<Violation> violations = new ArrayList<>();
|
||||||
String fileContent = FileHelper.readFile(positionFile);
|
String fileContent = FileHelper.readFile(positionFile);
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
@@ -77,6 +86,10 @@ public class FixedViolationParser extends Parser {
|
|||||||
String alarmType = positionStr[0];
|
String alarmType = positionStr[0];
|
||||||
|
|
||||||
Violation violation = new Violation(startLine, endLine, alarmType);
|
Violation violation = new Violation(startLine, endLine, alarmType);
|
||||||
|
violation.setFileName(fileName.replaceAll("#", "/"));
|
||||||
|
if (uselessViolations.contains(violation)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
violations.add(violation);
|
violations.add(violation);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -139,4 +152,7 @@ public class FixedViolationParser extends Parser {
|
|||||||
return alarmTypes;
|
return alarmTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUselessViolations(List<Violation> uselessViolations) {
|
||||||
|
this.uselessViolations = uselessViolations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ public class FixedViolationSingleStatementParser extends FixedViolationParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read the positions of checked violations
|
// Read the positions of checked violations
|
||||||
List<Violation> violations = readPositionsAndAlarmTypes();
|
List<Violation> violations = readViolations(revFile.getName());
|
||||||
for (HierarchicalActionSet actionSet : actionSets) {
|
for (HierarchicalActionSet actionSet : actionSets) {
|
||||||
// position of buggy statements
|
// position of buggy statements
|
||||||
int startPosition = 0;
|
int startPosition = 0;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class TestHunkParser {
|
|||||||
StringBuilder alarmTypes = new StringBuilder();
|
StringBuilder alarmTypes = new StringBuilder();
|
||||||
|
|
||||||
int a = 0;
|
int a = 0;
|
||||||
int counter = 0;
|
// int counter = 0;
|
||||||
for (MessageFile msgFile : msgFiles) {
|
for (MessageFile msgFile : msgFiles) {
|
||||||
FixedViolationHunkParser parser = new FixedViolationHunkParser();
|
FixedViolationHunkParser parser = new FixedViolationHunkParser();
|
||||||
parser.setPositionFile(msgFile.getPositionFile());
|
parser.setPositionFile(msgFile.getPositionFile());
|
||||||
|
|||||||
Reference in New Issue
Block a user