示例#1
0
 public static bool ContainsGlobalStatement(this ISyntaxFacts syntaxFacts, SyntaxNode node)
 => node.ChildNodes().Any(c => c.RawKind == syntaxFacts.SyntaxKinds.GlobalStatement);
示例#2
0
        private static SyntaxNode ReplaceHeader(ISyntaxFacts syntaxFacts, AbstractFileHeaderHelper fileHeaderHelper, SyntaxTrivia newLineTrivia, SyntaxNode root, string expectedFileHeader)
        {
            // Skip single line comments, whitespace, and end of line trivia until a blank line is encountered.
            var triviaList = root.GetLeadingTrivia();

            // True if the current line is blank so far (empty or whitespace); otherwise, false. The first line is
            // assumed to not be blank, which allows the analysis to detect a file header which follows a blank line at
            // the top of the file.
            var onBlankLine = false;

            // The set of indexes to remove from 'triviaList'. After removing these indexes, the remaining trivia (if
            // any) will be preserved in the document along with the replacement header.
            var removalList = new List <int>();

            // The number of spaces to indent the new header. This is expected to match the indentation of the header
            // which is being replaced.
            var leadingSpaces = string.Empty;

            // The number of spaces found so far on the current line. This will become 'leadingSpaces' if the spaces are
            // followed by a comment which is considered a header comment.
            var possibleLeadingSpaces = string.Empty;

            // Need to do this with index so we get the line endings correct.
            for (var i = 0; i < triviaList.Count; i++)
            {
                var triviaLine = triviaList[i];
                if (triviaLine.RawKind == syntaxFacts.SyntaxKinds.SingleLineCommentTrivia)
                {
                    if (possibleLeadingSpaces != string.Empty)
                    {
                        // One or more spaces precedes the comment. Keep track of these spaces so we can indent the new
                        // header by the same amount.
                        leadingSpaces = possibleLeadingSpaces;
                    }

                    removalList.Add(i);
                    onBlankLine = false;
                }
                else if (triviaLine.RawKind == syntaxFacts.SyntaxKinds.WhitespaceTrivia)
                {
                    if (leadingSpaces == string.Empty)
                    {
                        possibleLeadingSpaces = triviaLine.ToFullString();
                    }

                    removalList.Add(i);
                }
                else if (triviaLine.RawKind == syntaxFacts.SyntaxKinds.EndOfLineTrivia)
                {
                    possibleLeadingSpaces = string.Empty;
                    removalList.Add(i);

                    if (onBlankLine)
                    {
                        break;
                    }
                    else
                    {
                        onBlankLine = true;
                    }
                }
                else
                {
                    break;
                }
            }

            // Remove copyright lines in reverse order.
            for (var i = removalList.Count - 1; i >= 0; i--)
            {
                triviaList = triviaList.RemoveAt(removalList[i]);
            }

            var newHeaderTrivia = CreateNewHeader(syntaxFacts, leadingSpaces + fileHeaderHelper.CommentPrefix, expectedFileHeader, newLineTrivia.ToFullString());

            // Add a blank line and any remaining preserved trivia after the header.
            newHeaderTrivia = newHeaderTrivia.Add(newLineTrivia).Add(newLineTrivia).AddRange(triviaList);

            // Insert header at top of the file.
            return(root.WithLeadingTrivia(newHeaderTrivia));
        }
 private static bool IsWordOrNumber(this ISyntaxFacts syntaxFacts, SyntaxToken token)
 => syntaxFacts.IsWord(token) || syntaxFacts.IsNumericLiteral(token);
示例#4
0
 protected abstract bool IsViableExtensionMethod(IMethodSymbol method, SyntaxNode expression, SemanticModel semanticModel, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken);
示例#5
0
 protected abstract bool TryAnalyzePatternCondition(
     ISyntaxFacts syntaxFacts, SyntaxNode conditionNode,
     [NotNullWhen(true)] out SyntaxNode?conditionPartToCheck, out bool isEquals);
示例#6
0
 protected AbstractSyntaxTriviaService(ISyntaxFacts syntaxFacts, int endOfLineKind)
 {
     _syntaxFacts   = syntaxFacts;
     _endOfLineKind = endOfLineKind;
 }
示例#7
0
 protected abstract bool CanAddImportForMethod(string diagnosticId, ISyntaxFacts syntaxFacts, SyntaxNode node, out TSimpleNameSyntax nameNode);
