Ejemplo n.º 1
0
 protected SourceEnumConstantSymbol(SourceMemberContainerTypeSymbol containingEnum, EnumMemberDeclarationSyntax syntax, DiagnosticBag diagnostics)
     : base(containingEnum, syntax.Identifier.ValueText, syntax.GetReference(), syntax.Identifier.GetLocation())
 {
     if (this.Name == WellKnownMemberNames.EnumBackingFieldName)
     {
         diagnostics.Add(ErrorCode.ERR_ReservedEnumerator, this.Location, WellKnownMemberNames.EnumBackingFieldName);
     }
 }
Ejemplo n.º 2
0
 public static SourceEnumConstantSymbol CreateExplicitValuedConstant(
     SourceMemberContainerTypeSymbol containingEnum,
     EnumMemberDeclarationSyntax syntax,
     DiagnosticBag diagnostics)
 {
     var initializer = syntax.EqualsValue;
     Debug.Assert(initializer != null);
     return new ExplicitValuedEnumConstantSymbol(containingEnum, syntax, initializer, diagnostics);
 }
        public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            var symbol = model.GetDeclaredSymbol(node);
            this.declaredItems.Add(new DeclaredItemDocument
            {
                Name = symbol.Name,
                Location = this.model.SyntaxTree.GetLineSpan(node.Span, false).StartLinePosition.Line,
                Identifier = symbol.ToDisplayString(),
                Type = "EnumMember"

            });
            base.VisitEnumMemberDeclaration(node);
        }
Ejemplo n.º 4
0
 public static SourceEnumConstantSymbol CreateImplicitValuedConstant(
     SourceMemberContainerTypeSymbol containingEnum,
     EnumMemberDeclarationSyntax syntax,
     SourceEnumConstantSymbol otherConstant,
     int otherConstantOffset,
     DiagnosticBag diagnostics)
 {
     if ((object)otherConstant == null)
     {
         Debug.Assert(otherConstantOffset == 0);
         return new ZeroValuedEnumConstantSymbol(containingEnum, syntax, diagnostics);
     }
     else
     {
         Debug.Assert(otherConstantOffset > 0);
         return new ImplicitValuedEnumConstantSymbol(containingEnum, syntax, otherConstant, (uint)otherConstantOffset, diagnostics);
     }
 }
Ejemplo n.º 5
0
        public override SyntaxNode VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            if (node.EqualsValue == null)
            {
                lastValue++;
                return node.WithEqualsValue(Syntax.EqualsValueClause(Syntax.Token(SyntaxKind.EqualsToken),
                    Syntax.LiteralExpression(SyntaxKind.NumericLiteralExpression, Syntax.Literal(lastValue))
                    ));
            }
            else
            {
                ExpressionSyntax expr = node.EqualsValue.Value;
                if (expr.Kind == SyntaxKind.NumericLiteralExpression)
                {
                    lastValue = int.Parse(expr.ToString());
                    return node;
                }

                throw new NotImplementedException("enum with non-literal explicit value");
            }

            return base.VisitEnumMemberDeclaration(node);
        }
Ejemplo n.º 6
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     AsChild(node, node.Identifier.Text, node.Identifier.GetLocation(), node.AttributeLists.Span);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Given a enum member declaration, get the corresponding field symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares an enum member.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public override IFieldSymbol GetDeclaredSymbol(EnumMemberDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     return (IFieldSymbol)GetDeclaredMemberSymbol(declarationSyntax);
 }
            private void ClassifyUpdate(EnumMemberDeclarationSyntax oldNode, EnumMemberDeclarationSyntax newNode)
            {
                if (!SyntaxFactory.AreEquivalent(oldNode.Identifier, newNode.Identifier))
                {
                    ReportError(RudeEditKind.Renamed);
                    return;
                }

                Debug.Assert(!SyntaxFactory.AreEquivalent(oldNode.EqualsValue, newNode.EqualsValue));
                ReportError(RudeEditKind.InitializerUpdate);
            }
Ejemplo n.º 9
0
 /// <summary>
 /// Given a enum member declaration, get the corresponding field symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares an enum member.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public abstract IFieldSymbol GetDeclaredSymbol(EnumMemberDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken));
Ejemplo n.º 10
0
 public override IFieldSymbol GetDeclaredSymbol(EnumMemberDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define member inside member.
     return null;
 }
