internal SqlProcedureDefinitionFormatter(FormatterVisitor visitor, SqlProcedureDefinition codeObject)
     : base(visitor, codeObject)
 {
     NewLineSeparatedListFormatter = new NewLineSeparatedListFormatter(visitor, codeObject, true);
     CommaSeparatedListFormatter   = new CommaSeparatedListFormatter(visitor, codeObject, true);
     foundTokenWith = false;
 }
Esempio n. 2
0
        public override ASTNodeFormatter Create(FormatterVisitor visitor, SqlCodeObject codeObject)
        {
            Validate.IsNotNull(nameof(visitor), visitor);
            Validate.IsNotNull(nameof(codeObject), codeObject);

            return(DoCreate(visitor, codeObject as T));
        }
Esempio n. 3
0
        public ASTNodeFormatterT(FormatterVisitor visitor, T codeObject)
        {
            Validate.IsNotNull(nameof(visitor), visitor);
            Validate.IsNotNull(nameof(codeObject), codeObject);

            Visitor    = visitor;
            CodeObject = codeObject;
        }
        private void DoFormat(string input, FormatOptions options, bool verifyOutput, Action <FormatterVisitor> postFormatAction)
        {
            Validate.IsNotNull(nameof(input), input);
            Validate.IsNotNull(nameof(options), options);

            ParseResult   result  = Parser.Parse(input);
            FormatContext context = new FormatContext(result.Script, options);

            FormatterVisitor visitor = new FormatterVisitor(context, ServiceProvider);

            result.Script.Accept(visitor);
            if (verifyOutput)
            {
                visitor.VerifyFormat();
            }

            postFormatAction?.Invoke(visitor);
        }
Esempio n. 5
0
        public SqlTableDefinitionFormatter(FormatterVisitor visitor, SqlTableDefinition codeObject)
            : base(visitor, codeObject)
        {
            CommaSeparatedListFormatter = new CommaSeparatedListFormatter(visitor, codeObject, true);

            // figure out the size of paddings required to align column definitions in a "columnar" form
            if (FormatOptions.AlignColumnDefinitionsInColumns)
            {
                int range1MaxLength = 0;
                int range2MaxLength = 0;

                foreach (SqlCodeObject child in CodeObject.Children)
                {
                    if (child is SqlColumnDefinition && !(child is SqlComputedColumnDefinition))
                    {
                        SqlIdentifier identifierChild = child.Children.ElementAtOrDefault(0) as SqlIdentifier;

                        if (identifierChild == null)
                        {
                            throw new FormatFailedException("unexpected token at index start Token Index");
                        }

                        string s1 = child.TokenManager.GetText(identifierChild.Position.startTokenNumber, identifierChild.Position.endTokenNumber);
                        range1MaxLength = Math.Max(range1MaxLength, s1.Length);

                        SqlDataTypeSpecification dataTypeChildchild = child.Children.ElementAtOrDefault(1) as SqlDataTypeSpecification;

                        // token "timestamp" should be ignorred
                        if (dataTypeChildchild != null)
                        {
                            string s2 = child.TokenManager.GetText(dataTypeChildchild.Position.startTokenNumber, dataTypeChildchild.Position.endTokenNumber);
                            range2MaxLength = Math.Max(range2MaxLength, s2.Length);
                        }
                    }
                }

                PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition        d1 = new PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition(typeof(SqlIdentifier), typeof(SqlDataTypeSpecification), range1MaxLength + 1);
                PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition        d2 = new PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition(typeof(SqlDataTypeSpecification), null, range2MaxLength + 1);
                List <PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition> columnSpacingFormatDefinitions = new List <PaddedSpaceSeparatedListFormatter.ColumnSpacingFormatDefinition>(2);
                columnSpacingFormatDefinitions.Add(d1);
                columnSpacingFormatDefinitions.Add(d2);
                Visitor.Context.CurrentColumnSpacingFormatDefinitions = columnSpacingFormatDefinitions;
            }
        }
Esempio n. 6
0
 internal SqlBinaryBooleanExpressionFormatter(FormatterVisitor visitor, SqlBinaryBooleanExpression codeObject)
     : base(visitor, codeObject)
 {
     SpaceSeparatedListFormatter = new SpaceSeparatedListFormatter(visitor, codeObject, true);
 }
Esempio n. 7
0
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlBinaryBooleanExpression codeObject)
 {
     return(new SqlBinaryBooleanExpressionFormatter(visitor, codeObject));
 }
Esempio n. 8
0
 internal SqlQuerySpecificationFormatter(FormatterVisitor visitor, SqlQuerySpecification codeObject)
     : base(visitor, codeObject)
 {
     WhiteSpaceSeparatedListFormatter = new NewLineSeparatedListFormatter(visitor, codeObject, false);
 }
