本文整理汇总了C#中SyntaxToken类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken类的具体用法?C# SyntaxToken怎么用?C# SyntaxToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxToken类属于命名空间,在下文中一共展示了SyntaxToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryDetermineOverridableMembers
static bool TryDetermineOverridableMembers(SemanticModel semanticModel, SyntaxToken startToken, Accessibility seenAccessibility, out ISet<ISymbol> overridableMembers, CancellationToken cancellationToken)
{
var result = new HashSet<ISymbol>();
var containingType = semanticModel.GetEnclosingSymbol<INamedTypeSymbol>(startToken.SpanStart, cancellationToken);
if (containingType != null && !containingType.IsScriptClass && !containingType.IsImplicitClass)
{
if (containingType.TypeKind == TypeKind.Class || containingType.TypeKind == TypeKind.Struct)
{
var baseTypes = containingType.GetBaseTypes().Reverse();
foreach (var type in baseTypes)
{
cancellationToken.ThrowIfCancellationRequested();
// Prefer overrides in derived classes
RemoveOverriddenMembers(result, type, cancellationToken);
// Retain overridable methods
AddProtocolMembers(semanticModel, result, containingType, type, cancellationToken);
}
// Don't suggest already overridden members
RemoveOverriddenMembers(result, containingType, cancellationToken);
}
}
// Filter based on accessibility
if (seenAccessibility != Accessibility.NotApplicable)
{
result.RemoveWhere(m => m.DeclaredAccessibility != seenAccessibility);
}
overridableMembers = result;
return overridableMembers.Count > 0;
}
示例2: GetTextChangeSpan
private TextSpan GetTextChangeSpan(SyntaxToken stringLiteral, int position)
{
return PathCompletionUtilities.GetTextChangeSpan(
quotedPath: stringLiteral.ToString(),
quotedPathStart: stringLiteral.SpanStart,
position: position);
}
示例3: GetCollapsibleStart
private static int GetCollapsibleStart(SyntaxToken firstToken)
{
// If the *next* token has any leading comments, we use the end of the last one.
// If not, we check *this* token to see if it has any trailing comments and use the last one;
// otherwise, we use the end of this token.
var start = firstToken.Span.End;
var nextToken = firstToken.GetNextToken();
if (nextToken.Kind() != SyntaxKind.None && nextToken.HasLeadingTrivia)
{
var lastLeadingCommentTrivia = nextToken.LeadingTrivia.GetLastComment();
if (lastLeadingCommentTrivia != null)
{
start = lastLeadingCommentTrivia.Value.Span.End;
}
}
if (firstToken.HasTrailingTrivia)
{
var lastTrailingCommentTrivia = firstToken.TrailingTrivia.GetLastComment();
if (lastTrailingCommentTrivia != null)
{
start = lastTrailingCommentTrivia.Value.Span.End;
}
}
return start;
}
示例4: IsAfterNameEqualsArgument
private bool IsAfterNameEqualsArgument(SyntaxToken token)
{
var argumentList = token.Parent as AttributeArgumentListSyntax;
if (token.Kind() == SyntaxKind.CommaToken && argumentList != null)
{
foreach (var item in argumentList.Arguments.GetWithSeparators())
{
if (item.IsToken && item.AsToken() == token)
{
return false;
}
if (item.IsNode)
{
var node = item.AsNode() as AttributeArgumentSyntax;
if (node.NameEquals != null)
{
return true;
}
}
}
}
return false;
}
示例5: GetTextBetween
public override string GetTextBetween(SyntaxToken token1, SyntaxToken token2)
{
var text = base.GetTextBetween(token1, token2);
Contract.ThrowIfFalse(text == _debugNodeData.GetTextBetween(token1, token2));
return text;
}
示例6: CheckDeclarationName
private static void CheckDeclarationName(MemberDeclarationSyntax member, SyntaxToken identifier, SyntaxNodeAnalysisContext context)
{
var symbol = context.SemanticModel.GetDeclaredSymbol(member);
if (ClassName.IsTypeComRelated(symbol?.ContainingType) ||
symbol.IsInterfaceImplementationOrMemberOverride() ||
symbol.IsExtern)
{
return;
}
if (identifier.ValueText.StartsWith("_", StringComparison.Ordinal) ||
identifier.ValueText.EndsWith("_", StringComparison.Ordinal))
{
context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
identifier.ValueText, MessageFormatUnderscore));
return;
}
string suggestion;
if (TryGetChangedName(identifier.ValueText, out suggestion))
{
var messageEnding = string.Format(MessageFormatNonUnderscore, suggestion);
context.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(), MethodKindNameMapping[member.Kind()],
identifier.ValueText, messageEnding));
}
}
示例7: GetPreviousEmptyLines
private IEnumerable<SyntaxTrivia> GetPreviousEmptyLines(SyntaxToken openBrace)
{
var result = new List<SyntaxTrivia>();
var lineOfOpenBrace = openBrace.GetLineSpan().StartLinePosition.Line;
var lineToCheck = lineOfOpenBrace - 1;
while (lineToCheck > -1)
{
var trivias = openBrace.LeadingTrivia
.Where(t => t.GetLineSpan().StartLinePosition.Line == lineToCheck)
.ToList();
var endOfLineTrivia = trivias.Where(t => t.IsKind(SyntaxKind.EndOfLineTrivia)).ToList();
if (endOfLineTrivia.Any() && trivias.Except(endOfLineTrivia).All(t => t.IsKind(SyntaxKind.WhitespaceTrivia)))
{
lineToCheck--;
result.AddRange(trivias);
}
else
{
break;
}
}
return result;
}
示例8: MethodDeclaration
public static MethodDeclarationSyntax MethodDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
TypeSyntax returnType,
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
SyntaxToken identifier,
TypeParameterListSyntax typeParameterList,
ParameterListSyntax parameterList,
SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
BlockSyntax body,
SyntaxToken semicolonToken)
{
return SyntaxFactory.MethodDeclaration(
attributeLists,
modifiers,
default(SyntaxToken),
returnType,
explicitInterfaceSpecifier,
identifier,
typeParameterList,
parameterList,
constraintClauses,
body,
default(ArrowExpressionClauseSyntax),
semicolonToken);
}
示例9: HandleCloseBracketToken
private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
if (!token.Parent.IsKind(SyntaxKind.AttributeList))
{
return;
}
if (token.IsFirstInLine())
{
return;
}
SyntaxToken precedingToken = token.GetPreviousToken();
if (!precedingToken.HasTrailingTrivia)
{
return;
}
if (!precedingToken.TrailingTrivia.Last().IsKind(SyntaxKind.WhitespaceTrivia))
{
return;
}
// Closing attribute brackets must not be preceded by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.RemoveImmediatePreceding));
}
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:31,代码来源:SA1017ClosingAttributeBracketsMustBeSpacedCorrectly.cs
示例10: CreatePragmaDirectiveTrivia
private SyntaxTriviaList CreatePragmaDirectiveTrivia(SyntaxToken disableOrRestoreKeyword, Diagnostic diagnostic, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine)
{
var id = SyntaxFactory.IdentifierName(diagnostic.Id);
var ids = new SeparatedSyntaxList<ExpressionSyntax>().Add(id);
var pragmaDirective = SyntaxFactory.PragmaWarningDirectiveTrivia(disableOrRestoreKeyword, ids, true);
var pragmaDirectiveTrivia = SyntaxFactory.Trivia(pragmaDirective.WithAdditionalAnnotations(Formatter.Annotation));
var endOfLineTrivia = SyntaxFactory.EndOfLine(@"
");
var triviaList = SyntaxFactory.TriviaList(pragmaDirectiveTrivia);
var title = diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture);
if (!string.IsNullOrWhiteSpace(title))
{
var titleComment = SyntaxFactory.Comment(string.Format(" // {0}", title)).WithAdditionalAnnotations(Formatter.Annotation);
triviaList = triviaList.Add(titleComment);
}
if (needsLeadingEndOfLine)
{
triviaList = triviaList.Insert(0, endOfLineTrivia);
}
if (needsTrailingEndOfLine)
{
triviaList = triviaList.Add(endOfLineTrivia);
}
return triviaList;
}
示例11: UvssEventTriggerSyntax
/// <summary>
/// Initializes a new instance of the <see cref="UvssEventTriggerSyntax"/> class.
/// </summary>
internal UvssEventTriggerSyntax(
SyntaxToken triggerKeyword,
SyntaxToken eventKeyword,
UvssEventNameSyntax eventName,
UvssEventTriggerArgumentList argumentList,
SyntaxToken qualifierToken,
UvssBlockSyntax body)
: base(SyntaxKind.EventTrigger)
{
this.TriggerKeyword = triggerKeyword;
ChangeParent(triggerKeyword);
this.EventKeyword = eventKeyword;
ChangeParent(eventKeyword);
this.EventName = eventName;
ChangeParent(eventName);
this.ArgumentList = argumentList;
ChangeParent(argumentList);
this.QualifierToken = qualifierToken;
ChangeParent(qualifierToken);
this.Body = body;
ChangeParent(body);
SlotCount = 6;
UpdateIsMissing();
}
示例12: HandleOpenBracketToken
private static void HandleOpenBracketToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
bool firstInLine = token.IsFirstInLine();
bool precededBySpace = true;
bool ignorePrecedingSpaceProblem = false;
if (!firstInLine)
{
precededBySpace = token.IsPrecededByWhitespace();
// ignore if handled by SA1026
ignorePrecedingSpaceProblem = precededBySpace && token.GetPreviousToken().IsKind(SyntaxKind.NewKeyword);
}
bool followedBySpace = token.IsFollowedByWhitespace();
bool lastInLine = token.IsLastInLine();
if (!firstInLine && precededBySpace && !ignorePrecedingSpaceProblem && !lastInLine && followedBySpace)
{
// Opening square bracket must {neither preceded nor followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "neither preceded nor followed"));
}
else if (!firstInLine && precededBySpace && !ignorePrecedingSpaceProblem)
{
// Opening square bracket must {not be preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "not be preceded"));
}
else if (!lastInLine && followedBySpace)
{
// Opening square bracket must {not be followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), "not be followed"));
}
}
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:33,代码来源:SA1010OpeningSquareBracketsMustBeSpacedCorrectly.cs
示例13: CreatePragmaDirectiveTriviaAsync
private async Task<SyntaxTriviaList> CreatePragmaDirectiveTriviaAsync(
SyntaxToken disableOrRestoreKeyword, Diagnostic diagnostic, Func<SyntaxNode, Task<SyntaxNode>> formatNode, bool needsLeadingEndOfLine, bool needsTrailingEndOfLine)
{
var id = SyntaxFactory.IdentifierName(diagnostic.Id);
var ids = new SeparatedSyntaxList<ExpressionSyntax>().Add(id);
var pragmaDirective = SyntaxFactory.PragmaWarningDirectiveTrivia(disableOrRestoreKeyword, ids, true);
pragmaDirective = (PragmaWarningDirectiveTriviaSyntax)await formatNode(pragmaDirective).ConfigureAwait(false);
var pragmaDirectiveTrivia = SyntaxFactory.Trivia(pragmaDirective);
var endOfLineTrivia = SyntaxFactory.ElasticCarriageReturnLineFeed;
var triviaList = SyntaxFactory.TriviaList(pragmaDirectiveTrivia);
var title = diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture);
if (!string.IsNullOrWhiteSpace(title))
{
var titleComment = SyntaxFactory.Comment(string.Format(" // {0}", title)).WithAdditionalAnnotations(Formatter.Annotation);
triviaList = triviaList.Add(titleComment);
}
if (needsLeadingEndOfLine)
{
triviaList = triviaList.Insert(0, endOfLineTrivia);
}
if (needsTrailingEndOfLine)
{
triviaList = triviaList.Add(endOfLineTrivia);
}
return triviaList;
}
示例14: FixOpenBraceNextToken
/// <summary>
/// Remove the extra new lines on the token which immediately follows an open brace.
/// </summary>
private static SyntaxToken FixOpenBraceNextToken(SyntaxToken token)
{
if (!token.HasLeadingTrivia)
{
return token;
}
if (token.Kind() == SyntaxKind.CloseBraceToken &&
token.LeadingTrivia.All(x => x.IsKind(SyntaxKind.WhitespaceTrivia) || x.IsKind(SyntaxKind.EndOfLineTrivia)))
{
// This is an open / close brace combo with no content inbetween. Just return the
// close brace and let the formatter handle the white space issues. If there was a new line
// between the two it will be attached to the open brace and hence maintained.
return token.WithLeadingTrivia(SyntaxTriviaList.Empty);
}
// Remove all of the new lines at the top
var triviaList = token.LeadingTrivia;
var list = new List<SyntaxTrivia>(triviaList.Count);
var index = MovePastSimpleNewLines(triviaList, 0);
while (index < triviaList.Count)
{
list.Add(triviaList[index]);
index++;
}
var newTriviaList = SyntaxFactory.TriviaList(list);
return token.WithLeadingTrivia(newTriviaList);
}
示例15: GetPathThroughLastSlash
private string GetPathThroughLastSlash(SyntaxToken stringLiteral, int position)
{
return PathCompletionUtilities.GetPathThroughLastSlash(
quotedPath: stringLiteral.ToString(),
quotedPathStart: stringLiteral.SpanStart,
position: position);
}