Ejemplo n.º 11
0
        public static void AnalyzeEnumDeclaration(SyntaxNodeAnalysisContext context)
        {
            var enumDeclaration = (EnumDeclarationSyntax)context.Node;

            SeparatedSyntaxList <EnumMemberDeclarationSyntax> members = enumDeclaration.Members;

            int count = members.Count;

            if (count <= 1)
            {
                return;
            }

            SyntaxTree tree = context.Node.SyntaxTree;

            bool?isPrevSingleLine = null;

            for (int i = 1; i < count; i++)
            {
                SyntaxToken commaToken = members.GetSeparator(i - 1);

                SyntaxTriviaList trailingTrivia = commaToken.TrailingTrivia;

                SyntaxTrivia lastTrailingTrivia = trailingTrivia.LastOrDefault();

                if (!lastTrailingTrivia.IsKind(SyntaxKind.EndOfLineTrivia))
                {
                    isPrevSingleLine = false;
                    continue;
                }

                EnumMemberDeclarationSyntax member = members[i];

                SyntaxTrivia documentationCommentTrivia = member.GetDocumentationCommentTrivia();

                bool hasDocumentationComment = !documentationCommentTrivia.IsKind(SyntaxKind.None);

                if (!hasDocumentationComment)
                {
                    bool isSingleLine = tree.IsSingleLineSpan(member.Span, context.CancellationToken);

                    if (isSingleLine)
                    {
                        if (isPrevSingleLine == null)
                        {
                            isPrevSingleLine = tree.IsSingleLineSpan(TextSpan.FromBounds(members[i - 1].SpanStart, commaToken.Span.End), context.CancellationToken);
                        }

                        if (isPrevSingleLine == true)
                        {
                            isPrevSingleLine = isSingleLine;
                            continue;
                        }
                    }

                    isPrevSingleLine = isSingleLine;
                }
                else
                {
                    isPrevSingleLine = null;
                }

                if (member
                    .GetLeadingTrivia()
                    .FirstOrDefault()
                    .IsKind(SyntaxKind.EndOfLineTrivia))
                {
                    continue;
                }

                int end = (hasDocumentationComment) ? documentationCommentTrivia.SpanStart : member.SpanStart;

                if (tree.GetLineCount(TextSpan.FromBounds(commaToken.Span.End, end), context.CancellationToken) == 2)
                {
                    DiagnosticHelpers.ReportDiagnostic(context,
                                                       DiagnosticDescriptors.AddEmptyLineBetweenDeclarations,
                                                       lastTrailingTrivia);
                }
            }
        }
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     CheckXmlDocForErrors(node, semanticModel.GetDeclaredSymbol(node));
 }
Ejemplo n.º 13
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     LogicalLineCount++;
     base.VisitEnumMemberDeclaration(node);
 }
Ejemplo n.º 14
0
 public ExplicitValuedEnumConstantSymbol(
     SourceMemberContainerTypeSymbol containingEnum,
     EnumMemberDeclarationSyntax syntax,
     EqualsValueClauseSyntax initializer,
     DiagnosticBag diagnostics) :
     base(containingEnum, syntax, diagnostics)
 {
     this.equalsValueNodeRef = initializer.GetReference();
 }
Ejemplo n.º 15
0
 // 枚举成员
 public virtual void VisitEnumMemberDeclarationSyntax(EnumMemberDeclarationSyntax value)
 {
     DefaultVisit(value);
 }
Ejemplo n.º 16
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     AsChild(node, node.Identifier.Text, node.Identifier.GetLocation());
 }
Ejemplo n.º 17
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     InsertLLOCMap(node.GetLocation());
     base.VisitEnumMemberDeclaration(node);
 }
Ejemplo n.º 18
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     WriteLine($"{node.Identifier}{node.EqualsValue},");
 }
 //
 // Summary:
 //     Called when the visitor visits a EnumMemberDeclarationSyntax node.
 public virtual void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node);
