HHH-14217 Code style
This commit is contained in:
parent
cf995a1571
commit
916513a7eb
|
@ -15,7 +15,7 @@ import java.util.Set;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class AnsiSqlKeywords {
|
public final class AnsiSqlKeywords {
|
||||||
/**
|
/**
|
||||||
* Singleton access
|
* Singleton access
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,7 @@ public class AnsiSqlKeywords {
|
||||||
|
|
||||||
private final Set<String> keywordsSql2003;
|
private final Set<String> keywordsSql2003;
|
||||||
|
|
||||||
public AnsiSqlKeywords() {
|
private AnsiSqlKeywords() {
|
||||||
final Set<String> keywordsSql2003 = new HashSet<String>();
|
final Set<String> keywordsSql2003 = new HashSet<String>();
|
||||||
keywordsSql2003.add( "ADD" );
|
keywordsSql2003.add( "ADD" );
|
||||||
keywordsSql2003.add( "ALL" );
|
keywordsSql2003.add( "ALL" );
|
||||||
|
@ -281,5 +281,4 @@ public class AnsiSqlKeywords {
|
||||||
return keywordsSql2003;
|
return keywordsSql2003;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ public class HighlightingFormatter implements Formatter {
|
||||||
* @param stringCode the ANSI escape code to use for highlighting SQL strings
|
* @param stringCode the ANSI escape code to use for highlighting SQL strings
|
||||||
*/
|
*/
|
||||||
public HighlightingFormatter(String keywordCode, String stringCode, String quotedCode) {
|
public HighlightingFormatter(String keywordCode, String stringCode, String quotedCode) {
|
||||||
keywordEscape =escape(keywordCode);
|
keywordEscape =escape( keywordCode );
|
||||||
stringEscape = escape(stringCode);
|
stringEscape = escape( stringCode );
|
||||||
quotedEscape = escape(quotedCode);
|
quotedEscape = escape( quotedCode );
|
||||||
normalEscape = escape("0");
|
normalEscape = escape( "0" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,46 +60,47 @@ public class HighlightingFormatter implements Formatter {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
boolean inString = false;
|
boolean inString = false;
|
||||||
boolean inQuoted = false;
|
boolean inQuoted = false;
|
||||||
for (StringTokenizer tokenizer = new StringTokenizer( sql, symbolsAndWs, true );
|
for ( StringTokenizer tokenizer = new StringTokenizer( sql, symbolsAndWs, true );
|
||||||
tokenizer.hasMoreTokens(); ) {
|
tokenizer.hasMoreTokens(); ) {
|
||||||
String token = tokenizer.nextToken();
|
String token = tokenizer.nextToken();
|
||||||
switch (token) {
|
switch ( token ) {
|
||||||
case "\"":
|
case "\"":
|
||||||
case "`": // for MySQL
|
case "`": // for MySQL
|
||||||
if (inString) {
|
if ( inString ) {
|
||||||
result.append(token);
|
result.append( token );
|
||||||
}
|
}
|
||||||
else if (inQuoted) {
|
else if ( inQuoted ) {
|
||||||
inQuoted = false;
|
inQuoted = false;
|
||||||
result.append(token).append(normalEscape);
|
result.append( token ).append( normalEscape );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inQuoted = true;
|
inQuoted = true;
|
||||||
result.append(quotedEscape).append(token);
|
result.append( quotedEscape ).append( token );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "'":
|
case "'":
|
||||||
if (inQuoted) {
|
if ( inQuoted ) {
|
||||||
result.append("'");
|
result.append( "'" );
|
||||||
}
|
}
|
||||||
else if (inString) {
|
else if ( inString ) {
|
||||||
inString = false;
|
inString = false;
|
||||||
result.append("'").append(normalEscape);
|
result.append( "'" ).append( normalEscape );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inString = true;
|
inString = true;
|
||||||
result.append(stringEscape).append("'");
|
result.append( stringEscape ).append( "'" );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ( KEYWORDS.contains( token.toUpperCase() ) ) {
|
if ( KEYWORDS.contains( token.toUpperCase() ) ) {
|
||||||
result.append(keywordEscape).append(token).append(normalEscape);
|
result.append( keywordEscape ).append( token ).append( normalEscape );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.append(token);
|
result.append( token );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue