Example #1
0
        public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
        {
            FixAttributesAndDocComment(operatorDeclaration);

            ForceSpacesBefore(operatorDeclaration.LParToken, policy.SpaceBeforeMethodDeclarationParentheses);
            if (operatorDeclaration.Parameters.Any())
            {
                ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceWithinMethodDeclarationParentheses);
                FormatArguments(operatorDeclaration);
            }
            else
            {
                ForceSpacesAfter(operatorDeclaration.LParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses);
                ForceSpacesBefore(operatorDeclaration.RParToken, policy.SpaceBetweenEmptyMethodDeclarationParentheses);
            }

            if (!operatorDeclaration.Body.IsNull)
            {
                FixOpenBrace(policy.MethodBraceStyle, operatorDeclaration.Body.LBraceToken);
                VisitBlockWithoutFixingBraces(operatorDeclaration.Body, policy.IndentMethodBody);
                FixClosingBrace(policy.MethodBraceStyle, operatorDeclaration.Body.RBraceToken);
            }
        }
        void WriteMemberDeclarationName(IMember member, TokenWriter writer, AlFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration    node       = astBuilder.ConvertEntity(member);

            if ((ConversionFlags & ConversionFlags.ShowDeclaringType) == ConversionFlags.ShowDeclaringType)
            {
                ConvertType(member.DeclaringType, writer, formattingPolicy);
                writer.WriteToken(Roles.Dot, ".");
            }
            switch (member.SymbolKind)
            {
            case SymbolKind.Indexer:
                writer.WriteKeyword(Roles.Identifier, "self");
                break;

            case SymbolKind.Constructor:
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

            case SymbolKind.Destructor:
                writer.WriteToken(DestructorDeclaration.TildeRole, "~");
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

            case SymbolKind.Operator:
                switch (member.Name)
                {
                case "op_Implicit":
                    writer.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                case "op_Explicit":
                    writer.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
                    writer.Space();
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    ConvertType(member.ReturnType, writer, formattingPolicy);
                    break;

                default:
                    writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                    writer.Space();
                    var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                    if (operatorType.HasValue)
                    {
                        writer.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
                    }
                    else
                    {
                        writer.WriteIdentifier(node.NameToken);
                    }
                    break;
                }
                break;

            default:
                writer.WriteIdentifier(Identifier.Create(member.Name));
                break;
            }
            if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.SymbolKind == SymbolKind.Method)
            {
                var outputVisitor = new AlOutputVisitor(writer, formattingPolicy);
                outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter));
            }
        }
Example #3
0
 void IAstVisitor.VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
 {
     Visit(EnterOperatorDeclaration, LeaveOperatorDeclaration, operatorDeclaration);
 }
 public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration)
 {
     // skip
 }