Ejemplo n.º 20
0
        private static async Task <Document> DeclareExplicitValueAsync(
            Document document,
            EnumDeclarationSyntax enumDeclaration,
            INamedTypeSymbol enumSymbol,
            bool isFlags,
            bool useBitShift,
            ImmutableArray <ulong> values,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            List <ulong> reservedValues = values.ToList();

            SeparatedSyntaxList <EnumMemberDeclarationSyntax> members = enumDeclaration.Members;

            SeparatedSyntaxList <EnumMemberDeclarationSyntax> newMembers = members;

            for (int i = 0; i < members.Count; i++)
            {
                if (members[i].EqualsValue == null)
                {
                    IFieldSymbol fieldSymbol = semanticModel.GetDeclaredSymbol(members[i], cancellationToken);

                    ulong?value = null;

                    if (isFlags)
                    {
                        Optional <ulong> optional = FlagsUtility <ulong> .Instance.GetUniquePowerOfTwo(reservedValues);

                        if (optional.HasValue &&
                            ConvertHelpers.CanConvertFromUInt64(optional.Value, enumSymbol.EnumUnderlyingType.SpecialType))
                        {
                            value = optional.Value;
                        }
                    }
                    else
                    {
                        value = SymbolUtility.GetEnumValueAsUInt64(fieldSymbol.ConstantValue, enumSymbol);
                    }

                    if (value != null)
                    {
                        reservedValues.Add(value.Value);

                        ExpressionSyntax expression;

                        if (useBitShift &&
                            value.Value > 1)
                        {
                            var power = (int)Math.Log(Convert.ToDouble(value.Value), 2);

                            expression = LeftShiftExpression(NumericLiteralExpression(1), NumericLiteralExpression(power));
                        }
                        else
                        {
                            expression = NumericLiteralExpression(value.Value, enumSymbol.EnumUnderlyingType.SpecialType);
                        }

                        EnumMemberDeclarationSyntax newMember = members[i].Update(
                            members[i].AttributeLists,
                            members[i].Modifiers,
                            members[i].Identifier.WithoutTrailingTrivia(),
                            EqualsValueClause(expression).WithTrailingTrivia(members[i].Identifier.TrailingTrivia));

                        newMembers = newMembers.ReplaceAt(i, newMember);
                    }
                }
            }

            EnumDeclarationSyntax newEnumDeclaration = enumDeclaration.WithMembers(newMembers);

            return(await document.ReplaceNodeAsync(enumDeclaration, newEnumDeclaration, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 21
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     base.VisitEnumMemberDeclaration(node);
     Append(node);
 }
Ejemplo n.º 22
0
 public ZeroValuedEnumConstantSymbol(
     SourceMemberContainerTypeSymbol containingEnum,
     EnumMemberDeclarationSyntax syntax,
     DiagnosticBag diagnostics)
     : base(containingEnum, syntax, diagnostics)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Given a enum member declaration, get the corresponding field symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares an enum member.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public override IFieldSymbol GetDeclaredSymbol(EnumMemberDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetDeclaredSymbol, message: this.SyntaxTree.FilePath, cancellationToken: cancellationToken))
     {
         return (IFieldSymbol)GetDeclaredMemberSymbol(declarationSyntax);
     }
 }
Ejemplo n.º 24
0
            public ImplicitValuedEnumConstantSymbol(
                SourceMemberContainerTypeSymbol containingEnum,
                EnumMemberDeclarationSyntax syntax,
                SourceEnumConstantSymbol otherConstant,
                uint otherConstantOffset,
                DiagnosticBag diagnostics) :
                base(containingEnum, syntax, diagnostics)
            {
                Debug.Assert((object)otherConstant != null);
                Debug.Assert(otherConstantOffset > 0);

                this.otherConstant = otherConstant;
                this.otherConstantOffset = otherConstantOffset;
            }
 public EnumMemberDeclarationTranslation(EnumMemberDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
 }
Ejemplo n.º 26
0
        public void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            WriteLeadingTrivia(node);

            _writer.WriteIndent();

            WriteAttributes(
                node,
                _writer.Configuration.LineBreaksAndWrapping.Other.PlaceFieldAttributeOnSameLine
            );

            _writer.WriteIdentifier(node.Identifier);

            if (node.EqualsValue != null)
                node.EqualsValue.Accept(this);

            var parent = node.Parent as EnumDeclarationSyntax;

            if (
                parent == null ||
                parent.Members.IndexOf(node) < parent.Members.Count - 1
            )
                _writer.WriteSyntax(Syntax.Comma);

            _writer.WriteLine();

            WriteTrailingTrivia(node);
        }
Ejemplo n.º 27
0
 public static string EnumMemberDeclaration(EnumMemberDeclarationSyntax declaration)
 {
     var output = declaration.Identifier.Text;
     if (declaration.EqualsValue != null)
     {
         output += " " + SyntaxNode(declaration.EqualsValue);
     }
     return output;
 }
Ejemplo n.º 28
0
 public override SyntaxNode VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     if (node == null)
         return null;
     var symbol = m_model.GetDeclaredSymbol(node);
     node = (EnumMemberDeclarationSyntax)base.VisitEnumMemberDeclaration(node);
     if (!IsPrivateOrInternal(symbol.DeclaredAccessibility))
         node = (EnumMemberDeclarationSyntax)ApplyDocComment(node, symbol.GetDocumentationCommentId());
     return node;
 }
