Просмотр исходного кода

Remove possibility to use the singular index in frontends, thus enforcing line and column indices.

Timur Sağlam 4 лет назад
Родитель
Сommit
fe5e51bcf5

+ 0 - 8
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.
      */

+ 0 - 5
jplag.frontend-utils/src/main/java/de/jplag/Token.java

@@ -58,11 +58,6 @@ public abstract class Token {
         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.

+ 10 - 16
jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java

@@ -19,24 +19,23 @@ public class ComparisonReportMapper {
     public void writeComparisonReports(JPlagResult jPlagResult, String path) {
         int numberOfComparisons = jPlagResult.getOptions().getMaximumNumberOfComparisons();
         List<JPlagComparison> comparisons = jPlagResult.getComparisons(numberOfComparisons);
-        writeComparisons(jPlagResult, path, comparisons);
+        writeComparisons(path, comparisons);
     }
 
-    private void writeComparisons(JPlagResult jPlagResult, String path, List<JPlagComparison> comparisons) {
+    private void writeComparisons(String path, List<JPlagComparison> comparisons) {
         for (JPlagComparison comparison : comparisons) {
             var comparisonReport = new ComparisonReport(comparison.getFirstSubmission().getName(), comparison.getSecondSubmission().getName(),
-                    comparison.similarity(), convertMatchesToReportMatches(jPlagResult, comparison));
+                    comparison.similarity(), convertMatchesToReportMatches(comparison));
             String fileName = comparisonReport.firstSubmissionId().concat("-").concat(comparisonReport.secondSubmissionId()).concat(".json");
             FILE_WRITER.saveAsJSON(comparisonReport, path, fileName);
         }
     }
 
-    private List<Match> convertMatchesToReportMatches(JPlagResult result, JPlagComparison comparison) {
-        return comparison.getMatches().stream()
-                .map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList();
+    private List<Match> convertMatchesToReportMatches(JPlagComparison comparison) {
+        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 @@ public class ComparisonReportMapper {
         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();
-    }
-
 }