Skip to content

Commit

Permalink
remove final from parameter lists
Browse files Browse the repository at this point in the history
  • Loading branch information
nilswende committed Oct 24, 2024
1 parent 497c810 commit 0d74d07
Show file tree
Hide file tree
Showing 30 changed files with 177 additions and 159 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/wn/dbml/compiler/DbmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class DbmlParser {
*
* @param dbml a DBML string
*/
public static Database parse(final String dbml) {
public static Database parse(String dbml) {
return new ParserImpl().parse(new LexerImpl(dbml));
}

Expand All @@ -24,7 +24,7 @@ public static Database parse(final String dbml) {
*
* @param dbml a DBML reader
*/
public static Database parse(final Reader dbml) {
public static Database parse(Reader dbml) {
return new ParserImpl().parse(new LexerImpl(dbml));
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/wn/dbml/compiler/ParsingException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class ParsingException extends RuntimeException {
private final Position position;

public ParsingException(final Position position, final String msg) {
public ParsingException(Position position, String msg) {
super(position + " " + msg);
this.position = position;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/wn/dbml/compiler/lexer/AbstractLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ abstract class AbstractLexer implements Lexer {
protected final LookaheadReader reader;
private boolean ended;

public AbstractLexer(final String string) {
public AbstractLexer(String string) {
this(new StringReader(string));
}

public AbstractLexer(final Reader reader) {
public AbstractLexer(Reader reader) {
this.reader = new LookaheadReader(reader);
}

Expand All @@ -30,7 +30,7 @@ public Token nextToken() {
return token;
}

private boolean isEndToken(final Token token) {
private boolean isEndToken(Token token) {
var type = token.getType();
return type == TokenType.EOF || type == TokenType.ILLEGAL;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/wn/dbml/compiler/lexer/Char.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ final class Char {
private Char() {
}

public static boolean isDigit(final int c) {
public static boolean isDigit(int c) {
return '0' <= c && c <= '9';
}

public static boolean isLetter(final int c) {
public static boolean isLetter(int c) {
return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z';
}

public static boolean isLinebreak(final int c) {
public static boolean isLinebreak(int c) {
return c == '\n' || c == '\r';
}

public static boolean isWordChar(final int c) {
public static boolean isWordChar(int c) {
return isLetter(c) || isDigit(c) || c == '_';
}

public static boolean isHexDigit(final int c) {
public static boolean isHexDigit(int c) {
return '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F';
}
}
28 changes: 14 additions & 14 deletions src/main/java/com/wn/dbml/compiler/lexer/LexerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class LexerImpl extends AbstractLexer {
private static final String OUTPUT_LINEBREAK = "\n";
private static final String OUTPUT_SPACE = " ";

public LexerImpl(final String string) {
public LexerImpl(String string) {
super(string);
}

public LexerImpl(final Reader reader) {
public LexerImpl(Reader reader) {
super(reader);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ protected Token nextTokenImpl() {
};
}

private Token nextWord(final int next) {
private Token nextWord(int next) {
var word = nextWholeWord(next);
return KeywordType.of(word) == KeywordType.MULTI
? nextMultiKeyword(word)
Expand All @@ -62,7 +62,7 @@ private Token nextWord(final int next) {
: new TokenImpl(word);
}

private String nextWholeWord(final int next) {
private String nextWholeWord(int next) {
var sb = new StringBuilder();
var c = next;
while (true) {
Expand All @@ -74,7 +74,7 @@ private String nextWholeWord(final int next) {
return sb.toString();
}

private Token nextMultiKeyword(final String prefix) {
private Token nextMultiKeyword(String prefix) {
var separatorToken = nextTokenImpl();
var separatorValue = separatorToken.getValue();
if (!TokenType.isMultiSeparator(separatorValue)) {
Expand All @@ -101,15 +101,15 @@ private Token nextMultiKeyword(final String prefix) {
};
}

private Token nextLTSymbol(final int lt) {
private Token nextLTSymbol(int lt) {
if (reader.lookahead() == '>') {
skipChars(1);
return new TokenImpl(TokenType.NE, "<>");
}
return new TokenImpl(TokenType.LT, lt);
}

private Token nextString(final int quote) {
private Token nextString(int quote) {
var lookahead = reader.lookahead(2);
if (quote == '\'' && lookahead.startsWith("''")) {
skipChars(2);
Expand All @@ -119,7 +119,7 @@ private Token nextString(final int quote) {
}
}

private Token nextMultiLineString(final String quote, final TokenType tokenType) {
private Token nextMultiLineString(String quote, TokenType tokenType) {
var multiLineSb = new MultiLineStringBuilder(OUTPUT_LINEBREAK);
var sb = new StringBuilder();
while (true) {
Expand Down Expand Up @@ -153,13 +153,13 @@ private Token nextMultiLineString(final String quote, final TokenType tokenType)
return new TokenImpl(tokenType, multiLineSb.toString());
}

private String appendEscaped(final String escaped, final StringBuilder sb) {
private String appendEscaped(String escaped, StringBuilder sb) {
sb.append(escaped);
skipChars(escaped.length());
return reader.lookahead(escaped.length());
}

private Token nextSingleLineString(final int quote) {
private Token nextSingleLineString(int quote) {
var sb = new StringBuilder();
while (true) {
var c = reader.nextChar();
Expand Down Expand Up @@ -189,17 +189,17 @@ private Token nextSingleLineString(final int quote) {
return new TokenImpl(type, sb.toString());
}

private int appendEscaped(final int escaped, final StringBuilder sb) {
private int appendEscaped(int escaped, StringBuilder sb) {
sb.append((char) escaped);
skipChars(1);
return reader.lookahead();
}

private Token nextExpression(final int quote) {
private Token nextExpression(int quote) {
return nextSingleLineString(quote);
}

private Token nextComment(final int forwardSlash) {
private Token nextComment(int forwardSlash) {
var next = reader.lookahead();
if (next == '/') {
skipChars(1);
Expand Down Expand Up @@ -234,7 +234,7 @@ private Token nextColor() {
return new TokenImpl(TokenType.ILLEGAL, color);
}

private void skipChars(final int length) {
private void skipChars(int length) {
for (int i = 0; i < length; i++) {
reader.nextChar();
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/wn/dbml/compiler/lexer/LookaheadReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.wn.dbml.compiler.Position;

import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PushbackReader;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.util.Objects;

class LookaheadReader {
Expand All @@ -11,11 +15,11 @@ class LookaheadReader {
private int line = 1, column = 0;
private boolean wasLinebreak;

public LookaheadReader(final Reader reader) {
public LookaheadReader(Reader reader) {
this(reader, DEFAULT_LOOKAHEAD_BUFFER_SIZE);
}

public LookaheadReader(final Reader reader, final int size) {
public LookaheadReader(Reader reader, int size) {
if (size < DEFAULT_LOOKAHEAD_BUFFER_SIZE) throw new IllegalArgumentException("Cannot decrease the buffer size");
var buffered = Objects.requireNonNull(reader) instanceof BufferedReader ? reader : new BufferedReader(reader);
this.reader = new PushbackReader(buffered, size);
Expand Down Expand Up @@ -58,7 +62,7 @@ public int lookahead() {
return c;
}

public String lookahead(final int length) {
public String lookahead(int length) {
var sb = new StringBuilder();
for (int i = 0; i < length; i++) {
var c = read();
Expand All @@ -70,15 +74,15 @@ public String lookahead(final int length) {
return chars;
}

public void pushback(final int c) {
public void pushback(int c) {
try {
reader.unread(c);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public void pushback(final String chars) {
public void pushback(String chars) {
try {
reader.unread(chars.toCharArray());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public MultiLineStringBuilder() {
this(System.lineSeparator());
}

public MultiLineStringBuilder(final String linebreak) {
public MultiLineStringBuilder(String linebreak) {
this.linebreak = linebreak;
}

public void appendLine(final String line) {
public void appendLine(String line) {
lines.add(line);
}

Expand All @@ -29,23 +29,23 @@ public String toString() {
return String.join(linebreak, lines);
}

private void removeLeadingSpaces(final List<String> lines) {
private void removeLeadingSpaces(List<String> lines) {
lines.stream()
.filter(l -> !l.isBlank())
.mapToInt(this::countLeadingSpaces)
.min()
.ifPresent(minLeadingSpaces -> lines.replaceAll(l -> l.substring(Math.min(minLeadingSpaces, l.length()))));
}

private int countLeadingSpaces(final String line) {
private int countLeadingSpaces(String line) {
int i = 0;
while (i < line.length() && line.charAt(i) == ' ') {
i++;
}
return i;
}

private List<String> dropSurroundingBlankLines(final List<String> lines) {
private List<String> dropSurroundingBlankLines(List<String> lines) {
var list = lines;
list = dropLeadingBlankLines(list);
Collections.reverse(list);
Expand All @@ -54,7 +54,7 @@ private List<String> dropSurroundingBlankLines(final List<String> lines) {
return list;
}

private List<String> dropLeadingBlankLines(final List<String> lines) {
private List<String> dropLeadingBlankLines(List<String> lines) {
return lines.stream()
.dropWhile(String::isBlank)
.collect(Collectors.toCollection(ArrayList::new));
Expand Down
Loading

0 comments on commit 0d74d07

Please sign in to comment.