示例#8
0
 public static bool IsGlobalAttribute(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => syntaxFacts.IsGlobalAssemblyAttribute(node) || syntaxFacts.IsGlobalModuleAttribute(node);
示例#9
0
 public static bool IsReservedOrContextualKeyword(this ISyntaxFacts syntaxFacts, SyntaxToken token)
 => syntaxFacts.IsReservedKeyword(token) || syntaxFacts.IsContextualKeyword(token);
示例#10
0
 public static bool IsUsingStatement(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.UsingStatement;
示例#11
0
 public static bool IsAttribute(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.Attribute;
示例#12
0
 public static bool IsLocalDeclarationStatement(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.LocalDeclarationStatement;
示例#13
0
 public static bool IsForEachStatement(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.ForEachStatement;
示例#14
0
 public static bool IsExpressionStatement(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.ExpressionStatement;
示例#15
0
 public static void GetPartsOfAssignmentStatement(
     this ISyntaxFacts syntaxFacts, SyntaxNode statement,
     out SyntaxNode left, out SyntaxNode right)
 {
     syntaxFacts.GetPartsOfAssignmentStatement(statement, out left, out _, out right);
 }
示例#16
0
 public static bool IsParameter(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.Parameter;
示例#17
0
 public static SyntaxNode GetExpressionOfInvocationExpression(
     this ISyntaxFacts syntaxFacts, SyntaxNode node)
 {
     syntaxFacts.GetPartsOfInvocationExpression(node, out var expression, out _);
     return(expression);
 }
示例#18
0
 public static bool IsTypeConstraint(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.TypeConstraint;
        protected override IEnumerable <SyntaxNode> ExtractNodesSimple(SyntaxNode?node, ISyntaxFacts syntaxFacts)
        {
            if (node == null)
            {
                yield break;
            }

            foreach (var extractedNode in base.ExtractNodesSimple(node, syntaxFacts))
            {
                yield return(extractedNode);
            }

            // `var a = b;`
            // -> `var a = b`;
            if (node is LocalDeclarationStatementSyntax localDeclaration)
            {
                yield return(localDeclaration.Declaration);
            }

            // var `a = b`;
            if (node is VariableDeclaratorSyntax declarator)
            {
                var declaration = declarator.Parent;
                if (declaration?.Parent is LocalDeclarationStatementSyntax localDeclarationStatement)
                {
                    var variables = syntaxFacts.GetVariablesOfLocalDeclarationStatement(localDeclarationStatement);
                    if (variables.Count == 1)
                    {
                        // -> `var a = b`;
                        yield return(declaration);

                        // -> `var a = b;`
                        yield return(localDeclarationStatement);
                    }
                }
            }
        }
示例#20
0
 public static bool IsVariableDeclarator(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.VariableDeclarator;
示例#21
0
 protected abstract bool CanAddImportForGetAsyncEnumerator(string diagnosticId, ISyntaxFacts syntaxFactsService, SyntaxNode node);
示例#22
0
 public static bool IsTypeArgumentList(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.TypeArgumentList;
示例#23
0
 protected AbstractUseCompoundAssignmentDiagnosticAnalyzer(
     ISyntaxFacts syntaxFacts,
     ImmutableArray <(TSyntaxKind exprKind, TSyntaxKind assignmentKind, TSyntaxKind tokenKind)> kinds)
示例#24
0
 public static bool IsWord(this ISyntaxFacts syntaxFacts, SyntaxToken token)
 {
     return(syntaxFacts.IsIdentifier(token) ||
            syntaxFacts.IsReservedOrContextualKeyword(token) ||
            syntaxFacts.IsPreprocessorKeyword(token));
 }
示例#25
0
 protected AbstractAddExplicitCastCodeFixProvider(ISyntaxFacts syntaxFacts)
 => SyntaxFacts = syntaxFacts;
示例#26
0
 public static bool IsAnyMemberAccessExpression(
     this ISyntaxFacts syntaxFacts, SyntaxNode node)
 {
     return(syntaxFacts.IsSimpleMemberAccessExpression(node) || syntaxFacts.IsPointerMemberAccessExpression(node));
 }
 protected Analyzer(ISyntaxFacts syntaxFacts, Feature features)
 {
     _syntaxFacts = syntaxFacts;
     Features     = features;
 }
示例#28
0
 public static bool IsRegularOrDocumentationComment(this ISyntaxFacts syntaxFacts, SyntaxTrivia trivia)
 => syntaxFacts.IsRegularComment(trivia) || syntaxFacts.IsDocumentationComment(trivia);
示例#29
0
 public static bool SpansPreprocessorDirective(this ISyntaxFacts service, SyntaxNode node)
 => service.SpansPreprocessorDirective(SpecializedCollections.SingletonEnumerable(node));
示例#30
0
 public static bool IsTupleExpression(this ISyntaxFacts syntaxFacts, [NotNullWhen(true)] SyntaxNode?node)
 => node?.RawKind == syntaxFacts.SyntaxKinds.TupleExpression;