本文整理汇总了C#中SyntaxTrivia.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTrivia.Kind方法的具体用法?C# SyntaxTrivia.Kind怎么用?C# SyntaxTrivia.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTrivia
的用法示例。
在下文中一共展示了SyntaxTrivia.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia)
{
if (trivia == _region)
{
_nests = 0;
return SyntaxFactory.ElasticSpace;
}
else if (_nests >= 0)
{
_nests++;
}
}
else if (trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
{
if (_nests == 0)
{
_nests = -1;
return SyntaxFactory.ElasticSpace;
}
else if (_nests >= 0)
{
_nests--;
}
}
return base.VisitTrivia(trivia);
}
开发者ID:miya2000,项目名称:RemoveRegionCodeRefactoringSample,代码行数:29,代码来源:RemoveRegionCodeRefactoringSampleProvider.cs
示例2: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.WhitespaceTrivia ||
trivia.Kind() == SyntaxKind.EndOfLineTrivia)
return SyntaxTrivia(SyntaxKind.WhitespaceTrivia, string.Empty);
return base.VisitTrivia(trivia);
}
示例3: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
SyntaxTrivia updatedTrivia = base.VisitTrivia(trivia);
if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia ||
trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
{
// Remove the trivia entirely by returning default(SyntaxTrivia).
updatedTrivia = default(SyntaxTrivia);
}
return updatedTrivia;
}
示例4: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
SyntaxTrivia updatedTrivia = base.VisitTrivia(trivia);
if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia ||
trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
{
// Remove the trivia entirely by returning SyntaxFactory.ElasticSpace.
updatedTrivia = SyntaxFactory.ElasticSpace;
}
return updatedTrivia;
}
示例5: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
{
if (IsBeginningOrEndOfDocumentComment(trivia))
{
return base.VisitTrivia(trivia);
}
else
{
var triviaText = trivia.ToFullString();
var newTriviaText = triviaText.AdjustIndentForXmlDocExteriorTrivia(
_forceIndentation,
_indentation,
_indentationDelta,
_optionSet.GetOption(FormattingOptions.UseTabs, LanguageNames.CSharp),
_optionSet.GetOption(FormattingOptions.TabSize, LanguageNames.CSharp));
if (triviaText == newTriviaText)
{
return base.VisitTrivia(trivia);
}
var parsedNewTrivia = SyntaxFactory.DocumentationCommentExterior(newTriviaText);
return parsedNewTrivia;
}
}
return base.VisitTrivia(trivia);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:32,代码来源:CSharpTriviaFormatter.DocumentationCommentExteriorCommentRewriter.cs
示例6: UnsupportedTriviaKind
private static bool UnsupportedTriviaKind(SyntaxTrivia trivia)
{
switch (trivia.Kind())
{
case SyntaxKind.WhitespaceTrivia:
case SyntaxKind.EndOfLineTrivia:
case SyntaxKind.MultiLineCommentTrivia:
return false;
default:
return true;
}
}
示例7: IsMultiLine
public static bool IsMultiLine(SyntaxTrivia trivia)
{
switch (trivia.Kind())
{
case SyntaxKind.EndOfLineTrivia:
return true;
case SyntaxKind.WhitespaceTrivia:
case SyntaxKind.SingleLineCommentTrivia:
return false;
// todo could possibly optimize for structured trivia
default:
return trivia.ToFullString().IndexOf('\n') >= 0;
}
}
示例8: AcceptableSingleLineTrivia
private static bool AcceptableSingleLineTrivia(SyntaxTrivia trivia)
{
switch (trivia.Kind())
{
case SyntaxKind.WhitespaceTrivia:
case SyntaxKind.EndOfLineTrivia:
return true;
case SyntaxKind.MultiLineCommentTrivia:
var lineSpan = trivia.GetLineSpan();
return lineSpan.StartLinePosition.Line == lineSpan.EndLinePosition.Line;
default:
return false;
}
}
示例9: HasEmptyComment
private bool HasEmptyComment(SyntaxTrivia trivia)
{
if (trivia.Kind() != SyntaxKind.SingleLineCommentTrivia)
{
return false;
}
var triviaText = trivia.ToFullString();
// double comment is a sign for stylecop to ignore that comment
if (triviaText.IndexOf("////", StringComparison.Ordinal) != -1)
{
return false;
}
var index = triviaText.IndexOf("//", StringComparison.Ordinal);
if (index == -1)
{
return false;
}
while (triviaText.Length > index && triviaText[index] == '/')
{
index++;
}
if (triviaText.Length <= index)
{
// empty comment
return true;
}
while (triviaText.Length > index && char.IsWhiteSpace(triviaText[index]))
{
index++;
}
if (triviaText.Length <= index)
{
// comment contains only whitespace
return true;
}
return false;
}
示例10: AnalyzeWhitespacesInTrivia
private static void AnalyzeWhitespacesInTrivia(SyntaxTrivia trivia, ref AnalysisResult result)
{
// trivia already has text. getting text should be noop
Debug.Assert(trivia.Kind() == SyntaxKind.WhitespaceTrivia);
Debug.Assert(trivia.Width() == trivia.FullWidth());
int space = 0;
int tab = 0;
int unknownWhitespace = 0;
var text = trivia.ToString();
for (int i = 0; i < trivia.Width(); i++)
{
if (text[i] == ' ')
{
space++;
}
else if (text[i] == '\t')
{
if (result.Space > 0)
{
result.HasTabAfterSpace = true;
}
tab++;
}
else
{
unknownWhitespace++;
}
}
// set result
result.Space += space;
result.Tab += tab;
result.HasUnknownWhitespace |= unknownWhitespace > 0;
result.TreatAsElastic |= trivia.IsElastic();
}
示例11: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.Kind() != SyntaxKind.MultiLineDocumentationCommentTrivia)
{
base.VisitTrivia(trivia);
return;
}
var tokens = trivia.ToFullString()
.RemoveLeadingAndTrailingMultiLineComments()
.SplitOnNewLines(StringSplitOptions.None);
var builder = new StringBuilder();
foreach (var token in tokens)
{
var currentToken = token.RemoveLeadingSpacesAndAsterisk();
var decodedToken = System.Net.WebUtility.HtmlDecode(currentToken);
builder.AppendLine(decodedToken);
}
var text = builder.ToString();
var line = _firstVisit
? trivia.SyntaxTree.GetLineSpan(trivia.Span).StartLinePosition.Line
: _lineNumberOverride.GetValueOrDefault(0);
this.Blocks.Add(new TextBlock(text, line));
}
示例12: OnPreprocessor
private bool OnPreprocessor(SyntaxTrivia trivia, int currentIndex)
{
if (!SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
{
return false;
}
if (!this.UseIndentation)
{
return true;
}
// preprocessor must be at from column 0
if (_indentation != 0)
{
return true;
}
ResetStateAfterNewLine(currentIndex);
return false;
}
示例13: OnSkippedTokensOrText
private bool OnSkippedTokensOrText(SyntaxTrivia trivia)
{
if (trivia.Kind() != SyntaxKind.SkippedTokensTrivia &&
trivia.Kind() != SyntaxKind.PreprocessingMessageTrivia)
{
return false;
}
return Contract.FailWithReturn<bool>("This can't happen");
}
示例14: IsComment
private static bool IsComment(SyntaxTrivia trivia)
{
return TriviaKinds.Contains(trivia.Kind());
}
示例15: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
bool isDocComment = SyntaxFacts.IsDocumentationCommentTrivia(trivia.Kind());
if (isDocComment ||
trivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
{
Results.AppendLine();
Results.Append(trivia.ToFullString().Trim());
Results.Append(" (Parent Token: ");
Results.Append(trivia.Token.Kind());
Results.Append(")");
if (isDocComment)
{
// Trivia for xml documentation comments have additional 'structure'
// available under a child DocumentationCommentSyntax.
Assert.True(trivia.HasStructure);
var documentationComment =
(DocumentationCommentTriviaSyntax)trivia.GetStructure();
Assert.True(documentationComment.ParentTrivia == trivia);
Results.Append(" (Structured)");
}
}
base.VisitTrivia(trivia);
}