public static bool IsOperator(this SyntaxToken token) { var kind = token.Kind(); return ((SyntaxFacts.IsAnyUnaryExpression(kind) && (token.Parent is PrefixUnaryExpressionSyntax || token.Parent is PostfixUnaryExpressionSyntax)) || (SyntaxFacts.IsBinaryExpression(kind) && token.Parent is BinaryExpressionSyntax) || (SyntaxFacts.IsAssignmentExpressionOperatorToken(kind) && token.Parent is AssignmentExpressionSyntax)); }
private static bool TryGetTextForOperator(SyntaxToken token, Document document, out string text) { if (token.IsKind(SyntaxKind.ExclamationToken) && token.Parent.IsKind(SyntaxKind.SuppressNullableWarningExpression)) { text = Keyword("nullForgiving"); return(true); } var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>(); if (syntaxFacts.IsOperator(token) || syntaxFacts.IsPredefinedOperator(token) || SyntaxFacts.IsAssignmentExpressionOperatorToken(token.Kind())) { text = Keyword(syntaxFacts.GetText(token.RawKind)); return(true); } if (token.IsKind(SyntaxKind.ColonColonToken)) { text = "::_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.ColonToken) && token.Parent is NameColonSyntax) { text = "namedParameter_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.QuestionToken) && token.Parent is ConditionalExpressionSyntax) { text = "?_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.EqualsGreaterThanToken)) { text = "=>_CSharpKeyword"; return(true); } text = null; return(false); }
private bool TryGetTextForOperator(SyntaxToken token, Document document, out string text) { var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>(); if (syntaxFacts.IsOperator(token) || syntaxFacts.IsPredefinedOperator(token) || SyntaxFacts.IsAssignmentExpressionOperatorToken(token.Kind())) { text = Keyword(syntaxFacts.GetText(token.RawKind)); return(true); } if (token.IsKind(SyntaxKind.ColonColonToken)) { text = "::_CSharpKeyword"; return(true); } if (token.Kind() == SyntaxKind.ColonToken && token.Parent is NameColonSyntax) { text = "cs_namedParameter"; return(true); } if (token.IsKind(SyntaxKind.QuestionToken) && token.Parent is ConditionalExpressionSyntax) { text = "?_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.EqualsGreaterThanToken)) { text = "=>_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.PlusEqualsToken)) { text = "+=_CSharpKeyword"; return(true); } if (token.IsKind(SyntaxKind.MinusEqualsToken)) { text = "-=_CSharpKeyword"; return(true); } text = null; return(false); }