private ExpressionSyntax SimplifyInvocation(InvocationExpressionSyntax invocation) { var expression = invocation.Expression; if (expression is MemberAccessExpressionSyntax memberAccess) { var symbolMap = SemanticMap.From( _document.SemanticModel, memberAccess.Expression, _cancellationToken ); var anySideEffects = symbolMap.AllReferencedSymbols.Any( s => s.Kind == SymbolKind.Method || s.Kind == SymbolKind.Property ); if (anySideEffects) { var annotation = WarningAnnotation.Create( "Warning: Expression may have side effects. Code meaning may change." ); expression = expression.ReplaceNode( memberAccess.Expression, memberAccess.Expression.WithAdditionalAnnotations(annotation) ); } } return(expression.Parenthesize().WithAdditionalAnnotations(Formatter.Annotation)); }
private ExpressionSyntax SimplifyInvocation(InvocationExpressionSyntax invocation) { var expression = invocation.Expression; if (expression is MemberAccessExpressionSyntax memberAccess) { var symbolMap = SemanticMap.From(_document.SemanticModel, memberAccess.Expression, _cancellationToken); var anySideEffects = symbolMap.AllReferencedSymbols.Any(s => s.Kind is SymbolKind.Method or SymbolKind.Property); if (anySideEffects) { var annotation = WarningAnnotation.Create(CSharpFeaturesResources.Warning_Expression_may_change_code_meaning); expression = expression.ReplaceNode(memberAccess.Expression, memberAccess.Expression.WithAdditionalAnnotations(annotation)); } } return(expression.Parenthesize() .WithAdditionalAnnotations(Formatter.Annotation)); }
public static SemanticMap GetSemanticMap(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { return(SemanticMap.From(semanticModel, node, cancellationToken)); }