/// <summary> /// If the given node is within a preprocessing directive, gets the preprocessing symbol info for it. /// </summary> /// <param name="node">Preprocessing symbol identifier node.</param> public PreprocessingSymbolInfo GetPreprocessingSymbolInfo(IdentifierNameSyntax node) { CheckSyntaxNode(node); if (node.Ancestors().Any(n => SyntaxFacts.IsPreprocessorDirective(n.Kind()))) { bool isDefined = this.SyntaxTree.IsPreprocessorSymbolDefined(node.Identifier.ValueText, node.Identifier.SpanStart); return new PreprocessingSymbolInfo(new PreprocessingSymbol(node.Identifier.ValueText), isDefined); } return PreprocessingSymbolInfo.None; }
public override void VisitIdentifierName(IdentifierNameSyntax node) { base.VisitIdentifierName(node); var ancestors = node.Ancestors(); if (ancestors.Any(n => (n is MemberAccessExpressionSyntax) || (n is InvocationExpressionSyntax))) return; Check(node, true); }
// corrects the register statement to be RegisterSyntaxNodeAction private async Task<Document> CorrectRegisterAsync(Document document, IdentifierNameSyntax declaration, CancellationToken c) { SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); var memberExpression = declaration.Parent as MemberAccessExpressionSyntax; var invocationExpression = memberExpression.Parent as InvocationExpressionSyntax; string methodName = CodeFixHelper.GetRegisterMethodName(invocationExpression); if (methodName == null) { methodName = "AnalyzeIfStatement"; } SyntaxNode newExpression = CodeFixHelper.CreateRegister(generator, declaration.Ancestors().OfType<MethodDeclarationSyntax>().First(), methodName); return await ReplaceNode(declaration.FirstAncestorOrSelf<ExpressionStatementSyntax>(), newExpression.WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.CarriageReturnLineFeed, SyntaxFactory.ParseLeadingTrivia("// Calls the method (first argument) to perform analysis whenever a SyntaxNode of kind IfStatement is found").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"))), document); }