Prechádzať zdrojové kódy

Remove code smells detected by sonarcloud

Robin Maisch 4 rokov pred
rodič
commit
382d349fd0

+ 6 - 5
jplag.frontend.golang/src/main/java/de/jplag/golang/GoListener.java

@@ -2,9 +2,7 @@ package de.jplag.golang;
 
 import static de.jplag.golang.GoTokenConstants.*;
 
-import java.util.Arrays;
-import java.util.Optional;
-import java.util.Stack;
+import java.util.*;
 
 import org.antlr.v4.runtime.Token;
 import org.antlr.v4.runtime.tree.TerminalNode;
@@ -16,11 +14,11 @@ public class GoListener extends GoParserBaseListener {
 
     public static final int NONE = -1;
     private final GoParserAdapter parserAdapter;
-    private final Stack<GoBlockContext> blockContexts;
+    private final Deque<GoBlockContext> blockContexts;
 
     public GoListener(GoParserAdapter parserAdapter) {
         this.parserAdapter = parserAdapter;
-        blockContexts = new Stack<>();
+        blockContexts = new LinkedList<>();
     }
 
     /**
@@ -477,6 +475,9 @@ public class GoListener extends GoParserBaseListener {
             }
             case "{" -> transformToken(getCurrentContext().getBegin(), token);
             case "}" -> transformToken(getCurrentContext().getEnd(), token);
+            default -> {
+                // do nothing.
+            }
         }
         super.visitTerminal(node);
     }

+ 2 - 2
jplag.frontend.golang/src/main/java/de/jplag/golang/GoParserAdapter.java

@@ -44,8 +44,8 @@ public class GoParserAdapter extends AbstractParser {
             currentFile = fileName;
 
             GoLexer lexer = new GoLexer(CharStreams.fromStream(inputStream));
-            CommonTokenStream tokens = new CommonTokenStream(lexer);
-            GoParser parser = new GoParser(tokens);
+            CommonTokenStream tokenStream = new CommonTokenStream(lexer);
+            GoParser parser = new GoParser(tokenStream);
 
             ParserRuleContext entryContext = parser.sourceFile();
             ParseTreeWalker treeWalker = new ParseTreeWalker();

+ 4 - 0
jplag.frontend.golang/src/main/java/de/jplag/golang/grammar/GoTokenUtils.java

@@ -14,4 +14,8 @@ public class GoTokenUtils {
     public static GoToken getDummyToken(int type, String fileName) {
         return new GoToken(type, fileName, NOT_SET, NOT_SET, NOT_SET);
     }
+
+    private GoTokenUtils() {
+        // Utility class, should not be instantiated.
+    }
 }

+ 1 - 1
jplag.frontend.golang/src/test/java/de/jplag/golang/GoFrontendTest.java

@@ -27,7 +27,7 @@ import de.jplag.TokenPrinter;
 import de.jplag.golang.grammar.GoTokenUtils;
 import de.jplag.testutils.TestErrorConsumer;
 
-public class GoFrontendTest {
+class GoFrontendTest {
     /**
      * Test source file that is supposed to produce a complete set of tokens, i.e. all types of tokens.
      */

+ 2 - 2
jplag/src/test/java/de/jplag/special/TokenPrinterTest.java

@@ -52,9 +52,9 @@ public class TokenPrinterTest extends TestBase {
         });
     }
 
-    @Disabled
+    @Disabled("No meaningful test, just an aid to design frontend")
     @Test
-    public void printGoFiles() {
+    void printGoFiles() {
         printSubmissions(options -> options.setLanguageOption(LanguageOption.GO_LANG));
     }