public class FormatterFactory extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FormatterFactory.IFormatterBuilderCreator<E extends AbstractStmtFormatter>
the callback interface to achieve the formatter builder
|
| Constructor and Description |
|---|
FormatterFactory() |
public FormatterFactory()
public static SelectStmtFormatter createSelectStmtFormatter(GFmtOpt opt)
opt - optionspublic static InsertStmtFormatter createInsertStmtFormatter(GFmtOpt opt)
public static DeleteStmtFormatter createDeleteStmtFormatter(GFmtOpt opt)
public static UpdateStmtFormatter createUpdateStmtFormatter(GFmtOpt opt)
public static CreateTableStmtFormatter createCreateTableStmtFormatter(GFmtOpt opt)
public static DeclareStmtFormatter createDeclareStmtFormatter(GFmtOpt opt)
public static ExecuteStmtFormatter createExecuteStmtFormatter(GFmtOpt opt)
public static SetStmtFormatter createSetStmtFormatter(GFmtOpt opt)
public static IfStmtFormatter createIfStmtFormatter(GFmtOpt opt)
public static PlsqlIfStmtFormatter createPlsqlIfStmtFormatter(GFmtOpt opt)
public static PlsqlStmtFormatter createPlsqlStmtFormatter(GFmtOpt opt)
public static GoStmtFormatter createGoStmtFormatter(GFmtOpt opt)
public static CompactModeStmtFormatter createCompactModeStmtFormatter(GFmtOpt opt)
public static ReturnStmtFormatter createReturnStmtFormatter(GFmtOpt opt)
public static CreateViewStmtFormatter createCreateViewStmtFormatter(GFmtOpt opt)
public static CreateMaterializedViewStmtFormatter createCreateMaterializedViewStmtFormatter(GFmtOpt opt)
public static AlterTableStmtFormatter createAlterTableStatement(GFmtOpt opt)
public static <E extends AbstractStmtFormatter> E createFormatter(GFmtOpt opt, Class<E> clazz, FormatterFactory.IFormatterBuilderCreator<E> creater)
E - opt - clazz - creater - public static void processStatement(GFmtOpt option, TCustomSqlStatement sql)
public static boolean isNotNeedFormat(TCustomSqlStatement sql)
public static boolean isNotNeedFormat(TSourceToken t)
public static void processBlockStmt(GFmtOpt opt, TMssqlBlock stmt, TSourceToken ifToken)
public static String pp(TGSqlParser parser, GFmtOpt option)
public static Pp2FormatResult pp2(TGSqlParser parser, Pp2FormatOptions opts)
This is the first thing to know about pp2: it is not a second,
competing layout engine, and it has no layout style of its own for SQL
that parses. When the whole of parser.sqltext parses, pp2 calls
pp(TGSqlParser, GFmtOpt) on the whole document with these same
options and returns pp's own output, byte for byte. Changing a
working pp() call to pp2() therefore does not change how
already-formattable SQL comes out; it only changes what happens to SQL
that pp() could not format at all.
Precisely, each call walks this ladder and stops at the first rung that succeeds:
FormatterFactory.pp over the whole
document and checks the output with a token-equivalence guard (same
solid and comment tokens, same order, ignoring whitespace and
keyword case). If the guard passes, that text is the answer:
status OK, every
region reported as
GUARDED_AST.
This rung is governed by
Pp2FormatOptions.wholeDocumentFastPath (default
true); set it to false to force the regional
pipeline below.FormatterFactory.pp, behind the same guard. One broken
statement therefore costs pp-quality layout for that statement only,
not for the whole script.LEXICAL_ISLAND
or
CONSERVATIVE,
and lifts the overall status to
OK_WITH_RECOVERY.Pp2FormatResult.getRegions() tells you which rung ran where,
and Pp2FormatResult.getDiagnostics() carries the per-region
parser errors. A result whose regions are all GUARDED_AST is pp
output; anything else marks the part of the input pp could not reach.
pp(TGSqlParser, GFmtOpt)pp() requires the caller to have run parser.parse()
and got 0 back. pp2 does not: it parses internally and
ignores whatever parse state the caller left behind, so a
TGSqlParser carrying only sqltext and a vendor is
enough.pp() on malformed SQL yields nothing usable. pp2 always
returns text and never throws for non-null inputs.This is the single additive pp2 bridge (plan §4.1/S17). It does not
change the behavior of pp(TGSqlParser, GFmtOpt) or any other
existing method. The heavy lifting lives in
gudusoft.gsqlparser.pp2.engine.Pp2Engine.
parser - carries the SQL text (parser.sqltext) and dialect
(parser.getDbVendor()); need not be parsed firstopts - pp2 formatting options; must not be nullPp2FormatResult with per-region renderer
choice, status, and diagnostics; never nullNullPointerException - if parser or opts is nullpublic static String pp2(TGSqlParser parser, GFmtOpt opt)
pp(TGSqlParser, GFmtOpt)
signature: returns the formatted text directly, so it is a drop-in
replacement for a pp() call.
The caller's GFmtOpt is copied into a Pp2FormatOptions
via Pp2FormatOptions.from(GFmtOpt) so casing / comma / indent
options carry over. Byte-parity with pp() on parseable input is
not an approximation of pp's style — on that input pp2 calls
pp() and returns its output unchanged; see
pp2(TGSqlParser, Pp2FormatOptions) for the full ladder.
TGSqlParser parser = new TGSqlParser(EDbVendor.dbvoracle);
parser.sqltext = sql; // no parse() call needed
String formatted = FormatterFactory.pp2(parser, GFmtOptFactory.newInstance());
This overload discards the per-region detail. Call
pp2(TGSqlParser, Pp2FormatOptions) instead when you need to know
whether any part of the input fell back to pp2's own renderers (i.e. was
not formatted by pp).
parser - carries the SQL text and dialect; need not be parsed firstopt - existing formatter options; must not be nullNullPointerException - if parser or opt is nullpublic static OutputConfig getOutputConfig()
setOutputConfig(gudusoft.gsqlparser.pp.output.OutputConfig), or null. Formatting never sets it.null when each call follows its own
GFmtOpt.outputFmtpublic static void setOutputConfig(OutputConfig outputConfig)
pp(TGSqlParser, GFmtOpt) and SqlFormatter.format(gudusoft.gsqlparser.TGSqlParser, gudusoft.gsqlparser.pp.para.GFmtOpt) call, in every
thread, print with this config whatever its option's outputFmt says, until it is set back to
null (the default), after which each call prints as its own option says again. Customise the
config before setting it, not while calls may be printing with it.outputConfig - the config to print every call with, for example an
HtmlOutputConfig with custom colors; null to let each call follow its optionpublic static AllStmtsFormatter createAllStmtsFormatter(GFmtOpt option)
public static void clearAllObject(String sessionId)