Пример #1
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     base.VisitEventDeclaration(node);
     if (node.AccessorList != null)
     {
         foreach (var accessor in node.AccessorList.Accessors)
         {
             _members.Add(accessor);
         }
     }
 }
Пример #2
0
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            base.VisitEventDeclaration(node);
            if (node.Parent is InterfaceDeclarationSyntax)
                return node;

            var symbol = semanticModel.GetDeclaredSymbol(node);

            var type = symbol.ContainingType;
            if (type == null)
                return node;

            var faceMembers = symbol.ImplementedInterfaceMember();
            if (faceMembers.Count() != 1)
                return node;

            var interfaceNode = faceMembers.Single().GetSyntaxNodes().Single().Parent.Parent;
            if (interfaceNode.GetDocumentationCommentText() == "" ||
                interfaceNode.GetDocumentationCommentText().Equals(node.GetDocumentationCommentText()))
                return node;

            return node.WithDocumentationComment(interfaceNode.GetDocumentationCommentText());
        }
Пример #3
0
        public static SyntaxNode RemoveModifierFromNode(SyntaxNode node, SyntaxKind modifier)
        {
            //there seem to be no base classes to support WithModifiers.
            //dynamic modifiersNode = node;
            //return modifiersNode.WithModifiers(SyntaxFactory.TokenList(modifiersNode.Modifiers.Where(m => !m.IsKind(SyntaxKind.PrivateKeyword))));

            MethodDeclarationSyntax methodNode = node as MethodDeclarationSyntax;

            if (methodNode != null)
            {
                return(methodNode.WithModifiers(SyntaxFactory.TokenList(methodNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(methodNode.GetLeadingTrivia()));
            }

            FieldDeclarationSyntax fieldNode = node as FieldDeclarationSyntax;

            if (fieldNode != null)
            {
                return(fieldNode.WithModifiers(SyntaxFactory.TokenList(fieldNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(fieldNode.GetLeadingTrivia()));
            }

            PropertyDeclarationSyntax propertyNode = node as PropertyDeclarationSyntax;

            if (propertyNode != null)
            {
                return(propertyNode.WithModifiers(SyntaxFactory.TokenList(propertyNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(propertyNode.GetLeadingTrivia()));
            }

            IndexerDeclarationSyntax indexerNode = node as IndexerDeclarationSyntax;

            if (indexerNode != null)
            {
                return(indexerNode.WithModifiers(SyntaxFactory.TokenList(indexerNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(indexerNode.GetLeadingTrivia()));
            }

            EventDeclarationSyntax eventNode = node as EventDeclarationSyntax;

            if (eventNode != null)
            {
                return(eventNode.WithModifiers(SyntaxFactory.TokenList(eventNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(eventNode.GetLeadingTrivia()));
            }

            ConstructorDeclarationSyntax ctrNode = node as ConstructorDeclarationSyntax;

            if (ctrNode != null)
            {
                return(ctrNode.WithModifiers(SyntaxFactory.TokenList(ctrNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(ctrNode.GetLeadingTrivia()));
            }

            OperatorDeclarationSyntax opNode = node as OperatorDeclarationSyntax;

            if (opNode != null)
            {
                return(opNode.WithModifiers(SyntaxFactory.TokenList(opNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(opNode.GetLeadingTrivia()));
            }

            ClassDeclarationSyntax classNode = node as ClassDeclarationSyntax;

            if (classNode != null)
            {
                return(classNode.WithModifiers(SyntaxFactory.TokenList(classNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(classNode.GetLeadingTrivia()));
            }

            InterfaceDeclarationSyntax interfaceNode = node as InterfaceDeclarationSyntax;

            if (interfaceNode != null)
            {
                return(interfaceNode.WithModifiers(SyntaxFactory.TokenList(interfaceNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(interfaceNode.GetLeadingTrivia()));
            }

            StructDeclarationSyntax structNode = node as StructDeclarationSyntax;

            if (structNode != null)
            {
                return(structNode.WithModifiers(SyntaxFactory.TokenList(structNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(structNode.GetLeadingTrivia()));
            }

            var enumNode = node as EnumDeclarationSyntax;

            if (enumNode != null)
            {
                return(enumNode.WithModifiers(SyntaxFactory.TokenList(enumNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(enumNode.GetLeadingTrivia()));
            }

            var delegateNode = node as DelegateDeclarationSyntax;

            if (delegateNode != null)
            {
                return(delegateNode.WithModifiers(SyntaxFactory.TokenList(delegateNode.Modifiers.Where(m => !m.IsKind(modifier))))
                       .WithLeadingTrivia(delegateNode.GetLeadingTrivia()));
            }
            return(node);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitEventDeclaration(node);
 }
Пример #5
0
		private void AppendParameters(EventDeclarationSyntax syntax, StringBuilder builder)
		{
			builder.Append("(");
			var symbol = ModelExtensions.GetSymbolInfo(_semanticModel, syntax.Type).Symbol as ITypeSymbol;
			if (symbol != null)
			{
				var typeName = ResolveTypeName(symbol);
				builder.Append(typeName);
			}

			builder.Append(")");
		}
        /// <summary>
        /// Add the field and respect StyleCop ordering.
        /// </summary>
        /// <param name="editor">The <see cref="DocumentEditor"/>.</param>
        /// <param name="containingType">The containing type.</param>
        /// <param name="event">The <see cref="EventDeclarationSyntax"/>.</param>
        /// <param name="comparer">The <see cref="IComparer{MemberDeclarationSyntax}"/>. If null <see cref="MemberDeclarationComparer.Default"/> is used.</param>
        /// <returns>The <paramref name="editor"/>.</returns>
        public static DocumentEditor AddEvent(this DocumentEditor editor, ClassDeclarationSyntax containingType, EventDeclarationSyntax @event, IComparer <MemberDeclarationSyntax>?comparer = null)
        {
            if (editor is null)
            {
                throw new System.ArgumentNullException(nameof(editor));
            }

            if (containingType is null)
            {
                throw new System.ArgumentNullException(nameof(containingType));
            }

            if (@event is null)
            {
                throw new System.ArgumentNullException(nameof(@event));
            }

            editor.ReplaceNode(
                containingType,
                node => node.AddSorted(@event, comparer));
            return(editor);
        }
        private async Task<Document> ImplementVirtualEventPropertyAsync(Document document, EventDeclarationSyntax declaration, CancellationToken c)
        {
            // Need the left (IdentifierNameSyntax) of the Accessor Statement for the AssignmentExpressionSyntax
            var accessor = declaration.AccessorList.Accessors.First();
            var statements = accessor.Body.Statements.OfType<ExpressionStatementSyntax>();
            // Need to fine where the right side of an Add statement is "value":
            var eventFieldName = statements.Where(s => (s.Expression as AssignmentExpressionSyntax)?.OperatorToken.Kind() == SyntaxKind.PlusEqualsToken)
                .Where(s => ((s.Expression as AssignmentExpressionSyntax)?.Right as IdentifierNameSyntax)?.Identifier.ValueText == "value")
                .Select(s => ((s.Expression as AssignmentExpressionSyntax)?.Left as IdentifierNameSyntax)?.Identifier.ValueText).First();

            var raiseMethod = CreateRaiseMethod(declaration.Identifier.ValueText, eventFieldName, (declaration.Type as GenericNameSyntax));

            var root = await document.GetSyntaxRootAsync(c);
            var newRoot = root.InsertNodesAfter(declaration, new SyntaxNode[] { raiseMethod });
            // Note that we need to find the node again
            declaration = newRoot.FindToken(declaration.Span.Start).Parent.AncestorsAndSelf()
                .OfType<EventDeclarationSyntax>().First();

            var modifiers = declaration.Modifiers;
            var virtualToken = modifiers.Single(m => m.Kind() == SyntaxKind.VirtualKeyword);

            var newDeclaration = declaration.ReplaceToken(virtualToken, Token(SyntaxKind.None));
            newRoot = newRoot.ReplaceNode(declaration, newDeclaration
                .WithTrailingTrivia(TriviaList(CarriageReturnLineFeed, CarriageReturnLineFeed)));
            return document.WithSyntaxRoot(newRoot);
        }
Пример #8
0
		public override void VisitEventDeclaration(EventDeclarationSyntax node)
		{
			_members.Add(node);
		}
        public static BaseDocumentationCommentData GenerateFromBase(EventDeclarationSyntax eventDeclaration, SemanticModel semanticModel, CancellationToken cancellationToken = default(CancellationToken))
        {
            IEventSymbol eventSymbol = semanticModel.GetDeclaredSymbol(eventDeclaration, cancellationToken);

            return(GenerateFromBase(eventSymbol, semanticModel, eventDeclaration.SpanStart, cancellationToken));
        }
Пример #10
0
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
 {
     if (node == null)
         return null;
     var symbol = m_model.GetDeclaredSymbol(node);
     node = (EventDeclarationSyntax)base.VisitEventDeclaration(node);
     if (!IsPrivateOrInternal(symbol.DeclaredAccessibility))
         node = (EventDeclarationSyntax)ApplyDocComment(node, symbol.GetDocumentationCommentId());
     return node;
 }
Пример #11
0
 /// <inheritdoc />
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node) => this.Next();
Пример #12
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     new EventDeclarationVisitor(Context).Visit(node);
 }
        private async static Task <Document> ImplementVirtualEventPropertyAsync(Document document, EventDeclarationSyntax declaration, CancellationToken c)
        {
            // Need the left (IdentifierNameSyntax) of the Accessor Statement for the AssignmentExpressionSyntax
            var accessor   = declaration.AccessorList.Accessors.First();
            var statements = accessor.Body.Statements.OfType <ExpressionStatementSyntax>();
            // Need to fine where the right side of an Add statement is "value":
            var eventFieldName = statements.Where(s => (s.Expression as AssignmentExpressionSyntax)?.OperatorToken.Kind() == SyntaxKind.PlusEqualsToken)
                                 .Where(s => ((s.Expression as AssignmentExpressionSyntax)?.Right as IdentifierNameSyntax)?.Identifier.ValueText == "value")
                                 .Select(s => ((s.Expression as AssignmentExpressionSyntax)?.Left as IdentifierNameSyntax)?.Identifier.ValueText).First();

            var raiseMethod = CreateRaiseMethod(declaration.Identifier.ValueText, eventFieldName, (declaration.Type as GenericNameSyntax));

            var root = await document.GetSyntaxRootAsync(c);

            var newRoot = root.InsertNodesAfter(declaration, new SyntaxNode[] { raiseMethod });

            // Note that we need to find the node again
            declaration = newRoot.FindToken(declaration.Span.Start).Parent.AncestorsAndSelf()
                          .OfType <EventDeclarationSyntax>().First();

            var modifiers    = declaration.Modifiers;
            var virtualToken = modifiers.Single(m => m.Kind() == SyntaxKind.VirtualKeyword);

            var newDeclaration = declaration.ReplaceToken(virtualToken, Token(SyntaxKind.None));

            newRoot = newRoot.ReplaceNode(declaration, newDeclaration
                                          .WithTrailingTrivia(TriviaList(CarriageReturnLineFeed, CarriageReturnLineFeed)));
            return(document.WithSyntaxRoot(newRoot));
        }
        private static Task <Document> RemoveVirtualEventPropertyAsync(Document document, EventDeclarationSyntax declaration, CancellationToken c)
        {
            var modifiers    = declaration.Modifiers;
            var virtualToken = modifiers.Single(m => m.Kind() == SyntaxKind.VirtualKeyword);

            return(RemoveVirtualTokenAsync(document, virtualToken, c));
        }
Пример #15
0
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
 {
     node = (EventDeclarationSyntax)base.VisitEventDeclaration(node);
     Classes.Add(node);
     return(node);
 }
Пример #16
0
        internal static bool TryGetEventAccessors(EventDeclarationSyntax @event, out AccessorDeclarationSyntax add, out AccessorDeclarationSyntax remove)
        {
            var accessors = @event.AccessorList.Accessors;
            add = accessors.FirstOrDefault(ad => ad.CSharpKind() == SyntaxKind.GetAccessorDeclaration);
            remove = accessors.FirstOrDefault(ad => ad.CSharpKind() == SyntaxKind.SetAccessorDeclaration);

            return accessors.Count == 2 && add != null && remove != null;
        }
Пример #17
0
 public static void ComputeRefactoring(RefactoringContext context, EventDeclarationSyntax eventDeclaration, SemanticModel semanticModel)
 {
     ComputeRefactoring(context, eventDeclaration, eventDeclaration.Modifiers, eventDeclaration.ExplicitInterfaceSpecifier, semanticModel);
 }
 //
 // Summary:
 //     Called when the visitor visits a EventDeclarationSyntax node.
 public virtual void VisitEventDeclaration(EventDeclarationSyntax node);
        internal static Accessibility GetDeclaredAccessibility(this BasePropertyDeclarationSyntax syntax, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (syntax == null)
            {
                throw new ArgumentNullException(nameof(syntax));
            }

            if (semanticModel == null)
            {
                throw new ArgumentNullException(nameof(semanticModel));
            }

            AccessLevel accessLevel = GetAccessLevel(syntax.Modifiers);

            if (accessLevel != AccessLevel.NotSpecified)
            {
                return(accessLevel.ToAccessibility());
            }

            PropertyDeclarationSyntax propertyDeclarationSyntax = syntax as PropertyDeclarationSyntax;

            if (propertyDeclarationSyntax != null)
            {
                if (propertyDeclarationSyntax.ExplicitInterfaceSpecifier == null)
                {
                    return(Accessibility.Private);
                }
                else
                {
                    return(Accessibility.Public);
                }
            }

            IndexerDeclarationSyntax indexerDeclarationSyntax = syntax as IndexerDeclarationSyntax;

            if (indexerDeclarationSyntax != null)
            {
                if (indexerDeclarationSyntax.ExplicitInterfaceSpecifier == null)
                {
                    return(Accessibility.Private);
                }
                else
                {
                    return(Accessibility.Public);
                }
            }

            EventDeclarationSyntax eventDeclarationSyntax = syntax as EventDeclarationSyntax;

            if (eventDeclarationSyntax != null)
            {
                if (eventDeclarationSyntax.ExplicitInterfaceSpecifier == null)
                {
                    return(Accessibility.Private);
                }
                else
                {
                    return(Accessibility.Public);
                }
            }

            ISymbol declaredSymbol = semanticModel.GetDeclaredSymbol(syntax, cancellationToken);

            return(declaredSymbol?.DeclaredAccessibility ?? Accessibility.NotApplicable);
        }
			public override void VisitEventDeclaration (EventDeclarationSyntax node)
			{
				base.VisitEventDeclaration (node);
				Append (node);
			}
Пример #21
0
 /// <summary>
 /// Same as SemanticModel.GetDeclaredSymbol but works when <paramref name="node"/> is not in the syntax tree.
 /// </summary>
 /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
 /// <param name="node">The <see cref="EventDeclarationSyntax"/>.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
 /// <returns>An <see cref="IEventSymbol"/> or null.</returns>
 public static IEventSymbol GetDeclaredSymbolSafe(this SemanticModel semanticModel, EventDeclarationSyntax node, CancellationToken cancellationToken)
 {
     return(semanticModel.SemanticModelFor(node)
            ?.GetDeclaredSymbol(node, cancellationToken));
 }
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     CheckXmlDocForErrors(node, semanticModel.GetDeclaredSymbol(node));
 }
Пример #23
0
 /// <summary>
 /// Try getting the <see cref="IEventSymbol"/> for the node.
 /// Gets the semantic model for the tree if the node is not in the tree corresponding to <paramref name="semanticModel"/>.
 /// </summary>
 /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
 /// <param name="node">The <see cref="EventDeclarationSyntax"/>.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
 /// <param name="symbol">The symbol if found.</param>
 /// <returns>True if a symbol was found.</returns>
 public static bool TryGetSymbol(this SemanticModel semanticModel, EventDeclarationSyntax node, CancellationToken cancellationToken, out IEventSymbol symbol)
 {
     symbol = GetDeclaredSymbolSafe(semanticModel, node, cancellationToken);
     return(symbol != null);
 }
Пример #24
0
 public override IEventSymbol GetDeclaredSymbol(EventDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define event inside member.
     return null;
 }
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, EventDeclarationSyntax eventDeclaration)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.MarkMemberAsStatic) &&
                eventDeclaration.Span.Contains(context.Span) &&
                MarkMemberAsStaticRefactoring.CanRefactor(eventDeclaration))
            {
                context.RegisterRefactoring(
                    "Mark event as static",
                    cancellationToken => MarkMemberAsStaticRefactoring.RefactorAsync(context.Document, eventDeclaration, cancellationToken));
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.CopyDocumentationCommentFromBaseMember) &&
                eventDeclaration.HeaderSpan().Contains(context.Span))
            {
                await CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoringAsync(context, eventDeclaration).ConfigureAwait(false);
            }
        }
        private static SyntaxNode HandleEventDeclaration(EventDeclarationSyntax node)
        {
            SyntaxToken triviaToken = node.EventKeyword;
            if (triviaToken.IsMissing)
            {
                return null;
            }

            SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref triviaToken, SyntaxKind.PrivateKeyword);
            return node
                .WithEventKeyword(triviaToken)
                .WithModifiers(modifiers)
                .WithoutFormatting();
        }
Пример #27
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
 }
Пример #28
0
        public string Signature(bool forSorting)
        {
            string prefix = forSorting ? ClassPath + "." : "";

            if (!forSorting && IsStatic)
            {
                prefix = "static ";
            }

            {
                MethodDeclarationSyntax method = Member as MethodDeclarationSyntax;
                if (method != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}.{method.Identifier}(");
                    }
                    else
                    {
                        signature.Append($"{prefix}{method.ReturnType} {method.Identifier}(");
                    }
                    int parameterCount = method.ParameterList.Parameters.Count;
                    for (int i = 0; i < parameterCount; i++)
                    {
                        if (i > 0)
                        {
                            signature.Append(", ");
                        }
                        var parameter = method.ParameterList.Parameters[i];
                        for (int j = 0; j < parameter.Modifiers.Count; j++)
                        {
                            signature.Append(parameter.Modifiers[j].Text);
                            signature.Append(" ");
                        }

                        string paramType  = parameter.Type.ToString();
                        int    angleIndex = paramType.IndexOf('<');
                        if (angleIndex > 0)
                        {
                            string prefixType  = paramType.Substring(0, angleIndex);
                            int    prefixIndex = prefixType.LastIndexOf('.');
                            if (prefixIndex > 0)
                            {
                                prefixType = prefixType.Substring(prefixIndex + 1);
                            }
                            string genericType  = paramType.Substring(angleIndex + 1);
                            int    genericIndex = genericType.LastIndexOf('.');
                            if (genericIndex > 0)
                            {
                                genericType = genericType.Substring(genericIndex + 1);
                            }
                            paramType = prefixType + "<" + genericType;
                        }
                        else
                        {
                            int index = paramType.LastIndexOf('.');
                            if (index > 0)
                            {
                                paramType = paramType.Substring(index + 1);
                            }
                        }
                        signature.Append(paramType);
                        if (!forSorting)
                        {
                            signature.Append($" {parameter.Identifier}");
                        }
                    }
                    signature.Append(")");
                    return(signature.ToString());
                }
            }
            {
                PropertyDeclarationSyntax property = Member as PropertyDeclarationSyntax;
                if (property != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}.{property.Identifier}");
                    }
                    else
                    {
                        string proptype = $"{property.Type}";
                        int    index    = proptype.LastIndexOf('.');
                        if (index > 0)
                        {
                            proptype = proptype.Substring(index + 1);
                        }
                        signature.Append($"{prefix}{proptype} {property.Identifier}");
                    }
                    return(signature.ToString());
                }
            }
            {
                EventDeclarationSyntax evt = Member as EventDeclarationSyntax;
                if (evt != null)
                {
                    var signature = new System.Text.StringBuilder();
                    signature.Append($"{prefix}{evt.Identifier}");
                    return(signature.ToString());
                }
            }
            {
                OperatorDeclarationSyntax op = Member as OperatorDeclarationSyntax;
                if (op != null)
                {
                    var signature = new System.Text.StringBuilder();
                    signature.Append($"{prefix}{op.OperatorToken}");
                    return(signature.ToString());
                }
            }
            {
                EventFieldDeclarationSyntax eventField = Member as EventFieldDeclarationSyntax;
                if (eventField != null)
                {
                    var    signature   = new System.Text.StringBuilder();
                    string declaration = eventField.ToString();
                    int    index       = declaration.LastIndexOf(' ');
                    declaration = declaration.Substring(index + 1, declaration.Length - 1 - (index + 1));
                    signature.Append($"{prefix}{declaration}");
                    return(signature.ToString());
                }
            }
            {
                ConstructorDeclarationSyntax constructor = Member as ConstructorDeclarationSyntax;
                if (constructor != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}(");
                    }
                    else
                    {
                        if (IsStatic)
                        {
                            signature.Append("static ");
                        }
                        var parent = new ParsedType(Member.Parent as BaseTypeDeclarationSyntax, null);
                        signature.Append($"{parent.Name}(");
                    }
                    int parameterCount = constructor.ParameterList.Parameters.Count;
                    for (int i = 0; i < parameterCount; i++)
                    {
                        if (i > 0)
                        {
                            signature.Append(", ");
                        }
                        var    parameter  = constructor.ParameterList.Parameters[i];
                        string paramType  = parameter.Type.ToString();
                        int    angleIndex = paramType.IndexOf('<');
                        if (angleIndex > 0)
                        {
                            string prefixType  = paramType.Substring(0, angleIndex);
                            int    prefixIndex = prefixType.LastIndexOf('.');
                            if (prefixIndex > 0)
                            {
                                prefixType = prefixType.Substring(prefixIndex + 1);
                            }
                            string genericType  = paramType.Substring(angleIndex + 1);
                            int    genericIndex = genericType.LastIndexOf('.');
                            if (genericIndex > 0)
                            {
                                genericType = genericType.Substring(genericIndex + 1);
                            }
                            paramType = prefixType + "<" + genericType;
                        }
                        else
                        {
                            int index = paramType.LastIndexOf('.');
                            if (index > 0)
                            {
                                paramType = paramType.Substring(index + 1);
                            }
                        }
                        signature.Append(paramType);
                        if (!forSorting)
                        {
                            signature.Append($" {parameter.Identifier}");
                        }
                    }
                    signature.Append(")");
                    return(signature.ToString());
                }
            }
            {
                EnumMemberDeclarationSyntax enumMember = Member as EnumMemberDeclarationSyntax;
                if (enumMember != null)
                {
                    var signature = enumMember.ToString();
                    var items     = signature.Split(new char[] { '\n' });
                    signature = items[items.Length - 1];
                    return(signature);
                }
            }
            throw new NotImplementedException();
        }
Пример #29
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     base.VisitEventDeclaration(node);
     Append(node);
 }
Пример #30
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitEventDeclaration(node);
 }
Пример #31
0
        public void VisitEventDeclaration(EventDeclarationSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            WriteLeadingTrivia(node);

            _writer.WriteIndent();

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

            WriteMemberModifiers(node.Modifiers);

            _writer.WriteKeyword(PrinterKeyword.Event);
            _writer.WriteSpace();

            node.Type.Accept(this);

            _writer.WriteSpace();

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

            _writer.WriteIdentifier(node.Identifier);

            node.AccessorList.Accept(this);

            WriteTrailingTrivia(node);
        }
Пример #32
0
		public override void VisitEventDeclaration(EventDeclarationSyntax node)
		{
			base.VisitEventDeclaration(node);
			AddAccessorNode(node.AccessorList, SyntaxKind.AddAccessorDeclaration);
			AddAccessorNode(node.AccessorList, SyntaxKind.RemoveAccessorDeclaration);
		}
Пример #33
0
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            if (!node.Identifier.IsMissing)
                return node;

            string event_name    = node.Type.ToString();
            string delegate_name = event_name + "_delegate";

            Debug.Assert(pending_ == null);
            pending_ = new ResolveEventArguments(delegate_name, ctx_, members_, node.Modifiers);

            return SyntaxFactory.EventDeclaration(SyntaxFactory.IdentifierName(delegate_name), SyntaxFactory.Identifier(event_name)).
                                    WithModifiers(node.Modifiers).
                                    WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List( new AccessorDeclarationSyntax[]
                                    {
                                        SyntaxFactory.AccessorDeclaration(SyntaxKind.AddAccessorDeclaration,
                                            SyntaxFactory.Block(SyntaxFactory.List(new StatementSyntax[]
                                            {
                                                Compiler.EventAccessor(event_name, true)
                                            }))),

                                        SyntaxFactory.AccessorDeclaration(SyntaxKind.RemoveAccessorDeclaration,
                                            SyntaxFactory.Block(SyntaxFactory.List(new StatementSyntax[]
                                            {
                                                Compiler.EventAccessor(event_name, false)
                                            }))),
                                    })));
        }
Пример #34
0
 public EventPropertyNode CreateEventPropertyNode(EventDeclarationSyntax declaration, IMemberContainer container)
 {
     return(new EventPropertyNodeWithSymbols(declaration, container, semanticModel));
 }
Пример #35
0
 private Doc PrintEventDeclarationSyntax(EventDeclarationSyntax node)
 {
     return(this.PrintBasePropertyDeclarationSyntax(node));
 }
Пример #36
0
        public static void Go(OutputWriter writer, EventDeclarationSyntax property)
        {
            writer.WriteLine("\r\n");
            var rEf = ""; //" ref ";// ref should be used based on analysis, is the return type a single var or not
            //TODO, doesnt ref make things slower ?, though it makes proprties behave as in c#

            var isInterface = property.Parent is InterfaceDeclarationSyntax;

            var add =
                property.AccessorList.Accessors.SingleOrDefault(
                    o => o.Keyword.RawKind == (decimal) SyntaxKind.AddKeyword);
            var remove =
                property.AccessorList.Accessors.SingleOrDefault(
                    o => o.Keyword.RawKind == (decimal) SyntaxKind.RemoveKeyword);
            var eventSymbol = TypeProcessor.GetDeclaredSymbol(property);

            var methodSymbol =
                (TypeProcessor.GetDeclaredSymbol(add) ?? TypeProcessor.GetDeclaredSymbol(remove)) as IMethodSymbol;

            ITypeSymbol interfaceImplemented;
            ISymbol[] proxies;
            ;

            var methodName = WriteIdentifierName.TransformIdentifier(MemberUtilities.GetMethodName(eventSymbol, ref isInterface, out interfaceImplemented, out proxies));

            Action<AccessorDeclarationSyntax, bool> writeRegion = (region, get) =>
            {
                writer.WriteIndent();

                //                if (property.Modifiers.Any(SyntaxKind.PrivateKeyword))
                //                    writer.HeaderWriter.Write("private:\n");
                //
                //                if (property.Modifiers.Any(SyntaxKind.PublicKeyword) || property.Modifiers.Any(SyntaxKind.InternalKeyword))
                //                    writer.HeaderWriter.Write("public ");
                var typeinfo = TypeProcessor.GetTypeInfo(property.Type);
                var isPtr = "";

                var typeString = TypeProcessor.ConvertType(property.Type) + isPtr + " ";

                if (property.Modifiers.Any(SyntaxKind.AbstractKeyword) || region.Body == null)
                    writer.Write(" abstract ");

                if (property.Modifiers.Any(SyntaxKind.OverrideKeyword))
                    writer.Write(" override ");

               
                writer.Write("void ");
             
               
             

                writer.Write(
                    (get ? "Add_" : "Remove_") + methodName + "( " + typeString + " value");

                if (isInterface)
                {
                    writer.WriteLine(" , " + TypeProcessor.ConvertType(interfaceImplemented) + " __ij = null");
                }

                    writer.Write(" )");

                if (property.Modifiers.Any(SyntaxKind.AbstractKeyword) || region.Body == null)
                    writer.Write(";\r\n");
                else
                {
                    //                    writer.Write(";\r\n");

                    writer.OpenBrace();
                    // writer.Write(" =\r\n");
                    Core.WriteBlock(writer, region.Body.As<BlockSyntax>());

                    writer.CloseBrace();
                    writer.Write("\r\n");
                }
            };

            if (add == null && remove == null)
                throw new Exception("Event must have both a add and remove");

            {
               
                var name = WriteIdentifierName.TransformIdentifier(property.Identifier.Text);
                var type = property.Type;
                var typeinfo = TypeProcessor.GetTypeInfo(type);
                var modifiers = property.Modifiers;
                var typeString = TypeProcessor.ConvertType(type)  + " ";
                var isStatic = false;
                //Handle Auto Properties

                var accessors = property.AccessorList.Accessors; //.Where(o=>o.Body==null);
                var accessString = "";
                if (modifiers.Any(SyntaxKind.PrivateKeyword))
                    accessString += (" private ");

                if (modifiers.Any(SyntaxKind.PublicKeyword) || modifiers.Any(SyntaxKind.InternalKeyword) ||
                    modifiers.Any(SyntaxKind.ProtectedKeyword) || modifiers.Any(SyntaxKind.AbstractKeyword) ||
                    isInterface)
                    accessString += (" public ");

             

                var IsStatic = "";

                if (modifiers.Any(SyntaxKind.StaticKeyword))
                {
                    isStatic = true;
                    IsStatic = accessString += " static ";
                    //  writer.HeaderWriter.Write("static ");
                }

                var fieldName = "__evt__" + name + (interfaceImplemented!=null?TypeProcessor.ConvertType(interfaceImplemented)
                    .Replace("(","_").Replace("!", "_").Replace(")", "_").Replace(".", "_") :"");
                if (!(property.Parent is InterfaceDeclarationSyntax))
                {
                    if (!isStatic)
                    {
                        writer.Write("private " + "__Event!(" + typeString + ") " + fieldName + ";\r\n");
                        // Internal Field used for event
                        writer.Write(accessString);
                        writer.WriteLine("__Event!(" + typeString + ") " + name + "(" + (interfaceImplemented!=null ? (  TypeProcessor.ConvertType(interfaceImplemented) + " __ij = null") :"")+") @property");
                        writer.OpenBrace();

                        writer.WriteLine("if (" + fieldName + " is null)");
                        writer.OpenBrace();
                        writer.Write(fieldName + " =  new " + "__Event!(" + typeString + ")(new Action__G!(" +
                                     typeString +
                                     ")(&Add_" + name + "),new Action__G!(" + typeString + ")(&Remove_" + name + ") );");
                        writer.CloseBrace();
                        writer.Write("return " + fieldName + ";");
                        writer.CloseBrace();
                    }
                    else
                    {
                        writer.Write(IsStatic);
                        writer.Write("__Event!(" + typeString + ") " + name + ";\r\n");
                    }
                }

//
                var isOverride = property.Modifiers.Any(SyntaxKind.NewKeyword) ||
                                 property.Modifiers.Any(SyntaxKind.OverrideKeyword)
                    ? " override "
                    : "";
                var isVirtual = //property.Modifiers.Any(SyntaxKind.VirtualKeyword) ||
                    property.Modifiers.Any(SyntaxKind.AbstractKeyword) || isInterface
                        ? " abstract "
                        : "";

                //Adder
                if (add != null && add.Body == null)
                {
                    writer.Write(IsStatic);
                    //if (property.Modifiers.Any(SyntaxKind.AbstractKeyword)||isInterface)
                    {
                        writer.WriteLine(" " + isVirtual + " void Add_" + name + "(" + typeString + " value)" +
                                         isOverride + "" + ";");
                    }
//					else
//						writer.WriteLine(" "+isVirtual + " void Add_" + name + "(" + typeString + " value)" +
//							isOverride + " {" + fieldName + " = value;}");
                }
                else if (add != null)
                {
                    writer.Write(IsStatic);
                    writeRegion(add, true);
                }

                //Remover
                if (remove != null && remove.Body == null)
                {
                    writer.Write(IsStatic);
                    //if (property.Modifiers.Any(SyntaxKind.AbstractKeyword)||isInterface)
                    {
                        writer.WriteLine(" " + isVirtual + " void Remove_" + name + "(" + typeString + " value)" +
                                         isOverride + "" + ";");
                    }
                  }
                else if (remove != null)
                {
                    writer.Write(IsStatic);
                    writeRegion(remove, false);
                }

                if (isStatic)
                {
                    var staticWriter = new OutputWriter("", "", false);

                    staticWriter.Write(name);

                    staticWriter.Write(" =  new " + "__Event!(" + typeString + ")(new Action__G!(" + typeString +
                                       ")(&Add_" + name + "),new Action__G!(" + typeString +
                                       ")(&Remove_" + name + ") )");

                    staticWriter.Write(";");

                    staticWriter.WriteLine();

                    Context.Instance.StaticInits.Add(staticWriter.ToString());
                }

            }
        }
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     FindSpellingMistakesForIdentifier(node.Identifier);
     base.VisitEventDeclaration(node);
 }
Пример #38
0
 /// <summary>
 /// Given a syntax node that declares a (custom) event, get the corresponding event symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares a event.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public override IEventSymbol GetDeclaredSymbol(EventDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetDeclaredSymbol, message: this.SyntaxTree.FilePath, cancellationToken: cancellationToken))
     {
         return (IEventSymbol)GetDeclaredMemberSymbol(declarationSyntax);
     }
 }
Пример #39
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     AddDependentType(node.Type);
     base.VisitEventDeclaration(node);
 }
