/// <summary> /// Get a walker with all mutations for <paramref name="property"/>. /// </summary> /// <param name="property">The <see cref="IPropertySymbol"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>A walker with all mutations for <paramref name="property"/>.</returns> public static MutationWalker For(IPropertySymbol property, SemanticModel semanticModel, CancellationToken cancellationToken) { if (FieldOrProperty.TryCreate(property, out var fieldOrProperty)) { return(For(fieldOrProperty, semanticModel, cancellationToken)); } return(Borrow(() => new MutationWalker())); }
/// <summary> /// Initializes a new instance of the <see cref="FieldOrPropertyAndDeclaration"/> struct. /// </summary> /// <param name="property">The <see cref="IPropertySymbol"/>.</param> /// <param name="declaration">The <see cref="PropertyDeclarationSyntax"/>.</param> public FieldOrPropertyAndDeclaration(IPropertySymbol property, PropertyDeclarationSyntax declaration) { if (property is null) { throw new ArgumentNullException(nameof(property)); } this.FieldOrProperty = new FieldOrProperty(property); this.Declaration = declaration ?? throw new ArgumentNullException(nameof(declaration)); }
/// <summary> /// Initializes a new instance of the <see cref="FieldOrPropertyAndDeclaration"/> struct. /// </summary> /// <param name="field">The <see cref="IFieldSymbol"/>.</param> /// <param name="declaration">The <see cref="FieldDeclarationSyntax"/>.</param> public FieldOrPropertyAndDeclaration(IFieldSymbol field, FieldDeclarationSyntax declaration) { if (field is null) { throw new ArgumentNullException(nameof(field)); } this.FieldOrProperty = new FieldOrProperty(field); this.Declaration = declaration ?? throw new ArgumentNullException(nameof(declaration)); }
/// <summary> /// Get a walker with all mutations for <paramref name="symbol"/>. /// </summary> /// <param name="symbol">The <see cref="ISymbol"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>A walker with all mutations for <paramref name="symbol"/>.</returns> public static MutationWalker For(ISymbol symbol, SemanticModel semanticModel, CancellationToken cancellationToken) { if (LocalOrParameter.TryCreate(symbol, out var localOrParameter)) { return(For(localOrParameter, semanticModel, cancellationToken)); } if (FieldOrProperty.TryCreate(symbol, out var fieldOrProperty)) { return(For(fieldOrProperty, semanticModel, cancellationToken)); } return(Borrow(() => new MutationWalker())); }
/// <summary> /// Get a walker with all mutations for <paramref name="fieldOrProperty"/>. /// </summary> /// <param name="fieldOrProperty">The <see cref="FieldOrProperty"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>A walker with all mutations for <paramref name="fieldOrProperty"/>.</returns> public static MutationWalker For(FieldOrProperty fieldOrProperty, SemanticModel semanticModel, CancellationToken cancellationToken) { if (fieldOrProperty.Symbol.ContainingType.TrySingleDeclaration(cancellationToken, out TypeDeclarationSyntax? typeDeclaration)) { var walker = Borrow(typeDeclaration, SearchScope.Instance, semanticModel, cancellationToken); walker.assignments.RemoveAll(x => !IsFieldOrProperty(x.Left)); walker.prefixUnaries.RemoveAll(x => !IsFieldOrProperty(x.Operand)); walker.postfixUnaries.RemoveAll(x => !IsFieldOrProperty(x.Operand)); walker.refOrOutArguments.RemoveAll(x => !IsFieldOrProperty(x.Expression)); return(walker); } return(Borrow(() => new MutationWalker())); bool IsFieldOrProperty(ExpressionSyntax expression) { return(semanticModel.TryGetSymbol(expression, cancellationToken, out var symbol) && SymbolComparer.Equal(symbol, fieldOrProperty.Symbol)); } }