Quellcode durchsuchen

Fix some code style issues in the text frontend.

Timur Sağlam vor 4 Jahren
Ursprung
Commit
7c402af3a9

+ 5 - 5
jplag.frontend.text/src/main/antlr/text.g

@@ -50,7 +50,7 @@ options
 {
     public void newline() {
         super.newline();
-        ((InputState) inputState).column = 1;
+        ((InputState) inputState).setColumnIndex(1);
     }
 
     public void consume() throws antlr.CharStreamException {
@@ -58,16 +58,16 @@ options
             InputState state = (InputState) inputState;
             if (text.length() == 0) {
                 // remember token start column
-                state.tokenColumn = state.column;
+                state.setTokenColumnIndex(state.getColumnIndex());
             }
-            state.column++;
+            state.setColumnIndex(state.getColumnIndex() + 1);
         }
         super.consume();
     }
 
     protected Token makeToken(int t) {
         ParserToken token = (ParserToken) super.makeToken(t);
-        token.setColumn(((InputState) inputState).tokenColumn);
+        token.setColumn(((InputState) inputState).getTokenColumnIndex());
         return token;
     }
 }
@@ -88,7 +88,7 @@ SPECIALS : ('#' | '$' | '%' | '&' | '+' | '<' | '=' | '*' |
 
 // Whitespace -- ignored
 SPACE : ( ' '
-	  |	'\t' //{ ((InputState)inputState).column += 7; }
+	  |	'\t' //{ ((InputState)inputState).setColumnIndex((InputState)inputState).getColumnIndex() + 7); }
 	  |	'\f'
 	  |     '\240'
 	  |     ('\001' .. '\010')

+ 26 - 9
jplag.frontend.text/src/main/java/de/jplag/text/InputState.java

@@ -10,31 +10,48 @@ import antlr.LexerSharedInputState;
  * This object contains the data associated with an input stream of characters. Multiple lexers share a single
  * LexerSharedInputState to lex the same input stream.
  */
-@SuppressWarnings({"java:S1104", "java:S2387"})
 public class InputState extends LexerSharedInputState {
-    public int column = 0;
-    public int tokenColumn = 0;
+    private int columnIndex;
+    private int tokenColumnIndex;
 
     public InputState(InputBuffer inputBuffer) {
         super(inputBuffer);
-        column = 1;
-        line = 1;
+        initialize();
     }
 
     public InputState(InputStream inputStream) {
         super(inputStream);
-        column = 1;
-        line = 1;
+        initialize();
     }
 
     public InputState(Reader inputReader) {
         super(inputReader);
-        column = 1;
-        line = 1;
+        initialize();
     }
 
     @Override
     public int getLine() {
         return line;
     }
+
+    public int getColumnIndex() {
+        return columnIndex;
+    }
+
+    public void setColumnIndex(int columnIndex) {
+        this.columnIndex = columnIndex;
+    }
+
+    public int getTokenColumnIndex() {
+        return tokenColumnIndex;
+    }
+
+    public void setTokenColumnIndex(int tokenColumnIndex) {
+        this.tokenColumnIndex = tokenColumnIndex;
+    }
+
+    private final void initialize() {
+        columnIndex = 1;
+        line = 1;
+    }
 }

+ 5 - 1
jplag.frontend.text/src/main/java/de/jplag/text/Parser.java

@@ -12,7 +12,7 @@ import de.jplag.TokenList;
 
 public class Parser extends AbstractParser {
 
-    protected Hashtable<String, Integer> table = new Hashtable<>();
+    private final Hashtable<String, Integer> table = new Hashtable<>();
     protected int serial = 1; // 0 is FILE_END token
 
     private TokenList tokens;
@@ -84,4 +84,8 @@ public class Parser extends AbstractParser {
         }
         return true;
     }
+
+    protected Hashtable<String, Integer> getTable() {
+        return table;
+    }
 }

+ 1 - 1
jplag.frontend.text/src/main/java/de/jplag/text/ParserToken.java

@@ -9,7 +9,7 @@ public class ParserToken extends Token {
     private int line = -1;
 
     /**
-     * This variable holds the column of the current token in its line.
+     * This variable holds the columnIndex of the current token in its line.
      */
     private int column = -1;
 

+ 2 - 2
jplag.frontend.text/src/main/java/de/jplag/text/TextToken.java

@@ -10,14 +10,14 @@ public class TextToken extends Token {
 
     private static int getSerial(String text, Parser parser) {
         text = text.toLowerCase();
-        Integer serial = parser.table.get(text);
+        Integer serial = parser.getTable().get(text);
         if (serial == null) {
             serial = parser.serial;
             if (parser.serial == Integer.MAX_VALUE)
                 parser.outOfSerials();
             else
                 parser.serial++;
-            parser.table.put(text, serial);
+            parser.getTable().put(text, serial);
         }
         return serial;
     }