Skip to content

Commit 7049e62

Browse files
committed
Remove redundant parentheses and enforce a PMD rule for it
1 parent eecd963 commit 7049e62

10 files changed

Lines changed: 20 additions & 21 deletions

File tree

configs/pmd-rules.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
<!-- TODO -->
4747
<exclude name="ShortClassName" />
4848
<exclude name="FormalParameterNamingConventions" />
49-
<exclude name="UselessParentheses" />
5049
<exclude name="LinguisticNaming" />
5150
<exclude name="ConfusingTernary" />
5251
<exclude name="PrematureDeclaration" />

src/sqlancer/mysql/MySQLSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public MySQLRowValue getRandomRowValue(Connection con, MySQLStateToReproduce sta
133133
// }
134134
values.put(column, constant);
135135
}
136-
assert (!randomRowValues.next());
136+
assert !randomRowValues.next();
137137
state.randomRowValues = values;
138138
return new MySQLRowValue(this, values);
139139
}

src/sqlancer/mysql/gen/MySQLTableGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private Query create() {
6767
sb.append(" ");
6868
appendTableOptions();
6969
appendPartitionOptions();
70-
if ((tableHasNullableColumn || setPrimaryKey) && (engine == MySQLEngine.CSV)) {
70+
if ((tableHasNullableColumn || setPrimaryKey) && engine == MySQLEngine.CSV) {
7171
if (true) { // TODO
7272
// results in an error
7373
throw new IgnoreMeException();

src/sqlancer/postgres/PostgresSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public PostgresRowValue getRandomRowValue(Connection con, PostgresStateToReprodu
9494
}
9595
values.put(column, constant);
9696
}
97-
assert (!randomRowValues.next());
97+
assert !randomRowValues.next();
9898
state.randomRowValues = values;
9999
return new PostgresRowValue(this, values);
100100
}

src/sqlancer/postgres/PostgresToStringVisitor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ private void appendType(PostgresCastOperation cast) {
252252
public void visit(PostgresBetweenOperation op) {
253253
sb.append("(");
254254
visit(op.getExpr());
255-
if (PostgresProvider.generateOnlyKnown && (op.getExpr().getExpressionType() == PostgresDataType.TEXT
256-
&& op.getLeft().getExpressionType() == PostgresDataType.TEXT)) {
255+
if (PostgresProvider.generateOnlyKnown && op.getExpr().getExpressionType() == PostgresDataType.TEXT
256+
&& op.getLeft().getExpressionType() == PostgresDataType.TEXT) {
257257
sb.append(" COLLATE \"C\"");
258258
}
259259
sb.append(") BETWEEN ");
@@ -264,8 +264,8 @@ public void visit(PostgresBetweenOperation op) {
264264
visit(op.getLeft());
265265
sb.append(") AND (");
266266
visit(op.getRight());
267-
if (PostgresProvider.generateOnlyKnown && (op.getExpr().getExpressionType() == PostgresDataType.TEXT
268-
&& op.getRight().getExpressionType() == PostgresDataType.TEXT)) {
267+
if (PostgresProvider.generateOnlyKnown && op.getExpr().getExpressionType() == PostgresDataType.TEXT
268+
&& op.getRight().getExpressionType() == PostgresDataType.TEXT) {
269269
sb.append(" COLLATE \"C\"");
270270
}
271271
sb.append(")");

src/sqlancer/postgres/ast/PostgresConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public PostgresConstant cast(PostgresDataType type) {
7171
case BOOLEAN:
7272
return this;
7373
case INT:
74-
return PostgresConstant.createIntConstant((value) ? 1 : 0);
74+
return PostgresConstant.createIntConstant(value ? 1 : 0);
7575
case TEXT:
7676
return PostgresConstant.createTextConstant(value ? "true" : "false");
7777
default:

src/sqlancer/sqlite3/SQLite3CollateHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ private SQLite3CollateHelper() {
1212
}
1313

1414
public static boolean shouldGetSubexpressionAffinity(SQLite3Expression expression) {
15-
return (expression instanceof SQLite3UnaryOperation
16-
&& ((SQLite3UnaryOperation) expression).getOperation() == UnaryOperator.PLUS)
15+
return expression instanceof SQLite3UnaryOperation
16+
&& ((SQLite3UnaryOperation) expression).getOperation() == UnaryOperator.PLUS
1717
|| expression instanceof Cast || expression instanceof SQLite3ColumnName;
1818
}
1919

src/sqlancer/sqlite3/ast/SQLite3Cast.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ private static SQLite3Constant convertInternal(SQLite3Constant value, boolean co
151151
BigDecimal first = new BigDecimal(substring);
152152
long longValue = first.longValue();
153153
BigDecimal second = BigDecimal.valueOf(longValue);
154-
boolean isWithinConvertibleRange = (longValue >= MIN_INT_FOR_WHICH_CONVERSION_TO_INT_IS_TRIED
155-
&& longValue <= MAX_INT_FOR_WHICH_CONVERSION_TO_INT_IS_TRIED) && convertRealToInt;
154+
boolean isWithinConvertibleRange = longValue >= MIN_INT_FOR_WHICH_CONVERSION_TO_INT_IS_TRIED
155+
&& longValue <= MAX_INT_FOR_WHICH_CONVERSION_TO_INT_IS_TRIED && convertRealToInt;
156156
boolean isFloatingPointNumber = substring.contains(".") || substring.toUpperCase().contains("E");
157157
boolean doubleShouldBeConvertedToInt = isFloatingPointNumber && first.compareTo(second) == 0
158158
&& isWithinConvertibleRange;
159159
boolean isInteger = !isFloatingPointNumber && first.compareTo(second) == 0;
160-
if (doubleShouldBeConvertedToInt || (isInteger && !convertIntToReal)) {
160+
if (doubleShouldBeConvertedToInt || isInteger && !convertIntToReal) {
161161
// see https://www.sqlite.org/src/tktview/afdc5a29dc
162162
return SQLite3Constant.createIntConstant(first.longValue());
163163
} else {

src/sqlancer/sqlite3/gen/SQLite3Common.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static String createIndexName(int nr) {
4343
public static String getCheckConstraint(SQLite3GlobalState globalState, List<SQLite3Column> columns) {
4444
SQLite3Expression expression = new SQLite3ExpressionGenerator(globalState).setColumns(columns)
4545
.generateExpression();
46-
return (" CHECK ( " + SQLite3Visitor.asString(expression) + ")");
46+
return " CHECK ( " + SQLite3Visitor.asString(expression) + ")";
4747
}
4848

4949
public static SQLite3Expression getTrueExpression(List<SQLite3Column> columns, SQLite3GlobalState globalState) {

src/sqlancer/sqlite3/schema/SQLite3Schema.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,12 @@ public static SQLite3Schema fromConnection(Connection con) throws SQLException {
378378
continue;
379379
}
380380
String sqlString = rs.getString("sql") == null ? "" : rs.getString("sql").toLowerCase();
381-
if ((tableName.startsWith("sqlite_") /* && !tableName.startsWith("sqlite_stat") */)
382-
|| tableType.equals("index") || tableType.equals("trigger") || tableName.endsWith("_idx")
383-
|| tableName.endsWith("_docsize") || tableName.endsWith("_content")
384-
|| tableName.endsWith("_data") || tableName.endsWith("_config")
385-
|| tableName.endsWith("_segdir") || tableName.endsWith("_stat")
386-
|| tableName.endsWith("_segments") || tableName.contains("_")) {
381+
if (tableName.startsWith("sqlite_") || tableType.equals("index") || tableType.equals("trigger")
382+
|| tableName.endsWith("_idx") || tableName.endsWith("_docsize")
383+
|| tableName.endsWith("_content") || tableName.endsWith("_data")
384+
|| tableName.endsWith("_config") || tableName.endsWith("_segdir")
385+
|| tableName.endsWith("_stat") || tableName.endsWith("_segments")
386+
|| tableName.contains("_")) {
387387
isReadOnly = true;
388388
continue; // TODO
389389
} else if (sqlString.contains("using dbstat")) {

0 commit comments

Comments
 (0)