From 0d74d0775565a6d0295ee9da06a2f4a8a199e3d0 Mon Sep 17 00:00:00 2001 From: nilswende Date: Thu, 24 Oct 2024 18:24:30 +0200 Subject: [PATCH] remove final from parameter lists --- .../java/com/wn/dbml/compiler/DbmlParser.java | 4 +- .../wn/dbml/compiler/ParsingException.java | 2 +- .../wn/dbml/compiler/lexer/AbstractLexer.java | 6 +-- .../java/com/wn/dbml/compiler/lexer/Char.java | 10 ++-- .../com/wn/dbml/compiler/lexer/LexerImpl.java | 28 +++++----- .../dbml/compiler/lexer/LookaheadReader.java | 16 +++--- .../lexer/MultiLineStringBuilder.java | 12 ++--- .../wn/dbml/compiler/parser/ParserImpl.java | 54 +++++++++---------- .../wn/dbml/compiler/parser/RingBuffer.java | 4 +- .../wn/dbml/compiler/parser/TokenAccess.java | 28 +++++----- .../wn/dbml/compiler/token/KeywordType.java | 2 +- .../com/wn/dbml/compiler/token/Literals.java | 8 +-- .../com/wn/dbml/compiler/token/TokenImpl.java | 8 +-- .../com/wn/dbml/compiler/token/TokenType.java | 6 +-- src/main/java/com/wn/dbml/model/Column.java | 8 +-- src/main/java/com/wn/dbml/model/Database.java | 23 ++++---- src/main/java/com/wn/dbml/model/Enum.java | 6 +-- .../java/com/wn/dbml/model/EnumValue.java | 6 +-- src/main/java/com/wn/dbml/model/Index.java | 14 +++-- src/main/java/com/wn/dbml/model/Name.java | 12 ++--- src/main/java/com/wn/dbml/model/Note.java | 2 +- src/main/java/com/wn/dbml/model/Project.java | 4 +- src/main/java/com/wn/dbml/model/Relation.java | 4 +- .../java/com/wn/dbml/model/Relationship.java | 6 +-- src/main/java/com/wn/dbml/model/Schema.java | 22 ++++---- src/main/java/com/wn/dbml/model/Table.java | 23 ++++---- .../java/com/wn/dbml/model/TableGroup.java | 6 +-- .../java/com/wn/dbml/compiler/LexerTest.java | 6 +-- .../java/com/wn/dbml/compiler/ParserTest.java | 4 +- .../dbml/compiler/parser/ParserImplTest.java | 2 +- 30 files changed, 177 insertions(+), 159 deletions(-) diff --git a/src/main/java/com/wn/dbml/compiler/DbmlParser.java b/src/main/java/com/wn/dbml/compiler/DbmlParser.java index 3c6bd69..aefeec7 100644 --- a/src/main/java/com/wn/dbml/compiler/DbmlParser.java +++ b/src/main/java/com/wn/dbml/compiler/DbmlParser.java @@ -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)); } @@ -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)); } } diff --git a/src/main/java/com/wn/dbml/compiler/ParsingException.java b/src/main/java/com/wn/dbml/compiler/ParsingException.java index fb4c3af..0d74c24 100644 --- a/src/main/java/com/wn/dbml/compiler/ParsingException.java +++ b/src/main/java/com/wn/dbml/compiler/ParsingException.java @@ -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; } diff --git a/src/main/java/com/wn/dbml/compiler/lexer/AbstractLexer.java b/src/main/java/com/wn/dbml/compiler/lexer/AbstractLexer.java index 42d6227..10987fd 100644 --- a/src/main/java/com/wn/dbml/compiler/lexer/AbstractLexer.java +++ b/src/main/java/com/wn/dbml/compiler/lexer/AbstractLexer.java @@ -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); } @@ -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; } diff --git a/src/main/java/com/wn/dbml/compiler/lexer/Char.java b/src/main/java/com/wn/dbml/compiler/lexer/Char.java index 57f240a..0b7eab0 100644 --- a/src/main/java/com/wn/dbml/compiler/lexer/Char.java +++ b/src/main/java/com/wn/dbml/compiler/lexer/Char.java @@ -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'; } } diff --git a/src/main/java/com/wn/dbml/compiler/lexer/LexerImpl.java b/src/main/java/com/wn/dbml/compiler/lexer/LexerImpl.java index c0cb348..07f85cb 100644 --- a/src/main/java/com/wn/dbml/compiler/lexer/LexerImpl.java +++ b/src/main/java/com/wn/dbml/compiler/lexer/LexerImpl.java @@ -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); } @@ -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) @@ -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) { @@ -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)) { @@ -101,7 +101,7 @@ 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, "<>"); @@ -109,7 +109,7 @@ private Token nextLTSymbol(final int lt) { 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); @@ -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) { @@ -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(); @@ -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); @@ -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(); } diff --git a/src/main/java/com/wn/dbml/compiler/lexer/LookaheadReader.java b/src/main/java/com/wn/dbml/compiler/lexer/LookaheadReader.java index 6d18041..195b67e 100644 --- a/src/main/java/com/wn/dbml/compiler/lexer/LookaheadReader.java +++ b/src/main/java/com/wn/dbml/compiler/lexer/LookaheadReader.java @@ -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 { @@ -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); @@ -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(); @@ -70,7 +74,7 @@ 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) { @@ -78,7 +82,7 @@ public void pushback(final int c) { } } - public void pushback(final String chars) { + public void pushback(String chars) { try { reader.unread(chars.toCharArray()); } catch (IOException e) { diff --git a/src/main/java/com/wn/dbml/compiler/lexer/MultiLineStringBuilder.java b/src/main/java/com/wn/dbml/compiler/lexer/MultiLineStringBuilder.java index 0cf8cdc..103e902 100644 --- a/src/main/java/com/wn/dbml/compiler/lexer/MultiLineStringBuilder.java +++ b/src/main/java/com/wn/dbml/compiler/lexer/MultiLineStringBuilder.java @@ -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); } @@ -29,7 +29,7 @@ public String toString() { return String.join(linebreak, lines); } - private void removeLeadingSpaces(final List lines) { + private void removeLeadingSpaces(List lines) { lines.stream() .filter(l -> !l.isBlank()) .mapToInt(this::countLeadingSpaces) @@ -37,7 +37,7 @@ private void removeLeadingSpaces(final List lines) { .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++; @@ -45,7 +45,7 @@ private int countLeadingSpaces(final String line) { return i; } - private List dropSurroundingBlankLines(final List lines) { + private List dropSurroundingBlankLines(List lines) { var list = lines; list = dropLeadingBlankLines(list); Collections.reverse(list); @@ -54,7 +54,7 @@ private List dropSurroundingBlankLines(final List lines) { return list; } - private List dropLeadingBlankLines(final List lines) { + private List dropLeadingBlankLines(List lines) { return lines.stream() .dropWhile(String::isBlank) .collect(Collectors.toCollection(ArrayList::new)); diff --git a/src/main/java/com/wn/dbml/compiler/parser/ParserImpl.java b/src/main/java/com/wn/dbml/compiler/parser/ParserImpl.java index 098148c..b80e673 100644 --- a/src/main/java/com/wn/dbml/compiler/parser/ParserImpl.java +++ b/src/main/java/com/wn/dbml/compiler/parser/ParserImpl.java @@ -39,7 +39,7 @@ public class ParserImpl implements Parser { private Database database; @Override - public Database parse(final Lexer lexer) { + public Database parse(Lexer lexer) { relationshipDefinitions = new ArrayList<>(); tokenAccess = new TokenAccess(lexer); database = new Database(); @@ -90,7 +90,7 @@ private void parseProject() { database.setProject(project); } - private void parseProjectProperty(final Project project) { + private void parseProjectProperty(Project project) { var property = tokenValue(); next(COLON); next(stringTypes()); @@ -131,7 +131,7 @@ private Table parseTableHead() { return table; } - private void parseTableSetting(final Table table) { + private void parseTableSetting(Table table) { if (typeIs(HEADERCOLOR)) { addSetting(table, TableSetting.HEADERCOLOR, COLOR); } else if (typeIs(NOTE)) { @@ -139,7 +139,7 @@ private void parseTableSetting(final Table table) { } } - private void parseTableBody(final Table table) { + private void parseTableBody(Table table) { next(LITERAL); parseColumn(table); loop: @@ -156,7 +156,7 @@ private void parseTableBody(final Table table) { } } - private void parseColumn(final Table table) { + private void parseColumn(Table table) { var name = tokenValue(); if (table.containsColumn(name)) { error("Column '%s' is already defined", Name.of(table, name)); @@ -196,7 +196,7 @@ private String parseColumnDatatype() { } } - private void parseColumnSetting(final Column column) { + private void parseColumnSetting(Column column) { switch (tokenType()) { case NOT_NULL, NULL -> addSetting(column, ColumnSetting.NOT_NULL); case PRIMARY_KEY, PK -> addSetting(column, ColumnSetting.PRIMARY_KEY); @@ -209,7 +209,7 @@ private void parseColumnSetting(final Column column) { } } - private RelationshipDefinition parseInlineRef(final Column columnFrom) { + private RelationshipDefinition parseInlineRef(Column columnFrom) { String name = null; next(LITERAL, DSTRING, COLON); // name if (typeIs(LITERAL, DSTRING)) { @@ -225,7 +225,7 @@ private RelationshipDefinition parseInlineRef(final Column columnFrom) { new EnumMap<>(RelationshipSetting.class)); } - private void parseIndexes(final Table table) { + private void parseIndexes(Table table) { next(LBRACE); do { next(LPAREN, LITERAL, EXPR); @@ -234,7 +234,7 @@ private void parseIndexes(final Table table) { next(RBRACE); } - private void parseIndex(final Table table) { + private void parseIndex(Table table) { try (var ignored = new LinebreakMode()) { var index = table.addIndex(); if (typeIs(LPAREN)) { @@ -264,7 +264,7 @@ private void parseIndex(final Table table) { } } - private void parseIndexColumn(final Table table, final Index index) { + private void parseIndexColumn(Table table, Index index) { var columnName = tokenValue(); if (typeIs(LITERAL) && !table.containsColumn(columnName)) { error("Column '%s' is not defined", columnName); @@ -274,7 +274,7 @@ private void parseIndexColumn(final Table table, final Index index) { } } - private void parseIndexSetting(final Index index) { + private void parseIndexSetting(Index index) { switch (tokenType()) { case UNIQUE -> addSetting(index, IndexSetting.UNIQUE); case NAME -> addSetting(index, IndexSetting.NAME, stringTypes()); @@ -384,7 +384,7 @@ private void parseEnum() { } } - private void parseEnumSetting(final EnumValue value) { + private void parseEnumSetting(EnumValue value) { if (typeIs(NOTE)) { value.setNote(parseInlineNote()); } else { @@ -436,7 +436,7 @@ private void createRelationships() { } } - private List validateColumnNames(final RelationshipDefinition definition, final ColumnNames names) { + private List validateColumnNames(RelationshipDefinition definition, ColumnNames names) { var schema = database.getOrCreateSchema(names.schema()); if (!schema.containsTable(names.table())) { error(definition, "Table '%s' is not defined", Name.of(schema, names.table())); @@ -450,7 +450,7 @@ private List validateColumnNames(final RelationshipDefinition definition return names.columns().stream().map(table::getColumn).toList(); } - private Table findTable(final TableName tableName) { + private Table findTable(TableName tableName) { var table = database.getAlias(tableName.table()); if (table == null) { var tableSchema = database.getOrCreateSchema(tableName.schema()); @@ -492,7 +492,7 @@ private ColumnName parseColumnName() { return new ColumnName(schemaName, tableName, columnName); } - private ColumnNames parseRefColumnNames(final TokenType... after) { + private ColumnNames parseRefColumnNames(TokenType... after) { String schemaName = Schema.DEFAULT_NAME, tableName, columnName; var columnNames = new ArrayList(); next(LITERAL, DSTRING); // schemaName, tableName @@ -521,7 +521,7 @@ private ColumnNames parseRefColumnNames(final TokenType... after) { return new ColumnNames(schemaName, tableName, columnNames); } - private void parseRefColumnNames(final List columnNames) { + private void parseRefColumnNames(List columnNames) { do { next(LITERAL, DSTRING); // columnName columnNames.add(tokenValue()); @@ -546,7 +546,7 @@ private Note parseInlineNote() { return new Note(tokenValue()); } - private void addSetting(final SettingHolder holder, final T setting, final TokenType... types) { + private void addSetting(SettingHolder holder, T setting, TokenType... types) { if (types != null && types.length > 0) { next(COLON); next(types); @@ -558,17 +558,17 @@ private TokenType[] stringTypes() { return new TokenType[]{SSTRING, DSTRING, TSTRING}; } - private TokenType[] stringTypesOr(final TokenType... types) { + private TokenType[] stringTypesOr(TokenType... types) { return types != null && types.length > 0 ? concat(stringTypes(), types) : stringTypes(); } - private static T[] concat(final T[] first, final T[] second) { + private static T[] concat(T[] first, T[] second) { var result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); return result; } - private void next(final TokenType... types) { + private void next(TokenType... types) { tokenAccess.next(types); } @@ -580,31 +580,31 @@ private String tokenValue() { return tokenAccess.value(); } - private boolean lookaheadTypeIs(final TokenType type) { + private boolean lookaheadTypeIs(TokenType type) { return tokenAccess.lookaheadTypeIs(type); } - private boolean typeIs(final TokenType type) { + private boolean typeIs(TokenType type) { return tokenAccess.typeIs(type); } - private boolean typeIs(final TokenType... types) { + private boolean typeIs(TokenType... types) { return tokenAccess.typeIs(types); } - private void expected(final TokenType... types) { + private void expected(TokenType... types) { tokenAccess.expected(types); } - private void error(final RelationshipDefinition definition, final String msg, final Object... args) { + private void error(RelationshipDefinition definition, String msg, Object... args) { error(definition, String.format(msg, args)); } - private void error(final RelationshipDefinition definition, final String msg) { + private void error(RelationshipDefinition definition, String msg) { throw new ParsingException(definition.position(), msg); } - private void error(final String msg, final Object... args) { + private void error(String msg, Object... args) { tokenAccess.error(msg, args); } diff --git a/src/main/java/com/wn/dbml/compiler/parser/RingBuffer.java b/src/main/java/com/wn/dbml/compiler/parser/RingBuffer.java index 2ee8eab..fd8084a 100644 --- a/src/main/java/com/wn/dbml/compiler/parser/RingBuffer.java +++ b/src/main/java/com/wn/dbml/compiler/parser/RingBuffer.java @@ -7,13 +7,13 @@ class RingBuffer { private final Deque queue; private final int size; - public RingBuffer(final int size) { + public RingBuffer(int size) { if (size < 1) throw new IllegalArgumentException("Illegal Size: " + size); queue = new ArrayDeque<>(size); this.size = size; } - public void add(final E e) { + public void add(E e) { if (queue.size() == size) { poll(); } diff --git a/src/main/java/com/wn/dbml/compiler/parser/TokenAccess.java b/src/main/java/com/wn/dbml/compiler/parser/TokenAccess.java index 1ca55c8..8114039 100644 --- a/src/main/java/com/wn/dbml/compiler/parser/TokenAccess.java +++ b/src/main/java/com/wn/dbml/compiler/parser/TokenAccess.java @@ -24,11 +24,11 @@ class TokenAccess { private Token token; private boolean ignoreLinebreaks = true, ignoreSpaces = true; - TokenAccess(final Lexer lexer) { + TokenAccess(Lexer lexer) { this.lexer = Objects.requireNonNull(lexer); } - public void next(final TokenType... types) { + public void next(TokenType... types) { if (types != null && types.length > 0) { token = nextToken(); if (shouldParseAsLiteral(types)) { @@ -54,7 +54,7 @@ private Token nextTokenFromLexer() { return token; } - private boolean skipToken(final Token token) { + private boolean skipToken(Token token) { return token != null && ( // skip token.getType() == COMMENT @@ -65,13 +65,13 @@ private boolean skipToken(final Token token) { ); } - private boolean shouldParseAsLiteral(TokenType[] types) { + private boolean shouldParseAsLiteral(TokenType... types) { return !type().isWhitespace() && !type().isMultiKeyword() && Arrays.stream(types).noneMatch(this::typeIs) && Arrays.stream(types).anyMatch(TokenType::isLiteral); } - private Token nextLiteral(final TokenType... types) { + private Token nextLiteral(TokenType... types) { var typeSet = Set.of(types); if (typeSet.contains(BLITERAL)) { if (Literals.isBooleanLiteral(value())) { @@ -124,35 +124,35 @@ public String value() { return token.getValue(); } - public boolean lookaheadTypeIs(final TokenType type) { + public boolean lookaheadTypeIs(TokenType type) { return lookahead().getType() == type; } - public boolean typeIs(final TokenType type) { + public boolean typeIs(TokenType type) { return type() == type; } - public boolean typeIs(final TokenType... types) { + public boolean typeIs(TokenType... types) { return Arrays.stream(types).anyMatch(this::typeIs); } - public void expecting(final Token token, final TokenType... types) { + public void expecting(Token token, TokenType... types) { var any = Arrays.stream(types).filter(t -> t == token.getType()).findAny(); if (any.isEmpty() && types.length > 0) { expected(types); } } - public void expected(final TokenType... types) { + public void expected(TokenType... types) { var expected = Arrays.stream(types).map(Objects::toString).collect(Collectors.joining(", ")); error("unexpected token '%s', expected %s. Last tokens: %s", type(), expected, lastTokens); } - public void error(final String msg, final Object... args) { + public void error(String msg, Object... args) { error(String.format(msg, args)); } - public void error(final String msg) { + public void error(String msg) { throw new ParsingException(position(), msg); } @@ -160,11 +160,11 @@ public Position position() { return lookahead.isEmpty() ? lexer.getPosition() : lookahead.peek().position(); } - public void setIgnoreLinebreaks(final boolean ignoreLinebreaks) { + public void setIgnoreLinebreaks(boolean ignoreLinebreaks) { this.ignoreLinebreaks = ignoreLinebreaks; } - public void setIgnoreSpaces(final boolean ignoreSpaces) { + public void setIgnoreSpaces(boolean ignoreSpaces) { this.ignoreSpaces = ignoreSpaces; } diff --git a/src/main/java/com/wn/dbml/compiler/token/KeywordType.java b/src/main/java/com/wn/dbml/compiler/token/KeywordType.java index 2500e02..fd589bb 100644 --- a/src/main/java/com/wn/dbml/compiler/token/KeywordType.java +++ b/src/main/java/com/wn/dbml/compiler/token/KeywordType.java @@ -39,7 +39,7 @@ public enum KeywordType { * * @param word a word */ - public static KeywordType of(final String word) { + public static KeywordType of(String word) { return KEYWORDS.getOrDefault(TokenType.normalize(word), KeywordType.NO); } } diff --git a/src/main/java/com/wn/dbml/compiler/token/Literals.java b/src/main/java/com/wn/dbml/compiler/token/Literals.java index 2f29116..e1c079e 100644 --- a/src/main/java/com/wn/dbml/compiler/token/Literals.java +++ b/src/main/java/com/wn/dbml/compiler/token/Literals.java @@ -20,7 +20,7 @@ private Literals() { * @param value a string * @return the subtype or else null */ - public static TokenType getSubType(final String value) { + public static TokenType getSubType(String value) { if (isBooleanLiteral(value)) { return TokenType.BLITERAL; } else if (isNumberLiteral(value)) { @@ -34,7 +34,7 @@ public static TokenType getSubType(final String value) { * * @param value a string */ - public static boolean isBooleanLiteral(final String value) { + public static boolean isBooleanLiteral(String value) { return value != null && BOOLEAN.contains(value); } @@ -43,7 +43,7 @@ public static boolean isBooleanLiteral(final String value) { * * @param value a string */ - public static boolean isNumberLiteral(final String value) { + public static boolean isNumberLiteral(String value) { return value != null && NUMBER.matcher(value).matches(); } @@ -52,7 +52,7 @@ public static boolean isNumberLiteral(final String value) { * * @param value a string */ - public static boolean isSubType(final String value) { + public static boolean isSubType(String value) { return getSubType(value) != null; } } diff --git a/src/main/java/com/wn/dbml/compiler/token/TokenImpl.java b/src/main/java/com/wn/dbml/compiler/token/TokenImpl.java index b03adb5..933410d 100644 --- a/src/main/java/com/wn/dbml/compiler/token/TokenImpl.java +++ b/src/main/java/com/wn/dbml/compiler/token/TokenImpl.java @@ -9,21 +9,21 @@ public class TokenImpl implements Token { private final TokenType type; private final String value; - public TokenImpl(final TokenType type, final int value) { + public TokenImpl(TokenType type, int value) { this(type, value < 0 ? "" : Character.toString(value)); } - public TokenImpl(final String value) { + public TokenImpl(String value) { this(TokenType.of(value), value); } - public TokenImpl(final TokenType type, final String value) { + public TokenImpl(TokenType type, String value) { this.type = type; this.value = value; } @Override - public Token withType(final TokenType tokenType) { + public Token withType(TokenType tokenType) { return new TokenImpl(tokenType, value); } diff --git a/src/main/java/com/wn/dbml/compiler/token/TokenType.java b/src/main/java/com/wn/dbml/compiler/token/TokenType.java index a136077..028426f 100644 --- a/src/main/java/com/wn/dbml/compiler/token/TokenType.java +++ b/src/main/java/com/wn/dbml/compiler/token/TokenType.java @@ -95,11 +95,11 @@ public enum TokenType { * @param word a word * @return a keyword or else {@link TokenType#LITERAL} */ - public static TokenType of(final String word) { + public static TokenType of(String word) { return KEYWORDS.getOrDefault(normalize(word), TokenType.LITERAL); } - static String normalize(final String word) { + static String normalize(String word) { return word.toUpperCase().replace(TokenType.MULTI_SEPARATOR, TokenType.MULTI_SEPARATOR_ENUM); } @@ -108,7 +108,7 @@ static String normalize(final String word) { * * @param string a string */ - public static boolean isMultiSeparator(final String string) { + public static boolean isMultiSeparator(String string) { return string.length() == 1 && string.charAt(0) == MULTI_SEPARATOR; } diff --git a/src/main/java/com/wn/dbml/model/Column.java b/src/main/java/com/wn/dbml/model/Column.java index afb467f..686693c 100644 --- a/src/main/java/com/wn/dbml/model/Column.java +++ b/src/main/java/com/wn/dbml/model/Column.java @@ -11,7 +11,7 @@ public class Column implements SettingHolder { private final Map settings = new EnumMap<>(ColumnSetting.class); private Note note; - Column(final Table table, final String name, final String type) { + Column(Table table, String name, String type) { this.table = Objects.requireNonNull(table); this.name = Objects.requireNonNull(name); this.type = Objects.requireNonNull(type); @@ -34,7 +34,7 @@ public Map getSettings() { } @Override - public void addSetting(final ColumnSetting setting, final String value) { + public void addSetting(ColumnSetting setting, String value) { settings.put(setting, value); } @@ -42,12 +42,12 @@ public Note getNote() { return note; } - public void setNote(final Note note) { + public void setNote(Note note) { this.note = note; } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Column column = (Column) o; diff --git a/src/main/java/com/wn/dbml/model/Database.java b/src/main/java/com/wn/dbml/model/Database.java index f026075..4d698ec 100644 --- a/src/main/java/com/wn/dbml/model/Database.java +++ b/src/main/java/com/wn/dbml/model/Database.java @@ -1,6 +1,11 @@ package com.wn.dbml.model; -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * The top-level representation of a DBML file. @@ -10,13 +15,13 @@ public class Database { private final Set relationships = new LinkedHashSet<>(); private Project project; - public Schema getOrCreateSchema(final String name) { + public Schema getOrCreateSchema(String name) { var schema = new Schema(name); schemas.putIfAbsent(schema, schema); return schemas.get(schema); } - public Schema getSchema(final String name) { + public Schema getSchema(String name) { return schemas.get(new Schema(name)); } @@ -24,11 +29,11 @@ public Set getSchemas() { return Collections.unmodifiableSet(schemas.keySet()); } - public boolean containsAlias(final String alias) { + public boolean containsAlias(String alias) { return getAlias(alias) != null; } - public Table getAlias(final String alias) { + public Table getAlias(String alias) { return getSchemas().stream() .flatMap(s -> s.getTables().stream()) .filter(t -> alias.equals(t.getAlias())) @@ -36,17 +41,17 @@ public Table getAlias(final String alias) { .orElse(null); } - public Relationship createRelationship(final String name, final Relation relation, final List from, final List to, Map settings) { + public Relationship createRelationship(String name, Relation relation, List from, List to, Map settings) { var relationship = new Relationship(name, relation, from, to, settings); var added = relationships.add(relationship); return added ? relationship : null; } - public boolean containsRelationship(final String name) { + public boolean containsRelationship(String name) { return getRelationship(name) != null; } - public Relationship getRelationship(final String name) { + public Relationship getRelationship(String name) { return relationships.stream().filter(c -> c.getName().equals(name)).findAny().orElse(null); } @@ -58,7 +63,7 @@ public Project getProject() { return project; } - public void setProject(final Project project) { + public void setProject(Project project) { this.project = project; } diff --git a/src/main/java/com/wn/dbml/model/Enum.java b/src/main/java/com/wn/dbml/model/Enum.java index 9d87fd9..81273e6 100644 --- a/src/main/java/com/wn/dbml/model/Enum.java +++ b/src/main/java/com/wn/dbml/model/Enum.java @@ -10,7 +10,7 @@ public class Enum { private final String name; private final Set values = new LinkedHashSet<>(); - Enum(final Schema schema, final String name) { + Enum(Schema schema, String name) { this.schema = Objects.requireNonNull(schema); this.name = Objects.requireNonNull(name); } @@ -23,7 +23,7 @@ public String getName() { return name; } - public EnumValue addValue(final String name) { + public EnumValue addValue(String name) { var value = new EnumValue(this, name); var added = values.add(value); return added ? value : null; @@ -34,7 +34,7 @@ public Set getValues() { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Enum anEnum = (Enum) o; diff --git a/src/main/java/com/wn/dbml/model/EnumValue.java b/src/main/java/com/wn/dbml/model/EnumValue.java index 84f56d3..18dae82 100644 --- a/src/main/java/com/wn/dbml/model/EnumValue.java +++ b/src/main/java/com/wn/dbml/model/EnumValue.java @@ -7,7 +7,7 @@ public class EnumValue { private final String name; private Note note; - EnumValue(final Enum anEnum, final String name) { + EnumValue(Enum anEnum, String name) { this.anEnum = anEnum; this.name = name; } @@ -16,12 +16,12 @@ public Note getNote() { return note; } - public void setNote(final Note note) { + public void setNote(Note note) { this.note = note; } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final EnumValue enumValue = (EnumValue) o; diff --git a/src/main/java/com/wn/dbml/model/Index.java b/src/main/java/com/wn/dbml/model/Index.java index 7aff69b..0372056 100644 --- a/src/main/java/com/wn/dbml/model/Index.java +++ b/src/main/java/com/wn/dbml/model/Index.java @@ -1,6 +1,10 @@ package com.wn.dbml.model; -import java.util.*; +import java.util.Collections; +import java.util.EnumMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; public class Index implements SettingHolder { @@ -9,7 +13,7 @@ public class Index implements SettingHolder { private final Map settings = new EnumMap<>(IndexSetting.class); private Note note; - Index(final Table table) { + Index(Table table) { this.table = Objects.requireNonNull(table); } @@ -17,7 +21,7 @@ public Table getTable() { return table; } - public boolean addColumn(final String column) { + public boolean addColumn(String column) { var containsColumn = columns.containsKey(column); if (!containsColumn) { columns.put(column, table.getColumn(column)); @@ -30,7 +34,7 @@ public Map getColumns() { } @Override - public void addSetting(final IndexSetting setting, final String value) { + public void addSetting(IndexSetting setting, String value) { settings.put(setting, value); } @@ -42,7 +46,7 @@ public Note getNote() { return note; } - public void setNote(final Note note) { + public void setNote(Note note) { this.note = note; } diff --git a/src/main/java/com/wn/dbml/model/Name.java b/src/main/java/com/wn/dbml/model/Name.java index b1732a5..5622454 100644 --- a/src/main/java/com/wn/dbml/model/Name.java +++ b/src/main/java/com/wn/dbml/model/Name.java @@ -9,27 +9,27 @@ public final class Name { private Name() { } - public static String of(final Schema schema, final String table) { + public static String of(Schema schema, String table) { return ofTable(schema.toString(), table); } - public static String of(final Table table, final String column) { + public static String of(Table table, String column) { return table + "." + column; } - public static String of(final Enum anEnum, final String value) { + public static String of(Enum anEnum, String value) { return anEnum + "." + value; } - public static String ofTable(final String schema, final String table) { + public static String ofTable(String schema, String table) { return schema.equals(Schema.DEFAULT_NAME) ? table : schema + '.' + table; } - public static String ofColumn(final String schema, final String table, final String column) { + public static String ofColumn(String schema, String table, String column) { return ofTable(schema, table) + '.' + column; } - public static String ofColumns(final String schema, final String table, final List columns) { + public static String ofColumns(String schema, String table, List columns) { return ofTable(schema, table) + ".(" + String.join(", ", columns) + ')'; } } diff --git a/src/main/java/com/wn/dbml/model/Note.java b/src/main/java/com/wn/dbml/model/Note.java index e1d98e8..ba9eafe 100644 --- a/src/main/java/com/wn/dbml/model/Note.java +++ b/src/main/java/com/wn/dbml/model/Note.java @@ -3,7 +3,7 @@ public class Note { private final String value; - public Note(final String value) { + public Note(String value) { this.value = value; } diff --git a/src/main/java/com/wn/dbml/model/Project.java b/src/main/java/com/wn/dbml/model/Project.java index a2b1dbc..36aaef0 100644 --- a/src/main/java/com/wn/dbml/model/Project.java +++ b/src/main/java/com/wn/dbml/model/Project.java @@ -8,7 +8,7 @@ public class Project { private final Map properties = new LinkedHashMap<>(); private Note note; - public Project(final String name) { + public Project(String name) { this.name = name; } @@ -24,7 +24,7 @@ public Note getNote() { return note; } - public void setNote(final Note note) { + public void setNote(Note note) { this.note = note; } diff --git a/src/main/java/com/wn/dbml/model/Relation.java b/src/main/java/com/wn/dbml/model/Relation.java index d8861ce..f63e436 100644 --- a/src/main/java/com/wn/dbml/model/Relation.java +++ b/src/main/java/com/wn/dbml/model/Relation.java @@ -9,11 +9,11 @@ public enum Relation { MANY_TO_MANY("<>"); private final String symbol; - Relation(final String symbol) { + Relation(String symbol) { this.symbol = symbol; } - public static Relation of(final String symbol) { + public static Relation of(String symbol) { return Arrays.stream(values()).filter(r -> r.symbol.equals(symbol)).findAny().orElse(null); } diff --git a/src/main/java/com/wn/dbml/model/Relationship.java b/src/main/java/com/wn/dbml/model/Relationship.java index c926c47..c6e16c8 100644 --- a/src/main/java/com/wn/dbml/model/Relationship.java +++ b/src/main/java/com/wn/dbml/model/Relationship.java @@ -11,7 +11,7 @@ public class Relationship implements SettingHolder { private final List from, to; private final Map settings; - Relationship(final String name, final Relation relation, final List from, final List to, Map settings) { + Relationship(String name, Relation relation, List from, List to, Map settings) { this.name = name; this.relation = Objects.requireNonNull(relation); this.from = Objects.requireNonNull(from); @@ -36,7 +36,7 @@ public List getTo() { } @Override - public void addSetting(final RelationshipSetting setting, final String value) { + public void addSetting(RelationshipSetting setting, String value) { settings.put(setting, value); } @@ -45,7 +45,7 @@ public Map getSettings() { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Relationship that = (Relationship) o; diff --git a/src/main/java/com/wn/dbml/model/Schema.java b/src/main/java/com/wn/dbml/model/Schema.java index cdbd5fa..2a13b73 100644 --- a/src/main/java/com/wn/dbml/model/Schema.java +++ b/src/main/java/com/wn/dbml/model/Schema.java @@ -12,7 +12,7 @@ public class Schema { private final Set enums = new LinkedHashSet<>(); private final Set tableGroups = new LinkedHashSet<>(); - Schema(final String name) { + Schema(String name) { this.name = Objects.requireNonNull(name); } @@ -20,15 +20,15 @@ public String getName() { return name; } - public boolean containsTable(final String tableName) { + public boolean containsTable(String tableName) { return getTable(tableName) != null; } - public Table getTable(final String tableName) { + public Table getTable(String tableName) { return tables.stream().filter(c -> c.getName().equals(tableName)).findAny().orElse(null); } - public Table createTable(final String name) { + public Table createTable(String name) { var table = new Table(this, name); var added = tables.add(table); return added ? table : null; @@ -38,15 +38,15 @@ public Set getTables() { return Collections.unmodifiableSet(tables); } - public boolean containsEnum(final String enumName) { + public boolean containsEnum(String enumName) { return getEnum(enumName) != null; } - public Enum getEnum(final String enumName) { + public Enum getEnum(String enumName) { return enums.stream().filter(c -> c.getName().equals(enumName)).findAny().orElse(null); } - public Enum createEnum(final String name) { + public Enum createEnum(String name) { var anEnum = new Enum(this, name); var added = enums.add(anEnum); return added ? anEnum : null; @@ -56,15 +56,15 @@ public Set getEnums() { return Collections.unmodifiableSet(enums); } - public boolean containsTableGroup(final String tableGroupName) { + public boolean containsTableGroup(String tableGroupName) { return getTableGroup(tableGroupName) != null; } - public TableGroup getTableGroup(final String tableGroupName) { + public TableGroup getTableGroup(String tableGroupName) { return tableGroups.stream().filter(c -> c.getName().equals(tableGroupName)).findAny().orElse(null); } - public TableGroup createTableGroup(final String name) { + public TableGroup createTableGroup(String name) { var tableGroup = new TableGroup(this, name); var added = tableGroups.add(tableGroup); return added ? tableGroup : null; @@ -75,7 +75,7 @@ public Set getTableGroups() { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Schema schema = (Schema) o; diff --git a/src/main/java/com/wn/dbml/model/Table.java b/src/main/java/com/wn/dbml/model/Table.java index 1cabd56..ed260a3 100644 --- a/src/main/java/com/wn/dbml/model/Table.java +++ b/src/main/java/com/wn/dbml/model/Table.java @@ -1,6 +1,11 @@ package com.wn.dbml.model; -import java.util.*; +import java.util.Collections; +import java.util.EnumMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; public class Table implements SettingHolder { private final Schema schema; @@ -11,7 +16,7 @@ public class Table implements SettingHolder { private String alias; private Note note; - Table(final Schema schema, final String name) { + Table(Schema schema, String name) { this.schema = Objects.requireNonNull(schema); this.name = Objects.requireNonNull(name); } @@ -25,7 +30,7 @@ public String getName() { } @Override - public void addSetting(final TableSetting setting, final String value) { + public void addSetting(TableSetting setting, String value) { settings.put(setting, value); } @@ -33,15 +38,15 @@ public Map getSettings() { return Collections.unmodifiableMap(settings); } - public boolean containsColumn(final String columnName) { + public boolean containsColumn(String columnName) { return getColumn(columnName) != null; } - public Column getColumn(final String columnName) { + public Column getColumn(String columnName) { return columns.stream().filter(c -> c.getName().equals(columnName)).findAny().orElse(null); } - public Column addColumn(final String columnName, final String datatype) { + public Column addColumn(String columnName, String datatype) { var column = new Column(this, columnName, datatype); var added = columns.add(column); return added ? column : null; @@ -65,7 +70,7 @@ public String getAlias() { return alias; } - public void setAlias(final String alias) { + public void setAlias(String alias) { this.alias = alias; } @@ -73,12 +78,12 @@ public Note getNote() { return note; } - public void setNote(final Note note) { + public void setNote(Note note) { this.note = note; } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Table table = (Table) o; diff --git a/src/main/java/com/wn/dbml/model/TableGroup.java b/src/main/java/com/wn/dbml/model/TableGroup.java index bff6fbe..df0ff84 100644 --- a/src/main/java/com/wn/dbml/model/TableGroup.java +++ b/src/main/java/com/wn/dbml/model/TableGroup.java @@ -11,7 +11,7 @@ public class TableGroup { private final Set
tables = new LinkedHashSet<>(); private Note note; - TableGroup(final Schema schema, final String name) { + TableGroup(Schema schema, String name) { this.schema = Objects.requireNonNull(schema); this.name = Objects.requireNonNull(name); } @@ -24,7 +24,7 @@ public String getName() { return name; } - public boolean addTable(final Table table) { + public boolean addTable(Table table) { return tables.add(table); } @@ -41,7 +41,7 @@ public void setNote(Note note) { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final TableGroup that = (TableGroup) o; diff --git a/src/test/java/com/wn/dbml/compiler/LexerTest.java b/src/test/java/com/wn/dbml/compiler/LexerTest.java index 3019b87..45abd62 100644 --- a/src/test/java/com/wn/dbml/compiler/LexerTest.java +++ b/src/test/java/com/wn/dbml/compiler/LexerTest.java @@ -16,7 +16,7 @@ class LexerTest { - private Lexer getLexer(final String dbml) { + private Lexer getLexer(String dbml) { return new LexerImpl(dbml); } @@ -68,7 +68,7 @@ void testMultiKeyword() { @ParameterizedTest @MethodSource - void testString(final char quote, final TokenType expectedType) { + void testString(char quote, TokenType expectedType) { var str = "test string \\ with unicode 倀"; var dbml = quote + str + quote; var lexer = getLexer(dbml); @@ -234,7 +234,7 @@ void testSpaceNoCollapsing() { @ParameterizedTest @MethodSource - void testColor(final String color, final TokenType expectedType) { + void testColor(String color, TokenType expectedType) { var dbml = "#" + color; var lexer = getLexer(dbml); diff --git a/src/test/java/com/wn/dbml/compiler/ParserTest.java b/src/test/java/com/wn/dbml/compiler/ParserTest.java index de1082e..8335492 100644 --- a/src/test/java/com/wn/dbml/compiler/ParserTest.java +++ b/src/test/java/com/wn/dbml/compiler/ParserTest.java @@ -17,11 +17,11 @@ class ParserTest { - private Database parse(final String dbml) { + private Database parse(String dbml) { return new ParserImpl().parse(new LexerImpl(dbml)); } - private Schema getDefaultSchema(final Database database) { + private Schema getDefaultSchema(Database database) { return database.getSchema(Schema.DEFAULT_NAME); } diff --git a/src/test/java/com/wn/dbml/compiler/parser/ParserImplTest.java b/src/test/java/com/wn/dbml/compiler/parser/ParserImplTest.java index 3d63394..d843503 100644 --- a/src/test/java/com/wn/dbml/compiler/parser/ParserImplTest.java +++ b/src/test/java/com/wn/dbml/compiler/parser/ParserImplTest.java @@ -7,7 +7,7 @@ class ParserImplTest { - private Database parse(final String dbml) { + private Database parse(String dbml) { return new ParserImpl().parse(new LexerImpl(dbml)); }