Robin Maisch 4 лет назад
Родитель
Сommit
e539c3d99a

+ 4 - 3
jplag.frontend.R/src/main/java/de/jplag/R/JplagRListener.java

@@ -11,8 +11,9 @@ import de.jplag.R.grammar.RListener;
 import de.jplag.R.grammar.RParser;
 
 /**
- * Listener class for visiting the R ANTLR parse tree. Transforms the visited ANTLR token into JPlag tokens.
- * Based on an R frontend for JPlag v2.15 by Olmo Kramer, see their <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag fork</a>.
+ * Listener class for visiting the R ANTLR parse tree. Transforms the visited ANTLR token into JPlag tokens. Based on an
+ * R frontend for JPlag v2.15 by Olmo Kramer, see their
+ * <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag fork</a>.
  * @author Robin Maisch
  */
 public class JplagRListener implements RListener, RFilterListener, RTokenConstants {
@@ -172,7 +173,7 @@ public class JplagRListener implements RListener, RFilterListener, RTokenConstan
 
     @Override
     public void enterWhile_statement(RParser.While_statementContext ctx) {
-       transformToken(WHILE_BEGIN, ctx.getStart());
+        transformToken(WHILE_BEGIN, ctx.getStart());
     }
 
     @Override

+ 2 - 2
jplag.frontend.R/src/main/java/de/jplag/R/RToken.java

@@ -1,8 +1,8 @@
 package de.jplag.R;
 
 /**
- * This class represents the occurrence of an R Token in the source code.
- * Based on an R frontend for JPlag v2.15 by Olmo Kramer, see their <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag fork</a>.
+ * This class represents the occurrence of an R Token in the source code. Based on an R frontend for JPlag v2.15 by Olmo
+ * Kramer, see their <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag fork</a>.
  * @author Robin Maisch
  */
 public class RToken extends de.jplag.Token implements RTokenConstants {

+ 3 - 2
jplag.frontend.R/src/main/java/de/jplag/R/RTokenConstants.java

@@ -3,8 +3,9 @@ package de.jplag.R;
 import de.jplag.TokenConstants;
 
 /**
- * Tokens in R that are deemed important when comparing submissions for plagiarisms.
- * Based on an R frontend for JPlag v2.15 by Olmo Kramer, see their <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag fork</a>.
+ * Tokens in R that are deemed important when comparing submissions for plagiarisms. Based on an R frontend for JPlag
+ * v2.15 by Olmo Kramer, see their <a href="https://github.com/CodeGra-de/jplag/tree/master/jplag.frontend.R">JPlag
+ * fork</a>.
  * @author Robin Maisch
  */
 public interface RTokenConstants extends TokenConstants {

+ 30 - 25
jplag.frontend.R/src/test/java/de/jplag/R/RFrontendTest.java

@@ -1,14 +1,7 @@
 package de.jplag.R;
 
-import de.jplag.Token;
-import de.jplag.TokenConstants;
-import de.jplag.TokenList;
-import de.jplag.TokenPrinter;
-import de.jplag.testutils.TestErrorConsumer;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.*;
 import java.nio.file.Files;
@@ -17,22 +10,30 @@ import java.util.List;
 import java.util.stream.IntStream;
 import java.util.stream.StreamSupport;
 
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import de.jplag.Token;
+import de.jplag.TokenConstants;
+import de.jplag.TokenList;
+import de.jplag.TokenPrinter;
+import de.jplag.testutils.TestErrorConsumer;
 
 public class RFrontendTest {
 
     /**
-     *  Regular expression for comments.
+     * Regular expression for comments.
      */
     private static final String R_COMMENT = "#.*";
 
     /**
-     *  Test source file that is supposed to produce a complete set of tokens, i.e. all types of tokens.
+     * Test source file that is supposed to produce a complete set of tokens, i.e. all types of tokens.
      */
     private static final String COMPLETE_TEST_FILE = "Complete.R";
     private final Logger logger = LoggerFactory.getLogger("R frontend test");
-    private final String[] testFiles = new String[]{"Game.r", COMPLETE_TEST_FILE};
+    private final String[] testFiles = new String[] {"Game.r", COMPLETE_TEST_FILE};
     private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "R").toFile();
     private Language language;
 
@@ -45,12 +46,13 @@ public class RFrontendTest {
     @Test
     void parseTestFiles() {
         for (String fileName : testFiles) {
-            TokenList tokens = language.parse(testFileLocation, new String[]{fileName});
+            TokenList tokens = language.parse(testFileLocation, new String[] {fileName});
             String output = TokenPrinter.printTokens(tokens, testFileLocation, List.of(fileName));
             logger.info(output);
 
             testSourceCoverage(fileName, tokens);
-            if (fileName.equals(COMPLETE_TEST_FILE)) testTokenCoverage(tokens, fileName);
+            if (fileName.equals(COMPLETE_TEST_FILE))
+                testTokenCoverage(tokens, fileName);
         }
     }
 
@@ -67,13 +69,16 @@ public class RFrontendTest {
             String commentExpression = getCommentExpression();
 
             // All lines that contain code
-            var codeLines = IntStream.range(1, lines.size() + 1).filter(idx -> !lines.get(idx - 1).matches("\\s*(%s)?".formatted(commentExpression))).toArray();
+            var codeLines = IntStream.range(1, lines.size() + 1).filter(idx -> !lines.get(idx - 1).matches("\\s*(%s)?".formatted(commentExpression)))
+                    .toArray();
             // All lines that contain token
             var tokenLines = IntStream.range(0, tokens.size()).mapToObj(tokens::getToken).mapToInt(Token::getLine).distinct().toArray();
 
             if (codeLines.length > tokenLines.length) {
-                var diffLine = IntStream.range(0, codeLines.length).dropWhile(lineIdx -> lineIdx < tokenLines.length && codeLines[lineIdx] == tokenLines[lineIdx]).findFirst();
-                diffLine.ifPresent(lineIdx -> fail("Line %d of file '%s' is not represented in the token list.".formatted(codeLines[lineIdx], fileName)));
+                var diffLine = IntStream.range(0, codeLines.length)
+                        .dropWhile(lineIdx -> lineIdx < tokenLines.length && codeLines[lineIdx] == tokenLines[lineIdx]).findFirst();
+                diffLine.ifPresent(
+                        lineIdx -> fail("Line %d of file '%s' is not represented in the token list.".formatted(codeLines[lineIdx], fileName)));
             }
             assertArrayEquals(codeLines, tokenLines);
         } catch (IOException exception) {
@@ -88,15 +93,15 @@ public class RFrontendTest {
      * @param fileName The file name of the complete code example
      */
     private void testTokenCoverage(TokenList tokens, String fileName) {
-        var foundTokens = StreamSupport.stream(tokens.allTokens().spliterator(), true).mapToInt(Token::getType)
-                .sorted().distinct().toArray();
+        var foundTokens = StreamSupport.stream(tokens.allTokens().spliterator(), true).mapToInt(Token::getType).sorted().distinct().toArray();
         // Exclude SEPARATOR_TOKEN, as it does not occur
-        var allTokens = IntStream.range(0, RTokenConstants.NUM_DIFF_TOKENS)
-                .filter(i -> i != TokenConstants.SEPARATOR_TOKEN).toArray();
+        var allTokens = IntStream.range(0, RTokenConstants.NUM_DIFF_TOKENS).filter(i -> i != TokenConstants.SEPARATOR_TOKEN).toArray();
 
         if (allTokens.length > foundTokens.length) {
-            var diffLine = IntStream.range(0, allTokens.length).dropWhile(lineIdx -> lineIdx < foundTokens.length && allTokens[lineIdx] == foundTokens[lineIdx]).findFirst();
-            diffLine.ifPresent(lineIdx -> fail("Token type %s was not found in the complete code example '%s'.".formatted(new RToken(allTokens[lineIdx], fileName, -1, -1, -1).type2string(), fileName)));
+            var diffLine = IntStream.range(0, allTokens.length)
+                    .dropWhile(lineIdx -> lineIdx < foundTokens.length && allTokens[lineIdx] == foundTokens[lineIdx]).findFirst();
+            diffLine.ifPresent(lineIdx -> fail("Token type %s was not found in the complete code example '%s'."
+                    .formatted(new RToken(allTokens[lineIdx], fileName, -1, -1, -1).type2string(), fileName)));
         }
         assertArrayEquals(allTokens, foundTokens);
     }

+ 0 - 5
pom.xml

@@ -162,11 +162,6 @@
                 <artifactId>R</artifactId>
                 <version>${project.version}</version>
             </dependency>
-            <dependency>
-                <groupId>${project.groupId}</groupId>
-                <artifactId>scala</artifactId>
-                <version>${project.version}</version>
-            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>cpp</artifactId>