Ejemplo n.º 29
0
            public void Add(EnumMemberDeclarationSyntax node)
            {
                /*        // Summary:
                //     Gets the attribute declaration list.
                public SyntaxList<AttributeListSyntax> AttributeLists { get; }
                public EqualsValueClauseSyntax EqualsValue { get; }
                //
                // Summary:
                //     Gets the identifier.
                public SyntaxToken Identifier { get; }
                 */
                // add field info

                TypeExtraInfo tei = Chunk.AddTypeExtraInfo(this.Class,Model);
                tei.AddEnumMember(node.Identifier.ToString(), node.EqualsValue != null ? node.EqualsValue.Value : null);

                /*
                // Summary:
                //     Gets the attribute declaration list.
                public override SyntaxList<AttributeListSyntax> AttributeLists { get; }
                public override VariableDeclarationSyntax Declaration { get; }
                //
                // Summary:
                //     Gets the modifier list.
                public override SyntaxTokenList Modifiers { get; }
                public override SyntaxToken SemicolonToken { get; }
                 */

                // add to metadata for runtime type building
                FlatArrayBuilder fab = new FlatArrayBuilder();

                fab.Add(FlatValue.Int32((int)ClassMemberType.StaticField));
                //TypeInfo ti = Chunk.Model.GetTypeInfo(node..Type);

                fab.Add(FlatValue.String(Class.GetFullyQualifiedName()));

                {
                    FlatArrayBuilder varList = new FlatArrayBuilder();
                    varList.Add(FlatValue.String(node.Identifier.ToString()));
                    fab.Add(varList.GetFlatValue());
                }
                {
                    FlatArrayBuilder valueList = new FlatArrayBuilder();
                    if (node.EqualsValue != null)
                    {
                        if (node.EqualsValue.Value.Kind == SyntaxKind.NumericLiteralExpression)
                        {
                            valueList.Add(FlatValue.Int32(int.Parse(node.EqualsValue.Value.ToString())));
                        }
                        else
                        {
                            throw new NotImplementedException("Enum member without numeric literal expression");
                        }
                    }
                    else
                    {
                        throw new NotImplementedException("Enum member without numeric literal expression");
                    }

                    fab.Add(valueList.GetFlatValue());
                }

                Members.Add(fab.GetFlatValue());
            }
			public override void VisitEnumMemberDeclaration (EnumMemberDeclarationSyntax node)
			{
				base.VisitEnumMemberDeclaration (node);
				Append (node);
			}
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     WriteLine($"{node.Identifier}{node.EqualsValue},");
 }
        private string GetVariablePrototype(EnumMemberDeclarationSyntax node, IFieldSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                return GetNodeKey(node).Name;
            }

            var builder = new StringBuilder();

            AppendVariablePrototype(builder, symbol, flags, GetName(node));

            if ((flags & PrototypeFlags.Initializer) != 0 &&
                node.EqualsValue != null &&
                node.EqualsValue.Value != null &&
                !node.EqualsValue.Value.IsMissing)
            {
                builder.Append(" = ");
                builder.Append(node.EqualsValue.Value);
            }

            return builder.ToString();
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Traverse AST node that represents enumeration constant declaration
 /// </summary>
 /// <param name="node">AST node.</param>
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     try
     {
         if (!node.Identifier.Span.IsEmpty)
         {
             var symbol = _sm.GetDeclaredSymbol(node);
             if (!_defined.Contains(symbol))
             {
                 _defined.Add(symbol);
                 var def = Def.For(symbol: symbol, type: "enum field", name: symbol.Name).At(_path, node.Identifier.Span);
                 def.Exported = true;
                 AddDef(def);
             }
         }
         base.VisitEnumMemberDeclaration(node);
     }
     catch (Exception e)
     {
     }
 }
            private VirtualTreePoint GetStartPoint(SourceText text, EnumMemberDeclarationSyntax node, EnvDTE.vsCMPart part)
            {
                int startPosition;

                switch (part)
                {
                    case EnvDTE.vsCMPart.vsCMPartName:
                    case EnvDTE.vsCMPart.vsCMPartAttributes:
                    case EnvDTE.vsCMPart.vsCMPartHeader:
                    case EnvDTE.vsCMPart.vsCMPartWhole:
                    case EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter:
                    case EnvDTE.vsCMPart.vsCMPartHeaderWithAttributes:
                        throw Exceptions.ThrowENotImpl();

                    case EnvDTE.vsCMPart.vsCMPartAttributesWithDelimiter:
                        if (node.AttributeLists.Count == 0)
                        {
                            throw Exceptions.ThrowEFail();
                        }

                        goto case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes;

                    case EnvDTE.vsCMPart.vsCMPartWholeWithAttributes:
                        startPosition = node.SpanStart;
                        break;

                    case EnvDTE.vsCMPart.vsCMPartBody:
                        throw Exceptions.ThrowEFail();

                    case EnvDTE.vsCMPart.vsCMPartNavigate:
                        startPosition = node.Identifier.SpanStart;
                        break;

                    default:
                        throw Exceptions.ThrowEInvalidArg();
                }

                return new VirtualTreePoint(node.SyntaxTree, text, startPosition);
            }
