From 42cfd3080d02efa66d6b5929a0b7e945ea18616b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Sa=C4=9Flam?= Date: Fri, 12 Aug 2022 12:05:24 +0200 Subject: [PATCH] Remove possibility to use the singular index in frontends, thus enforcing line and column indices. --- .../src/main/java/de/jplag/Language.java | 8 -------- .../src/main/java/de/jplag/Token.java | 5 ----- .../mapper/ComparisonReportMapper.java | 18 ++++++------------ 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/jplag.frontend-utils/src/main/java/de/jplag/Language.java b/jplag.frontend-utils/src/main/java/de/jplag/Language.java index e876d40b6..afe71ee4f 100644 --- a/jplag.frontend-utils/src/main/java/de/jplag/Language.java +++ b/jplag.frontend-utils/src/main/java/de/jplag/Language.java @@ -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. */ diff --git a/jplag.frontend-utils/src/main/java/de/jplag/Token.java b/jplag.frontend-utils/src/main/java/de/jplag/Token.java index 63e54cb24..74ff176de 100644 --- a/jplag.frontend-utils/src/main/java/de/jplag/Token.java +++ b/jplag.frontend-utils/src/main/java/de/jplag/Token.java @@ -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. diff --git a/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java b/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java index 1cc7d410d..309d2ed62 100644 --- a/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java +++ b/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java @@ -32,11 +32,10 @@ private void writeComparisons(JPlagResult jPlagResult, String path, List 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()); @@ -44,17 +43,12 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat 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(); - } - }