Update
This commit is contained in:
@@ -12,6 +12,10 @@ OUTPUT/
|
|||||||
*.pdf
|
*.pdf
|
||||||
Dataset/
|
Dataset/
|
||||||
GumTreeInput/
|
GumTreeInput/
|
||||||
|
GumTreeInput1/
|
||||||
|
GumTreeOutput1/
|
||||||
|
GumTreeResults/
|
||||||
|
|
||||||
*TestParser.java
|
*TestParser.java
|
||||||
src/main/java/edu/lu/uni/serval/FixPatternParser/TestParser.java
|
src/main/java/edu/lu/uni/serval/FixPatternParser/TestParser.java
|
||||||
# Package Files #
|
# Package Files #
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<!-- <dependency>
|
||||||
<groupId>edu.lu.uni.serval</groupId>
|
<groupId>edu.lu.uni.serval</groupId>
|
||||||
<artifactId>MyCluster</artifactId>
|
<artifactId>MyCluster</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<groupId>edu.lu.uni.serval</groupId>
|
<groupId>edu.lu.uni.serval</groupId>
|
||||||
<artifactId>MyFeatureLearner</artifactId>
|
<artifactId>MyFeatureLearner</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>edu.lu.uni</groupId>
|
<groupId>edu.lu.uni</groupId>
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ public class CommitPatchHunkParser extends CommitPatchParser {
|
|||||||
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks(diffEntryFile);
|
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks(diffEntryFile);
|
||||||
//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();
|
||||||
List<HunkFixPattern> allHunkFixPatternss = hunkFilter.filterActionsByDiffEntryHunk2(diffentryHunks, actionSets, revFile, prevFile);
|
List<HunkFixPattern> allHunkFixPatterns = hunkFilter.filterActionsByDiffEntryHunk2(diffentryHunks, actionSets, revFile, prevFile);
|
||||||
|
|
||||||
for (HunkFixPattern hunkFixPattern : allHunkFixPatternss) {
|
for (HunkFixPattern hunkFixPattern : allHunkFixPatterns) {
|
||||||
// Range of buggy source code
|
// Range of buggy source code
|
||||||
int startLine = 0;
|
int startLine = 0;
|
||||||
int endLine = 0;
|
int endLine = 0;
|
||||||
|
|||||||
+16
-21
@@ -37,6 +37,12 @@ public class CommitPatchSingleStatementParser extends CommitPatchParser {
|
|||||||
if (actionSets.size() > 0) {
|
if (actionSets.size() > 0) {
|
||||||
// DiffEntry Hunks: filter out big hunks.
|
// DiffEntry Hunks: filter out big hunks.
|
||||||
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks(diffEntryFile);
|
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks(diffEntryFile);
|
||||||
|
CUCreator cuCreator = new CUCreator();
|
||||||
|
CompilationUnit prevUnit = cuCreator.createCompilationUnit(prevFile);
|
||||||
|
CompilationUnit revUnit = cuCreator.createCompilationUnit(revFile);
|
||||||
|
if (prevUnit == null || revUnit == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (HierarchicalActionSet actionSet : actionSets) {
|
for (HierarchicalActionSet actionSet : actionSets) {
|
||||||
// position of buggy statements
|
// position of buggy statements
|
||||||
int startPosition = 0;
|
int startPosition = 0;
|
||||||
@@ -80,31 +86,21 @@ public class CommitPatchSingleStatementParser extends CommitPatchParser {
|
|||||||
endPosition2 = startPosition2 + newNode.getLength();
|
endPosition2 = startPosition2 + newNode.getLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {// DEL actions and MOV actions: we don't need these
|
} else {// DEL actions and MOV actions: we don't need these actions, as for now.
|
||||||
// actions, as for now.
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (startPosition == 0 || startPosition2 == 0) {
|
if (startPosition == 0 || startPosition2 == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUCreator cuCreator = new CUCreator();
|
|
||||||
CompilationUnit prevUnit = cuCreator.createCompilationUnit(prevFile);
|
|
||||||
CompilationUnit revUnit = cuCreator.createCompilationUnit(revFile);
|
|
||||||
if (prevUnit == null || revUnit == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get line numbers.
|
// Get line numbers.
|
||||||
int startLine = prevUnit.getLineNumber(startPosition);
|
int startLine = prevUnit.getLineNumber(startPosition);
|
||||||
int endLine = prevUnit.getLineNumber(endPosition);
|
int endLine = prevUnit.getLineNumber(endPosition);
|
||||||
int startLine2 = revUnit.getLineNumber(startPosition2);
|
int startLine2 = revUnit.getLineNumber(startPosition2);
|
||||||
int endLine2 = revUnit.getLineNumber(endPosition2);
|
int endLine2 = revUnit.getLineNumber(endPosition2);
|
||||||
if (endLine - startLine >= Configuration.HUNK_SIZE - 2
|
if (endLine - startLine >= Configuration.HUNK_SIZE - 2 || endLine2 - startLine2 >= Configuration.HUNK_SIZE - 2)
|
||||||
|| endLine2 - startLine2 >= Configuration.HUNK_SIZE - 2)
|
|
||||||
continue;
|
continue;
|
||||||
// Filter out the modify actions, which are not in the DiffEntry
|
// Filter out the modify actions, which are not in the DiffEntry hunks.
|
||||||
// hunks.
|
|
||||||
DiffEntryHunk hunk = matchHunk(startLine, endLine, startLine2, endLine2, actionStr, diffentryHunks);
|
DiffEntryHunk hunk = matchHunk(startLine, endLine, startLine2, endLine2, actionStr, diffentryHunks);
|
||||||
if (hunk == null) {
|
if (hunk == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -117,8 +113,7 @@ public class CommitPatchSingleStatementParser extends CommitPatchParser {
|
|||||||
SimplifyTree abstractIdentifier = new SimplifyTree();
|
SimplifyTree abstractIdentifier = new SimplifyTree();
|
||||||
abstractIdentifier.abstractTree(actionSet);
|
abstractIdentifier.abstractTree(actionSet);
|
||||||
SimpleTree simpleTree = actionSet.getSimpleTree();
|
SimpleTree simpleTree = actionSet.getSimpleTree();
|
||||||
if (simpleTree == null) { // Failed to get the simple tree for
|
if (simpleTree == null) { // Failed to get the simple tree for INS actions.
|
||||||
// INS actions.
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,12 +137,12 @@ public class CommitPatchSingleStatementParser extends CommitPatchParser {
|
|||||||
this.patchesSourceCode += Configuration.PATCH_SIGNAL + "\n" + patchSourceCode + "\n";
|
this.patchesSourceCode += Configuration.PATCH_SIGNAL + "\n" + patchSourceCode + "\n";
|
||||||
this.sizes += size + "\n";
|
this.sizes += size + "\n";
|
||||||
this.astEditScripts += astEditScripts + "\n";
|
this.astEditScripts += astEditScripts + "\n";
|
||||||
// 2. source code: raw tokens
|
// // 2. source code: raw tokens
|
||||||
String rawTokenEditScripts = getRawTokenEditScripts(actionSet);
|
// String rawTokenEditScripts = getRawTokenEditScripts(actionSet);
|
||||||
// 3. abstract identifiers:
|
// // 3. abstract identifiers:
|
||||||
String abstractIdentifiersEditScripts = getAbstractIdentifiersEditScripts(actionSet);
|
// String abstractIdentifiersEditScripts = getAbstractIdentifiersEditScripts(actionSet);
|
||||||
// 4. semi-source code:
|
// // 4. semi-source code:
|
||||||
String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet);
|
// String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet);
|
||||||
|
|
||||||
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" +
|
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" +
|
||||||
// simpleTree.toString() + "\n";
|
// simpleTree.toString() + "\n";
|
||||||
|
|||||||
+22
-15
@@ -12,7 +12,6 @@ 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.DiffEntryHunk;
|
||||||
import edu.lu.uni.serval.diffentry.DiffEntryReader;
|
import edu.lu.uni.serval.diffentry.DiffEntryReader;
|
||||||
import edu.lu.uni.serval.gumtree.regroup.ActionFilter;
|
|
||||||
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
import edu.lu.uni.serval.gumtree.regroup.HierarchicalActionSet;
|
||||||
import edu.lu.uni.serval.gumtree.regroup.HunkActionFilter;
|
import edu.lu.uni.serval.gumtree.regroup.HunkActionFilter;
|
||||||
import edu.lu.uni.serval.gumtree.regroup.HunkFixPattern;
|
import edu.lu.uni.serval.gumtree.regroup.HunkFixPattern;
|
||||||
@@ -21,7 +20,7 @@ import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
|||||||
import edu.lu.uni.serval.utils.MapSorter;
|
import edu.lu.uni.serval.utils.MapSorter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse fix patterns with GumTree.
|
* Parse fix violations with GumTree.
|
||||||
*
|
*
|
||||||
* @author kui.liu
|
* @author kui.liu
|
||||||
*
|
*
|
||||||
@@ -29,36 +28,44 @@ import edu.lu.uni.serval.utils.MapSorter;
|
|||||||
public class FixedViolationHunkParser extends FixedViolationParser {
|
public class FixedViolationHunkParser extends FixedViolationParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseFixPatterns(File prevFile, File revFile, File positionsFile) {
|
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
||||||
|
|
||||||
// GumTree results
|
// GumTree results
|
||||||
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree(prevFile, revFile);
|
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree(prevFile, revFile);
|
||||||
|
|
||||||
if (actionSets.size() > 0) {
|
if (actionSets.size() > 0) {
|
||||||
Map<Integer, Integer> positions = readPositions(positionsFile);
|
Map<Integer, Integer> positions = readPositions();
|
||||||
if (positions.size() > 1) {
|
if (positions.size() > 1) {
|
||||||
MapSorter<Integer, Integer> sorter = new MapSorter<>();
|
MapSorter<Integer, Integer> sorter = new MapSorter<>();
|
||||||
positions = sorter.sortByKeyAscending(positions);
|
positions = sorter.sortByKeyAscending(positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DiffEntryHunk> diffentryHunks1 = new DiffEntryReader().readHunks(diffentryFile);
|
||||||
|
int index = 0;
|
||||||
|
int hunkListSize = diffentryHunks1.size();
|
||||||
|
// Map<Integer, DiffEntryHunk> diffentryHunks = new HashMap<>();
|
||||||
|
// Select hunks by positions of violations.
|
||||||
|
List<DiffEntryHunk> diffentryHunks = new ArrayList<>();
|
||||||
for (Map.Entry<Integer, Integer> entry : positions.entrySet()) {
|
for (Map.Entry<Integer, Integer> entry : positions.entrySet()) {
|
||||||
// only statements
|
int startRange = entry.getKey();
|
||||||
for (HierarchicalActionSet actionSet : actionSets) {
|
int endRange = entry.getValue();
|
||||||
String astNodeType = actionSet.getAstNodeType();
|
for (; index < hunkListSize; index ++) {
|
||||||
if (astNodeType.endsWith("Statement") || "FieldDeclaration".equals(astNodeType)) {
|
DiffEntryHunk hunk = diffentryHunks1.get(index);
|
||||||
|
int startLine = hunk.getBugLineStartNum();
|
||||||
}
|
int range = hunk.getBugRange();
|
||||||
|
if (startRange > startLine + range) continue;
|
||||||
|
if (endRange < startLine) break;
|
||||||
|
// startRange and endRange
|
||||||
|
// diffentryHunks.put(startRange, hunk);
|
||||||
|
diffentryHunks.add(hunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionFilter filter = new ActionFilter();
|
|
||||||
// DiffEntry size: filter out big hunks.
|
|
||||||
List<DiffEntryHunk> diffentryHunks = new DiffEntryReader().readHunks(positionsFile);
|
|
||||||
//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();
|
||||||
List<HunkFixPattern> allHunkFixPatternss = hunkFilter.filterActionsByDiffEntryHunk2(diffentryHunks, actionSets, revFile, prevFile);
|
List<HunkFixPattern> allHunkFixPatterns = hunkFilter.filterActionsByDiffEntryHunk2(diffentryHunks, actionSets, revFile, prevFile);
|
||||||
|
|
||||||
for (HunkFixPattern hunkFixPattern : allHunkFixPatternss) {
|
for (HunkFixPattern hunkFixPattern : allHunkFixPatterns) {
|
||||||
// Range of buggy source code
|
// Range of buggy source code
|
||||||
int startLine = 0;
|
int startLine = 0;
|
||||||
int endLine = 0;
|
int endLine = 0;
|
||||||
|
|||||||
+8
-2
@@ -18,8 +18,14 @@ import edu.lu.uni.serval.utils.FileHelper;
|
|||||||
*/
|
*/
|
||||||
public class FixedViolationParser extends Parser {
|
public class FixedViolationParser extends Parser {
|
||||||
|
|
||||||
|
File positionFile = null;
|
||||||
|
|
||||||
|
public void setPositionFile(File positionFile) {
|
||||||
|
this.positionFile = positionFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseFixPatterns(File prevFile, File revFile, File positionFile) {
|
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean inPositions(int startLine, int endLine, Map<Integer, Integer> positions) {
|
protected boolean inPositions(int startLine, int endLine, Map<Integer, Integer> positions) {
|
||||||
@@ -31,7 +37,7 @@ public class FixedViolationParser extends Parser {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<Integer, Integer> readPositions(File positionFile) {
|
protected Map<Integer, Integer> readPositions() {
|
||||||
Map<Integer, Integer> positions = new HashMap<>();
|
Map<Integer, Integer> positions = new HashMap<>();
|
||||||
String fileContent = FileHelper.readFile(positionFile);
|
String fileContent = FileHelper.readFile(positionFile);
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
|
|||||||
+17
-26
@@ -19,7 +19,7 @@ import edu.lu.uni.serval.gumtree.regroup.SimpleTree;
|
|||||||
import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse fix patterns with GumTree.
|
* Parse fixed violations with GumTree.
|
||||||
*
|
*
|
||||||
* @author kui.liu
|
* @author kui.liu
|
||||||
*
|
*
|
||||||
@@ -27,13 +27,20 @@ import edu.lu.uni.serval.gumtree.regroup.SimplifyTree;
|
|||||||
public class FixedViolationSingleStatementParser extends FixedViolationParser {
|
public class FixedViolationSingleStatementParser extends FixedViolationParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseFixPatterns(File prevFile, File revFile, File positionFile) {
|
public void parseFixPatterns(File prevFile, File revFile, File diffentryFile) {
|
||||||
// GumTree results
|
// GumTree results
|
||||||
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree(prevFile, revFile);
|
List<HierarchicalActionSet> actionSets = parseChangedSourceCodeWithGumTree(prevFile, revFile);
|
||||||
|
|
||||||
if (actionSets.size() > 0) {
|
if (actionSets.size() > 0) {
|
||||||
// DiffEntry Hunks: filter out big hunks.
|
CUCreator cuCreator = new CUCreator();
|
||||||
Map<Integer, Integer> positions = readPositions(positionFile);
|
CompilationUnit prevUnit = cuCreator.createCompilationUnit(prevFile);
|
||||||
|
CompilationUnit revUnit = cuCreator.createCompilationUnit(revFile);
|
||||||
|
if (prevUnit == null || revUnit == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the positions of checked violations
|
||||||
|
Map<Integer, Integer> positions = readPositions();
|
||||||
for (HierarchicalActionSet actionSet : actionSets) {
|
for (HierarchicalActionSet actionSet : actionSets) {
|
||||||
// position of buggy statements
|
// position of buggy statements
|
||||||
int startPosition = 0;
|
int startPosition = 0;
|
||||||
@@ -76,29 +83,13 @@ public class FixedViolationSingleStatementParser extends FixedViolationParser {
|
|||||||
endPosition2 = startPosition2 + newNode.getLength();
|
endPosition2 = startPosition2 + newNode.getLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (actionStr.startsWith("MOV")) {// DEL actions and MOV actions: we don't need these actions, as for now.
|
} else {// DEL actions and MOV actions: we don't need these actions, as for now.
|
||||||
continue;
|
|
||||||
// startPosition = actionSet.getStartPosition();
|
|
||||||
// endPosition = startPosition + actionSet.getLength();
|
|
||||||
// ITree node = actionSet.getNode().getParent();
|
|
||||||
// startPosition2 = node.getPos();
|
|
||||||
// endPosition2 = startPosition2 + node.getLength();
|
|
||||||
} else {
|
|
||||||
startPosition = actionSet.getStartPosition();
|
|
||||||
endPosition = startPosition + actionSet.getLength();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (startPosition == 0 || startPosition2 == 0) {
|
if (startPosition == 0 || startPosition2 == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUCreator cuCreator = new CUCreator();
|
|
||||||
CompilationUnit prevUnit = cuCreator.createCompilationUnit(prevFile);
|
|
||||||
CompilationUnit revUnit = cuCreator.createCompilationUnit(revFile);
|
|
||||||
if (prevUnit == null || revUnit == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get line numbers.
|
// Get line numbers.
|
||||||
int startLine = prevUnit.getLineNumber(startPosition);
|
int startLine = prevUnit.getLineNumber(startPosition);
|
||||||
int endLine = prevUnit.getLineNumber(endPosition);
|
int endLine = prevUnit.getLineNumber(endPosition);
|
||||||
@@ -138,11 +129,11 @@ public class FixedViolationSingleStatementParser extends FixedViolationParser {
|
|||||||
this.sizes += size + "\n";
|
this.sizes += size + "\n";
|
||||||
this.astEditScripts += astEditScripts + "\n";
|
this.astEditScripts += astEditScripts + "\n";
|
||||||
// 2. source code: raw tokens
|
// 2. source code: raw tokens
|
||||||
String rawTokenEditScripts = getRawTokenEditScripts(actionSet);
|
// String rawTokenEditScripts = getRawTokenEditScripts(actionSet);
|
||||||
// 3. abstract identifiers:
|
// // 3. abstract identifiers:
|
||||||
String abstractIdentifiersEditScripts = getAbstractIdentifiersEditScripts(actionSet);
|
// String abstractIdentifiersEditScripts = getAbstractIdentifiersEditScripts(actionSet);
|
||||||
// 4. semi-source code:
|
// // 4. semi-source code:
|
||||||
String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet);
|
// String semiSourceCodeEditScripts = getSemiSourceCodeEditScripts(actionSet);
|
||||||
|
|
||||||
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n";
|
// this.buggyTrees += Configuration.BUGGY_TREE_TOKEN + "\n" + simpleTree.toString() + "\n";
|
||||||
this.tokensOfSourceCode += Tokenizer.getTokensDeepFirst(simpleTree).trim() + "\n";
|
this.tokensOfSourceCode += Tokenizer.getTokensDeepFirst(simpleTree).trim() + "\n";
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ public class AkkaParser {
|
|||||||
List<MessageFile> msgFiles = new ArrayList<>();
|
List<MessageFile> msgFiles = new ArrayList<>();
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
|
if (!file.isDirectory()) continue;
|
||||||
String projectFolder = file.getPath();
|
String projectFolder = file.getPath();
|
||||||
File revFileFolder = new File(projectFolder + "/revFiles/");// revised file folder
|
File revFileFolder = new File(projectFolder + "/revFiles/");// revised file folder
|
||||||
File[] revFiles = revFileFolder.listFiles();
|
File[] revFiles = revFileFolder.listFiles();
|
||||||
|
|
||||||
for (File revFile : revFiles) {
|
for (File revFile : revFiles) {
|
||||||
if (revFile.getName().endsWith(".java")) {
|
if (revFile.getName().endsWith(".java")) {
|
||||||
File prevFile = new File(projectFolder + "/prevFiles/prev_" + revFile.getName());// previous file
|
File prevFile = new File(projectFolder + "/prevFiles/prev_" + revFile.getName());// previous file
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class MessageFile {
|
|||||||
private File revFile;
|
private File revFile;
|
||||||
private File prevFile;
|
private File prevFile;
|
||||||
private File diffEntryFile;
|
private File diffEntryFile;
|
||||||
|
private File positionFile;
|
||||||
|
|
||||||
public MessageFile(File revFile, File prevFile, File diffEntryFile) {
|
public MessageFile(File revFile, File prevFile, File diffEntryFile) {
|
||||||
super();
|
super();
|
||||||
@@ -27,4 +28,12 @@ public class MessageFile {
|
|||||||
return diffEntryFile;
|
return diffEntryFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getPositionFile() {
|
||||||
|
return positionFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPositionFile(File positionFile) {
|
||||||
|
this.positionFile = positionFile;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,4 +77,76 @@ public class DiffEntryReader {
|
|||||||
return diffentryHunks;
|
return diffentryHunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read all hunks without considering their sizes.
|
||||||
|
*
|
||||||
|
* @param diffentryFile
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<DiffEntryHunk> readHunks2(File diffentryFile) {
|
||||||
|
List<DiffEntryHunk> diffentryHunks = new ArrayList<>();
|
||||||
|
String content = FileHelper.readFile(diffentryFile);
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new StringReader(content));
|
||||||
|
String line = null;
|
||||||
|
int startLine = 0;
|
||||||
|
int range = 0;
|
||||||
|
int startLine2 = 0;
|
||||||
|
int range2 = 0;
|
||||||
|
StringBuilder hunk = new StringBuilder();
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (RegExp.filterSignal(line.trim())) {
|
||||||
|
if (hunk.length() > 0) {
|
||||||
|
if (startLine > 0) {
|
||||||
|
DiffEntryHunk diffEntryHunk = new DiffEntryHunk(startLine, startLine2, range, range2);
|
||||||
|
diffEntryHunk.setHunk(hunk.toString());
|
||||||
|
diffentryHunks.add(diffEntryHunk);
|
||||||
|
}
|
||||||
|
hunk.setLength(0);
|
||||||
|
}
|
||||||
|
int plusIndex = line.indexOf("+");
|
||||||
|
String lineNum = line.substring(4, plusIndex);
|
||||||
|
String[] nums = lineNum.split(",");
|
||||||
|
startLine = Integer.parseInt(nums[0].trim());
|
||||||
|
if (nums.length == 2) {
|
||||||
|
range = Integer.parseInt(nums[1].trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
String lineNum2 = line.substring(plusIndex) .trim();
|
||||||
|
lineNum2 = lineNum2.substring(1, lineNum2.length() - 2);
|
||||||
|
String[] nums2 = lineNum2.split(",");
|
||||||
|
startLine2 = Integer.parseInt(nums2[0].trim());
|
||||||
|
if (nums2.length == 2) {
|
||||||
|
range2 = Integer.parseInt(nums2[1].trim());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hunk.append(line + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startLine > 0) {
|
||||||
|
DiffEntryHunk diffEntryHunk = new DiffEntryHunk(startLine, startLine2, range, range2);
|
||||||
|
diffEntryHunk.setHunk(hunk.toString());
|
||||||
|
diffentryHunks.add(diffEntryHunk);
|
||||||
|
}
|
||||||
|
hunk.setLength(0);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
reader = null;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return diffentryHunks;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user