Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Tighten Checkstyle ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Dec 31, 2023
1 parent 40bc90a commit 3d7acee
Show file tree
Hide file tree
Showing 30 changed files with 340 additions and 317 deletions.
73 changes: 36 additions & 37 deletions src/main/java/net/ucanaccess/commands/DDLCommandEnlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void enlistCreateTable(String _sql, DDLType _ddlType) throws SQLExceptio
}
}
c4io = new CreateTableCommand(tn, execId, columnMap);
} catch (Exception ignore) {
} catch (Exception _ignored) {
c4io = new CreateTableCommand(tn, execId);
}

Expand Down Expand Up @@ -202,38 +202,37 @@ private void enlistAlterRename(DDLType ddlType) throws SQLException {
}
}

private String[] checkEscaped(String _ll, String rl, String[] colDecls, String tknt) {
if (colDecls[0].startsWith(_ll) && tknt.indexOf(rl, 1) > 0) {
for (int k = 0; k < colDecls.length; k++) {
if (colDecls[k].endsWith(rl)) {
String[] colDecls0 = new String[colDecls.length - k];
colDecls0[0] = tknt.substring(1, tknt.substring(1).indexOf(rl) + 1);
private String[] checkEscaped(String _ll, String _rl, String[] _colDecls, String _tknt) {
if (_colDecls[0].startsWith(_ll) && _tknt.indexOf(_rl, 1) > 0) {
for (int k = 0; k < _colDecls.length; k++) {
if (_colDecls[k].endsWith(_rl)) {
String[] colDecls0 = new String[_colDecls.length - k];
colDecls0[0] = _tknt.substring(1, _tknt.substring(1).indexOf(_rl) + 1);
for (int y = 1; y < colDecls0.length; y++) {
colDecls0[y] = colDecls[y + k];
colDecls0[y] = _colDecls[y + k];
}
colDecls = colDecls0;
_colDecls = colDecls0;
break;
}
}
}
return colDecls;
return _colDecls;
}

private void parseColumnTypes(List<String> typeList, List<String> defaultList,
List<Boolean> notNullList, String tknt) {
private void parseColumnTypes(List<String> _typeList, List<String> _defaultList, List<Boolean> _notNullList, String _tknt) {

String[] colDecls = tknt.split("[\\s\n\r]+");
colDecls = checkEscaped("[", "]", colDecls, tknt);
colDecls = checkEscaped("`", "`", colDecls, tknt);
String[] colDecls = _tknt.split("[\\s\n\r]+");
colDecls = checkEscaped("[", "]", colDecls, _tknt);
colDecls = checkEscaped("`", "`", colDecls, _tknt);
String escaped = SQLConverter.isListedAsKeyword(colDecls[0].toUpperCase()) ? colDecls[0].toUpperCase()
: SQLConverter.basicEscapingIdentifier(colDecls[0]);
columnMap.put(escaped, colDecls[0]);

boolean reset = false;
if (tknt.matches("[\\s\n\r]*\\d+[\\s\n\r]*\\).*")) {
if (_tknt.matches("[\\s\n\r]*\\d+[\\s\n\r]*\\).*")) {
reset = true;
tknt = tknt.substring(tknt.indexOf(')') + 1).trim();
colDecls = tknt.split("[\\s\n\r]+");
_tknt = _tknt.substring(_tknt.indexOf(')') + 1).trim();
colDecls = _tknt.split("[\\s\n\r]+");
}

if (!reset && colDecls.length < 2) {
Expand All @@ -245,38 +244,38 @@ private void parseColumnTypes(List<String> typeList, List<String> defaultList,
colDecls[1] = "NUMERIC";
decDef = true;
}
typeList.add(colDecls[1]);
_typeList.add(colDecls[1]);

}

if ((colDecls.length > 2 || reset && colDecls.length == 2)
&& "not".equalsIgnoreCase(colDecls[colDecls.length - 2])
&& "null".equalsIgnoreCase(colDecls[colDecls.length - 1])) {
notNullList.add(true);
_notNullList.add(true);
} else if (!decDef) {
notNullList.add(false);
_notNullList.add(false);
}

if (!decDef) {
defaultList.add(value(SQLConverter.getDDLDefault(tknt)));
_defaultList.add(value(SQLConverter.getDDLDefault(_tknt)));
}

types = typeList.toArray(new String[0]);
defaults = defaultList.toArray(new String[0]);
notNulls = notNullList.toArray(new Boolean[0]);
types = _typeList.toArray(new String[0]);
defaults = _defaultList.toArray(new String[0]);
notNulls = _notNullList.toArray(new Boolean[0]);
}

// getting AUTOINCREMENT and GUID
private void parseTypesFromCreateStatement(String sql) throws SQLException {
sql = sql.replaceAll("([\\s\n\r]+)((?i)DECIMAL)([\\s\n\r]*\\()", "$1NUMERIC(")
private void parseTypesFromCreateStatement(String _sql) throws SQLException {
_sql = _sql.replaceAll("([\\s\n\r]+)((?i)DECIMAL)([\\s\n\r]*\\()", "$1NUMERIC(")
.replaceAll("([\\s\n\r]+)((?i)NUMERIC)([\\s\n\r]*\\()", "$1NUMERIC(");
int startDecl = sql.indexOf('(');
int endDecl = sql.lastIndexOf(')');
int startDecl = _sql.indexOf('(');
int endDecl = _sql.lastIndexOf(')');

if (startDecl >= endDecl) {
throw new UcanaccessSQLException(ExceptionMessages.INVALID_CREATE_STATEMENT);
}
String decl = sql.substring(startDecl + 1, endDecl);
String decl = _sql.substring(startDecl + 1, endDecl);
String[] tokens = decl.split(",");

List<String> typeList = new ArrayList<>();
Expand All @@ -290,17 +289,17 @@ private void parseTypesFromCreateStatement(String sql) throws SQLException {
}
}

private String value(String value) {
if (value == null) {
private String value(String _value) {
if (_value == null) {
return null;
}
if (value.startsWith("\"") && value.endsWith("\"")) {
return value.substring(1, value.length() - 1).replace("\"\"", "\"");
if (_value.startsWith("\"") && _value.endsWith("\"")) {
return _value.substring(1, _value.length() - 1).replace("\"\"", "\"");
}
if (value.startsWith("'") && value.endsWith("'")) {
return value.substring(1, value.length() - 1).replace("''", "'");
if (_value.startsWith("'") && _value.endsWith("'")) {
return _value.substring(1, _value.length() - 1).replace("''", "'");
}
return value;
return _value;
}

}
9 changes: 4 additions & 5 deletions src/main/java/net/ucanaccess/console/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ public static void main(String[] _args) throws Exception {

try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
} catch (ClassNotFoundException e) {

System.err.println(e.getMessage());
} catch (ClassNotFoundException _ex) {
System.err.println(_ex.getMessage());
System.err.println("Check your classpath!");
System.exit(1);
}
Expand All @@ -95,7 +94,7 @@ public static void main(String[] _args) throws Exception {
if (path.endsWith(";")) {
path = path.substring(0, path.length() - 1);
}
if (path.equalsIgnoreCase("quit")) {
if ("quit".equalsIgnoreCase(path)) {
System.out.println("I'm so unhappy. Goodbye.");
System.exit(1);
}
Expand Down Expand Up @@ -230,7 +229,7 @@ private void start(String[] commands) {
} else {
userInput = readInput();
}
if (userInput.equalsIgnoreCase("quit")) {
if ("quit".equalsIgnoreCase(userInput)) {
connected = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ucanaccess/converters/DFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private String convertDFunctions() {
sql0 = sql0.replaceFirst(DFUNCTIONS_WHERE_DYNAMIC.replaceFirst("_", fun), sb.toString());
}
}
} catch (SQLException ignored) {
} catch (SQLException _ignored) {
}
return sql0;
}
Expand Down
Loading

0 comments on commit 3d7acee

Please sign in to comment.