Skip to content

Commit f5d35d0

Browse files
style: Appease PMD
1 parent 399e1d7 commit f5d35d0

4 files changed

Lines changed: 65 additions & 48 deletions

File tree

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ Block Block() #Block : {
774774
}
775775
}
776776

777-
Statements Statements() #Statements : {
777+
Statements Statements() #Statements: {
778778
Statements stmts = new Statements();
779779
List<Statement> list = new ArrayList<Statement>();
780780

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public void testParseExpression2() throws Exception {
5757

5858
@Test
5959
public void testParseExpressionNonPartial() throws Exception {
60-
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parseExpression("a+", false));
60+
assertThrows(JSQLParserException.class,
61+
() -> CCJSqlParserUtil.parseExpression("a+", false));
6162

6263
}
6364

@@ -68,7 +69,8 @@ public void testParseExpressionFromStringFail() throws Exception {
6869

6970
@Test
7071
public void testParseExpressionFromRaderFail() throws Exception {
71-
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parse(new StringReader("whatever$")));
72+
assertThrows(JSQLParserException.class,
73+
() -> CCJSqlParserUtil.parse(new StringReader("whatever$")));
7274
}
7375

7476
@Test
@@ -91,14 +93,17 @@ public void testParseCondExpressionFail() throws Exception {
9193
@Test
9294
public void testParseFromStreamFail() throws Exception {
9395
assertThrows(JSQLParserException.class,
94-
() -> CCJSqlParserUtil.parse(new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8))));
96+
() -> CCJSqlParserUtil
97+
.parse(new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8))));
9598

9699
}
97100

98101
@Test
99102
public void testParseFromStreamWithEncodingFail() throws Exception {
100103
assertThrows(JSQLParserException.class,
101-
() -> CCJSqlParserUtil.parse(new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8.name()));
104+
() -> CCJSqlParserUtil.parse(
105+
new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8)),
106+
StandardCharsets.UTF_8.name()));
102107

103108
}
104109

@@ -110,7 +115,8 @@ public void testParseCondExpressionNonPartial() throws Exception {
110115

111116
@Test
112117
public void testParseCondExpressionNonPartial2() throws Exception {
113-
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parseCondExpression("x=92 lasd y=29", false));
118+
assertThrows(JSQLParserException.class,
119+
() -> CCJSqlParserUtil.parseCondExpression("x=92 lasd y=29", false));
114120
}
115121

116122
@Test
@@ -121,22 +127,23 @@ public void testParseCondExpressionPartial2() throws Exception {
121127

122128
@Test
123129
public void testParseCondExpressionIssue471() throws Exception {
124-
Expression result = CCJSqlParserUtil.parseCondExpression("(SSN,SSM) IN ('11111111111111', '22222222222222')");
130+
Expression result = CCJSqlParserUtil
131+
.parseCondExpression("(SSN,SSM) IN ('11111111111111', '22222222222222')");
125132
assertEquals("(SSN, SSM) IN ('11111111111111', '22222222222222')", result.toString());
126133
}
127134

128135
@Test
129136
public void testParseStatementsIssue691() throws Exception {
130137
Statements result = CCJSqlParserUtil.parseStatements(
131138
"select * from dual;\n"
132-
+ "\n"
133-
+ "select\n"
134-
+ "*\n"
135-
+ "from\n"
136-
+ "dual;\n"
137-
+ "\n"
138-
+ "select *\n"
139-
+ "from dual;");
139+
+ "\n"
140+
+ "select\n"
141+
+ "*\n"
142+
+ "from\n"
143+
+ "dual;\n"
144+
+ "\n"
145+
+ "select *\n"
146+
+ "from dual;");
140147
assertEquals("SELECT * FROM dual;\n"
141148
+ "SELECT * FROM dual;\n"
142149
+ "SELECT * FROM dual;\n", result.toString());
@@ -169,19 +176,21 @@ public void accept(Statement statement) {
169176
public void testParseStatementsFail() throws Exception {
170177
// This will not fail, but always return the Unsupported Statements
171178
// Since we can't LOOKAHEAD in the Statements() production
172-
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parseStatements("select * from dual;WHATEVER!!"));
179+
assertThrows(JSQLParserException.class,
180+
() -> CCJSqlParserUtil.parseStatements("select * from dual;WHATEVER!!"));
173181
}
174182

175183
@Test
176184
public void testParseASTFail() throws Exception {
177-
assertThrows(JSQLParserException.class, () -> CCJSqlParserUtil.parseAST("select * from dual;WHATEVER!!"));
185+
assertThrows(JSQLParserException.class,
186+
() -> CCJSqlParserUtil.parseAST("select * from dual;WHATEVER!!"));
178187
}
179188

180189
@Test
181190
public void testParseStatementsIssue691_2() throws Exception {
182191
Statements result = CCJSqlParserUtil.parseStatements(
183192
"select * from dual;\n"
184-
+ "---test");
193+
+ "---test");
185194
assertEquals("SELECT * FROM dual;\n", result.toString());
186195
}
187196

