Skip to content

Commit

Permalink
Repair Report Match Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nestabentum committed Aug 8, 2022
1 parent ae8868c commit ef5fb08
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,25 @@ private List<Match> convertMatchesToReportMatches(JPlagResult result, JPlagCompa
.map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList();
}

private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean usesIndex) {
private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean languageSupportsColumnsAndLines) {
TokenList tokensFirst = comparison.getFirstSubmission().getTokenList();
TokenList tokensSecond = comparison.getSecondSubmission().getTokenList();
Token startTokenFirst = tokensFirst.getToken(match.startOfFirst());
Token endTokenFirst = tokensFirst.getToken(match.startOfFirst() + match.length() - 1);
Token startTokenSecond = tokensSecond.getToken(match.startOfSecond());
Token endTokenSecond = tokensSecond.getToken(match.startOfSecond() + match.length() - 1);

int startFirst = usesIndex ? startTokenFirst.getIndex() : startTokenFirst.getLine();
int endFirst = usesIndex ? endTokenFirst.getIndex() : endTokenFirst.getLine();
int startSecond = usesIndex ? startTokenSecond.getIndex() : startTokenSecond.getLine();
int endSecond = usesIndex ? endTokenSecond.getIndex() : endTokenSecond.getLine();
int startFirst = getPosition(languageSupportsColumnsAndLines, startTokenFirst);
int endFirst = getPosition(languageSupportsColumnsAndLines, endTokenFirst);
int startSecond = getPosition(languageSupportsColumnsAndLines, startTokenSecond);
int endSecond = getPosition(languageSupportsColumnsAndLines, endTokenSecond);
int tokens = match.length();

return new Match(startTokenFirst.getFile(), startTokenSecond.getFile(), startFirst, endFirst, startSecond, endSecond, tokens);
}

private int getPosition(boolean languageSupportsColumnsAndLines, Token token) {
return languageSupportsColumnsAndLines ? token.getLine() : token.getIndex();
}

}

0 comments on commit ef5fb08

Please sign in to comment.