Skip to content

Commit

Permalink
Update ChangeExtractor.java
Browse files Browse the repository at this point in the history
Bug found during feature extraction
  • Loading branch information
Luca Di Grazia authored Feb 9, 2024
1 parent 9ea16cd commit 8cc9584
Showing 1 changed file with 64 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,69 +102,74 @@ public File extractCodeChangesToFile(File f) {
}

private void parseLine() {
String trimmedLine = line.substring(1).trim();

if (isCommitLine(line)) {
commit = getCommit(line);


} else if (previousLine.startsWith("Date:")) { // begins with "Date:
workListcommitMessage.clear();
commitMessageFlag = true;



} else if (isOldFileNameLine(line)) {
fileNameOld = getOldFileName(line);

} else if (isNewFileLine(line)) {
fileNameNew = getNewFileName(line);

} else if (isPositionLine(line)) {
position = getPosition(line);
parseLineNumbers();

} else if (isLineWithPrefix(line, '-')) {
if (previousPrefix == '+') {
makeNewCodeChange();
try{
String trimmedLine = line.substring(1).trim();

if (isCommitLine(line)) {
commit = getCommit(line);


} else if (previousLine.startsWith("Date:")) { // begins with "Date:
workListcommitMessage.clear();
commitMessageFlag = true;



} else if (isOldFileNameLine(line)) {
fileNameOld = getOldFileName(line);

} else if (isNewFileLine(line)) {
fileNameNew = getNewFileName(line);

} else if (isPositionLine(line)) {
position = getPosition(line);
parseLineNumbers();

} else if (isLineWithPrefix(line, '-')) {
if (previousPrefix == '+') {
makeNewCodeChange();
lineOld++;
lineNew++;
}
if (previousPrefix == ' ') {
lineBeforeCodeChange = previousLine.substring(1).trim();
}

previousPrefix = '-';
workListOld.add(trimmedLine);

} else if (isLineWithPrefix(line, '+')) {
if (previousPrefix == ' ') {
lineBeforeCodeChange = previousLine.substring(1).trim();
}
previousPrefix = '+';
workListNew.add(trimmedLine);

} else if (startsWithSpace(line)) {
if (previousPrefix == '+' || previousPrefix == '-') {
makeNewCodeChange();
}


if (commitMessageFlag) {
if (line.length() > 4) {
if (!line.substring(4).trim().isEmpty()) {
workListcommitMessage.add(line.substring(4).trim());
}
}
}

lineOld++;
lineNew++;
previousPrefix = ' ';
}
if (previousPrefix == ' ') {
lineBeforeCodeChange = previousLine.substring(1).trim();
}

previousPrefix = '-';
workListOld.add(trimmedLine);

} else if (isLineWithPrefix(line, '+')) {
if (previousPrefix == ' ') {
lineBeforeCodeChange = previousLine.substring(1).trim();
}
previousPrefix = '+';
workListNew.add(trimmedLine);

} else if (startsWithSpace(line)) {
if (previousPrefix == '+' || previousPrefix == '-') {
makeNewCodeChange();

else if (line.startsWith("diff") && commitMessageFlag) {
commitMessageFlag = false;
}


if (commitMessageFlag) {
if (line.length() > 4) {
if (!line.substring(4).trim().isEmpty()) {
workListcommitMessage.add(line.substring(4).trim());
}
}
}

lineOld++;
lineNew++;
previousPrefix = ' ';
}

else if (line.startsWith("diff") && commitMessageFlag) {
commitMessageFlag = false;
} catch (Exception e) {
// Handle the exception
System.err.println("An error occurred: " + e.getMessage());
}

}
Expand Down

0 comments on commit 8cc9584

Please sign in to comment.