@@ -193,9 +202,11 @@ public void testParseStatementIssue742() throws Exception {
193202
+ " PRIMARY KEY (`id`),\n"
194203
+ " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n"
195204
+ ")");
196-
assertEquals("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` "
197-
+ "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` "
198-
+ "(`another_column_id`));\n", result.toString());
205+
assertEquals(
206+
"CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` "
207+
+ "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` "
208+
+ "(`another_column_id`));\n",
209+
result.toString());
199210
}
200211

201212
@Test
@@ -232,7 +243,8 @@ public void testNestingDepth() throws Exception {
232243
+ " , a.id_instrument_type\n"
233244
+ " , b.id_portfolio\n"
234245
+ " , c.attribute_value product_code\n"
235-
+ " , t.valid_date\n" + " , t.ccf\n"
246+
+ " , t.valid_date\n"
247+
+ " , t.ccf\n"
236248
+ " FROM cfe.instrument a\n"
237249
+ " INNER JOIN cfe.impairment b\n"
238250
+ " ON a.id_instrument = b.id_instrument\n"
@@ -258,26 +270,31 @@ public void testNestingDepth() throws Exception {
258270

259271
@Test
260272
public void testParseStatementIssue1250() throws Exception {
261-
Statement result = CCJSqlParserUtil.parse("Select test.* from (Select * from sch.PERSON_TABLE // root test\n) as test");
262-
assertEquals("SELECT test.* FROM (SELECT * FROM sch.PERSON_TABLE) AS test", result.toString());
273+
Statement result = CCJSqlParserUtil.parse(
274+
"Select test.* from (Select * from sch.PERSON_TABLE // root test\n) as test");
275+
assertEquals("SELECT test.* FROM (SELECT * FROM sch.PERSON_TABLE) AS test",
276+
result.toString());
263277
}
264278

265279
@Test
266280
public void testCondExpressionIssue1482() throws JSQLParserException {
267-
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", false);
281+
Expression expr = CCJSqlParserUtil
282+
.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", false);
268283
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", expr.toString());
269284
}
270285

271286
@Test
272287
public void testCondExpressionIssue1482_2() throws JSQLParserException {
273-
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", false);
288+
Expression expr = CCJSqlParserUtil.parseCondExpression(
289+
"test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", false);
274290
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", expr.toString());
275291
}
276292

277293
@Test
278294
public void testTimeOutIssue1582() throws InterruptedException {
279295
// This statement is INVALID on purpose
280-
// There are crafted INTO keywords in order to make it fail but only after a long time (40 seconds plus)
296+
// There are crafted INTO keywords in order to make it fail but only after a long time (40
297+
// seconds plus)
281298

282299
String sqlStr = ""
283300
+ "select\n"
@@ -309,15 +326,16 @@ public void execute() throws Throwable {
309326
}
310327
});
311328

312-
// With custom TIMEOUT 60 Seconds, we expect the statement to not timeout but to fail instead
329+
// With custom TIMEOUT 60 Seconds, we expect the statement to not timeout but to fail
330+
// instead
313331
// No TimeoutException wrapped into a Parser Exception must be thrown
314332
// Instead we expect a Parser Exception only
315333
assertThrows(JSQLParserException.class, new Executable() {
316334
@Override
317335
public void execute() throws Throwable {
318336
try {
319337
CCJSqlParserUtil.parse(sqlStr, parser -> {
320-
parser.withTimeOut(10000);
338+
parser.withTimeOut(60000);
321339
parser.withAllowComplexParsing(false);
322340
});
323341
} catch (JSQLParserException ex) {

src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ public void testRecursiveBracketExpressionIssue1019() {
124124
}
125125

126126
// maxDepth = 10 collides with the Parser Timeout = 6 seconds
127-
// temporarily restrict it to maxDepth = 8 for the moment
127+
// temporarily restrict it to maxDepth = 4 for the moment
128128
// @todo: implement methods to set the Parser Timeout explicitly and on demand
129129
// @todo Investigate performance deterioration since JSQLParser 5.0pre development
130130
@Test
131131
public void testRecursiveBracketExpressionIssue1019_2() throws JSQLParserException {
132-
doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 6);
132+
doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 4);
133133
}
134134

135135
@Test

src/test/java/net/sf/jsqlparser/util/APISanitation.java renamed to src/test/java/net/sf/jsqlparser/util/APISanitationTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.lang.reflect.TypeVariable;
2020
import java.util.Collection;
2121
import java.util.Comparator;
22-
import java.util.List;
22+
import java.util.Objects;
2323
import java.util.TreeSet;
2424
import java.util.logging.Level;
2525
import java.util.logging.Logger;
@@ -30,19 +30,19 @@ interface Visitor<T> {
3030
* @return {@code true} if the algorithm should visit more results, {@code false} if it should
3131
* terminate now.
3232
*/
33-
public boolean visit(T t);
33+
boolean visit(T t);
3434
}
3535

3636

37-
public class APISanitation {
38-
private final static TreeSet<Class> CLASSES = new TreeSet<>(new Comparator<Class>() {
37+
public class APISanitationTest {
38+
private final static TreeSet<Class<?>> CLASSES = new TreeSet<>(new Comparator<Class<?>>() {
3939
@Override
4040
public int compare(Class o1, Class o2) {
4141
return o1.getName().compareTo(o2.getName());
4242
}
4343
});
4444

45-
private final static Logger LOGGER = Logger.getLogger(APISanitation.class.getName());
45+
private final static Logger LOGGER = Logger.getLogger(APISanitationTest.class.getName());
4646

4747
public static void findClasses(Visitor<String> visitor) {
4848
String classpath = System.getProperty("java.class.path");
@@ -57,24 +57,22 @@ public static void findClasses(Visitor<String> visitor) {
5757

5858
private static boolean findClasses(File root, File file, Visitor<String> visitor) {
5959
if (file.isDirectory()) {
60-
for (File child : file.listFiles()) {
60+
for (File child : Objects.requireNonNull(file.listFiles())) {
6161
if (!findClasses(root, child, visitor)) {
6262
return false;
6363
}
6464
}
6565
} else if (file.getName().toLowerCase().endsWith(".class")) {
66-
if (!visitor.visit(createClassName(root, file))) {
67-
return false;
68-
}
66+
return visitor.visit(createClassName(root, file));
6967
}
7068

7169
return true;
7270
}
7371

7472
private static String createClassName(File root, File file) {
75-
StringBuffer sb = new StringBuffer();
73+
StringBuilder sb = new StringBuilder();
7674
String fileName = file.getName();
77-
sb.append(fileName.substring(0, fileName.lastIndexOf(".class")));
75+
sb.append(fileName, 0, fileName.lastIndexOf(".class"));
7876
File file1 = file.getParentFile();
7977
while (file1 != null && !file1.equals(root)) {
8078
sb.insert(0, '.').insert(0, file1.getName());
@@ -120,7 +118,7 @@ public MethodNamingException(String message, StackTraceElement stackTrace) {
120118
}
121119
}
122120

123-
private static Stream<Field> fields() throws Exception {
121+
private static Stream<Field> fields() {
124122
TreeSet<Field> fields = new TreeSet<>(new Comparator<Field>() {
125123
@Override
126124
public int compare(Field o1, Field o2) {
@@ -254,7 +252,7 @@ void testFieldAccess(Field field) throws MethodNamingException {
254252
}
255253
}
256254

257-
boolean testGenericType(Field field, Class boundClass) {
255+
boolean testGenericType(Field field, Class<?> boundClass) {
258256
Type listType = field.getGenericType();
259257
if (listType instanceof ParameterizedType) {
260258
ParameterizedType parameterizedType = (ParameterizedType) listType;
@@ -272,8 +270,8 @@ boolean testGenericType(Field field, Class boundClass) {
272270
ParameterizedType parameterizedType = (ParameterizedType) superclassType;
273271
if (parameterizedType != null) {
274272
for (final Type actualTypeArgument : parameterizedType.getActualTypeArguments()) {
275-
final TypeVariable<Class<List>> typeVariable =
276-
(TypeVariable<Class<List>>) actualTypeArgument;
273+
final TypeVariable<?> typeVariable =
274+
(TypeVariable<?>) actualTypeArgument;
277275
for (Type type : typeVariable.getBounds()) {
278276
if (type.getTypeName().equals(boundClass.getTypeName())) {
279277
return true;
@@ -284,7 +282,8 @@ boolean testGenericType(Field field, Class boundClass) {
284282
return false;
285283
}
286284

287-
private final static Class[] EXPRESSION_CLASSES = new Class[] {Expression.class, Column.class};
285+
private final static Class<?>[] EXPRESSION_CLASSES =
286+
new Class[] {Expression.class, Column.class};
288287

289288
@ParameterizedTest(name = "{index} Field {0}")
290289
@MethodSource("fields")
@@ -295,7 +294,7 @@ void testExpressionList(final Field field) throws MethodNamingException {
295294

296295
if (!fieldName.equalsIgnoreCase("$jacocoData")) {
297296
boolean isExpressionList = false;
298-
for (Class boundClass : EXPRESSION_CLASSES) {
297+
for (Class<?> boundClass : EXPRESSION_CLASSES) {
299298
if (Collection.class.isAssignableFrom(clazz)
300299
&& !ExpressionList.class.isAssignableFrom(clazz)) {
301300
isExpressionList |= testGenericType(field, boundClass);

0 commit comments

Comments
 (0)