Пример #40
0
    public override void VisitEventDeclaration(EventDeclarationSyntax node)
    {
      if (!node.Identifier.Span.IsEmpty)
      {
        var symbol = _sm.GetDeclaredSymbol(node);

        _defined.Add(symbol);

        var def = Def.For(symbol: symbol, type: "event", name: symbol.Name)
          .At(_path, node.Identifier.Span);

        if (symbol.IsExported())
        {
          def.Exported = true;
        }

        AddDef(def);
      }

      base.VisitEventDeclaration(node);
    }
Пример #41
0
 public override SyntaxToken VisitEventDeclaration(EventDeclarationSyntax node)
 {
     return(node.Identifier);
 }
Пример #42
0
        internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, Binder binder, EventDeclarationSyntax syntax, DiagnosticBag diagnostics) :
            base(containingType, syntax, syntax.Modifiers, syntax.ExplicitInterfaceSpecifier, syntax.Identifier, diagnostics)
        {
            ExplicitInterfaceSpecifierSyntax interfaceSpecifier = syntax.ExplicitInterfaceSpecifier;
            SyntaxToken nameToken = syntax.Identifier;
            bool isExplicitInterfaceImplementation = interfaceSpecifier != null;

            string aliasQualifierOpt;
            _name = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(binder, interfaceSpecifier, nameToken.ValueText, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt);

            _type = BindEventType(binder, syntax.Type, diagnostics);

            var explicitlyImplementedEvent = this.FindExplicitlyImplementedEvent(_explicitInterfaceType, nameToken.ValueText, interfaceSpecifier, diagnostics);

            // The runtime will not treat the accessors of this event as overrides or implementations
            // of those of another event unless both the signatures and the custom modifiers match.
            // Hence, in the case of overrides and *explicit* implementations, we need to copy the custom
            // modifiers that are in the signatures of the overridden/implemented event accessors.
            // (From source, we know that there can only be one overridden/implemented event, so there
            // are no conflicts.)  This is unnecessary for implicit implementations because, if the custom
            // modifiers don't match, we'll insert bridge methods for the accessors (explicit implementations 
            // that delegate to the implicit implementations) with the correct custom modifiers
            // (see SourceNamedTypeSymbol.ImplementInterfaceMember).

            // Note: we're checking if the syntax indicates explicit implementation rather,
            // than if explicitInterfaceType is null because we don't want to look for an
            // overridden event if this is supposed to be an explicit implementation.
            if (!isExplicitInterfaceImplementation)
            {
                // If this event is an override, we may need to copy custom modifiers from
                // the overridden event (so that the runtime will recognize it as an override).
                // We check for this case here, while we can still modify the parameters and
                // return type without losing the appearance of immutability.
                if (this.IsOverride)
                {
                    EventSymbol overriddenEvent = this.OverriddenEvent;
                    if ((object)overriddenEvent != null)
                    {
                        CopyEventCustomModifiers(overriddenEvent, ref _type, ContainingAssembly);
                    }
                }
            }
            else if ((object)explicitlyImplementedEvent != null)
            {
                CopyEventCustomModifiers(explicitlyImplementedEvent, ref _type, ContainingAssembly);
            }

            AccessorDeclarationSyntax addSyntax = null;
            AccessorDeclarationSyntax removeSyntax = null;
            foreach (AccessorDeclarationSyntax accessor in syntax.AccessorList.Accessors)
            {
                switch (accessor.Kind())
                {
                    case SyntaxKind.AddAccessorDeclaration:
                        if (addSyntax == null || addSyntax.Keyword.Span.IsEmpty)
                        {
                            addSyntax = accessor;
                        }
                        break;
                    case SyntaxKind.RemoveAccessorDeclaration:
                        if (removeSyntax == null || removeSyntax.Keyword.Span.IsEmpty)
                        {
                            removeSyntax = accessor;
                        }
                        break;
                }
            }

            _addMethod = CreateAccessorSymbol(addSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);
            _removeMethod = CreateAccessorSymbol(removeSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);

            if (containingType.IsInterfaceType())
            {
                if (addSyntax == null && removeSyntax == null) //NOTE: AND - different error code produced if one is present
                {
                    // CONSIDER: we're matching dev10, but it would probably be more helpful to give
                    // an error like ERR_EventPropertyInInterface.
                    diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this);
                }
            }
            else
            {
                if (addSyntax == null || removeSyntax == null)
                {
                    diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this);
                }
            }

            _explicitInterfaceImplementations =
                (object)explicitlyImplementedEvent == null ?
                    ImmutableArray<EventSymbol>.Empty :
                    ImmutableArray.Create<EventSymbol>(explicitlyImplementedEvent);
        }
 private string GetEventDefinition(EventDeclarationSyntax node) => GetFullyQualifiedName((TypeDeclarationSyntax)node.Parent) + "." + node.Identifier.ValueText;
 private Task<Document> RemoveVirtualEventPropertyAsync(Document document, EventDeclarationSyntax declaration, CancellationToken c)
 {
     var modifiers = declaration.Modifiers;
     var virtualToken = modifiers.Single(m => m.Kind() == SyntaxKind.VirtualKeyword);
     return RemoveVirtualTokenAsync(document, virtualToken, c);
 }
