@@ -207,8 +207,8 @@ else if ( quotedIdentifier && dialect.closeQuote()==token.charAt(0) ) {
207207 isOpenQuote = false ;
208208 }
209209 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 ) ) {
212212 result .append ( alias ).append ( '.' );
213213 }
214214 }
@@ -237,7 +237,7 @@ else if ( FUNCTION_WITH_FROM_KEYWORDS.contains(lcToken) && "(".equals( nextToken
237237 result .append (token );
238238 inExtractOrTrim = true ;
239239 }
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
241241 && isIdentifier ( token )
242242 && !isFunctionOrKeyword ( lcToken , nextToken , dialect , typeConfiguration )
243243 && !isLiteral ( lcToken , nextToken , sql , symbols , tokens ) ) {
@@ -274,31 +274,29 @@ else if ( inFromClause && ",".equals(lcToken) ) {
274274 return result .toString ();
275275 }
276276
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 ( "." );
279279 }
280280
281281 private static boolean isLiteral (
282282 String lcToken , String next ,
283283 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 () ) {
293289 // we need to look ahead in the token stream
294290 // to find the first non-blank token
295291 return lookPastBlankTokens ( sqlWhereString , symbols , tokens , 1 ,
296- (String nextToken )
297- -> "'" .equals (nextToken )
292+ (nextToken ) -> "'" .equals (nextToken )
298293 || lcToken .equals ("time" ) && "with" .equals (nextToken )
299294 || lcToken .equals ("timestamp" ) && "with" .equals (nextToken )
300295 || lcToken .equals ("time" ) && "zone" .equals (nextToken ) );
301296 }
297+ else {
298+ return "'" .equals (next );
299+ }
302300 }
303301 else {
304302 return false ;
@@ -351,15 +349,15 @@ public static List<String> collectColumnNames(String template) {
351349 int begin = 0 ;
352350 int match ;
353351 while ( ( match = template .indexOf (TEMPLATE , begin ) ) >= 0 ) {
354- int start = match + TEMPLATE .length () + 1 ;
352+ final int start = match + TEMPLATE .length () + 1 ;
355353 for ( int loc = start ;; loc ++ ) {
356354 if ( loc == template .length () - 1 ) {
357355 names .add ( template .substring ( start ) );
358356 begin = template .length ();
359357 break ;
360358 }
361359 else {
362- char ch = template .charAt ( loc );
360+ final char ch = template .charAt ( loc );
363361 if ( PUNCTUATION .indexOf (ch ) >= 0 || WHITESPACE .indexOf (ch ) >= 0 ) {
364362 names .add ( template .substring ( start , loc ) );
365363 begin = loc ;
@@ -401,17 +399,16 @@ private static boolean isType(String lcToken, TypeConfiguration typeConfiguratio
401399 }
402400
403401 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 );
412406 }
413407
414408 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+ };
416413 }
417414}
0 commit comments