public override void VisitExpressionStatement(ExpressionStatementSyntax node) { if (node.ShouldBeHidden()) { return; } if (this.InsideAutoIncludeMethodBlock) { var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; // this lambda has already been included so skip it if (IncludeMethodBlockContainsLambda && this.EndLine >= line) { return; } var allchildren = node.DescendantNodesAndTokens(descendIntoTrivia: true); if (allchildren.Any(a => a.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia)) { var walker = new CodeWithDocumentationWalker(ClassDepth, line, _propertyOrMethodName); walker.Visit(node.WithAdditionalAnnotations()); this.Blocks.AddRange(walker.Blocks); return; } base.VisitExpressionStatement(node); var code = node.WithoutLeadingTrivia().ToFullString(); code = code.RemoveNumberOfLeadingTabsAfterNewline(ClassDepth + 2); this.Blocks.Add(new CodeBlock(code, line, Language.CSharp, _propertyOrMethodName)); } else { base.VisitExpressionStatement(node); } }
private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode, ExpressionStatementSyntax expressionStatementParent, DiagnosticDescriptor descriptor) { // Make sure the invocation's containing type is not the same as the class that contains it if ((invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.DotToken)) && !invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.ThisExpression) || _.IsKind(SyntaxKind.BaseExpression))) && (!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) && !(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false) && !IsReturnValue(invocationNode)) { context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation())); } }
public override void VisitExpressionStatement(ExpressionStatementSyntax node) { if (this.InsideAutoIncludeMethodBlock) { var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; var allchildren = node.DescendantNodesAndTokens(descendIntoTrivia: true); if (allchildren.Any(a => a.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia)) { var walker = new CodeWithDocumentationWalker(ClassDepth, line); walker.Visit(node.WithAdditionalAnnotations()); this.Blocks.AddRange(walker.Blocks); return; } base.VisitExpressionStatement(node); this.Blocks.Add(new CodeBlock(node.WithoutLeadingTrivia().ToFullString(), line)); } else { base.VisitExpressionStatement(node); } }