Skip to content

Commit

Permalink
Remove possibility to use the singular index in frontends, thus enfor…
Browse files Browse the repository at this point in the history
…cing line and column indices.
  • Loading branch information
tsaglam committed Aug 12, 2022
1 parent 263e85e commit 42cfd30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
8 changes: 0 additions & 8 deletions jplag.frontend-utils/src/main/java/de/jplag/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ public interface Language {
*/
boolean hasErrors();

/**
* Determines whether the parser provide column information. If that is the case, line and column indices are used
* instead of a single token index.
*/
default boolean supportsColumns() {
return true;
}

/**
* Determines whether a fixed-width font should be used to display that language.
*/
Expand Down
5 changes: 0 additions & 5 deletions jplag.frontend-utils/src/main/java/de/jplag/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ public String getFile() {
return file;
}

// this is made to distinguish the character front end. Maybe other front ends can use it too?
public int getIndex() {
return -1;
}

/**
* Gives the length if the code sections represented by this token.
* @return the length in characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,23 @@ private void writeComparisons(JPlagResult jPlagResult, String path, List<JPlagCo
}

private List<Match> convertMatchesToReportMatches(JPlagResult result, JPlagComparison comparison) {
return comparison.getMatches().stream()
.map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList();
return comparison.getMatches().stream().map(match -> convertMatchToReportMatch(comparison, match)).toList();
}

private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean languageSupportsColumnsAndLines) {
private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match) {
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 = getPosition(languageSupportsColumnsAndLines, startTokenFirst);
int endFirst = getPosition(languageSupportsColumnsAndLines, endTokenFirst);
int startSecond = getPosition(languageSupportsColumnsAndLines, startTokenSecond);
int endSecond = getPosition(languageSupportsColumnsAndLines, endTokenSecond);
int startFirst = startTokenFirst.getLine();
int endFirst = endTokenFirst.getLine();
int startSecond = startTokenSecond.getLine();
int endSecond = endTokenSecond.getLine();
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 42cfd30

Please sign in to comment.