001package gudusoft.gsqlparser.pp.para;
002
003import gudusoft.gsqlparser.pp.para.styleenums.TAlignOption;
004import gudusoft.gsqlparser.pp.para.styleenums.TAlignStyle;
005import gudusoft.gsqlparser.pp.para.styleenums.TCaseOption;
006import gudusoft.gsqlparser.pp.para.styleenums.TCompactMode;
007import gudusoft.gsqlparser.pp.para.styleenums.TEmptyLinesOption;
008import gudusoft.gsqlparser.pp.para.styleenums.TLinefeedsCommaOption;
009
010/**
011 * Mutable configuration for the SQL pretty-printer.
012 *
013 * <p>Create an instance with {@link GFmtOptFactory}, finish configuring it,
014 * and pass it to the formatter. Do not modify an instance while formatting is
015 * in progress. The formatter uses {@link #sessionId} to associate processors
016 * and mediators with this option set.</p>
017 *
018 * <p>Every public field is documented with its default and its interaction
019 * with related options. Fields in the "Lifecycle and advanced controls"
020 * category are public for compatibility but are not ordinary presentation
021 * settings.</p>
022 *
023 * @author zhoujun
024 */
025public class GFmtOpt
026{
027
028        /**
029         * Identifies the formatting session used by formatter, processor, and
030         * mediator caches. Use a unique id for independently configured concurrent
031         * calls; the id is not rendered in the output.
032         *
033         * <p><b>Category:</b> Lifecycle and advanced controls</p>
034         * <p><b>Default:</b> Supplied to the constructor.</p>
035         */
036        public final String sessionId;
037
038        /**
039         * Enables the low-level source-token mutation operations that implement
040         * formatting. Setting this to {@code false} makes token add/remove helpers
041         * ignore requests and therefore disables most formatting; it is intended
042         * for diagnostics, not as a preserve-layout mode.
043         *
044         * <p><b>Category:</b> Lifecycle and advanced controls</p>
045         * <p><b>Default:</b> {@code true}.</p>
046         */
047        public boolean opearateSourceToken = true;
048
049        /**
050         * Chooses stacked or wrapped layout for SELECT result columns and is also
051         * reused by GROUP BY and ORDER BY lists. Stacked layout permits line breaks
052         * according to {@link #selectColumnlistComma}; wrapped layout keeps items on
053         * the current line. Alias alignment is applied only to stacked lists.
054         *
055         * <p><b>Category:</b> SELECT list and query clauses</p>
056         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
057         */
058        public TAlignStyle selectColumnlistStyle = TAlignStyle.AsStacked;
059
060        /**
061         * Chooses whether a comma ends the previous line or begins the next line in
062         * stacked SELECT, GROUP BY, and ORDER BY lists. The setting has no line-break
063         * effect when {@link #selectColumnlistStyle} is wrapped.
064         *
065         * <p><b>Category:</b> SELECT list and query clauses</p>
066         * <p><b>Default:</b> {@link TLinefeedsCommaOption#LfAfterComma}.</p>
067         */
068        public TLinefeedsCommaOption selectColumnlistComma = TLinefeedsCommaOption.LfAfterComma;
069
070        /**
071         * Places the first SELECT item on a line after SELECT. The same switch also
072         * places the first GROUP BY and ORDER BY item, and the HAVING expression,
073         * after their clause keywords; subsequent item breaks are controlled by the
074         * list style and comma option.
075         *
076         * <p><b>Category:</b> SELECT list and query clauses</p>
077         * <p><b>Default:</b> {@code false}.</p>
078         */
079        public boolean selectItemInNewLine = false;
080
081        /**
082         * Pads stacked SELECT expressions so their explicit or implicit aliases
083         * begin in the same column. It is ignored for wrapped lists and may be
084         * skipped for exceptionally wide lists to avoid excessive padding.
085         *
086         * <p><b>Category:</b> SELECT list and query clauses</p>
087         * <p><b>Default:</b> {@code true}.</p>
088         */
089        public boolean alignAliasInSelectList = true;
090
091        /**
092         * Adds a synthetic DISTINCT result-column node to the parsed SELECT list so
093         * it participates in stacking and comma-layout calculations. This mutates
094         * the statement's result-column list for formatting, although the rendered
095         * SQL semantics are unchanged.
096         *
097         * <p><b>Category:</b> SELECT list and query clauses</p>
098         * <p><b>Default:</b> {@code false}.</p>
099         */
100        public boolean treatDistinctAsVirtualColumn = false;
101
102        /**
103         * Chooses stacked or wrapped layout for comma-separated table sources in a
104         * FROM clause. JOIN clauses have their own newline and alignment controls.
105         *
106         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
107         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
108         */
109        public TAlignStyle selectFromclauseStyle = TAlignStyle.AsStacked;
110
111        /**
112         * Positions commas for stacked comma-separated FROM items. It is effective
113         * only when {@link #selectFromclauseStyle} is stacked.
114         *
115         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
116         * <p><b>Default:</b> {@link TLinefeedsCommaOption#LfAfterComma}.</p>
117         */
118        public TLinefeedsCommaOption selectFromclauseComma = TLinefeedsCommaOption.LfAfterComma;
119
120        /**
121         * Places the first table source on a new indented line after FROM (and the
122         * corresponding INTO table source where that clause shares this processor).
123         * When false, one space separates the clause keyword and first source.
124         *
125         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
126         * <p><b>Default:</b> {@code false}.</p>
127         */
128        public boolean fromClauseInNewLine = false;
129
130        /**
131         * Places the ON condition of a JOIN on a separate line. JOIN keywords are
132         * always normalized onto their own lines by the JOIN processor; this switch
133         * controls the additional break before ON.
134         *
135         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
136         * <p><b>Default:</b> {@code true}.</p>
137         */
138        public boolean selectFromclauseJoinOnInNewline = true;
139
140        /**
141         * Aligns the beginning of JOIN phrases with the FROM keyword rather than
142         * with the first table source. It does not control whether ON starts a new
143         * line; use {@link #selectFromclauseJoinOnInNewline} for that.
144         *
145         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
146         * <p><b>Default:</b> {@code false}.</p>
147         */
148        public boolean alignJoinWithFromKeyword = false;
149
150        /**
151         * Aligns leading AND and OR operators under the WHERE keyword. When false,
152         * boolean continuations use the expression formatter's normal indentation.
153         *
154         * <p><b>Category:</b> FROM, JOIN, and WHERE</p>
155         * <p><b>Default:</b> {@code false}.</p>
156         */
157        public boolean andOrUnderWhere = false;
158
159        /**
160         * Chooses stacked or wrapped layout for the target-column list of INSERT.
161         * Comma placement comes from {@link #defaultCommaOption} rather than the
162         * SELECT-specific comma option.
163         *
164         * <p><b>Category:</b> INSERT and general lists</p>
165         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
166         */
167        public TAlignStyle insertColumnlistStyle = TAlignStyle.AsStacked;
168
169        /**
170         * Chooses stacked or wrapped layout for each INSERT VALUES list. Comma
171         * placement comes from {@link #defaultCommaOption}.
172         *
173         * <p><b>Category:</b> INSERT and general lists</p>
174         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
175         */
176        public TAlignStyle insertValuelistStyle = TAlignStyle.AsStacked;
177
178        /**
179         * Places the opening parenthesis of a CREATE TABLE column list on a new line
180         * and indents it by {@link #indentLen}. If list items are also placed on new
181         * lines, they receive one additional indentation level.
182         *
183         * <p><b>Category:</b> CREATE TABLE</p>
184         * <p><b>Default:</b> {@code false}.</p>
185         */
186        public boolean beStyleCreatetableLeftBEOnNewline = false;
187
188        /**
189         * Places the closing parenthesis of a CREATE TABLE column list on its own
190         * line. Its indentation accounts for whether the opening parenthesis was
191         * also moved to a new line.
192         *
193         * <p><b>Category:</b> CREATE TABLE</p>
194         * <p><b>Default:</b> {@code false}.</p>
195         */
196        public boolean beStyleCreatetableRightBEOnNewline = false;
197
198        /**
199         * Places the first CREATE TABLE column or constraint on a new line after the
200         * opening parenthesis. Remaining items follow {@link #defaultAligntype} and
201         * {@link #defaultCommaOption}.
202         *
203         * <p><b>Category:</b> CREATE TABLE</p>
204         * <p><b>Default:</b> {@code false}.</p>
205         */
206        public boolean createtableListitemInNewLine = false;
207
208        /**
209         * Left- or right-aligns CREATE TABLE column names within the widest column-
210         * name width. It is applied only when {@link #defaultAligntype} is stacked.
211         *
212         * <p><b>Category:</b> CREATE TABLE</p>
213         * <p><b>Default:</b> {@link TAlignOption#AloLeft}.</p>
214         */
215        public TAlignOption createtableFieldlistAlignOption = TAlignOption.AloLeft;
216
217        /**
218         * Provides comma placement for formatter lists without a dedicated comma
219         * setting, including INSERT columns/values, UPDATE SET items, and CREATE
220         * TABLE columns and constraints.
221         *
222         * <p><b>Category:</b> INSERT and general lists</p>
223         * <p><b>Default:</b> {@link TLinefeedsCommaOption#LfAfterComma}.</p>
224         */
225        public TLinefeedsCommaOption defaultCommaOption = TLinefeedsCommaOption.LfAfterComma;
226
227        /**
228         * Provides stacked or wrapped layout for lists without a dedicated style,
229         * notably UPDATE SET and CREATE TABLE lists. INSERT has separate style fields
230         * but still uses {@link #defaultCommaOption} for commas.
231         *
232         * <p><b>Category:</b> INSERT and general lists</p>
233         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
234         */
235        public TAlignStyle defaultAligntype = TAlignStyle.AsStacked;
236
237        /**
238         * Sets the general indentation increment, in columns, used by nested clauses,
239         * expressions, CTE bodies, parameters, and many statement processors. More
240         * specialized indentation options add to, rather than replace, this value.
241         *
242         * <p><b>Category:</b> Indentation and procedural blocks</p>
243         * <p><b>Default:</b> {@code 2}.</p>
244         */
245        public Integer indentLen = 2;
246
247        /**
248         * Enables the final tab-alignment pass. The formatter first computes spaces,
249         * then pads each indented line to a multiple of {@link #tabSize}; this option
250         * does not replace all indentation characters with literal tab characters.
251         *
252         * <p><b>Category:</b> Indentation and procedural blocks</p>
253         * <p><b>Default:</b> {@code false}.</p>
254         */
255        public Boolean useTab = false;
256
257        /**
258         * Defines the tab-stop width used by the final tab-alignment pass when
259         * {@link #useTab} is enabled. Use a positive value.
260         *
261         * <p><b>Category:</b> Indentation and procedural blocks</p>
262         * <p><b>Default:</b> {@code 2}.</p>
263         */
264        public Integer tabSize = 2;
265
266        /**
267         * Reserved compatibility setting for stored-routine body indentation. The
268         * active formatter currently does not read this field; use
269         * {@link #beStyleBlockIndentSize} and {@link #indentLen} for effective body
270         * indentation.
271         *
272         * <p><b>Category:</b> Indentation and procedural blocks</p>
273         * <p><b>Default:</b> {@code 2}; currently has no effect.</p>
274         */
275        public Integer beStyleFunctionBodyIndent = 2;
276
277        /**
278         * Places a procedural BEGIN token on a new line. This is used by PL/SQL-like
279         * blocks and by SQL Server BEGIN/END block formatting, with vendor-specific
280         * paths applying the related indentation settings.
281         *
282         * <p><b>Category:</b> Indentation and procedural blocks</p>
283         * <p><b>Default:</b> {@code true}.</p>
284         */
285        public Boolean beStyleBlockLeftBEOnNewline = true;
286
287        /**
288         * Adds columns to the containing statement's indentation for a BEGIN token
289         * moved to a new line. It is meaningful when
290         * {@link #beStyleBlockLeftBEOnNewline} is true.
291         *
292         * <p><b>Category:</b> Indentation and procedural blocks</p>
293         * <p><b>Default:</b> {@code 2}.</p>
294         */
295        public Integer beStyleBlockLeftBEIndentSize = 2;
296
297        /**
298         * Controls END indentation for block paths where BEGIN remains on the current
299         * line. When BEGIN is moved, those paths align END using the BEGIN indent
300         * instead, so this value may be ignored.
301         *
302         * <p><b>Category:</b> Indentation and procedural blocks</p>
303         * <p><b>Default:</b> {@code 2}.</p>
304         */
305        public Integer beStyleBlockRightBEIndentSize = 2;
306
307        /**
308         * Adds indentation to statements inside BEGIN/END blocks and to returned
309         * query bodies in supported CREATE FUNCTION and CREATE VIEW forms. It is
310         * measured relative to the enclosing block marker.
311         *
312         * <p><b>Category:</b> Indentation and procedural blocks</p>
313         * <p><b>Default:</b> {@code 2}.</p>
314         */
315        public Integer beStyleBlockIndentSize = 2;
316
317        /**
318         * Adds indentation to a single statement controlled by IF or ELSE when the
319         * body is not represented as a BEGIN/END block. Block bodies instead use the
320         * block indentation options.
321         *
322         * <p><b>Category:</b> Indentation and procedural blocks</p>
323         * <p><b>Default:</b> {@code 2}.</p>
324         */
325        public Integer beStyleIfElseSingleStmtIndentSize = 2;
326
327        /**
328         * Keeps each WHEN condition and its THEN keyword on one line when true. When
329         * false, THEN starts a new line and its indentation additionally uses
330         * {@link #indentCaseThen}.
331         *
332         * <p><b>Category:</b> CASE expressions</p>
333         * <p><b>Default:</b> {@code false}.</p>
334         */
335        public Boolean caseWhenThenInSameLine = false;
336
337        /**
338         * Indents WHEN, ELSE, and END relative to the CASE keyword. The value is an
339         * absolute number of columns added at that CASE nesting level.
340         *
341         * <p><b>Category:</b> CASE expressions</p>
342         * <p><b>Default:</b> {@code 2}.</p>
343         */
344        public Integer indentCaseFromSwitch = 2;
345
346        /**
347         * Adds indentation to a line-broken THEN relative to its WHEN indentation.
348         * It is ignored when {@link #caseWhenThenInSameLine} is true.
349         *
350         * <p><b>Category:</b> CASE expressions</p>
351         * <p><b>Default:</b> {@code 0}.</p>
352         */
353        public Integer indentCaseThen = 0;
354
355        /**
356         * Left- or right-aligns multiword and single-word query clause labels such as
357         * SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY within their shared
358         * keyword width.
359         *
360         * <p><b>Category:</b> Keyword alignment and capitalization</p>
361         * <p><b>Default:</b> {@link TAlignOption#AloLeft}.</p>
362         */
363        public TAlignOption selectKeywordsAlignOption = TAlignOption.AloLeft;
364
365        /**
366         * Converts SQL keyword tokens to the selected case. Datatypes and recognized
367         * function names use their dedicated case settings instead.
368         *
369         * <p><b>Category:</b> Keyword alignment and capitalization</p>
370         * <p><b>Default:</b> {@link TCaseOption#CoUppercase}.</p>
371         */
372        public TCaseOption caseKeywords = TCaseOption.CoUppercase;
373
374        /**
375         * Converts unquoted identifier tokens that are not recognized as datatypes
376         * or function names. Table names, column names, table aliases and column
377         * aliases use {@link #caseTableName}, {@link #caseColumnName},
378         * {@link #caseTableAlias} and {@link #caseColumnAlias} instead when those
379         * are set. Changing case can change semantics in case-sensitive
380         * databases, so preserve case unless that transformation is intentional.
381         *
382         * <p><b>Category:</b> Keyword alignment and capitalization</p>
383         * <p><b>Default:</b> {@link TCaseOption#CoNoChange}.</p>
384         */
385        public TCaseOption caseIdentifier = TCaseOption.CoNoChange;
386
387        /**
388         * Converts unquoted table and view names, including a table name that
389         * qualifies a column ({@code orders.id}). CTE names are not tables here:
390         * they follow {@link #caseIdentifier}, as do schema and database names.
391         * What a name is comes from name resolution ({@code TSQLResolver2}), which
392         * runs only when the SQL parses; for SQL that does not, and when this is
393         * null, table names follow {@link #caseIdentifier}.
394         *
395         * <p>This setting and {@link #caseColumnName}, {@link #caseTableAlias} and
396         * {@link #caseColumnAlias} never change delimited names ({@code "x"},
397         * {@code [x]}, {@code `x`}). Where resolution does not report every use
398         * of a table name or table alias (SQL Server's
399         * {@code UPDATE o ... FROM orders o}, a view created and then used in one
400         * script) and following them would give one name two cases, all four are
401         * off for the whole input, which then uses {@link #caseIdentifier}.
402         *
403         * <p><b>Category:</b> Keyword alignment and capitalization</p>
404         * <p><b>Default:</b> {@code null} (follows {@link #caseIdentifier}).</p>
405         */
406        public TCaseOption caseTableName = null;
407
408        /**
409         * Converts the column name of unquoted column references
410         * ({@code order_id} in {@code o.order_id}), as name resolution finds
411         * them. For SQL that does not parse, and when this is null, column names
412         * follow {@link #caseIdentifier}.
413         *
414         * <p><b>Category:</b> Keyword alignment and capitalization</p>
415         * <p><b>Default:</b> {@code null} (follows {@link #caseIdentifier}).</p>
416         */
417        public TCaseOption caseColumnName = null;
418
419        /**
420         * Converts unquoted table aliases where they are declared
421         * ({@code orders o}, {@code (select ...) x}) and where they qualify a
422         * column that name resolution resolves to that table ({@code o.id}). For
423         * SQL that does not parse, and when this is null, table aliases follow
424         * {@link #caseIdentifier}.
425         *
426         * <p><b>Category:</b> Keyword alignment and capitalization</p>
427         * <p><b>Default:</b> {@code null} (follows {@link #caseIdentifier}).</p>
428         */
429        public TCaseOption caseTableAlias = null;
430
431        /**
432         * Converts unquoted column aliases where they are declared
433         * ({@code AS OrderId}, SQL Server's {@code OrderId = expr}). A reference
434         * to a column alias ({@code ORDER BY OrderId}) follows
435         * {@link #caseIdentifier}. For SQL that does not parse, and when this is
436         * null, column aliases follow {@link #caseIdentifier}.
437         *
438         * <p><b>Category:</b> Keyword alignment and capitalization</p>
439         * <p><b>Default:</b> {@code null} (follows {@link #caseIdentifier}).</p>
440         */
441        public TCaseOption caseColumnAlias = null;
442
443        /**
444         * Converts double-quoted identifier contents while preserving the quote
445         * characters. Quoted identifiers are frequently case-sensitive; use any
446         * value other than no-change with care.
447         *
448         * <p><b>Category:</b> Keyword alignment and capitalization</p>
449         * <p><b>Default:</b> {@link TCaseOption#CoNoChange}.</p>
450         */
451        public TCaseOption caseQuotedIdentifier = TCaseOption.CoNoChange;
452
453        /**
454         * Converts tokens recognized by the parser as function names, including
455         * built-in and user-defined calls where classification is available.
456         *
457         * <p><b>Category:</b> Keyword alignment and capitalization</p>
458         * <p><b>Default:</b> {@link TCaseOption#CoInitCap}.</p>
459         */
460        public TCaseOption caseFuncname = TCaseOption.CoInitCap;
461
462        /**
463         * Converts tokens recognized as datatype names. This classification takes
464         * precedence over the general keyword and identifier case settings.
465         *
466         * <p><b>Category:</b> Keyword alignment and capitalization</p>
467         * <p><b>Default:</b> {@link TCaseOption#CoUppercase}.</p>
468         */
469        public TCaseOption caseDatatype = TCaseOption.CoUppercase;
470
471        /**
472         * Inserts one space on both sides of recognized binary arithmetic and
473         * comparison operators. Unary plus and minus are kept adjacent to their
474         * operand regardless of this setting.
475         *
476         * <p><b>Category:</b> Whitespace and parentheses</p>
477         * <p><b>Default:</b> {@code true}.</p>
478         */
479        public Boolean wsPaddingOperatorArithmetic = true;
480
481        /**
482         * Inserts one space just inside the parameter-list parentheses of CREATE
483         * FUNCTION, PROCEDURE, PACKAGE, and TRIGGER declarations when parameters are
484         * present. It does not affect ordinary function calls.
485         *
486         * <p><b>Category:</b> Whitespace and parentheses</p>
487         * <p><b>Default:</b> {@code false}.</p>
488         */
489        public Boolean wsPaddingParenthesesInFunction = false;
490
491        /**
492         * Inserts one space just inside parentheses that group an expression, for
493         * example {@code ( a + b )}. Subqueries, function calls, and datatype
494         * parameters use separate options.
495         *
496         * <p><b>Category:</b> Whitespace and parentheses</p>
497         * <p><b>Default:</b> {@code true}.</p>
498         */
499        public Boolean wsPaddingParenthesesInExpression = true;
500
501        /**
502         * Inserts one space just inside parentheses that enclose a formatted
503         * subquery. Internal subquery line breaks and indentation are still produced
504         * by the nested statement formatter.
505         *
506         * <p><b>Category:</b> Whitespace and parentheses</p>
507         * <p><b>Default:</b> {@code false}.</p>
508         */
509        public Boolean wsPaddingParenthesesOfSubQuery = false;
510
511        /**
512         * Inserts one space just inside ordinary function-call parentheses. Stored-
513         * routine declaration parentheses use
514         * {@link #wsPaddingParenthesesInFunction} instead.
515         *
516         * <p><b>Category:</b> Whitespace and parentheses</p>
517         * <p><b>Default:</b> {@code false}.</p>
518         */
519        public Boolean wsPaddingParenthesesInFunctionCall = false;
520
521        /**
522         * Inserts one space just inside datatype-parameter parentheses, for example
523         * {@code VARCHAR( 20 )}. It applies only when the parser classifies the node
524         * as a type name.
525         *
526         * <p><b>Category:</b> Whitespace and parentheses</p>
527         * <p><b>Default:</b> {@code false}.</p>
528         */
529        public Boolean wsPaddingParenthesesOfTypename = false;
530
531        /**
532         * Places the AS keyword of each common table expression on a new line aligned
533         * under the CTE name area. When false, AS follows the CTE header after one
534         * space; the CTE query itself is formatted in both cases.
535         *
536         * <p><b>Category:</b> CTEs and declarations</p>
537         * <p><b>Default:</b> {@code true}.</p>
538         */
539        public Boolean cteNewlineBeforeAs = true;
540
541        /**
542         * Places the first variable declaration on a new indented line after DECLARE.
543         * Later declaration items are always stacked by the DECLARE formatter.
544         *
545         * <p><b>Category:</b> CTEs and declarations</p>
546         * <p><b>Default:</b> {@code false}.</p>
547         */
548        public Boolean linebreakAfterDeclare = false;
549
550        /**
551         * Chooses stacked or wrapped layout for stored-routine, package, trigger, and
552         * supported CREATE VIEW parameter declarations. Stacked parameters also have
553         * their names/types aligned by the parameter formatter.
554         *
555         * <p><b>Category:</b> Routine declarations and EXEC</p>
556         * <p><b>Default:</b> {@link TAlignStyle#AsStacked}.</p>
557         */
558        public TAlignStyle parametersStyle = TAlignStyle.AsStacked;
559
560        /**
561         * Positions commas for stacked stored-routine parameter declarations. It is
562         * effective when {@link #parametersStyle} is stacked.
563         *
564         * <p><b>Category:</b> Routine declarations and EXEC</p>
565         * <p><b>Default:</b> {@link TLinefeedsCommaOption#LfAfterComma}.</p>
566         */
567        public TLinefeedsCommaOption parametersComma = TLinefeedsCommaOption.LfAfterComma;
568
569        /**
570         * Places the opening parenthesis of a stored-routine parameter list on a new
571         * line. The setting applies only when a parameter declaration list exists.
572         *
573         * <p><b>Category:</b> Routine declarations and EXEC</p>
574         * <p><b>Default:</b> {@code false}.</p>
575         */
576        public Boolean beStyleFunctionLeftBEOnNewline = false;
577
578        /**
579         * Adds columns to the current indentation of a stored-routine opening
580         * parenthesis moved to a new line. It is ignored unless
581         * {@link #beStyleFunctionLeftBEOnNewline} is true.
582         *
583         * <p><b>Category:</b> Routine declarations and EXEC</p>
584         * <p><b>Default:</b> {@code 0}.</p>
585         */
586        public Integer beStyleFunctionLeftBEIndentSize = 0;
587
588        /**
589         * Places the closing parenthesis of a stored-routine parameter list on a new
590         * line. The setting applies only when a parameter declaration list exists.
591         *
592         * <p><b>Category:</b> Routine declarations and EXEC</p>
593         * <p><b>Default:</b> {@code true}.</p>
594         */
595        public Boolean beStyleFunctionRightBEOnNewline = true;
596
597        /**
598         * Adds columns relative to the routine declaration when a parameter-list
599         * closing parenthesis is moved to a new line. It is ignored unless
600         * {@link #beStyleFunctionRightBEOnNewline} is true.
601         *
602         * <p><b>Category:</b> Routine declarations and EXEC</p>
603         * <p><b>Default:</b> {@code 0}.</p>
604         */
605        public Integer beStyleFunctionRightBEIndentSize = 0;
606
607        /**
608         * Places the first stored-routine parameter on a new line and indents it one
609         * general indentation level beyond its current parameter-list indentation.
610         * Subsequent parameters follow the parameter style and comma settings.
611         *
612         * <p><b>Category:</b> Routine declarations and EXEC</p>
613         * <p><b>Default:</b> {@code false}.</p>
614         */
615        public Boolean beStyleFunctionFirstParamInNewline = false;
616
617        /**
618         * Places the first SQL Server EXEC/EXECUTE argument on a new line, indented by
619         * {@link #indentLen} from the statement. It does not control stored-routine
620         * declaration parameters.
621         *
622         * <p><b>Category:</b> Routine declarations and EXEC</p>
623         * <p><b>Default:</b> {@code true}.</p>
624         */
625        public Boolean linebreakBeforeParamInExec = true;
626
627        /**
628         * Determines how blank lines found between top-level statements are handled:
629         * remove them, collapse them to one blank line, or preserve their count.
630         * Statement-separating newlines themselves are always retained.
631         *
632         * <p><b>Category:</b> Blank lines and batches</p>
633         * <p><b>Default:</b> {@link TEmptyLinesOption#EloMergeIntoOne}.</p>
634         */
635        public TEmptyLinesOption emptyLines = TEmptyLinesOption.EloMergeIntoOne;
636
637        /**
638         * Inserts a blank line between statements inside supported BEGIN/END batches.
639         * It is applied in addition to the general {@link #emptyLines} policy.
640         *
641         * <p><b>Category:</b> Blank lines and batches</p>
642         * <p><b>Default:</b> {@code false}.</p>
643         */
644        public Boolean insertBlankLineInBatchSqls = false;
645
646        /**
647         * Suppresses the formatter's otherwise automatic blank line between adjacent
648         * SET or DECLARE-family statements. It does not remove ordinary separator
649         * newlines and does not override unrelated batch blank-line insertion.
650         *
651         * <p><b>Category:</b> Blank lines and batches</p>
652         * <p><b>Default:</b> {@code false}.</p>
653         */
654        public Boolean noEmptyLinesBetweenMultiSetStmts = false;
655
656        /**
657         * Prefixes every output line with a zero-padded line number. Width is based on
658         * the total formatted line count; margins are controlled by the line-number
659         * margin settings.
660         *
661         * <p><b>Category:</b> Line numbers</p>
662         * <p><b>Default:</b> {@code false}.</p>
663         */
664        public Boolean linenumberEnabled = false;
665
666        /**
667         * Starts generated line numbers at zero when true, or one when false. It has
668         * no effect unless {@link #linenumberEnabled} is enabled.
669         *
670         * <p><b>Category:</b> Line numbers</p>
671         * <p><b>Default:</b> {@code false} (one-based numbering).</p>
672         */
673        public Boolean linenumberZeroBased = false;
674
675        /**
676         * Inserts this many spaces before each generated line number. It has no
677         * effect unless {@link #linenumberEnabled} is enabled.
678         *
679         * <p><b>Category:</b> Line numbers</p>
680         * <p><b>Default:</b> {@code 0}.</p>
681         */
682        public Integer linenumberLeftMargin = 0;
683
684        /**
685         * Inserts this many spaces between each generated line number and the SQL
686         * text. It has no effect unless {@link #linenumberEnabled} is enabled.
687         *
688         * <p><b>Category:</b> Line numbers</p>
689         * <p><b>Default:</b> {@code 2}.</p>
690         */
691        public Integer linenumberRightMargin = 2;
692
693        /**
694         * Chooses stacked or wrapped layout for argument lists in ordinary function
695         * calls. This is independent from the stored-routine declaration parameter
696         * style.
697         *
698         * <p><b>Category:</b> Function calls</p>
699         * <p><b>Default:</b> {@link TAlignStyle#AsWrapped}.</p>
700         */
701        public TAlignStyle functionCallParametersStyle = TAlignStyle.AsWrapped;
702
703        /**
704         * Positions commas when ordinary function-call arguments use stacked layout.
705         * It has no line-break effect while
706         * {@link #functionCallParametersStyle} is wrapped.
707         *
708         * <p><b>Category:</b> Function calls</p>
709         * <p><b>Default:</b> {@link TLinefeedsCommaOption#LfAfterComma}.</p>
710         */
711        public TLinefeedsCommaOption functionCallParametersComma = TLinefeedsCommaOption.LfAfterComma;
712
713        /**
714         * Removes ordinary line and block comments before formatting and reparses the
715         * modified token stream. Oracle optimizer hints beginning with {@code /*+}
716         * are preserved. Because removal mutates the parser's token list, use a fresh
717         * parser if the original comments are needed later.
718         *
719         * <p><b>Category:</b> Comments, compact mode, and wrapping</p>
720         * <p><b>Default:</b> {@code false}.</p>
721         */
722        public Boolean removeComment = false;
723
724        /**
725         * Selects normal pretty-printing or compact output. {@code Cpmugly}
726         * short-circuits statement-specific layout, normalizes the token stream, and
727         * wraps only when {@link #lineWidth} is exceeded; most other layout options
728         * are therefore ignored.
729         *
730         * <p><b>Category:</b> Comments, compact mode, and wrapping</p>
731         * <p><b>Default:</b> {@link TCompactMode#CpmNone}.</p>
732         */
733        public TCompactMode compactMode = TCompactMode.CpmNone;
734
735        /**
736         * Sets the maximum line width used by compact mode. It is a soft limit:
737         * indivisible tokens longer than the value can still exceed it. The active
738         * normal pretty-printing pipeline does not currently use this field.
739         *
740         * <p><b>Category:</b> Comments, compact mode, and wrapping</p>
741         * <p><b>Default:</b> {@code 99}.</p>
742         */
743        public Integer lineWidth = 99;
744
745        /**
746         * Limits how many items are stacked at once in large SELECT-style lists. When
747         * a list exceeds the threshold, the comma processor packs several items per
748         * line up to {@link #lineWidth} (a comment ends the line, and an item that
749         * spans lines gets a line of its own) and alias alignment is skipped; use
750         * {@link Integer#MAX_VALUE} to disable the threshold.
751         *
752         * <p><b>Category:</b> Comments, compact mode, and wrapping</p>
753         * <p><b>Default:</b> {@code 20}. This option is available only in GSP Java.</p>
754         */
755        public Integer maxSelectListColumn = 20;
756
757        private final static GOutputFmt defaultOutputFmt = GOutputFmt.ofSql;
758
759        /**
760         * Selects the renderer used after token formatting. The active formatter
761         * supports {@link GOutputFmt#ofSql} and {@link GOutputFmt#ofhtml};
762         * {@link GOutputFmt#ofUnknown} falls back to SQL, while the other legacy enum
763         * values currently throw {@link UnsupportedOperationException}. Each
764         * {@code FormatterFactory.pp} and {@code SqlFormatter.format} call prints as
765         * its own option says, unless an output config was set with
766         * {@code FormatterFactory.setOutputConfig}: that one is used by every such
767         * call until it is set back to {@code null}. {@code FormatterFactory.pp2}
768         * returns SQL whatever this option says.
769         *
770         * <p><b>Category:</b> Output rendering</p>
771         * <p><b>Default:</b> {@link GOutputFmt#ofSql}.</p>
772         *
773         * @see GOutputFmt
774         */
775        public GOutputFmt outputFmt = defaultOutputFmt;
776
777        /**
778         * Replaces each literal tab in HTML output with this string. It is used only
779         * by the Java HTML renderer ({@code outputFmt == ofhtml}) and is independent
780         * of the tab-stop calculation controlled by {@link #useTab} and
781         * {@link #tabSize}.
782         *
783         * <p><b>Category:</b> Output rendering</p>
784         * <p><b>Default:</b> {@code "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"}.</p>
785         */
786        public String tabHtmlString = "&nbsp;&nbsp;&nbsp;&nbsp;";
787
788        /**
789         * Creates an option set for the supplied formatting-session id.
790         *
791         * @param sessionId cache key shared by components in one formatting call
792         */
793        public GFmtOpt( String sessionId )
794        {
795                this.sessionId = sessionId;
796        }
797
798}