Jan Wittler преди 4 години
родител
ревизия
0eb3b99777

+ 1 - 2
jplag.frontend-utils/src/main/java/de/jplag/Token.java

@@ -29,8 +29,7 @@ public abstract class Token {
         this.file = file;
         if (type == TokenConstants.FILE_END) {
             this.line = NO_VALUE;
-        }
-        else {
+        } else {
             this.line = line > 0 ? line : 1;
         }
     }

+ 1 - 1
jplag.frontend.kotlin/src/main/java/de/jplag/kotlin/KotlinParserAdapter.java

@@ -14,8 +14,8 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker;
 
 import de.jplag.AbstractParser;
 import de.jplag.ErrorConsumer;
-import de.jplag.TokenConstants;
 import de.jplag.Token;
+import de.jplag.TokenConstants;
 import de.jplag.kotlin.grammar.KotlinLexer;
 import de.jplag.kotlin.grammar.KotlinParser;
 

+ 2 - 1
jplag.frontend.kotlin/src/test/java/de/jplag/kotlin/KotlinFrontendTest.java

@@ -102,7 +102,8 @@ class KotlinFrontendTest {
             // All lines that contain code
             var codeLines = getCodeLines(lines);
             // All lines that contain token
-            var tokenLines = IntStream.range(0, tokens.size()).mapToObj(tokens::get).mapToInt(Token::getLine).filter(l -> l != Token.NO_VALUE).distinct().toArray();
+            var tokenLines = IntStream.range(0, tokens.size()).mapToObj(tokens::get).mapToInt(Token::getLine).filter(l -> l != Token.NO_VALUE)
+                    .distinct().toArray();
 
             if (codeLines.length > tokenLines.length) {
                 var diffLine = IntStream.range(0, codeLines.length)

+ 2 - 1
jplag.frontend.rlang/src/test/java/de/jplag/rlang/RFrontendTest.java

@@ -72,7 +72,8 @@ public class RFrontendTest {
             // All lines that contain code
             var codeLines = IntStream.range(1, lines.size() + 1).filter(idx -> !lines.get(idx - 1).matches(emptyLineExpression)).toArray();
             // All lines that contain token
-            var tokenLines = IntStream.range(0, tokens.size()).mapToObj(tokens::get).mapToInt(Token::getLine).filter(l -> l != Token.NO_VALUE).distinct().toArray();
+            var tokenLines = IntStream.range(0, tokens.size()).mapToObj(tokens::get).mapToInt(Token::getLine).filter(l -> l != Token.NO_VALUE)
+                    .distinct().toArray();
 
             if (codeLines.length > tokenLines.length) {
                 var diffLine = IntStream.range(0, codeLines.length)

+ 11 - 9
jplag/src/main/java/de/jplag/GreedyStringTiling.java

@@ -14,8 +14,8 @@ import de.jplag.options.JPlagOptions;
 
 /**
  * This class implements the Greedy String Tiling algorithm as introduced by Michael Wise. However, it is very specific
- * to the classes {@link Token}, and {@link Match}. While this class was reworked, it still contains
- * some quirks from the initial version.
+ * to the classes {@link Token}, and {@link Match}. While this class was reworked, it still contains some quirks from
+ * the initial version.
  * @see <a href=
  * "https://www.researchgate.net/publication/262763983_String_Similarity_via_Greedy_String_Tiling_and_Running_Karp-Rabin_Matching">
  * String Similarity via Greedy String Tiling and Running Karp−Rabin Matching </a>
@@ -30,8 +30,8 @@ public class GreedyStringTiling {
     }
 
     /**
-     * Preprocesses the given base code submission.
-     * Should be called before computing comparisons if there is a base code submission.
+     * Preprocesses the given base code submission. Should be called before computing comparisons if there is a base code
+     * submission.
      * @param baseSubmission is the base code submission. Must not be null.
      */
     public void preprocessBaseCodeSubmission(Submission baseSubmission) {
@@ -145,8 +145,8 @@ public class GreedyStringTiling {
     }
 
     /**
-     * Checks if the two referenced subsequences are equal and not marked.
-     * Comparison is performed backwards based on the assumption that the further tokens are away, the more likely they differ.
+     * Checks if the two referenced subsequences are equal and not marked. Comparison is performed backwards based on the
+     * assumption that the further tokens are away, the more likely they differ.
      * @param subsequenceLength the length of the subsequence to consider.
      * @param leftTokens The complete list of left tokens.
      * @param leftStartIndex The startIndex in the left token list.
@@ -156,7 +156,8 @@ public class GreedyStringTiling {
      * @param rightMarkedTokens The marked tokens of the right token list.
      * @return
      */
-    private boolean subsequencesAreMatchingAndNotMarked(int subsequenceLength, List<Token> leftTokens, int leftStartIndex, Set<Token> leftMarkedTokens, List<Token> rightTokens, int rightStartIndex, Set<Token> rightMarkedTokens) {
+    private boolean subsequencesAreMatchingAndNotMarked(int subsequenceLength, List<Token> leftTokens, int leftStartIndex,
+            Set<Token> leftMarkedTokens, List<Token> rightTokens, int rightStartIndex, Set<Token> rightMarkedTokens) {
         for (int offset = subsequenceLength - 1; offset >= 0; offset--) {
             Token leftToken = leftTokens.get(leftStartIndex + offset);
             Token rightToken = rightTokens.get(rightStartIndex + offset);
@@ -178,7 +179,7 @@ public class GreedyStringTiling {
 
     private Set<Token> initiallyMarkedTokens(List<Token> tokens, boolean isBaseCodeComparison) {
         Set<Token> markedTokens = new HashSet<Token>();
-        for (Token token: tokens) {
+        for (Token token : tokens) {
             if (token.type == FILE_END || token.type == SEPARATOR_TOKEN || (!isBaseCodeComparison && token.isBasecode() && options.hasBaseCode())) {
                 markedTokens.add(token);
             }
@@ -190,7 +191,8 @@ public class GreedyStringTiling {
         if (hashLookupTables.containsKey(submission)) {
             return hashLookupTables.get(submission);
         }
-        SubsequenceHashLookupTable lookupTable = new SubsequenceHashLookupTable(options.getMinimumTokenMatch(), submission.getTokenList(), markedTokens);
+        SubsequenceHashLookupTable lookupTable = new SubsequenceHashLookupTable(options.getMinimumTokenMatch(), submission.getTokenList(),
+                markedTokens);
         hashLookupTables.put(submission, lookupTable);
         return lookupTable;
     }

+ 8 - 10
jplag/src/main/java/de/jplag/SubsequenceHashLookupTable.java

@@ -7,8 +7,8 @@ import java.util.Map;
 import java.util.Set;
 
 /**
- * A class to generate and store hashes over a fixed length subsequence of a given list of tokens.
- * Hash generation is optimized to work in O(n).
+ * A class to generate and store hashes over a fixed length subsequence of a given list of tokens. Hash generation is
+ * optimized to work in O(n).
  */
 public class SubsequenceHashLookupTable {
     private static final int MAX_HASH_LENGTH = 25;
@@ -23,8 +23,7 @@ public class SubsequenceHashLookupTable {
     private Map<Integer, List<Integer>> hashTable;
 
     /**
-     * Generates a new subsequence hash lookup table.
-     * Performance is optimized to compute hashes in O(n).
+     * Generates a new subsequence hash lookup table. Performance is optimized to compute hashes in O(n).
      * @param windowSize the size of the subsequences.
      * @param tokens the tokens to hash over.
      * @param markedTokens the set of marked tokens.
@@ -76,10 +75,10 @@ public class SubsequenceHashLookupTable {
     }
 
     /**
-     * Creates hashes for all subsequences with windowSize.
-     * Code is optimized to perform in O(n) using a windowing approach.
+     * Creates hashes for all subsequences with windowSize. Code is optimized to perform in O(n) using a windowing approach.
      * Hashes are computed by \sum from (i=0 to windowSize) with hash(tokens[offset+i]) * pow(2, hashLength-1-i)
-     * @param markedTokens contains the marked tokens. Subsequences containing a marked token will receive the NO_HASH value.
+     * @param markedTokens contains the marked tokens. Subsequences containing a marked token will receive the NO_HASH
+     * value.
      */
     private void computeSubsequenceHashes(Set<Token> markedTokens) {
         int hash = 0;
@@ -113,9 +112,8 @@ public class SubsequenceHashLookupTable {
     private void addToHashTable(int startIndex, int subsequenceHash) {
         if (hashTable.containsKey(subsequenceHash)) {
             hashTable.get(subsequenceHash).add(startIndex);
-        }
-        else {
-            List<Integer> startIndexes = new  ArrayList<>();
+        } else {
+            List<Integer> startIndexes = new ArrayList<>();
             startIndexes.add(startIndex);
             hashTable.put(subsequenceHash, startIndexes);
         }