Пример #45
0
        internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, Binder binder, EventDeclarationSyntax syntax, DiagnosticBag diagnostics) :
            base(containingType, syntax, syntax.Modifiers, syntax.ExplicitInterfaceSpecifier, syntax.Identifier, diagnostics)
        {
            ExplicitInterfaceSpecifierSyntax interfaceSpecifier = syntax.ExplicitInterfaceSpecifier;
            SyntaxToken nameToken = syntax.Identifier;
            bool        isExplicitInterfaceImplementation = interfaceSpecifier != null;

            string aliasQualifierOpt;

            _name = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(binder, interfaceSpecifier, nameToken.ValueText, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt);

            _type = BindEventType(binder, syntax.Type, diagnostics);

            var explicitlyImplementedEvent = this.FindExplicitlyImplementedEvent(_explicitInterfaceType, nameToken.ValueText, interfaceSpecifier, diagnostics);

            this.FindExplicitlyImplementedMemberVerification(explicitlyImplementedEvent, diagnostics);

            // The runtime will not treat the accessors of this event as overrides or implementations
            // of those of another event unless both the signatures and the custom modifiers match.
            // Hence, in the case of overrides and *explicit* implementations, we need to copy the custom
            // modifiers that are in the signatures of the overridden/implemented event accessors.
            // (From source, we know that there can only be one overridden/implemented event, so there
            // are no conflicts.)  This is unnecessary for implicit implementations because, if the custom
            // modifiers don't match, we'll insert bridge methods for the accessors (explicit implementations
            // that delegate to the implicit implementations) with the correct custom modifiers
            // (see SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation).

            // Note: we're checking if the syntax indicates explicit implementation rather,
            // than if explicitInterfaceType is null because we don't want to look for an
            // overridden event if this is supposed to be an explicit implementation.
            if (!isExplicitInterfaceImplementation)
            {
                // If this event is an override, we may need to copy custom modifiers from
                // the overridden event (so that the runtime will recognize it as an override).
                // We check for this case here, while we can still modify the parameters and
                // return type without losing the appearance of immutability.
                if (this.IsOverride)
                {
                    EventSymbol overriddenEvent = this.OverriddenEvent;
                    if ((object)overriddenEvent != null)
                    {
                        CopyEventCustomModifiers(overriddenEvent, ref _type, ContainingAssembly);
                    }
                }
            }
            else if ((object)explicitlyImplementedEvent != null)
            {
                CopyEventCustomModifiers(explicitlyImplementedEvent, ref _type, ContainingAssembly);
            }

            AccessorDeclarationSyntax addSyntax    = null;
            AccessorDeclarationSyntax removeSyntax = null;

            foreach (AccessorDeclarationSyntax accessor in syntax.AccessorList.Accessors)
            {
                switch (accessor.Kind())
                {
                case SyntaxKind.AddAccessorDeclaration:
                    if (addSyntax == null)
                    {
                        addSyntax = accessor;
                    }
                    else
                    {
                        diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation());
                    }
                    break;

                case SyntaxKind.RemoveAccessorDeclaration:
                    if (removeSyntax == null)
                    {
                        removeSyntax = accessor;
                    }
                    else
                    {
                        diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation());
                    }
                    break;

                case SyntaxKind.GetAccessorDeclaration:
                case SyntaxKind.SetAccessorDeclaration:
                    diagnostics.Add(ErrorCode.ERR_AddOrRemoveExpected, accessor.Keyword.GetLocation());
                    break;

                case SyntaxKind.UnknownAccessorDeclaration:
                    // Don't need to handle UnknownAccessorDeclaration.  An error will have
                    // already been produced for it in the parser.
                    break;

                default:
                    throw ExceptionUtilities.UnexpectedValue(accessor.Kind());
                }
            }

            _addMethod    = CreateAccessorSymbol(addSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);
            _removeMethod = CreateAccessorSymbol(removeSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);

            if (containingType.IsInterfaceType())
            {
                if (addSyntax == null && removeSyntax == null) //NOTE: AND - different error code produced if one is present
                {
                    // CONSIDER: we're matching dev10, but it would probably be more helpful to give
                    // an error like ERR_EventPropertyInInterface.
                    diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this);
                }
            }
            else
            {
                if (addSyntax == null || removeSyntax == null)
                {
                    diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this);
                }
            }

            _explicitInterfaceImplementations =
                (object)explicitlyImplementedEvent == null ?
                ImmutableArray <EventSymbol> .Empty :
                ImmutableArray.Create <EventSymbol>(explicitlyImplementedEvent);
        }
        internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, Binder binder, EventDeclarationSyntax syntax, DiagnosticBag diagnostics) :
            base(containingType, syntax, syntax.Modifiers, isFieldLike: false,
                 interfaceSpecifierSyntaxOpt: syntax.ExplicitInterfaceSpecifier,
                 nameTokenSyntax: syntax.Identifier, diagnostics: diagnostics)
        {
            ExplicitInterfaceSpecifierSyntax interfaceSpecifier = syntax.ExplicitInterfaceSpecifier;
            SyntaxToken nameToken = syntax.Identifier;
            bool        isExplicitInterfaceImplementation = interfaceSpecifier != null;

            string aliasQualifierOpt;

            _name = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(binder, interfaceSpecifier, nameToken.ValueText, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt);

            _type = BindEventType(binder, syntax.Type, diagnostics);

            var explicitlyImplementedEvent = this.FindExplicitlyImplementedEvent(_explicitInterfaceType, nameToken.ValueText, interfaceSpecifier, diagnostics);

            this.FindExplicitlyImplementedMemberVerification(explicitlyImplementedEvent, diagnostics);

            // The runtime will not treat the accessors of this event as overrides or implementations
            // of those of another event unless both the signatures and the custom modifiers match.
            // Hence, in the case of overrides and *explicit* implementations, we need to copy the custom
            // modifiers that are in the signatures of the overridden/implemented event accessors.
            // (From source, we know that there can only be one overridden/implemented event, so there
            // are no conflicts.)  This is unnecessary for implicit implementations because, if the custom
            // modifiers don't match, we'll insert bridge methods for the accessors (explicit implementations
            // that delegate to the implicit implementations) with the correct custom modifiers
            // (see SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation).

            // Note: we're checking if the syntax indicates explicit implementation rather,
            // than if explicitInterfaceType is null because we don't want to look for an
            // overridden event if this is supposed to be an explicit implementation.
            if (!isExplicitInterfaceImplementation)
            {
                // If this event is an override, we may need to copy custom modifiers from
                // the overridden event (so that the runtime will recognize it as an override).
                // We check for this case here, while we can still modify the parameters and
                // return type without losing the appearance of immutability.
                if (this.IsOverride)
                {
                    EventSymbol overriddenEvent = this.OverriddenEvent;
                    if ((object)overriddenEvent != null)
                    {
                        CopyEventCustomModifiers(overriddenEvent, ref _type, ContainingAssembly);
                    }
                }
            }
            else if ((object)explicitlyImplementedEvent != null)
            {
                CopyEventCustomModifiers(explicitlyImplementedEvent, ref _type, ContainingAssembly);
            }

            AccessorDeclarationSyntax addSyntax    = null;
            AccessorDeclarationSyntax removeSyntax = null;

            if (syntax.AccessorList != null)
            {
                foreach (AccessorDeclarationSyntax accessor in syntax.AccessorList.Accessors)
                {
                    bool checkBody = false;

                    switch (accessor.Kind())
                    {
                    case SyntaxKind.AddAccessorDeclaration:
                        if (addSyntax == null)
                        {
                            addSyntax = accessor;
                            checkBody = true;
                        }
                        else
                        {
                            diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation());
                        }
                        break;

                    case SyntaxKind.RemoveAccessorDeclaration:
                        if (removeSyntax == null)
                        {
                            removeSyntax = accessor;
                            checkBody    = true;
                        }
                        else
                        {
                            diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation());
                        }
                        break;

                    case SyntaxKind.GetAccessorDeclaration:
                    case SyntaxKind.SetAccessorDeclaration:
                        diagnostics.Add(ErrorCode.ERR_AddOrRemoveExpected, accessor.Keyword.GetLocation());
                        break;

                    case SyntaxKind.UnknownAccessorDeclaration:
                        // Don't need to handle UnknownAccessorDeclaration.  An error will have
                        // already been produced for it in the parser.
                        break;

                    default:
                        throw ExceptionUtilities.UnexpectedValue(accessor.Kind());
                    }

                    if (checkBody && !IsAbstract && accessor.Body == null && accessor.ExpressionBody == null && accessor.SemicolonToken.Kind() == SyntaxKind.SemicolonToken)
                    {
                        diagnostics.Add(ErrorCode.ERR_AddRemoveMustHaveBody, accessor.SemicolonToken.GetLocation());
                    }
                }

                if (IsAbstract)
                {
                    if (!syntax.AccessorList.OpenBraceToken.IsMissing)
                    {
                        diagnostics.Add(ErrorCode.ERR_AbstractEventHasAccessors, syntax.AccessorList.OpenBraceToken.GetLocation(), this);
                    }
                }
                else if ((addSyntax == null || removeSyntax == null) && (!syntax.AccessorList.OpenBraceToken.IsMissing || !isExplicitInterfaceImplementation))
                {
                    diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this);
                }
            }
            else if (isExplicitInterfaceImplementation && !IsAbstract)
            {
                diagnostics.Add(ErrorCode.ERR_ExplicitEventFieldImpl, this.Locations[0]);
            }

            if (isExplicitInterfaceImplementation && IsAbstract && syntax.AccessorList == null)
            {
                Debug.Assert(containingType.IsInterface);

                Binder.CheckFeatureAvailability(syntax, MessageID.IDS_DefaultInterfaceImplementation, diagnostics, this.Locations[0]);

                if (!ContainingAssembly.RuntimeSupportsDefaultInterfaceImplementation)
                {
                    diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportDefaultInterfaceImplementation, this.Locations[0]);
                }

                _addMethod    = new SynthesizedEventAccessorSymbol(this, isAdder: true, explicitlyImplementedEvent, aliasQualifierOpt);
                _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, explicitlyImplementedEvent, aliasQualifierOpt);
            }
            else
            {
                _addMethod    = CreateAccessorSymbol(addSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);
                _removeMethod = CreateAccessorSymbol(removeSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics);
            }

            _explicitInterfaceImplementations =
                (object)explicitlyImplementedEvent == null ?
                ImmutableArray <EventSymbol> .Empty :
                ImmutableArray.Create <EventSymbol>(explicitlyImplementedEvent);
        }
