HHH-14217 Code style

This commit is contained in:
Sanne Grinovero 2020-09-30 16:51:27 +01:00
parent 6f9b650bcb
commit 758de18531
2 changed files with 21 additions and 21 deletions

View File

@ -15,7 +15,7 @@ import java.util.Set;
*
* @author Steve Ebersole
*/
public class AnsiSqlKeywords {
public final class AnsiSqlKeywords {
/**
* Singleton access
*/
@ -23,7 +23,7 @@ public class AnsiSqlKeywords {
private final Set<String> keywordsSql2003;
public AnsiSqlKeywords() {
private AnsiSqlKeywords() {
final Set<String> keywordsSql2003 = new HashSet<String>();
keywordsSql2003.add( "ADD" );
keywordsSql2003.add( "ALL" );
@ -281,5 +281,4 @@ public class AnsiSqlKeywords {
return keywordsSql2003;
}
}

View File

@ -48,10 +48,10 @@ public class HighlightingFormatter implements Formatter {
* @param stringCode the ANSI escape code to use for highlighting SQL strings
*/
public HighlightingFormatter(String keywordCode, String stringCode, String quotedCode) {
keywordEscape =escape(keywordCode);
stringEscape = escape(stringCode);
quotedEscape = escape(quotedCode);
normalEscape = escape("0");
keywordEscape =escape( keywordCode );
stringEscape = escape( stringCode );
quotedEscape = escape( quotedCode );
normalEscape = escape( "0" );
}
@Override
@ -60,46 +60,47 @@ public class HighlightingFormatter implements Formatter {
StringBuilder result = new StringBuilder();
boolean inString = false;
boolean inQuoted = false;
for (StringTokenizer tokenizer = new StringTokenizer( sql, symbolsAndWs, true );
for ( StringTokenizer tokenizer = new StringTokenizer( sql, symbolsAndWs, true );
tokenizer.hasMoreTokens(); ) {
String token = tokenizer.nextToken();
switch (token) {
switch ( token ) {
case "\"":
case "`": // for MySQL
if (inString) {
result.append(token);
if ( inString ) {
result.append( token );
}
else if (inQuoted) {
else if ( inQuoted ) {
inQuoted = false;
result.append(token).append(normalEscape);
result.append( token ).append( normalEscape );
}
else {
inQuoted = true;
result.append(quotedEscape).append(token);
result.append( quotedEscape ).append( token );
}
break;
case "'":
if (inQuoted) {
result.append("'");
if ( inQuoted ) {
result.append( "'" );
}
else if (inString) {
else if ( inString ) {
inString = false;
result.append("'").append(normalEscape);
result.append( "'" ).append( normalEscape );
}
else {
inString = true;
result.append(stringEscape).append("'");
result.append( stringEscape ).append( "'" );
}
break;
default:
if ( KEYWORDS.contains( token.toUpperCase() ) ) {
result.append(keywordEscape).append(token).append(normalEscape);
result.append( keywordEscape ).append( token ).append( normalEscape );
}
else {
result.append(token);
result.append( token );
}
}
}
return result.toString();
}
}