当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxToken.IsParentKind方法代码示例

本文整理汇总了C#中SyntaxToken.IsParentKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsParentKind方法的具体用法?C# SyntaxToken.IsParentKind怎么用?C# SyntaxToken.IsParentKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxToken的用法示例。


在下文中一共展示了SyntaxToken.IsParentKind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClassificationForIdentifer

        private static string GetClassificationForIdentifer(SyntaxToken token)
        {
            var typeDeclaration = token.Parent as BaseTypeDeclarationSyntax;

            if (typeDeclaration != null && typeDeclaration.Identifier == token)
            {
                return GetClassificationForTypeDeclarationIdentifier(token);
            }
            else if (token.IsParentKind(SyntaxKind.DelegateDeclaration) && ((DelegateDeclarationSyntax)token.Parent).Identifier == token)
            {
                return ClassificationTypeNames.DelegateName;
            }
            else if (token.IsParentKind(SyntaxKind.TypeParameter) && ((TypeParameterSyntax)token.Parent).Identifier == token)
            {
                return ClassificationTypeNames.TypeParameterName;
            }
            else if (IsActualContextualKeyword(token) || CouldBeVarKeywordInDeclaration(token))
            {
                return ClassificationTypeNames.Keyword;
            }
            else
            {
                return ClassificationTypeNames.Identifier;
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:25,代码来源:ClassificationHelpers.cs

示例2: GetAdjustSpacesOperation

        public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustSpacesOperation> nextOperation)
        {
            //////////////////////////////////////////////////////
            // ";" related operations
            if (currentToken.CSharpKind() == SyntaxKind.SemicolonToken)
            {
                // ; ;
                if (previousToken.CSharpKind() == SyntaxKind.SemicolonToken)
                {
                    return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
                }

                // ) ; with embedded statement case
                if (previousToken.CSharpKind() == SyntaxKind.CloseParenToken && previousToken.Parent.IsEmbeddedStatementOwnerWithCloseParen())
                {
                    return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
                }

                // * ;
                return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            // omitted tokens case
            if (previousToken.CSharpKind() == SyntaxKind.OmittedArraySizeExpressionToken ||
                previousToken.CSharpKind() == SyntaxKind.OmittedTypeArgumentToken ||
                currentToken.CSharpKind() == SyntaxKind.OmittedArraySizeExpressionToken ||
                currentToken.CSharpKind() == SyntaxKind.OmittedTypeArgumentToken)
            {
                return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            // some * "(" cases
            if (currentToken.CSharpKind() == SyntaxKind.OpenParenToken)
            {
                if (previousToken.CSharpKind() == SyntaxKind.IdentifierToken ||
                    previousToken.CSharpKind() == SyntaxKind.DefaultKeyword ||
                    previousToken.CSharpKind() == SyntaxKind.BaseKeyword ||
                    previousToken.CSharpKind() == SyntaxKind.ThisKeyword ||
                    previousToken.CSharpKind() == SyntaxKind.NewKeyword ||
                    previousToken.Parent.CSharpKind() == SyntaxKind.OperatorDeclaration ||
                    previousToken.IsGenericGreaterThanToken() ||
                    currentToken.IsParenInArgumentList())
                {
                    return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
                }
            }

            // empty () or []
            if (previousToken.ParenOrBracketContainsNothing(currentToken))
            {
                return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            // attribute case
            // , [
            if (previousToken.CSharpKind() == SyntaxKind.CommaToken && currentToken.CSharpKind() == SyntaxKind.OpenBracketToken && currentToken.Parent is AttributeListSyntax)
            {
                return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            // ] *
            if (previousToken.CSharpKind() == SyntaxKind.CloseBracketToken && previousToken.Parent is AttributeListSyntax)
            {
                // preserving dev10 behavior, in dev10 we didn't touch space after attribute
                return CreateAdjustSpacesOperation(0, AdjustSpacesOption.PreserveSpaces);
            }

            // * )
            // * [
            // * ]
            // * ,
            // * .
            // * ->
            switch (currentToken.CSharpKind())
            {
                case SyntaxKind.CloseParenToken:
                case SyntaxKind.OpenBracketToken:
                case SyntaxKind.CloseBracketToken:
                case SyntaxKind.CommaToken:
                case SyntaxKind.DotToken:
                case SyntaxKind.MinusGreaterThanToken:
                    return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
            }

            // case * :
            // default:
            // <label> :
            switch (currentToken.CSharpKind())
            {
                case SyntaxKind.ColonToken:
                    if (currentToken.IsParentKind(SyntaxKind.CaseSwitchLabel) ||
                        currentToken.IsParentKind(SyntaxKind.DefaultSwitchLabel) ||
                        currentToken.IsParentKind(SyntaxKind.LabeledStatement) ||
                        currentToken.IsParentKind(SyntaxKind.AttributeTargetSpecifier) ||
                        currentToken.IsParentKind(SyntaxKind.NameColon))
                    {
                        return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
                    }

                    break;
//.........这里部分代码省略.........
开发者ID:riversky,项目名称:roslyn,代码行数:101,代码来源:TokenBasedFormattingRule.cs

示例3: GetAdjustNewLinesOperation

        public override AdjustNewLinesOperation GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken, OptionSet optionSet, NextOperation<AdjustNewLinesOperation> nextOperation)
        {
            var operation = nextOperation.Invoke();
            if (operation == null)
            {
                // If there are more than one Type Parameter Constraint Clause then each go in separate line
                if (CommonFormattingHelpers.HasAnyWhitespaceElasticTrivia(previousToken, currentToken) &&
                    currentToken.RawKind == (int)SyntaxKind.WhereKeyword &&
                    currentToken.IsParentKind(SyntaxKind.TypeParameterConstraintClause))
                {
                    // Check if there is another TypeParameterConstraintClause before
                    if (previousToken.Parent.Ancestors().OfType<TypeParameterConstraintClauseSyntax>().Any())
                    {
                        return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                    }

                    // Check if there is another TypeParameterConstraintClause after
                    var firstTokenAfterTypeConstraint = currentToken.Parent.GetLastToken().GetNextToken();
                    var lastTokenForTypeConstraint = currentToken.Parent.GetLastToken().GetNextToken();
                    if (CommonFormattingHelpers.HasAnyWhitespaceElasticTrivia(lastTokenForTypeConstraint, firstTokenAfterTypeConstraint) &&
                        firstTokenAfterTypeConstraint.RawKind == (int)SyntaxKind.WhereKeyword &&
                        firstTokenAfterTypeConstraint.IsParentKind(SyntaxKind.TypeParameterConstraintClause))
                    {
                        return CreateAdjustNewLinesOperation(1, AdjustNewLinesOption.PreserveLines);
                    }
                }

                return null;
            }

            // if operation is already forced, return as it is.
            if (operation.Option == AdjustNewLinesOption.ForceLines)
            {
                return operation;
            }

            if (!CommonFormattingHelpers.HasAnyWhitespaceElasticTrivia(previousToken, currentToken))
            {
                return operation;
            }

            var betweenMemberOperation = GetAdjustNewLinesOperationBetweenMembers((SyntaxToken)previousToken, (SyntaxToken)currentToken);
            if (betweenMemberOperation != null)
            {
                return betweenMemberOperation;
            }

            var line = Math.Max(LineBreaksAfter(previousToken, currentToken), operation.Line);
            if (line == 0)
            {
                return CreateAdjustNewLinesOperation(0, AdjustNewLinesOption.PreserveLines);
            }

            return CreateAdjustNewLinesOperation(line, AdjustNewLinesOption.ForceLines);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:55,代码来源:ElasticTriviaFormattingRule.cs

示例4: LocalVariableConflict

        public bool LocalVariableConflict(
            SyntaxToken token)
        {
            if (token.IsParentKind(SyntaxKind.IdentifierName) &&
                token.Parent.IsParentKind(SyntaxKind.InvocationExpression) &&
                token.GetPreviousToken().CSharpKind() != SyntaxKind.DotToken &&
                token.GetNextToken().CSharpKind() != SyntaxKind.DotToken)
            {
                var expression = (ExpressionSyntax)token.Parent;
                var enclosingMemberDeclaration = expression.FirstAncestorOrSelf<MemberDeclarationSyntax>();
                if (enclosingMemberDeclaration != null)
                {
                    var locals = enclosingMemberDeclaration.GetLocalDeclarationMap()[token.ValueText];
                    if (locals.Length > 0)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:22,代码来源:CSharpRenameRewriterLanguageService.cs

示例5: RenameWithinToken

            private SyntaxToken RenameWithinToken(SyntaxToken oldToken, SyntaxToken newToken)
            {
                if (this.isProcessingComplexifiedSpans ||
                    (this.isProcessingTrivia == 0 &&
                    !this.stringAndCommentTextSpans.Contains(oldToken.Span)))
                {
                    return newToken;
                }

                if (this.isRenamingInStrings && newToken.IsKind(SyntaxKind.StringLiteralToken))
                {
                    newToken = RenameInStringLiteral(oldToken, newToken, SyntaxFactory.Literal);
                }

                if (this.isRenamingInComments)
                {
                    if (newToken.IsKind(SyntaxKind.XmlTextLiteralToken))
                    {
                        newToken = RenameInStringLiteral(oldToken, newToken, SyntaxFactory.XmlTextLiteral);
                    }
                    else if (newToken.IsKind(SyntaxKind.IdentifierToken) && newToken.IsParentKind(SyntaxKind.XmlName) && newToken.ValueText == this.originalText)
                    {
                        var newIdentifierToken = SyntaxFactory.Identifier(newToken.LeadingTrivia, replacementText, newToken.TrailingTrivia);
                        newToken = newToken.CopyAnnotationsTo(this.renameAnnotations.WithAdditionalAnnotations(newIdentifierToken, new RenameTokenSimplificationAnnotation() { OriginalTextSpan = oldToken.Span }));
                        AddModifiedSpan(oldToken.Span, newToken.Span);
                    }

                    if (newToken.HasLeadingTrivia)
                    {
                        var updatedToken = RenameInTrivia(oldToken, oldToken.LeadingTrivia);
                        if (updatedToken != oldToken)
                        {
                            newToken = newToken.WithLeadingTrivia(updatedToken.LeadingTrivia);
                        }
                    }

                    if (newToken.HasTrailingTrivia)
                    {
                        var updatedToken = RenameInTrivia(oldToken, oldToken.TrailingTrivia);
                        if (updatedToken != oldToken)
                        {
                            newToken = newToken.WithTrailingTrivia(updatedToken.TrailingTrivia);
                        }
                    }
                }

                return newToken;
            }
开发者ID:riversky,项目名称:roslyn,代码行数:48,代码来源:CSharpRenameRewriterLanguageService.cs

示例6: IsActualContextualKeyword

        private static bool IsActualContextualKeyword(SyntaxToken token)
        {
            if (token.IsParentKind(SyntaxKind.LabeledStatement))
            {
                var statement = (LabeledStatementSyntax)token.Parent;
                if (statement.Identifier == token)
                {
                    return false;
                }
            }

            // Ensure that the text and value text are the same. Otherwise, the identifier might
            // be escaped. I.e. "var", but not "@var"
            if (token.ToString() != token.ValueText)
            {
                return false;
            }

            // Standard cases.  We can just check the parent and see if we're
            // in the right position to be considered a contextual keyword
            if (token.Parent != null)
            {
                switch (token.ValueText)
                {
                    case FromKeyword:
                        var fromClause = token.Parent.FirstAncestorOrSelf<FromClauseSyntax>();
                        return fromClause != null && fromClause.FromKeyword == token;

                    case VarKeyword:
                        // we allow var any time it looks like a variable declaration, and is not in a
                        // field or event field.
                        return
                            token.Parent is IdentifierNameSyntax &&
                            token.Parent.Parent is VariableDeclarationSyntax &&
                            !(token.Parent.Parent.Parent is FieldDeclarationSyntax) &&
                            !(token.Parent.Parent.Parent is EventFieldDeclarationSyntax);
                }
            }

            return false;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:41,代码来源:ClassificationHelpers.cs


注:本文中的SyntaxToken.IsParentKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。