Esempio n. 9
0
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlInsertSpecification codeObject)
 {
     return(new SqlInsertSpecificationFormatter(visitor, codeObject));
 }
Esempio n. 10
0
 public abstract ASTNodeFormatter Create(FormatterVisitor visitor, SqlCodeObject codeObject);
Esempio n. 11
0
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlCommonTableExpression codeObject)
 {
     return(new SqlCommonTableExpressionFormatter(visitor, codeObject));
 }
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlCompoundStatement codeObject)
 {
     return(new SqlCompoundStatementFormatter(visitor, codeObject));
 }
 public NewLineSeparatedListFormatter(FormatterVisitor visitor, SqlCodeObject codeObject, bool incrementIndentLevelOnPrefixRegion)
     : base(visitor, codeObject, incrementIndentLevelOnPrefixRegion)
 {
 }
Esempio n. 14
0
 internal PaddedSpaceSeparatedListFormatter(FormatterVisitor visitor, SqlCodeObject codeObject, List <ColumnSpacingFormatDefinition> spacingDefinitions, bool incrementIndentLevelOnPrefixRegion)
     : base(visitor, codeObject, incrementIndentLevelOnPrefixRegion)
 {
     ColumnSpacingDefinitions = spacingDefinitions;
 }
 internal SqlDataTypeFormatter(FormatterVisitor visitor, SqlDataType codeObject)
     : base(visitor, codeObject)
 {
 }
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlDataType codeObject)
 {
     return(new SqlDataTypeFormatter(visitor, codeObject));
 }
Esempio n. 17
0
 public SqlQueryWithClauseFormatter(FormatterVisitor visitor, SqlQueryWithClause codeObject)
     : base(visitor, codeObject, true)
 {
 }
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlSelectClause codeObject)
 {
     return(new SqlSelectClauseFormatter(visitor, codeObject));
 }
 internal SqlSelectClauseFormatter(FormatterVisitor visitor, SqlSelectClause codeObject)
     : base(visitor, codeObject, visitor.Context.FormatOptions.PlaceEachReferenceOnNewLineInQueryStatements)
 {
     NewLineSeparatedListFormatter = new NewLineSeparatedListFormatter(visitor, codeObject, true);
 }
Esempio n. 20
0
 internal SqlQualifiedJoinTableExpressionFormatter(FormatterVisitor visitor, SqlQualifiedJoinTableExpression codeObject)
     : base(visitor, codeObject)
 {
     SpaceSeparatedListFormatter = new SpaceSeparatedListFormatter(visitor, codeObject, false);
 }
 internal SqlCompoundStatementFormatter(FormatterVisitor visitor, SqlCompoundStatement codeObject)
     : base(visitor, codeObject, true)
 {
 }
Esempio n. 22
0
 protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlColumnDefinition codeObject)
 {
     return(new SqlColumnDefinitionFormatter(visitor, codeObject));
 }
Esempio n. 23
0
 public SqlCommonTableExpressionFormatter(FormatterVisitor visitor, SqlCommonTableExpression codeObject)
     : base(visitor, codeObject)
 {
 }
Esempio n. 24
0
 protected abstract ASTNodeFormatter DoCreate(FormatterVisitor visitor, T codeObject);
Esempio n. 25
0
 internal SqlColumnDefinitionFormatter(FormatterVisitor visitor, SqlColumnDefinition codeObject)
     : base(visitor, codeObject)
 {
     SpaceSeparatedListFormatter = new PaddedSpaceSeparatedListFormatter(visitor, codeObject, Visitor.Context.CurrentColumnSpacingFormatDefinitions, true);
 }
Esempio n. 26
0
 internal SqlInsertSpecificationFormatter(FormatterVisitor visitor, SqlInsertSpecification codeObject)
     : base(visitor, codeObject)
 {
 }
 internal CommaSeparatedListFormatter(FormatterVisitor visitor, SqlCodeObject codeObject, bool placeEachElementOnNewLine)
     : base(visitor, codeObject)
 {
     PlaceEachElementOnNewLine = placeEachElementOnNewLine;
 }
Esempio n. 28
0
 internal SqlBinaryQueryExpressionFormatter(FormatterVisitor visitor, SqlBinaryQueryExpression codeObject)
     : base(visitor, codeObject)
 {
 }
 public SqlTableConstructorExpressionFormatter(FormatterVisitor visitor, SqlTableConstructorExpression codeObject)
     : base(visitor, codeObject, true)
 {
 }
Esempio n. 30
0
 internal SqlCreateProcedureStatementFormatter(FormatterVisitor visitor, SqlCreateProcedureStatement codeObject)
     : base(visitor, codeObject, false)
 {
 }