コード例 #1
0
        void FormatAccessor(Accessor accessor, BraceStyle braceStyle, PropertyFormatting blockFormatting, bool oneLine)
        {
            if (accessor.IsNull)
                return;
            if (!oneLine) {
                if (!IsLineIsEmptyUpToEol(accessor.StartLocation)) {
                    int offset = this.document.GetOffset(accessor.StartLocation);
                    int start = SearchWhitespaceStart(offset);
                    string indentString = this.curIndent.IndentString;
                    AddChange(start, offset - start, this.options.EolMarker + indentString);
                } else {
                    FixIndentation(accessor);
                }
            } else {
                blockFormatting = PropertyFormatting.ForceOneLine;
                if (!accessor.Body.IsNull) {
                    ForceSpacesBeforeRemoveNewLines(accessor.Body.LBraceToken, true);
                    ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                }
            }

            if (!accessor.IsNull) {
                if (!accessor.Body.IsNull) {
                    if (IsSimpleAccessor (accessor)) {
                        switch (blockFormatting) {
                            case PropertyFormatting.AllowOneLine:
                                if (accessor.Body.LBraceToken.StartLocation.Line != accessor.Body.RBraceToken.StartLocation.Line)
                                    goto case PropertyFormatting.ForceNewLine;
                                nextStatementIndent = " ";
                                VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                                if (!oneLine)
                                    ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                                break;
                            case PropertyFormatting.ForceOneLine:
                                FixOpenBrace(BraceStyle.EndOfLine, accessor.Body.LBraceToken);

                                var statement = accessor.Body.Statements.First();
                                ForceSpacesBeforeRemoveNewLines(statement, true);
                                statement.AcceptVisitor(this);
                                if (!oneLine)
                                    ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                                break;
                            case PropertyFormatting.ForceNewLine:
                                FixOpenBrace(braceStyle, accessor.Body.LBraceToken);
                                VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                                if (!oneLine)
                                    FixClosingBrace(braceStyle, accessor.Body.RBraceToken);
                                break;
                        }
                    } else {
                        FixOpenBrace(braceStyle, accessor.Body.LBraceToken);
                        VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                        FixClosingBrace(braceStyle, accessor.Body.RBraceToken);
                    }
                }
            }
        }
コード例 #2
0
        void FormatAccessor(Accessor accessor, BraceStyle braceStyle, PropertyFormatting blockFormatting, bool oneLine)
        {
            if (accessor.IsNull)
            {
                return;
            }
            if (!oneLine)
            {
                if (!IsLineIsEmptyUpToEol(accessor.StartLocation))
                {
                    int    offset       = this.document.GetOffset(accessor.StartLocation);
                    int    start        = SearchWhitespaceStart(offset);
                    string indentString = this.curIndent.IndentString;
                    AddChange(start, offset - start, this.options.EolMarker + indentString);
                }
                else
                {
                    FixIndentation(accessor);
                }
            }
            else
            {
                blockFormatting = PropertyFormatting.ForceOneLine;
                if (!accessor.Body.IsNull)
                {
                    ForceSpacesBeforeRemoveNewLines(accessor.Body.LBraceToken, true);
                    ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                }
            }


            if (!accessor.IsNull)
            {
                if (!accessor.Body.IsNull)
                {
                    if (IsSimpleAccessor(accessor))
                    {
                        switch (blockFormatting)
                        {
                        case PropertyFormatting.AllowOneLine:
                            if (accessor.Body.LBraceToken.StartLocation.Line != accessor.Body.RBraceToken.StartLocation.Line)
                            {
                                goto case PropertyFormatting.ForceNewLine;
                            }
                            nextStatementIndent = " ";
                            VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                            if (!oneLine)
                            {
                                ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                            }
                            break;

                        case PropertyFormatting.ForceOneLine:
                            FixOpenBrace(BraceStyle.EndOfLine, accessor.Body.LBraceToken);


                            var statement = accessor.Body.Statements.FirstOrDefault();
                            if (statement != null)
                            {
                                ForceSpacesBeforeRemoveNewLines(statement, true);
                                statement.AcceptVisitor(this);
                            }
                            if (!oneLine)
                            {
                                ForceSpacesBeforeRemoveNewLines(accessor.Body.RBraceToken, true);
                            }
                            break;

                        case PropertyFormatting.ForceNewLine:
                            FixOpenBrace(braceStyle, accessor.Body.LBraceToken);
                            VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                            if (!oneLine)
                            {
                                FixClosingBrace(braceStyle, accessor.Body.RBraceToken);
                            }
                            break;
                        }
                    }
                    else
                    {
                        FixOpenBrace(braceStyle, accessor.Body.LBraceToken);
                        VisitBlockWithoutFixingBraces(accessor.Body, policy.IndentBlocks);
                        FixClosingBrace(braceStyle, accessor.Body.RBraceToken);
                    }
                }
            }
        }