本文整理汇总了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;
}
}
示例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;
//.........这里部分代码省略.........
示例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);
}
示例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;
}
示例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;
}
示例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;
}