private static AccessorListSyntax GetNewAccessorList(AccessorListSyntax accessorList) { if (accessorList.IsSingleLine(includeExteriorTrivia: false)) { SyntaxTriviaList triviaList = accessorList .CloseBraceToken .LeadingTrivia .Add(NewLineTrivia()); return(Remover.RemoveWhitespaceOrEndOfLine(accessorList) .WithCloseBraceToken(accessorList.CloseBraceToken.WithLeadingTrivia(triviaList))); } else { return(accessorList.ReplaceNodes(accessorList.Accessors, (f, g) => { if (ShouldBeFormatted(f)) { return Remover.RemoveWhitespaceOrEndOfLine(f, f.Span); } else { return g; } })); } }
public static void Analyze(SyntaxNodeAnalysisContext context, AccessorListSyntax accessorList) { if (accessorList.Accessors.Any(f => f.Body != null)) { if (accessorList.IsSingleLine(includeExteriorTrivia: false)) { context.ReportDiagnostic(DiagnosticDescriptor, accessorList.GetLocation()); } else { foreach (AccessorDeclarationSyntax accessor in accessorList.Accessors) { if (ShouldBeFormatted(accessor)) { context.ReportDiagnostic(DiagnosticDescriptor, accessor.GetLocation()); } } } } else if (accessorList.IsParentKind(SyntaxKind.PropertyDeclaration) && accessorList.Accessors.All(f => f.AttributeLists.Count == 0) && !accessorList.IsSingleLine(includeExteriorTrivia: false)) { var propertyDeclaration = (PropertyDeclarationSyntax)accessorList.Parent; if (!propertyDeclaration.Identifier.IsMissing && !accessorList.CloseBraceToken.IsMissing) { TextSpan span = TextSpan.FromBounds( propertyDeclaration.Identifier.Span.End, accessorList.CloseBraceToken.Span.Start); if (propertyDeclaration .DescendantTrivia(span) .All(f => f.IsWhitespaceOrEndOfLineTrivia())) { context.ReportDiagnostic(DiagnosticDescriptor, accessorList.GetLocation()); } } } }
private static AccessorListSyntax GetNewAccessorList(AccessorListSyntax accessorList) { if (accessorList.IsSingleLine(includeExteriorTrivia: false)) { SyntaxTriviaList triviaList = accessorList.CloseBraceToken.LeadingTrivia .Add(CSharpFactory.NewLineTrivia()); return(Remover.RemoveWhitespaceOrEndOfLine(accessorList) .WithCloseBraceToken(accessorList.CloseBraceToken.WithLeadingTrivia(triviaList))); } else { return(AccessorSyntaxRewriter.VisitNode(accessorList)); } }
public static void Analyze(SyntaxNodeAnalysisContext context, AccessorListSyntax accessorList) { SyntaxList <AccessorDeclarationSyntax> accessors = accessorList.Accessors; if (accessors.Any(f => f.BodyOrExpressionBody() != null)) { if (accessorList.IsSingleLine(includeExteriorTrivia: false)) { ReportDiagnostic(context, accessorList); } else { foreach (AccessorDeclarationSyntax accessor in accessors) { if (ShouldBeFormatted(accessor)) { ReportDiagnostic(context, accessor); } } } } else { SyntaxNode parent = accessorList.Parent; switch (parent?.Kind()) { case SyntaxKind.PropertyDeclaration: { if (accessors.All(f => !f.AttributeLists.Any()) && !accessorList.IsSingleLine(includeExteriorTrivia: false)) { var propertyDeclaration = (PropertyDeclarationSyntax)parent; SyntaxToken identifier = propertyDeclaration.Identifier; if (!identifier.IsMissing) { SyntaxToken closeBrace = accessorList.CloseBraceToken; if (!closeBrace.IsMissing) { TextSpan span = TextSpan.FromBounds(identifier.Span.End, closeBrace.Span.Start); if (propertyDeclaration .DescendantTrivia(span) .All(f => f.IsWhitespaceOrEndOfLineTrivia())) { ReportDiagnostic(context, accessorList); } } } } break; } case SyntaxKind.IndexerDeclaration: { if (accessors.All(f => !f.AttributeLists.Any()) && !accessorList.IsSingleLine(includeExteriorTrivia: false)) { var indexerDeclaration = (IndexerDeclarationSyntax)parent; BracketedParameterListSyntax parameterList = indexerDeclaration.ParameterList; if (parameterList != null) { SyntaxToken closeBracket = parameterList.CloseBracketToken; if (!closeBracket.IsMissing) { SyntaxToken closeBrace = accessorList.CloseBraceToken; if (!closeBrace.IsMissing) { TextSpan span = TextSpan.FromBounds(closeBracket.Span.End, closeBrace.Span.Start); if (indexerDeclaration .DescendantTrivia(span) .All(f => f.IsWhitespaceOrEndOfLineTrivia())) { ReportDiagnostic(context, accessorList); } } } } } break; } } } }