Exemple #1
0
        public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
        {
            FixAttributesAndDocComment(propertyDeclaration);
            bool oneLine         = false;
            bool fixClosingBrace = false;
            PropertyFormatting propertyFormatting;

            if ((propertyDeclaration.Getter.IsNull || propertyDeclaration.Getter.Body.IsNull) &&
                (propertyDeclaration.Setter.IsNull || propertyDeclaration.Setter.Body.IsNull))
            {
                propertyFormatting = policy.AutoPropertyFormatting;
            }
            else
            {
                propertyFormatting = policy.SimplePropertyFormatting;
            }

            switch (propertyFormatting)
            {
            case PropertyFormatting.AllowOneLine:
                bool isSimple     = IsSimpleAccessor(propertyDeclaration.Getter) && IsSimpleAccessor(propertyDeclaration.Setter);
                int  accessorLine = propertyDeclaration.RBraceToken.StartLocation.Line;
                if (!propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull)
                {
                    accessorLine = propertyDeclaration.Getter.StartLocation.Line;
                }
                else if (propertyDeclaration.Getter.IsNull && !propertyDeclaration.Setter.IsNull)
                {
                    accessorLine = propertyDeclaration.Setter.StartLocation.Line;
                }
                else
                {
                    var acc = propertyDeclaration.Getter.StartLocation < propertyDeclaration.Setter.StartLocation ?
                              propertyDeclaration.Getter : propertyDeclaration.Setter;
                    accessorLine = acc.StartLocation.Line;
                }
                if (isSimple &&
                    Math.Min(propertyDeclaration.Getter.StartLocation.Line, propertyDeclaration.Setter.StartLocation.Line) == propertyDeclaration.LBraceToken.StartLocation.Line &&
                    propertyDeclaration.Getter.StartLocation.Line != propertyDeclaration.Setter.StartLocation.Line)
                {
                    goto case PropertyFormatting.ForceOneLine;
                }
                if (!isSimple || propertyDeclaration.LBraceToken.StartLocation.Line != accessorLine)
                {
                    fixClosingBrace = true;
                    FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken);
                }
                else
                {
                    ForceSpacesBefore(propertyDeclaration.Getter, true);
                    ForceSpacesBefore(propertyDeclaration.Setter, true);
                    ForceSpacesBeforeRemoveNewLines(propertyDeclaration.RBraceToken, true);
                    oneLine = true;
                }
                break;

            case PropertyFormatting.ForceNewLine:
                fixClosingBrace = true;
                FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken);
                break;

            case PropertyFormatting.ForceOneLine:
                isSimple = IsSimpleAccessor(propertyDeclaration.Getter) && IsSimpleAccessor(propertyDeclaration.Setter);
                if (isSimple)
                {
                    var lBraceToken = propertyDeclaration.LBraceToken;
                    var rBraceToken = propertyDeclaration.RBraceToken;
                    ForceSpacesBeforeRemoveNewLines(lBraceToken, true);
                    if (!propertyDeclaration.Getter.IsNull)
                    {
                        ForceSpacesBeforeRemoveNewLines(propertyDeclaration.Getter, true);
                    }
                    if (!propertyDeclaration.Setter.IsNull)
                    {
                        ForceSpacesBeforeRemoveNewLines(propertyDeclaration.Setter, true);
                    }

                    ForceSpacesBeforeRemoveNewLines(rBraceToken, true);
                    oneLine = true;
                }
                else
                {
                    fixClosingBrace = true;
                    FixOpenBrace(policy.PropertyBraceStyle, propertyDeclaration.LBraceToken);
                }
                break;
            }
            if (policy.IndentPropertyBody)
            {
                curIndent.Push(IndentType.Block);
            }

            FormatAccessor(propertyDeclaration.Getter, policy.PropertyGetBraceStyle, policy.SimpleGetBlockFormatting, oneLine);
            FormatAccessor(propertyDeclaration.Setter, policy.PropertySetBraceStyle, policy.SimpleSetBlockFormatting, oneLine);

            if (policy.IndentPropertyBody)
            {
                curIndent.Pop();
            }
            if (fixClosingBrace)
            {
                FixClosingBrace(policy.PropertyBraceStyle, propertyDeclaration.RBraceToken);
            }
        }
Exemple #2
0
 void IAstVisitor.VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
 {
     Visit(EnterPropertyDeclaration, LeavePropertyDeclaration, propertyDeclaration);
 }
 public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
 {
     // skip
 }