Пример #47
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     _members.Add(node);
 }
Пример #48
0
 /// <summary>
 /// Given a syntax node that declares a (custom) event, get the corresponding event symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares a event.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public abstract IEventSymbol GetDeclaredSymbol(EventDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken));
Пример #49
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     ConditionalStore(GetDeclaredSymbol(node), IsRemovableMember);
     base.VisitEventDeclaration(node);
 }
Пример #50
0
 public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
 {
     //Note:Event with body(add/remove method)
     //Extend:May add support depend on template, e.g. enyo
     this.AppendCompileIssue(node, IssueType.Error, IssueId.EventNotSupport);
     return node;
 }
 private static void AppendMethodIdentifier(EventDeclarationSyntax syntax, StringBuilder builder)
 {
     builder.Append(syntax.Identifier.ValueText);
 }
Пример #52
0
		private static void AppendMethodIdentifier(EventDeclarationSyntax syntax, StringBuilder builder)
		{
			builder.Append(syntax.Identifier.ValueText);
		}
Пример #53
0
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     VisitAttributeLists(node.AttributeLists);
     //base.VisitEventDeclaration(node);
 }
Пример #54
0
 /// <summary>
 /// Given a syntax node that declares a (custom) event, get the corresponding event symbol.
 /// </summary>
 /// <param name="declarationSyntax">The syntax node that declares a event.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The symbol that was declared.</returns>
 public override IEventSymbol GetDeclaredSymbol(EventDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
 {
     return (IEventSymbol)GetDeclaredMemberSymbol(declarationSyntax);
 }
 public override void VisitEventDeclaration(EventDeclarationSyntax node)
 {
     LogicalLineCount++;
     base.VisitEventDeclaration(node);
 }