コード例 #1
0
        /// <summary>
        /// Get all usages of <paramref name="localOrParameter"/>.
        /// </summary>
        /// <param name="localOrParameter">The <see cref="LocalOrParameter"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that cancels the operation.</param>
        /// <returns>A <see cref="UsagesWalker"/> for <paramref name="localOrParameter"/>.</returns>
        public static UsagesWalker Borrow(LocalOrParameter localOrParameter, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (localOrParameter.TryGetScope(cancellationToken, out var scope))
            {
                return(Borrow(localOrParameter.Symbol, scope, semanticModel, cancellationToken));
            }

            return(Borrow(() => new UsagesWalker()));
        }
コード例 #2
0
        /// <summary>
        /// Get a walker that has all uses of <paramref name="local"/>.
        /// </summary>
        /// <param name="local">The <see cref="ILocalSymbol"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>A walker that has all uses of <paramref name="local"/>.</returns>
        public static IdentifierNameWalker For(ILocalSymbol local, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (LocalOrParameter.TryCreate(local, out var localOrParameter))
            {
                return(For(localOrParameter, semanticModel, cancellationToken));
            }

            return(Borrow(() => new IdentifierNameWalker()));
        }
コード例 #3
0
        /// <summary>
        /// Get a walker with all mutations for <paramref name="parameter"/>.
        /// </summary>
        /// <param name="parameter">The <see cref="IParameterSymbol"/>.</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="parameter"/>.</returns>
        public static MutationWalker For(IParameterSymbol parameter, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (LocalOrParameter.TryCreate(parameter, out var localOrParameter))
            {
                return(For(localOrParameter, semanticModel, cancellationToken));
            }

            return(Borrow(() => new MutationWalker()));
        }
コード例 #4
0
        /// <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()));
        }
コード例 #5
0
        /// <summary>
        /// Get a walker that has all uses of <paramref name="localOrParameter"/>.
        /// </summary>
        /// <param name="localOrParameter">The <see cref="LocalOrParameter"/>.</param>
        /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>A walker that has all uses of <paramref name="localOrParameter"/>.</returns>
        public static IdentifierNameWalker For(LocalOrParameter localOrParameter, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (localOrParameter.TryGetScope(cancellationToken, out var scope))
            {
                var walker = BorrowAndVisit(scope, () => new IdentifierNameWalker());
                walker.RemoveAll(x => !IsMatch(x));
                return(walker);
            }

            return(Borrow(() => new IdentifierNameWalker()));

            bool IsMatch(IdentifierNameSyntax candidate)
            {
                return(candidate.IsSymbol(localOrParameter.Symbol, semanticModel, cancellationToken));
            }
        }
コード例 #6
0
        /// <summary>
        /// Get a walker with all mutations for <paramref name="localOrParameter"/>.
        /// </summary>
        /// <param name="localOrParameter">The <see cref="LocalOrParameter"/>.</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="localOrParameter"/>.</returns>
        public static MutationWalker For(LocalOrParameter localOrParameter, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (localOrParameter.TryGetScope(cancellationToken, out var node))
            {
                var walker = Borrow(node, SearchScope.Member, semanticModel, cancellationToken);
                walker.assignments.RemoveAll(x => !IsMatch(x.Left));
                walker.prefixUnaries.RemoveAll(x => !IsMatch(x.Operand));
                walker.postfixUnaries.RemoveAll(x => !IsMatch(x.Operand));
                walker.refOrOutArguments.RemoveAll(x => !IsMatch(x.Expression));
                return(walker);
            }

            return(Borrow(() => new MutationWalker()));

            bool IsMatch(ExpressionSyntax expression)
            {
                return(semanticModel.TryGetSymbol(expression, cancellationToken, out var symbol) &&
                       SymbolComparer.Equal(symbol, localOrParameter.Symbol));
            }
        }