@@ -207,8 +207,8 @@ else if ( quotedIdentifier && dialect.closeQuote()==token.charAt(0) ) {
207
207
isOpenQuote = false ;
208
208
}
209
209
if ( isOpenQuote
210
- && !inFromClause // don't want to append alias to tokens inside the from clause
211
- && notEndsWithDot ( previousToken ) ) {
210
+ && !inFromClause // don't want to append alias to tokens inside the FROM clause
211
+ && ! endsWithDot ( previousToken ) ) {
212
212
result .append ( alias ).append ( '.' );
213
213
}
214
214
}
@@ -237,7 +237,7 @@ else if ( FUNCTION_WITH_FROM_KEYWORDS.contains(lcToken) && "(".equals( nextToken
237
237
result .append (token );
238
238
inExtractOrTrim = true ;
239
239
}
240
- else if ( !inFromClause // don't want to append alias to tokens inside the from clause
240
+ else if ( !inFromClause // don't want to append alias to tokens inside the FROM clause
241
241
&& isIdentifier ( token )
242
242
&& !isFunctionOrKeyword ( lcToken , nextToken , dialect , typeConfiguration )
243
243
&& !isLiteral ( lcToken , nextToken , sql , symbols , tokens ) ) {
@@ -274,31 +274,29 @@ else if ( inFromClause && ",".equals(lcToken) ) {
274
274
return result .toString ();
275
275
}
276
276
277
- private static boolean notEndsWithDot (String token ) {
278
- return token == null || ! token .endsWith ( "." );
277
+ private static boolean endsWithDot (String token ) {
278
+ return token != null && token .endsWith ( "." );
279
279
}
280
280
281
281
private static boolean isLiteral (
282
282
String lcToken , String next ,
283
283
String sqlWhereString , String symbols , StringTokenizer tokens ) {
284
- if ( LITERAL_PREFIXES .contains ( lcToken ) && next != null ) {
285
- // easy cases first
286
- if ( "'" .equals (next ) ) {
287
- return true ;
288
- }
289
- else if ( !next .isBlank () ) {
290
- return false ;
291
- }
292
- else {
284
+ if ( next == null ) {
285
+ return false ;
286
+ }
287
+ else if ( LITERAL_PREFIXES .contains ( lcToken ) ) {
288
+ if ( next .isBlank () ) {
293
289
// we need to look ahead in the token stream
294
290
// to find the first non-blank token
295
291
return lookPastBlankTokens ( sqlWhereString , symbols , tokens , 1 ,
296
- (String nextToken )
297
- -> "'" .equals (nextToken )
292
+ (nextToken ) -> "'" .equals (nextToken )
298
293
|| lcToken .equals ("time" ) && "with" .equals (nextToken )
299
294
|| lcToken .equals ("timestamp" ) && "with" .equals (nextToken )
300
295
|| lcToken .equals ("time" ) && "zone" .equals (nextToken ) );
301
296
}
297
+ else {
298
+ return "'" .equals (next );
299
+ }
302
300
}
303
301
else {
304
302
return false ;
@@ -351,15 +349,15 @@ public static List<String> collectColumnNames(String template) {
351
349
int begin = 0 ;
352
350
int match ;
353
351
while ( ( match = template .indexOf (TEMPLATE , begin ) ) >= 0 ) {
354
- int start = match + TEMPLATE .length () + 1 ;
352
+ final int start = match + TEMPLATE .length () + 1 ;
355
353
for ( int loc = start ;; loc ++ ) {
356
354
if ( loc == template .length () - 1 ) {
357
355
names .add ( template .substring ( start ) );
358
356
begin = template .length ();
359
357
break ;
360
358
}
361
359
else {
362
- char ch = template .charAt ( loc );
360
+ final char ch = template .charAt ( loc );
363
361
if ( PUNCTUATION .indexOf (ch ) >= 0 || WHITESPACE .indexOf (ch ) >= 0 ) {
364
362
names .add ( template .substring ( start , loc ) );
365
363
begin = loc ;
@@ -401,17 +399,16 @@ private static boolean isType(String lcToken, TypeConfiguration typeConfiguratio
401
399
}
402
400
403
401
private static boolean isIdentifier (String token ) {
404
- if ( isBoolean ( token ) ) {
405
- return false ;
406
- }
407
- return token .charAt ( 0 ) == '`'
408
- || ( //allow any identifier quoted with backtick
409
- isLetter ( token .charAt ( 0 ) ) && //only recognizes identifiers beginning with a letter
410
- token .indexOf ( '.' ) < 0
411
- );
402
+ return token .charAt ( 0 ) == '`' // allow any identifier quoted with backtick
403
+ || isLetter ( token .charAt ( 0 ) ) // only recognizes identifiers beginning with a letter
404
+ && token .indexOf ( '.' ) < 0
405
+ && !isBoolean ( token );
412
406
}
413
407
414
408
private static boolean isBoolean (String token ) {
415
- return "true" .equals ( token ) || "false" .equals ( token );
409
+ return switch ( token .toLowerCase ( Locale .ROOT ) ) {
410
+ case "true" , "false" -> true ;
411
+ default -> false ;
412
+ };
416
413
}
417
414
}
0 commit comments