本文整理汇总了C#中SyntaxToken.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.GetLocation方法的具体用法?C# SyntaxToken.GetLocation怎么用?C# SyntaxToken.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxToken
的用法示例。
在下文中一共展示了SyntaxToken.GetLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FadeOutToken
private static void FadeOutToken(SyntaxNodeAnalysisContext context, SyntaxToken token)
{
if (!token.IsMissing)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.FadedToken, token.GetLocation()));
}
}
示例2: HandleOpenBraceToken
private static void HandleOpenBraceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
bool followedBySpace = token.IsFollowedByWhitespace();
if (token.Parent is InterpolationSyntax)
{
if (followedBySpace)
{
// Opening curly bracket must{} be {followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), " not", "followed"));
}
return;
}
bool precededBySpace = token.IsFirstInLine() || token.IsPrecededByWhitespace();
if (!precededBySpace)
{
// Opening curly bracket must{} be {preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), string.Empty, "preceded"));
}
if (!token.IsLastInLine() && !followedBySpace)
{
// Opening curly bracket must{} be {followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), string.Empty, "followed"));
}
}
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:34,代码来源:SA1012OpeningCurlyBracketsMustBeSpacedCorrectly.cs
示例3: HandleCloseBraceToken
private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
bool precededBySpace = token.IsFirstInLine() || token.IsPrecededByWhitespace();
if (token.Parent is InterpolationSyntax)
{
if (precededBySpace)
{
// Closing curly bracket must{ not} be {preceded} by a space.
var properties = TokenSpacingCodeFixProvider.RemovePreceding;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "preceded"));
}
return;
}
bool followedBySpace = token.IsFollowedByWhitespace();
bool lastInLine = token.IsLastInLine();
bool precedesSpecialCharacter;
if (!followedBySpace && !lastInLine)
{
SyntaxToken nextToken = token.GetNextToken();
precedesSpecialCharacter =
nextToken.IsKind(SyntaxKind.CloseParenToken)
|| nextToken.IsKind(SyntaxKind.CommaToken)
|| nextToken.IsKind(SyntaxKind.SemicolonToken)
|| nextToken.IsKind(SyntaxKind.DotToken)
|| (nextToken.IsKind(SyntaxKind.QuestionToken) && nextToken.GetNextToken(includeZeroWidth: true).IsKind(SyntaxKind.DotToken))
|| nextToken.IsKind(SyntaxKind.CloseBracketToken);
}
else
{
precedesSpecialCharacter = false;
}
if (!precededBySpace)
{
// Closing curly bracket must{} be {preceded} by a space.
var properties = TokenSpacingCodeFixProvider.InsertPreceding;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "preceded"));
}
if (!lastInLine && !precedesSpecialCharacter && !followedBySpace)
{
// Closing curly bracket must{} be {followed} by a space.
var properties = TokenSpacingCodeFixProvider.InsertFollowing;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed"));
}
}
示例4: HandleCloseBraceToken
private static void HandleCloseBraceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
bool precededBySpace = token.IsFirstInLine() || token.IsPrecededByWhitespace();
if (token.Parent is InterpolationSyntax)
{
if (precededBySpace)
{
// Closing curly bracket must{ not} be {preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), " not", "preceded"));
}
return;
}
bool followedBySpace = token.IsFollowedByWhitespace();
bool lastInLine = token.IsLastInLine();
bool precedesSpecialCharacter;
if (!followedBySpace && !lastInLine)
{
SyntaxToken nextToken = token.GetNextToken();
precedesSpecialCharacter =
nextToken.IsKind(SyntaxKind.CloseParenToken)
|| nextToken.IsKind(SyntaxKind.CommaToken)
|| nextToken.IsKind(SyntaxKind.SemicolonToken);
}
else
{
precedesSpecialCharacter = false;
}
if (!precededBySpace)
{
// Closing curly bracket must{} be {preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), string.Empty, "preceded"));
}
if (!lastInLine && !precedesSpecialCharacter && !followedBySpace)
{
// Closing curly bracket must{} be {followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), string.Empty, "followed"));
}
}
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:49,代码来源:SA1013ClosingCurlyBracketsMustBeSpacedCorrectly.cs
示例5: AddRangeVariable
internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identifier, DiagnosticBag diagnostics)
{
string name = identifier.ValueText;
var result = new RangeVariableSymbol(name, binder.ContainingMemberOrLambda, identifier.GetLocation());
bool error = false;
foreach (var existingRangeVariable in allRangeVariables.Keys)
{
if (existingRangeVariable.Name == name)
{
diagnostics.Add(ErrorCode.ERR_QueryDuplicateRangeVariable, identifier.GetLocation(), name);
error = true;
}
}
if (!error)
{
var collisionDetector = new LocalScopeBinder(binder);
collisionDetector.ValidateDeclarationNameConflictsInScope(result, diagnostics);
}
allRangeVariables.Add(result, ArrayBuilder<string>.GetInstance());
return result;
}
示例6: SourceLocalSymbol
private SourceLocalSymbol(
Symbol containingSymbol,
Binder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
LocalDeclarationKind declarationKind)
{
Debug.Assert(identifierToken.Kind() != SyntaxKind.None);
Debug.Assert(declarationKind != LocalDeclarationKind.None);
this.binder = binder;
_containingSymbol = containingSymbol;
_identifierToken = identifierToken;
_typeSyntax = typeSyntax;
_declarationKind = declarationKind;
// create this eagerly as it will always be needed for the EnsureSingleDefinition
_locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
}
示例7: SourceEventSymbol
// TODO: CLSCompliantAttribute
internal SourceEventSymbol(
SourceMemberContainerTypeSymbol containingType,
CSharpSyntaxNode syntax,
SyntaxTokenList modifiers,
ExplicitInterfaceSpecifierSyntax interfaceSpecifierSyntaxOpt,
SyntaxToken nameTokenSyntax,
DiagnosticBag diagnostics)
{
_location = nameTokenSyntax.GetLocation();
this.containingType = containingType;
_syntaxRef = syntax.GetReference();
var isExplicitInterfaceImplementation = interfaceSpecifierSyntaxOpt != null;
bool modifierErrors;
_modifiers = MakeModifiers(modifiers, isExplicitInterfaceImplementation, _location, diagnostics, out modifierErrors);
this.CheckAccessibility(_location, diagnostics);
}
示例8: SourceLocalSymbol
private SourceLocalSymbol(
Symbol containingSymbol,
Binder scopeBinder,
bool allowRefKind,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
LocalDeclarationKind declarationKind)
{
Debug.Assert(identifierToken.Kind() != SyntaxKind.None);
Debug.Assert(declarationKind != LocalDeclarationKind.None);
Debug.Assert(scopeBinder != null);
this._scopeBinder = scopeBinder;
this._containingSymbol = containingSymbol;
this._identifierToken = identifierToken;
this._typeSyntax = allowRefKind ? typeSyntax.SkipRef(out this._refKind) : typeSyntax;
this._declarationKind = declarationKind;
// create this eagerly as it will always be needed for the EnsureSingleDefinition
_locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());
}
示例9: HandleOpenBraceToken
private static void HandleOpenBraceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
bool followedBySpace = token.IsFollowedByWhitespace();
if (token.Parent is InterpolationSyntax)
{
if (followedBySpace)
{
// Opening brace must{} be {followed} by a space.
var properties = TokenSpacingProperties.RemoveFollowing;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, " not", "followed"));
}
return;
}
bool precededBySpace = token.IsFirstInLine() || token.IsPrecededByWhitespace(context.CancellationToken);
if (!precededBySpace)
{
// Opening brace must{} be {preceded} by a space.
var properties = TokenSpacingProperties.InsertPreceding;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "preceded"));
}
if (!token.IsLastInLine() && !followedBySpace)
{
// Opening brace must{} be {followed} by a space.
var properties = TokenSpacingProperties.InsertFollowing;
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties, string.Empty, "followed"));
}
}
示例10: DetermineIfRenamableSymbolAsync
private async Task<TriggerIdentifierKind> DetermineIfRenamableSymbolAsync(ISymbol symbol, Document document, SyntaxToken token)
{
// Get the source symbol if possible
var sourceSymbol = await SymbolFinder.FindSourceDefinitionAsync(symbol, document.Project.Solution, _cancellationToken).ConfigureAwait(false) ?? symbol;
if (!sourceSymbol.Locations.All(loc => loc.IsInSource))
{
return TriggerIdentifierKind.NotRenamable;
}
return sourceSymbol.Locations.Any(loc => loc == token.GetLocation())
? TriggerIdentifierKind.RenamableDeclaration
: TriggerIdentifierKind.RenamableReference;
}
示例11: HandleMinusToken
private static void HandleMinusToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
if (!token.Parent.IsKind(SyntaxKind.UnaryMinusExpression))
{
return;
}
bool precededBySpace = true;
bool firstInLine = token.IsFirstInLine();
bool followsSpecialCharacter = false;
bool followedBySpace = token.IsFollowedByWhitespace();
bool lastInLine = token.IsLastInLine();
if (!firstInLine)
{
precededBySpace = token.IsPrecededByWhitespace(context.CancellationToken);
SyntaxToken precedingToken = token.GetPreviousToken();
followsSpecialCharacter =
precedingToken.IsKind(SyntaxKind.OpenBracketToken)
|| precedingToken.IsKind(SyntaxKind.OpenParenToken)
|| precedingToken.IsKind(SyntaxKind.CloseParenToken);
}
if (!firstInLine)
{
if (!followsSpecialCharacter && !precededBySpace)
{
// Negative sign must{} be {preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.InsertPreceding, string.Empty, "preceded"));
}
else if (followsSpecialCharacter && precededBySpace)
{
// Negative sign must{ not} be {preceded} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.RemovePreceding, " not", "preceded"));
}
}
if (lastInLine || followedBySpace)
{
// Negative sign must{ not} be {followed} by a space.
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.RemoveFollowing, " not", "followed"));
}
}
示例12: CheckMatch
private static void CheckMatch(IEnumerable<ISymbol> members, SyntaxToken identifier, SyntaxNodeAnalysisContext c)
{
var matchingMember = members.FirstOrDefault(m => m.Name == identifier.Text);
if (matchingMember != null)
{
c.ReportDiagnostic(Diagnostic.Create(Rule, identifier.GetLocation(),
identifier.Text,
(matchingMember is IFieldSymbol) ? "field" : "property"));
}
}
示例13: HandleOpenBraceToken
private static void HandleOpenBraceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
bool followedBySpace = token.IsFollowedByWhitespace();
if (token.Parent is InterpolationSyntax)
{
if (followedBySpace)
{
// Opening curly bracket must{} be {followed} by a space.
var properties = new Dictionary<string, string>
{
[OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing,
[OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionRemove
};
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), " not", "followed"));
}
return;
}
bool precededBySpace = token.IsFirstInLine() || token.IsPrecededByWhitespace();
if (!precededBySpace)
{
// Opening curly bracket must{} be {preceded} by a space.
var properties = new Dictionary<string, string>
{
[OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding,
[OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert
};
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "preceded"));
}
if (!token.IsLastInLine() && !followedBySpace)
{
// Opening curly bracket must{} be {followed} by a space.
var properties = new Dictionary<string, string>
{
[OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationFollowing,
[OpenCloseSpacingCodeFixProvider.ActionKey] = OpenCloseSpacingCodeFixProvider.ActionInsert
};
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), properties.ToImmutableDictionary(), string.Empty, "followed"));
}
}
示例14: HandleRequiredSpaceToken
private static void HandleRequiredSpaceToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
{
if (token.IsMissing)
{
return;
}
if (token.HasTrailingTrivia)
{
if (token.TrailingTrivia.First().IsKind(SyntaxKind.WhitespaceTrivia))
{
return;
}
if (token.TrailingTrivia.First().IsKind(SyntaxKind.EndOfLineTrivia))
{
return;
}
}
context.ReportDiagnostic(Diagnostic.Create(Descriptor, token.GetLocation(), TokenSpacingProperties.InsertFollowing, token.Text, string.Empty));
}
示例15: CheckIdentifier
private static void CheckIdentifier(SyntaxNodeAnalysisContext context, SyntaxToken identifier)
{
if (identifier.IsMissing)
{
return;
}
string name = identifier.ValueText;
if (string.IsNullOrEmpty(name) || char.IsLower(name[0]))
{
return;
}
// Variable names must begin with lower-case letter
context.ReportDiagnostic(Diagnostic.Create(Descriptor, identifier.GetLocation(), name));
}
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:16,代码来源:SA1312VariableNamesMustBeginWithLowerCaseLetter.cs