private static void Analyze( SyntaxNodeAnalysisContext context, ParameterListSyntax parameterList, SeparatedSyntaxList <ParameterSyntax> parameters) { if (parameterList .DescendantTrivia(parameterList.Span) .All(f => f.IsWhitespaceOrEndOfLineTrivia())) { context.ReportDiagnostic( DiagnosticDescriptors.SimplifyLambdaExpressionParameterList, parameterList); foreach (ParameterSyntax parameter in parameters) { if (parameter.Type != null) { context.ReportNode(FadeOutDescriptor, parameter.Type); } } if (parameters.Count == 1) { context.ReportToken(FadeOutDescriptor, parameterList.OpenParenToken); context.ReportToken(FadeOutDescriptor, parameterList.CloseParenToken); } } }
private static void Analyze(SyntaxNodeAnalysisContext context, ParameterListSyntax parameterList) { if (parameterList .DescendantTrivia(parameterList.Span) .All(f => f.IsWhitespaceOrEndOfLineTrivia())) { context.ReportDiagnostic( DiagnosticDescriptors.SimplifyLambdaExpressionParameterList, parameterList.GetLocation()); FadeOut(context, parameterList); } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList) { SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters; if (parameters.Any()) { if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateParameter)) { var refactoring = new DuplicateParameterRefactoring(parameterList); refactoring.ComputeRefactoring(context, RefactoringIdentifiers.DuplicateParameter); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.CheckParameterForNull) && SeparatedSyntaxListSelection <ParameterSyntax> .TryCreate(parameterList.Parameters, context.Span, out SeparatedSyntaxListSelection <ParameterSyntax> selectedParameters)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CheckParameterForNullRefactoring.ComputeRefactoring(context, selectedParameters, semanticModel); } if (context.IsAnyRefactoringEnabled( RefactoringIdentifiers.IntroduceAndInitializeField, RefactoringIdentifiers.IntroduceAndInitializeProperty)) { IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList); } if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatParameterList) && (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(parameterList))) { if (parameterList.IsSingleLine()) { if (parameters.Count > 1) { context.RegisterRefactoring( "Format parameters on separate lines", cancellationToken => SyntaxFormatter.ToMultiLineAsync(context.Document, parameterList, cancellationToken), RefactoringIdentifiers.FormatParameterList); } } else if (parameterList.DescendantTrivia(parameterList.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia())) { context.RegisterRefactoring( "Format parameters on a single line", cancellationToken => SyntaxFormatter.ToSingleLineAsync(context.Document, parameterList, cancellationToken), RefactoringIdentifiers.FormatParameterList); } } } }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, ParameterListSyntax parameterList) { SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters; if (parameters.Any()) { if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyParameter)) { var refactoring = new CopyParameterRefactoring(parameterList); refactoring.ComputeRefactoring(context, RefactoringDescriptors.CopyParameter); } if (context.IsRefactoringEnabled(RefactoringDescriptors.CheckParameterForNull) && SeparatedSyntaxListSelection <ParameterSyntax> .TryCreate(parameterList.Parameters, context.Span, out SeparatedSyntaxListSelection <ParameterSyntax> selectedParameters)) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); CheckParameterForNullRefactoring.ComputeRefactoring(context, selectedParameters, semanticModel); } if (context.IsAnyRefactoringEnabled( RefactoringDescriptors.IntroduceAndInitializeField, RefactoringDescriptors.IntroduceAndInitializeProperty)) { IntroduceAndInitializeRefactoring.ComputeRefactoring(context, parameterList); } if (context.IsRefactoringEnabled(RefactoringDescriptors.WrapParameters) && (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(parameterList))) { if (parameterList.IsSingleLine()) { if (parameters.Count > 1) { context.RegisterRefactoring( "Wrap parameters", ct => SyntaxFormatter.WrapParametersAsync(context.Document, parameterList, ct), RefactoringDescriptors.WrapParameters); } } else if (parameterList.DescendantTrivia(parameterList.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia())) { context.RegisterRefactoring( "Unwrap parameters", ct => SyntaxFormatter.UnwrapExpressionAsync(context.Document, parameterList, ct), RefactoringDescriptors.WrapParameters); } } } }