Ejemplo n.º 35
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            var enumMemberTranslationUnit = new EnumMemberTranslationUnitFactory(node, this.semanticModel).Create();
            this.enumDeclaration.AddMember(enumMemberTranslationUnit);

            this.InvokeEnumMemberVisited(this, new WalkerEventArgs());
        }
Ejemplo n.º 36
0
        public override SyntaxNode VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            _output.Write(node.Identifier, node.Identifier.ValueText);
            _output.TrivialWrite(": ");
            var info = _semanticModel.GetDeclaredSymbol(node);
            string val;
            bool hasAttr = info.GetEnumValue(out val);

            if (node.EqualsValue != null)
            {
                if (hasAttr)
                {
                    this.AppendCompileIssue(node, IssueType.Error, IssueId.EnumFieldTwoValue);
                }
                else
                {
                    Visit(node.EqualsValue.Value);
                }
            }
            else
            {
                if (hasAttr)
                {
                    _output.Write(node, val);
                }
                else
                {
                    this.AppendCompileIssue(node, IssueType.Error, IssueId.EnumFieldNoValue, node);
                }
            }

            return node;
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EnumMemberDeclaration"/> class.
 /// </summary>
 /// <param name="enumMemberDeclarationNode"></param>
 public EnumMemberDeclaration(EnumMemberDeclarationSyntax enumMemberDeclarationNode)
     : this(enumMemberDeclarationNode, null)
 {
 }
            private bool CompareEnumMemberDeclarations(
                EnumMemberDeclarationSyntax oldEnumMember,
                EnumMemberDeclarationSyntax newEnumMember,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldEnumMember != null && newEnumMember != null);

                bool same = true;

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldEnumMember), CodeModelService.GetName(newEnumMember)))
                {
                    EnqueueChangeEvent(newEnumMember, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    same = false;
                }

                same &= CompareChildren(
                    CompareAttributeLists,
                    oldEnumMember.AttributeLists.AsReadOnlyList(),
                    newEnumMember.AttributeLists.AsReadOnlyList(),
                    newEnumMember,
                    CodeModelEventType.Unknown,
                    eventQueue);

                return same;
            }
Ejemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EnumMemberDeclaration"/> class.
 /// </summary>
 /// <param name="enumMemberDeclarationNode"></param>
 /// <param name="semanticModel"></param>
 public EnumMemberDeclaration(EnumMemberDeclarationSyntax enumMemberDeclarationNode, SemanticModel semanticModel)
     : base(enumMemberDeclarationNode, semanticModel)
 {
 }
        private Document Delete(Document document, EnumMemberDeclarationSyntax node)
        {
            var enumDeclaration = (EnumDeclarationSyntax)node.Parent;
            var members = enumDeclaration.Members;
            var newMembers = members.Remove(node);
            var newEnumDeclaration = enumDeclaration.WithMembers(newMembers);

            // If we're removing the last enum member, we may need to move any trailing trivia
            // to the enum member that comes before it.
            var memberIndex = members.IndexOf(node);
            if (memberIndex == members.Count - 1 && newMembers.Count > 0)
            {
                var trailingTrivia = node.GetTrailingTrivia();
                var lastMember = newEnumDeclaration.Members.Last();
                newEnumDeclaration = newEnumDeclaration.ReplaceNode(lastMember, lastMember.WithTrailingTrivia(trailingTrivia));
            }

            return document.ReplaceNodeAsync(enumDeclaration, newEnumDeclaration, CancellationToken.None)
                           .WaitAndGetResult_CodeModel(CancellationToken.None);
        }
Ejemplo n.º 41
0
 public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
 {
     throw new NotSupportedException();
 }