1479 lines
59 KiB
C#
1479 lines
59 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Diagnostics.CodeAnalysis;
|
||
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
||
|
|
using Microsoft.CodeAnalysis.Text;
|
||
|
|
using Roslyn.Utilities;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
|
||
|
|
|
||
|
|
internal class SyntaxNormalizer : CSharpSyntaxRewriter
|
||
|
|
{
|
||
|
|
private readonly TextSpan _consideredSpan;
|
||
|
|
|
||
|
|
private readonly int _initialDepth;
|
||
|
|
|
||
|
|
private readonly string _indentWhitespace;
|
||
|
|
|
||
|
|
private readonly bool _useElasticTrivia;
|
||
|
|
|
||
|
|
private readonly SyntaxTrivia _eolTrivia;
|
||
|
|
|
||
|
|
private bool _isInStructuredTrivia;
|
||
|
|
|
||
|
|
private SyntaxToken _previousToken;
|
||
|
|
|
||
|
|
private bool _afterLineBreak;
|
||
|
|
|
||
|
|
private bool _afterIndentation;
|
||
|
|
|
||
|
|
private bool _inSingleLineInterpolation;
|
||
|
|
|
||
|
|
private ArrayBuilder<SyntaxTrivia>? _indentations;
|
||
|
|
|
||
|
|
private static readonly SyntaxTrivia s_trimmedDocCommentExterior = SyntaxFactory.DocumentationCommentExterior("///");
|
||
|
|
|
||
|
|
private SyntaxNormalizer(TextSpan consideredSpan, int initialDepth, string indentWhitespace, string eolWhitespace, bool useElasticTrivia)
|
||
|
|
: base(visitIntoStructuredTrivia: true)
|
||
|
|
{
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
_consideredSpan = consideredSpan;
|
||
|
|
_initialDepth = initialDepth;
|
||
|
|
_indentWhitespace = indentWhitespace;
|
||
|
|
_useElasticTrivia = useElasticTrivia;
|
||
|
|
_eolTrivia = (useElasticTrivia ? SyntaxFactory.ElasticEndOfLine(eolWhitespace) : SyntaxFactory.EndOfLine(eolWhitespace));
|
||
|
|
_afterLineBreak = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static TNode Normalize<TNode>(TNode node, string indentWhitespace, string eolWhitespace, bool useElasticTrivia = false) where TNode : SyntaxNode
|
||
|
|
{
|
||
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxNormalizer syntaxNormalizer = new SyntaxNormalizer(((SyntaxNode)node).FullSpan, GetDeclarationDepth((SyntaxNode?)(object)node), indentWhitespace, eolWhitespace, useElasticTrivia);
|
||
|
|
TNode result = (TNode)(object)syntaxNormalizer.Visit((SyntaxNode?)(object)node);
|
||
|
|
syntaxNormalizer.Free();
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static SyntaxToken Normalize(SyntaxToken token, string indentWhitespace, string eolWhitespace, bool useElasticTrivia = false)
|
||
|
|
{
|
||
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxNormalizer syntaxNormalizer = new SyntaxNormalizer(((SyntaxToken)(ref token)).FullSpan, GetDeclarationDepth(token), indentWhitespace, eolWhitespace, useElasticTrivia);
|
||
|
|
SyntaxToken result = syntaxNormalizer.VisitToken(token);
|
||
|
|
syntaxNormalizer.Free();
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static SyntaxTriviaList Normalize(SyntaxTriviaList trivia, string indentWhitespace, string eolWhitespace, bool useElasticTrivia = false)
|
||
|
|
{
|
||
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxNormalizer syntaxNormalizer = new SyntaxNormalizer(((SyntaxTriviaList)(ref trivia)).FullSpan, GetDeclarationDepth(((SyntaxTriviaList)(ref trivia)).Token), indentWhitespace, eolWhitespace, useElasticTrivia);
|
||
|
|
SyntaxTriviaList triviaList = trivia;
|
||
|
|
SyntaxTrivia val = ((SyntaxTriviaList)(ref trivia)).ElementAt(0);
|
||
|
|
SyntaxTriviaList result = syntaxNormalizer.RewriteTrivia(triviaList, GetDeclarationDepth(((SyntaxTrivia)(ref val)).Token), isTrailing: false, indentAfterLineBreak: false, mustHaveSeparator: false, 0);
|
||
|
|
syntaxNormalizer.Free();
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Free()
|
||
|
|
{
|
||
|
|
if (_indentations != null)
|
||
|
|
{
|
||
|
|
_indentations.Free();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public override SyntaxToken VisitToken(SyntaxToken token)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (token.Kind() == SyntaxKind.None || (((SyntaxToken)(ref token)).IsMissing && ((SyntaxToken)(ref token)).FullWidth == 0))
|
||
|
|
{
|
||
|
|
return token;
|
||
|
|
}
|
||
|
|
try
|
||
|
|
{
|
||
|
|
SyntaxToken result = token;
|
||
|
|
int declarationDepth = GetDeclarationDepth(token);
|
||
|
|
result = ((SyntaxToken)(ref result)).WithLeadingTrivia(RewriteTrivia(((SyntaxToken)(ref token)).LeadingTrivia, declarationDepth, isTrailing: false, NeedsIndentAfterLineBreak(token), mustHaveSeparator: false, 0));
|
||
|
|
SyntaxToken nextRelevantToken = GetNextRelevantToken(token);
|
||
|
|
_afterLineBreak = IsLineBreak(token);
|
||
|
|
_afterIndentation = false;
|
||
|
|
int lineBreaksAfter = LineBreaksAfter(token, nextRelevantToken);
|
||
|
|
bool mustHaveSeparator = NeedsSeparator(token, nextRelevantToken);
|
||
|
|
result = ((SyntaxToken)(ref result)).WithTrailingTrivia(RewriteTrivia(((SyntaxToken)(ref token)).TrailingTrivia, declarationDepth, isTrailing: true, indentAfterLineBreak: false, mustHaveSeparator, lineBreaksAfter));
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
_previousToken = token;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxToken GetNextRelevantToken(SyntaxToken token)
|
||
|
|
{
|
||
|
|
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxToken nextToken = ((SyntaxToken)(ref token)).GetNextToken((Func<SyntaxToken, bool>)((SyntaxToken t) => SyntaxToken.NonZeroWidth(t) || t.Kind() == SyntaxKind.EndOfDirectiveToken), (Func<SyntaxTrivia, bool>)((SyntaxTrivia t) => t.Kind() == SyntaxKind.SkippedTokensTrivia));
|
||
|
|
if (((TextSpan)(ref _consideredSpan)).Contains(((SyntaxToken)(ref nextToken)).FullSpan))
|
||
|
|
{
|
||
|
|
return nextToken;
|
||
|
|
}
|
||
|
|
return default(SyntaxToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxTrivia GetIndentation(int count)
|
||
|
|
{
|
||
|
|
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
count = Math.Max(count - _initialDepth, 0);
|
||
|
|
int num = count + 1;
|
||
|
|
if (_indentations == null)
|
||
|
|
{
|
||
|
|
_indentations = ArrayBuilder<SyntaxTrivia>.GetInstance(num);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
_indentations.EnsureCapacity(num);
|
||
|
|
}
|
||
|
|
for (int i = _indentations.Count; i <= count; i++)
|
||
|
|
{
|
||
|
|
string text = ((i == 0) ? "" : (((object)_indentations[i - 1]/*cast due to constrained. prefix*/).ToString() + _indentWhitespace));
|
||
|
|
_indentations.Add(_useElasticTrivia ? SyntaxFactory.ElasticWhitespace(text) : SyntaxFactory.Whitespace(text));
|
||
|
|
}
|
||
|
|
return _indentations[count];
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsIndentAfterLineBreak(SyntaxToken token)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return !token.IsKind(SyntaxKind.EndOfFileToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
private int LineBreaksAfter(SyntaxToken currentToken, SyntaxToken nextToken)
|
||
|
|
{
|
||
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_035b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_039e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (_inSingleLineInterpolation)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (currentToken.IsKind(SyntaxKind.EndOfDirectiveToken))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (nextToken.Kind() == SyntaxKind.None)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (_isInStructuredTrivia)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
|
||
|
|
{
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref currentToken)).Parent;
|
||
|
|
if (IsAccessorListWithoutAccessorsWithBlockBody((parent != null) ? parent.Parent : null))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
SyntaxNode parent2 = ((SyntaxToken)(ref nextToken)).Parent;
|
||
|
|
bool flag = ((parent2 is InitializerExpressionSyntax || parent2 is AnonymousObjectCreationExpressionSyntax) ? true : false);
|
||
|
|
if (flag && !IsSingleLineInitializerContext(((SyntaxToken)(ref nextToken)).Parent))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
switch (currentToken.Kind())
|
||
|
|
{
|
||
|
|
case SyntaxKind.None:
|
||
|
|
return 0;
|
||
|
|
case SyntaxKind.OpenBraceToken:
|
||
|
|
return LineBreaksAfterOpenBrace(currentToken);
|
||
|
|
case SyntaxKind.FinallyKeyword:
|
||
|
|
return 1;
|
||
|
|
case SyntaxKind.CloseBraceToken:
|
||
|
|
return LineBreaksAfterCloseBrace(currentToken, nextToken);
|
||
|
|
case SyntaxKind.CloseParenToken:
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is PositionalPatternClauseSyntax)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (nextToken.IsKind(SyntaxKind.OpenBraceToken) && IsInitializerInSingleLineContext(((SyntaxToken)(ref nextToken)).Parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if ((!(((SyntaxToken)(ref currentToken)).Parent is StatementSyntax) || ((SyntaxToken)(ref nextToken)).Parent == ((SyntaxToken)(ref currentToken)).Parent) && nextToken.Kind() != SyntaxKind.OpenBraceToken && nextToken.Kind() != SyntaxKind.WhereKeyword)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
case SyntaxKind.CloseBracketToken:
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is AttributeListSyntax && !(((SyntaxToken)(ref currentToken)).Parent.Parent is ParameterSyntax))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case SyntaxKind.SemicolonToken:
|
||
|
|
return LineBreaksAfterSemicolon(currentToken, nextToken);
|
||
|
|
case SyntaxKind.CommaToken:
|
||
|
|
{
|
||
|
|
SyntaxNode parent2 = ((SyntaxToken)(ref currentToken)).Parent;
|
||
|
|
bool flag = ((parent2 is InitializerExpressionSyntax || parent2 is AnonymousObjectCreationExpressionSyntax) ? true : false);
|
||
|
|
if (flag && !IsSingleLineInitializerContext(((SyntaxToken)(ref nextToken)).Parent))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
parent2 = ((SyntaxToken)(ref currentToken)).Parent;
|
||
|
|
flag = ((parent2 is EnumDeclarationSyntax || parent2 is SwitchExpressionSyntax) ? true : false);
|
||
|
|
return flag ? 1 : 0;
|
||
|
|
}
|
||
|
|
case SyntaxKind.ElseKeyword:
|
||
|
|
return (nextToken.Kind() != SyntaxKind.IfKeyword) ? 1 : 0;
|
||
|
|
case SyntaxKind.ColonToken:
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is LabeledStatementSyntax || ((SyntaxToken)(ref currentToken)).Parent is SwitchLabelSyntax)
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case SyntaxKind.SwitchKeyword:
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is SwitchExpressionSyntax)
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if ((nextToken.IsKind(SyntaxKind.FromKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.FromClause)) || (nextToken.IsKind(SyntaxKind.LetKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.LetClause)) || (nextToken.IsKind(SyntaxKind.WhereKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.WhereClause)) || (nextToken.IsKind(SyntaxKind.JoinKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.JoinClause)) || (nextToken.IsKind(SyntaxKind.JoinKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.JoinIntoClause)) || (nextToken.IsKind(SyntaxKind.OrderByKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.OrderByClause)) || (nextToken.IsKind(SyntaxKind.SelectKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.SelectClause)) || (nextToken.IsKind(SyntaxKind.GroupKeyword) && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.GroupClause)))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
switch (nextToken.Kind())
|
||
|
|
{
|
||
|
|
case SyntaxKind.OpenBraceToken:
|
||
|
|
return LineBreaksBeforeOpenBrace(nextToken);
|
||
|
|
case SyntaxKind.CloseBraceToken:
|
||
|
|
return LineBreaksBeforeCloseBrace(nextToken);
|
||
|
|
case SyntaxKind.ElseKeyword:
|
||
|
|
case SyntaxKind.FinallyKeyword:
|
||
|
|
return 1;
|
||
|
|
case SyntaxKind.OpenBracketToken:
|
||
|
|
if (!(((SyntaxToken)(ref nextToken)).Parent is AttributeListSyntax) || ((SyntaxToken)(ref nextToken)).Parent.Parent is ParameterSyntax)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
case SyntaxKind.WhereKeyword:
|
||
|
|
return (((SyntaxToken)(ref currentToken)).Parent is TypeParameterListSyntax) ? 1 : 0;
|
||
|
|
default:
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsAccessorListWithoutAccessorsWithBlockBody(SyntaxNode? node)
|
||
|
|
{
|
||
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (node is AccessorListSyntax accessorListSyntax)
|
||
|
|
{
|
||
|
|
return accessorListSyntax.Accessors.All((Func<AccessorDeclarationSyntax, bool>)((AccessorDeclarationSyntax a) => a.Body == null));
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsAccessorListFollowedByInitializer([NotNullWhen(true)] SyntaxNode? node)
|
||
|
|
{
|
||
|
|
if (node is AccessorListSyntax { Parent: PropertyDeclarationSyntax parent })
|
||
|
|
{
|
||
|
|
return parent.Initializer != null;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int LineBreaksBeforeOpenBrace(SyntaxToken openBraceToken)
|
||
|
|
{
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref openBraceToken)).Parent;
|
||
|
|
if (parent.IsKind(SyntaxKind.Interpolation) || parent is PropertyPatternClauseSyntax || IsAccessorListWithoutAccessorsWithBlockBody(parent) || IsInitializerInSingleLineContext(parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int LineBreaksBeforeCloseBrace(SyntaxToken closeBraceToken)
|
||
|
|
{
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref closeBraceToken)).Parent;
|
||
|
|
if (parent.IsKind(SyntaxKind.Interpolation) || parent is PropertyPatternClauseSyntax || IsInitializerInSingleLineContext(parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int LineBreaksAfterOpenBrace(SyntaxToken openBraceToken)
|
||
|
|
{
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref openBraceToken)).Parent;
|
||
|
|
if (parent is PropertyPatternClauseSyntax || parent.IsKind(SyntaxKind.Interpolation) || IsAccessorListWithoutAccessorsWithBlockBody(parent) || IsInitializerInSingleLineContext(parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int LineBreaksAfterCloseBrace(SyntaxToken currentToken, SyntaxToken nextToken)
|
||
|
|
{
|
||
|
|
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref currentToken)).Parent;
|
||
|
|
bool flag = ((parent is SwitchExpressionSyntax || parent is PropertyPatternClauseSyntax) ? true : false);
|
||
|
|
bool flag2 = flag || parent.IsKind(SyntaxKind.Interpolation) || ((parent != null) ? parent.Parent : null) is AnonymousFunctionExpressionSyntax || IsAccessorListFollowedByInitializer(parent) || isCloseBraceFollowedByCommaOrSemicolon(currentToken, nextToken);
|
||
|
|
if (!flag2)
|
||
|
|
{
|
||
|
|
SyntaxNode parent2 = ((SyntaxToken)(ref nextToken)).Parent;
|
||
|
|
bool flag3 = ((parent2 is MemberAccessExpressionSyntax || parent2 is BracketedArgumentListSyntax) ? true : false);
|
||
|
|
flag2 = flag3;
|
||
|
|
}
|
||
|
|
if (flag2 || IsInitializerInSingleLineContext(parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (((parent != null) ? parent.Parent : null) is PropertyDeclarationSyntax property && IsSingleLineProperty(property) && ((SyntaxToken)(ref nextToken)).Parent is PropertyDeclarationSyntax property2 && IsSingleLineProperty(property2))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
SyntaxKind syntaxKind = nextToken.Kind();
|
||
|
|
switch (syntaxKind)
|
||
|
|
{
|
||
|
|
case SyntaxKind.CloseBraceToken:
|
||
|
|
case SyntaxKind.ElseKeyword:
|
||
|
|
case SyntaxKind.CatchKeyword:
|
||
|
|
case SyntaxKind.FinallyKeyword:
|
||
|
|
case SyntaxKind.EndOfFileToken:
|
||
|
|
return 1;
|
||
|
|
default:
|
||
|
|
if (syntaxKind == SyntaxKind.WhileKeyword && ((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.DoStatement))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
return 2;
|
||
|
|
}
|
||
|
|
static bool isCloseBraceFollowedByCommaOrSemicolon(SyntaxToken token, SyntaxToken token2)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
bool flag4 = token.IsKind(SyntaxKind.CloseBraceToken);
|
||
|
|
if (flag4)
|
||
|
|
{
|
||
|
|
SyntaxKind syntaxKind2 = token2.Kind();
|
||
|
|
bool flag5 = ((syntaxKind2 == SyntaxKind.SemicolonToken || syntaxKind2 == SyntaxKind.CommaToken) ? true : false);
|
||
|
|
flag4 = flag5;
|
||
|
|
}
|
||
|
|
return flag4;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int LineBreaksAfterSemicolon(SyntaxToken currentToken, SyntaxToken nextToken)
|
||
|
|
{
|
||
|
|
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent.IsKind(SyntaxKind.ForStatement))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (nextToken.Kind() == SyntaxKind.CloseBraceToken)
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent.IsKind(SyntaxKind.UsingDirective))
|
||
|
|
{
|
||
|
|
if (!((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.UsingDirective))
|
||
|
|
{
|
||
|
|
return 2;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent.IsKind(SyntaxKind.ExternAliasDirective))
|
||
|
|
{
|
||
|
|
if (!((SyntaxToken)(ref nextToken)).Parent.IsKind(SyntaxKind.ExternAliasDirective))
|
||
|
|
{
|
||
|
|
return 2;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is AccessorDeclarationSyntax && IsAccessorListWithoutAccessorsWithBlockBody(((SyntaxToken)(ref currentToken)).Parent.Parent))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref currentToken)).Parent is PropertyDeclarationSyntax property)
|
||
|
|
{
|
||
|
|
if (IsSingleLineProperty(property) && ((SyntaxToken)(ref nextToken)).Parent is PropertyDeclarationSyntax property2 && IsSingleLineProperty(property2))
|
||
|
|
{
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
return 2;
|
||
|
|
}
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsSeparatorForPropertyPattern(SyntaxToken token, SyntaxToken next)
|
||
|
|
{
|
||
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
PropertyPatternClauseSyntax propertyPatternClauseSyntax;
|
||
|
|
if (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.PropertyPatternClause))
|
||
|
|
{
|
||
|
|
propertyPatternClauseSyntax = (PropertyPatternClauseSyntax)(object)((SyntaxToken)(ref token)).Parent;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (!((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.PropertyPatternClause))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
propertyPatternClauseSyntax = (PropertyPatternClauseSyntax)(object)((SyntaxToken)(ref next)).Parent;
|
||
|
|
}
|
||
|
|
bool num = token.IsKind(SyntaxKind.OpenBraceToken);
|
||
|
|
bool flag = next.IsKind(SyntaxKind.OpenBraceToken);
|
||
|
|
bool flag2 = token.IsKind(SyntaxKind.CloseBraceToken);
|
||
|
|
bool flag3 = next.IsKind(SyntaxKind.CloseBraceToken);
|
||
|
|
if (num)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (flag3)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (propertyPatternClauseSyntax.Parent is RecursivePatternSyntax recursivePatternSyntax)
|
||
|
|
{
|
||
|
|
if (flag)
|
||
|
|
{
|
||
|
|
if (recursivePatternSyntax.Type != null || recursivePatternSyntax.PositionalPatternClause != null)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (flag2)
|
||
|
|
{
|
||
|
|
if (recursivePatternSyntax.Designation == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsSeparatorForPositionalPattern(SyntaxToken token, SyntaxToken next)
|
||
|
|
{
|
||
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
PositionalPatternClauseSyntax positionalPatternClauseSyntax;
|
||
|
|
if (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.PositionalPatternClause))
|
||
|
|
{
|
||
|
|
positionalPatternClauseSyntax = (PositionalPatternClauseSyntax)(object)((SyntaxToken)(ref token)).Parent;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (!((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.PositionalPatternClause))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
positionalPatternClauseSyntax = (PositionalPatternClauseSyntax)(object)((SyntaxToken)(ref next)).Parent;
|
||
|
|
}
|
||
|
|
bool num = token.IsKind(SyntaxKind.OpenParenToken);
|
||
|
|
bool flag = next.IsKind(SyntaxKind.OpenParenToken);
|
||
|
|
bool flag2 = token.IsKind(SyntaxKind.CloseParenToken);
|
||
|
|
bool flag3 = next.IsKind(SyntaxKind.CloseParenToken);
|
||
|
|
if (num)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (flag3)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (positionalPatternClauseSyntax.Parent is RecursivePatternSyntax recursivePatternSyntax)
|
||
|
|
{
|
||
|
|
if (flag)
|
||
|
|
{
|
||
|
|
if (recursivePatternSyntax.Type != null)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (flag2)
|
||
|
|
{
|
||
|
|
if (recursivePatternSyntax.PropertyPatternClause != null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (recursivePatternSyntax.Designation == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsSeparatorForListPattern(SyntaxToken token, SyntaxToken next)
|
||
|
|
{
|
||
|
|
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
ListPatternSyntax listPatternSyntax = (((SyntaxToken)(ref token)).Parent as ListPatternSyntax) ?? (((SyntaxToken)(ref next)).Parent as ListPatternSyntax);
|
||
|
|
if (listPatternSyntax == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.OpenBracketToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.OpenBracketToken))
|
||
|
|
{
|
||
|
|
return listPatternSyntax.Designation != null;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsSeparator(SyntaxToken token, SyntaxToken next)
|
||
|
|
{
|
||
|
|
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_032d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0410: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_041d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_047b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_051b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_053d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04db: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_054a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0559: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0575: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0566: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0592: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_078e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_079b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0604: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0704: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_080e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0711: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0637: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0821: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0822: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_071e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_082c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_082d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_074b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_072b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0837: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0838: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0758: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_066a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0765: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0772: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_077f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (((SyntaxToken)(ref token)).Parent == null || ((SyntaxToken)(ref next)).Parent == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (IsAccessorListWithoutAccessorsWithBlockBody(((SyntaxToken)(ref next)).Parent) || IsAccessorListWithoutAccessorsWithBlockBody(((SyntaxToken)(ref next)).Parent.Parent))
|
||
|
|
{
|
||
|
|
return !next.IsKind(SyntaxKind.SemicolonToken);
|
||
|
|
}
|
||
|
|
if (IsXmlTextToken(token.Kind()) || IsXmlTextToken(next.Kind()))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (next.Kind() == SyntaxKind.EndOfDirectiveToken)
|
||
|
|
{
|
||
|
|
if (IsKeyword(token.Kind()))
|
||
|
|
{
|
||
|
|
return ((SyntaxToken)(ref next)).LeadingWidth > 0;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if ((((SyntaxToken)(ref token)).Parent is AssignmentExpressionSyntax && AssignmentTokenNeedsSeparator(token.Kind())) || (((SyntaxToken)(ref next)).Parent is AssignmentExpressionSyntax && AssignmentTokenNeedsSeparator(next.Kind())) || (((SyntaxToken)(ref token)).Parent is BinaryExpressionSyntax && BinaryTokenNeedsSeparator(token.Kind())) || (((SyntaxToken)(ref next)).Parent is BinaryExpressionSyntax && BinaryTokenNeedsSeparator(next.Kind())))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.GreaterThanToken) && ((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.TypeArgumentList) && !SyntaxFacts.IsPunctuation(next.Kind()))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.GreaterThanToken) && ((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerParameterList))
|
||
|
|
{
|
||
|
|
SyntaxNode parent = ((SyntaxToken)(ref token)).Parent.Parent;
|
||
|
|
if (!(((parent != null) ? parent.Parent : null) is UsingDirectiveSyntax))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.CommaToken) && !next.IsKind(SyntaxKind.CommaToken) && !((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.EnumDeclaration))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.Kind() == SyntaxKind.SemicolonToken && next.Kind() != SyntaxKind.SemicolonToken && next.Kind() != SyntaxKind.CloseParenToken)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.SwitchKeyword) && ((SyntaxToken)(ref next)).Parent is SwitchExpressionSyntax)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.QuestionToken) && (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.ConditionalExpression) || ((SyntaxToken)(ref token)).Parent is TypeSyntax))
|
||
|
|
{
|
||
|
|
bool flag;
|
||
|
|
switch (((SyntaxToken)(ref token)).Parent.Parent?.Kind())
|
||
|
|
{
|
||
|
|
default:
|
||
|
|
flag = true;
|
||
|
|
break;
|
||
|
|
case SyntaxKind.TypeArgumentList:
|
||
|
|
case SyntaxKind.UsingDirective:
|
||
|
|
flag = false;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (flag)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.ColonToken))
|
||
|
|
{
|
||
|
|
if (!((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.InterpolationFormatClause))
|
||
|
|
{
|
||
|
|
return !((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.XmlPrefix);
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.ColonToken) && (((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.BaseList) || ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.TypeParameterConstraintClause) || ((SyntaxToken)(ref next)).Parent is ConstructorInitializerSyntax))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.CloseBracketToken) && IsWord(next.Kind()))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.CloseParenToken) && IsWord(next.Kind()) && ((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.TupleType))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if ((next.IsKind(SyntaxKind.QuestionToken) || next.IsKind(SyntaxKind.ColonToken)) && ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.ConditionalExpression))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.EqualsToken))
|
||
|
|
{
|
||
|
|
return !((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.XmlTextAttribute);
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.EqualsToken))
|
||
|
|
{
|
||
|
|
return !((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.XmlTextAttribute);
|
||
|
|
}
|
||
|
|
SyntaxKind syntaxKind;
|
||
|
|
if (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerType))
|
||
|
|
{
|
||
|
|
if (next.IsKind(SyntaxKind.AsteriskToken) && token.IsKind(SyntaxKind.DelegateKeyword))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.AsteriskToken) && ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.FunctionPointerCallingConvention))
|
||
|
|
{
|
||
|
|
syntaxKind = next.Kind();
|
||
|
|
if (syntaxKind - 8445 <= SyntaxKind.List || syntaxKind == SyntaxKind.IdentifierToken)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.FunctionPointerParameterList) && next.IsKind(SyntaxKind.LessThanToken))
|
||
|
|
{
|
||
|
|
syntaxKind = token.Kind();
|
||
|
|
if (syntaxKind == SyntaxKind.AsteriskToken)
|
||
|
|
{
|
||
|
|
goto IL_0453;
|
||
|
|
}
|
||
|
|
if (syntaxKind != SyntaxKind.CloseBracketToken)
|
||
|
|
{
|
||
|
|
if (syntaxKind - 8445 <= SyntaxKind.List)
|
||
|
|
{
|
||
|
|
goto IL_0453;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerUnmanagedCallingConventionList))
|
||
|
|
{
|
||
|
|
goto IL_0453;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerCallingConvention) && ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.FunctionPointerUnmanagedCallingConventionList) && next.IsKind(SyntaxKind.OpenBracketToken))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.FunctionPointerUnmanagedCallingConventionList) && ((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerUnmanagedCallingConventionList))
|
||
|
|
{
|
||
|
|
if (next.IsKind(SyntaxKind.IdentifierToken))
|
||
|
|
{
|
||
|
|
if (token.IsKind(SyntaxKind.OpenBracketToken))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.CommaToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.CommaToken))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.CloseBracketToken))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.LessThanToken) && ((SyntaxToken)(ref token)).Parent.IsKind(SyntaxKind.FunctionPointerParameterList))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.GreaterThanToken) && ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.FunctionPointerParameterList))
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.EqualsGreaterThanToken) || next.IsKind(SyntaxKind.EqualsGreaterThanToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (SyntaxFacts.IsLiteral(token.Kind()) && SyntaxFacts.IsLiteral(next.Kind()))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (next.IsKind(SyntaxKind.AsteriskToken) && ((SyntaxToken)(ref next)).Parent is PointerTypeSyntax)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (token.IsKind(SyntaxKind.AsteriskToken) && ((SyntaxToken)(ref token)).Parent is PointerTypeSyntax && (next.IsKind(SyntaxKind.IdentifierToken) || ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.IndexerDeclaration)))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (IsSingleLineInitializerContext(((SyntaxToken)(ref token)).Parent))
|
||
|
|
{
|
||
|
|
SyntaxNode parent2 = ((SyntaxToken)(ref next)).Parent;
|
||
|
|
bool flag = ((parent2 is InitializerExpressionSyntax || parent2 is AnonymousObjectCreationExpressionSyntax) ? true : false);
|
||
|
|
if (flag && next.IsKind(SyntaxKind.OpenBraceToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
parent2 = ((SyntaxToken)(ref token)).Parent;
|
||
|
|
flag = ((parent2 is InitializerExpressionSyntax || parent2 is AnonymousObjectCreationExpressionSyntax) ? true : false);
|
||
|
|
if (flag && token.IsKind(SyntaxKind.OpenBraceToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
parent2 = ((SyntaxToken)(ref next)).Parent;
|
||
|
|
flag = ((parent2 is InitializerExpressionSyntax || parent2 is AnonymousObjectCreationExpressionSyntax) ? true : false);
|
||
|
|
if (flag && next.IsKind(SyntaxKind.CloseBraceToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref next)).RawKind == 8200)
|
||
|
|
{
|
||
|
|
SyntaxNode parent2 = ((SyntaxToken)(ref next)).Parent;
|
||
|
|
if (parent2 != null && parent2.Parent is ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpressionSyntax)
|
||
|
|
{
|
||
|
|
TypeSyntax? returnType = parenthesizedLambdaExpressionSyntax.ReturnType;
|
||
|
|
if (returnType != null && returnType.GetLastToken() == token)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (IsKeyword(token.Kind()) && !next.IsKind(SyntaxKind.ColonToken) && !next.IsKind(SyntaxKind.DotToken) && !next.IsKind(SyntaxKind.QuestionToken) && !next.IsKind(SyntaxKind.SemicolonToken) && !next.IsKind(SyntaxKind.OpenBracketToken) && (!next.IsKind(SyntaxKind.OpenParenToken) || KeywordNeedsSeparatorBeforeOpenParen(token.Kind()) || ((SyntaxToken)(ref next)).Parent.IsKind(SyntaxKind.TupleType)) && !next.IsKind(SyntaxKind.CloseParenToken) && !next.IsKind(SyntaxKind.CloseBraceToken) && !next.IsKind(SyntaxKind.ColonColonToken) && !next.IsKind(SyntaxKind.GreaterThanToken) && !next.IsKind(SyntaxKind.CommaToken))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (IsWord(token.Kind()) && IsWord(next.Kind()))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref token)).Width > 1 && ((SyntaxToken)(ref next)).Width > 1)
|
||
|
|
{
|
||
|
|
char c = StringExtensions.Last(((SyntaxToken)(ref token)).Text);
|
||
|
|
char c2 = StringExtensions.First(((SyntaxToken)(ref next)).Text);
|
||
|
|
if (c == c2 && TokenCharacterCanBeDoubled(c))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (((SyntaxToken)(ref token)).Parent is RelationalPatternSyntax)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
syntaxKind = next.Kind();
|
||
|
|
if (syntaxKind - 8438 <= SyntaxKind.List)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
syntaxKind = token.Kind();
|
||
|
|
if (syntaxKind - 8438 <= (SyntaxKind)2)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (NeedsSeparatorForPropertyPattern(token, next))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (NeedsSeparatorForPositionalPattern(token, next))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (NeedsSeparatorForListPattern(token, next))
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
syntaxKind = ((SyntaxToken)(ref token)).Parent.Kind();
|
||
|
|
SyntaxKind syntaxKind2 = ((SyntaxToken)(ref next)).Parent.Kind();
|
||
|
|
if (syntaxKind != SyntaxKind.LineDirectivePosition)
|
||
|
|
{
|
||
|
|
if (syntaxKind == SyntaxKind.LineSpanDirectiveTrivia && syntaxKind2 == SyntaxKind.LineDirectivePosition)
|
||
|
|
{
|
||
|
|
goto IL_0881;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (syntaxKind2 == SyntaxKind.LineSpanDirectiveTrivia)
|
||
|
|
{
|
||
|
|
goto IL_0881;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
IL_0881:
|
||
|
|
return true;
|
||
|
|
IL_0453:
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool KeywordNeedsSeparatorBeforeOpenParen(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
switch (kind)
|
||
|
|
{
|
||
|
|
case SyntaxKind.TypeOfKeyword:
|
||
|
|
case SyntaxKind.SizeOfKeyword:
|
||
|
|
case SyntaxKind.DefaultKeyword:
|
||
|
|
case SyntaxKind.NewKeyword:
|
||
|
|
case SyntaxKind.ArgListKeyword:
|
||
|
|
case SyntaxKind.ThisKeyword:
|
||
|
|
case SyntaxKind.BaseKeyword:
|
||
|
|
case SyntaxKind.CheckedKeyword:
|
||
|
|
case SyntaxKind.UncheckedKeyword:
|
||
|
|
return false;
|
||
|
|
default:
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsXmlTextToken(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
if (kind - 8513 <= SyntaxKind.List)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool BinaryTokenNeedsSeparator(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
if (kind == SyntaxKind.DotToken || kind == SyntaxKind.MinusGreaterThanToken)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return SyntaxFacts.GetBinaryExpression(kind) != SyntaxKind.None;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool AssignmentTokenNeedsSeparator(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
return SyntaxFacts.GetAssignmentExpression(kind) != SyntaxKind.None;
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxTriviaList RewriteTrivia(SyntaxTriviaList triviaList, int depth, bool isTrailing, bool indentAfterLineBreak, bool mustHaveSeparator, int lineBreaksAfter)
|
||
|
|
{
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
ArrayBuilder<SyntaxTrivia> instance = ArrayBuilder<SyntaxTrivia>.GetInstance(((SyntaxTriviaList)(ref triviaList)).Count);
|
||
|
|
try
|
||
|
|
{
|
||
|
|
Enumerator enumerator = ((SyntaxTriviaList)(ref triviaList)).GetEnumerator();
|
||
|
|
while (((Enumerator)(ref enumerator)).MoveNext())
|
||
|
|
{
|
||
|
|
SyntaxTrivia current = ((Enumerator)(ref enumerator)).Current;
|
||
|
|
if (current.IsKind(SyntaxKind.WhitespaceTrivia) || current.IsKind(SyntaxKind.EndOfLineTrivia) || ((SyntaxTrivia)(ref current)).FullWidth == 0)
|
||
|
|
{
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
bool flag = (instance.Count > 0 && NeedsSeparatorBetween(instance.Last())) || (instance.Count == 0 && isTrailing);
|
||
|
|
if ((NeedsLineBreakBefore(current, isTrailing) || (instance.Count > 0 && NeedsLineBreakBetween(instance.Last(), current, isTrailing))) && !_afterLineBreak)
|
||
|
|
{
|
||
|
|
instance.Add(GetEndOfLine());
|
||
|
|
_afterLineBreak = true;
|
||
|
|
_afterIndentation = false;
|
||
|
|
}
|
||
|
|
if (_afterLineBreak)
|
||
|
|
{
|
||
|
|
if (!_afterIndentation && NeedsIndentAfterLineBreak(current))
|
||
|
|
{
|
||
|
|
instance.Add(GetIndentation(GetDeclarationDepth(current)));
|
||
|
|
_afterIndentation = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (flag)
|
||
|
|
{
|
||
|
|
instance.Add(GetSpace());
|
||
|
|
_afterLineBreak = false;
|
||
|
|
_afterIndentation = false;
|
||
|
|
}
|
||
|
|
if (((SyntaxTrivia)(ref current)).HasStructure)
|
||
|
|
{
|
||
|
|
SyntaxTrivia val = VisitStructuredTrivia(current);
|
||
|
|
instance.Add(val);
|
||
|
|
}
|
||
|
|
else if (current.IsKind(SyntaxKind.DocumentationCommentExteriorTrivia))
|
||
|
|
{
|
||
|
|
instance.Add(s_trimmedDocCommentExterior);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
instance.Add(current);
|
||
|
|
}
|
||
|
|
if (NeedsLineBreakAfter(current, isTrailing) && (instance.Count == 0 || !EndsInLineBreak(instance.Last())))
|
||
|
|
{
|
||
|
|
instance.Add(GetEndOfLine());
|
||
|
|
_afterLineBreak = true;
|
||
|
|
_afterIndentation = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (lineBreaksAfter > 0)
|
||
|
|
{
|
||
|
|
if (instance.Count > 0 && EndsInLineBreak(instance.Last()))
|
||
|
|
{
|
||
|
|
lineBreaksAfter--;
|
||
|
|
}
|
||
|
|
for (int i = 0; i < lineBreaksAfter; i++)
|
||
|
|
{
|
||
|
|
instance.Add(GetEndOfLine());
|
||
|
|
_afterLineBreak = true;
|
||
|
|
_afterIndentation = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (indentAfterLineBreak && _afterLineBreak && !_afterIndentation)
|
||
|
|
{
|
||
|
|
instance.Add(GetIndentation(depth));
|
||
|
|
_afterIndentation = true;
|
||
|
|
}
|
||
|
|
else if (mustHaveSeparator)
|
||
|
|
{
|
||
|
|
instance.Add(GetSpace());
|
||
|
|
_afterLineBreak = false;
|
||
|
|
_afterIndentation = false;
|
||
|
|
}
|
||
|
|
if (instance.Count == 0)
|
||
|
|
{
|
||
|
|
return default(SyntaxTriviaList);
|
||
|
|
}
|
||
|
|
if (instance.Count == 1)
|
||
|
|
{
|
||
|
|
return SyntaxFactory.TriviaList(instance.First());
|
||
|
|
}
|
||
|
|
return SyntaxFactory.TriviaList((IEnumerable<SyntaxTrivia>)instance);
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
instance.Free();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxTrivia GetSpace()
|
||
|
|
{
|
||
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (!_useElasticTrivia)
|
||
|
|
{
|
||
|
|
return SyntaxFactory.Space;
|
||
|
|
}
|
||
|
|
return SyntaxFactory.ElasticSpace;
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxTrivia GetEndOfLine()
|
||
|
|
{
|
||
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return _eolTrivia;
|
||
|
|
}
|
||
|
|
|
||
|
|
private SyntaxTrivia VisitStructuredTrivia(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
bool isInStructuredTrivia = _isInStructuredTrivia;
|
||
|
|
_isInStructuredTrivia = true;
|
||
|
|
SyntaxToken previousToken = _previousToken;
|
||
|
|
_previousToken = default(SyntaxToken);
|
||
|
|
SyntaxTrivia result = VisitTrivia(trivia);
|
||
|
|
_isInStructuredTrivia = isInStructuredTrivia;
|
||
|
|
_previousToken = previousToken;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsSeparatorBetween(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxKind syntaxKind = trivia.Kind();
|
||
|
|
if (syntaxKind == SyntaxKind.None || syntaxKind == SyntaxKind.WhitespaceTrivia || syntaxKind == SyntaxKind.DocumentationCommentExteriorTrivia)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return !SyntaxFacts.IsPreprocessorDirective(trivia.Kind());
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsLineBreakBetween(SyntaxTrivia trivia, SyntaxTrivia next, bool isTrailingTrivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (!NeedsLineBreakAfter(trivia, isTrailingTrivia))
|
||
|
|
{
|
||
|
|
return NeedsLineBreakBefore(next, isTrailingTrivia);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsLineBreakBefore(SyntaxTrivia trivia, bool isTrailingTrivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxKind syntaxKind = trivia.Kind();
|
||
|
|
if (syntaxKind == SyntaxKind.DocumentationCommentExteriorTrivia)
|
||
|
|
{
|
||
|
|
return !isTrailingTrivia;
|
||
|
|
}
|
||
|
|
return SyntaxFacts.IsPreprocessorDirective(syntaxKind);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsLineBreakAfter(SyntaxTrivia trivia, bool isTrailingTrivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxKind syntaxKind = trivia.Kind();
|
||
|
|
return syntaxKind switch
|
||
|
|
{
|
||
|
|
SyntaxKind.SingleLineCommentTrivia => true,
|
||
|
|
SyntaxKind.MultiLineCommentTrivia => !isTrailingTrivia,
|
||
|
|
_ => SyntaxFacts.IsPreprocessorDirective(syntaxKind),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool NeedsIndentAfterLineBreak(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
SyntaxKind syntaxKind = trivia.Kind();
|
||
|
|
if (syntaxKind - 8541 <= (SyntaxKind)4)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsLineBreak(SyntaxToken token)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
return token.Kind() == SyntaxKind.XmlTextLiteralNewLineToken;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool EndsInLineBreak(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (trivia.Kind() == SyntaxKind.EndOfLineTrivia)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if (trivia.Kind() == SyntaxKind.PreprocessingMessageTrivia || trivia.Kind() == SyntaxKind.DisabledTextTrivia)
|
||
|
|
{
|
||
|
|
string text = ((SyntaxTrivia)(ref trivia)).ToFullString();
|
||
|
|
if (text.Length > 0)
|
||
|
|
{
|
||
|
|
return SyntaxFacts.IsNewLine(StringExtensions.Last(text));
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (((SyntaxTrivia)(ref trivia)).HasStructure)
|
||
|
|
{
|
||
|
|
SyntaxNode structure = ((SyntaxTrivia)(ref trivia)).GetStructure();
|
||
|
|
SyntaxTriviaList trailingTrivia = structure.GetTrailingTrivia();
|
||
|
|
if (((SyntaxTriviaList)(ref trailingTrivia)).Count > 0)
|
||
|
|
{
|
||
|
|
return EndsInLineBreak(((SyntaxTriviaList)(ref trailingTrivia)).Last());
|
||
|
|
}
|
||
|
|
return IsLineBreak(structure.GetLastToken(false, false, false, false));
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsWord(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
if (kind != SyntaxKind.IdentifierToken)
|
||
|
|
{
|
||
|
|
return IsKeyword(kind);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsKeyword(SyntaxKind kind)
|
||
|
|
{
|
||
|
|
if (!SyntaxFacts.IsKeywordKind(kind))
|
||
|
|
{
|
||
|
|
return SyntaxFacts.IsPreprocessorKeyword(kind);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool TokenCharacterCanBeDoubled(char c)
|
||
|
|
{
|
||
|
|
switch (c)
|
||
|
|
{
|
||
|
|
case '"':
|
||
|
|
case '+':
|
||
|
|
case '-':
|
||
|
|
case ':':
|
||
|
|
case '<':
|
||
|
|
case '=':
|
||
|
|
case '?':
|
||
|
|
return true;
|
||
|
|
default:
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int GetDeclarationDepth(SyntaxToken token)
|
||
|
|
{
|
||
|
|
return GetDeclarationDepth(((SyntaxToken)(ref token)).Parent);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int GetDeclarationDepth(SyntaxTrivia trivia)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
return GetDeclarationDepth(((SyntaxTrivia)(ref trivia)).Token);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static int GetDeclarationDepth(SyntaxNode? node)
|
||
|
|
{
|
||
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (node == null)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (node.IsStructuredTrivia)
|
||
|
|
{
|
||
|
|
return GetDeclarationDepth(((SyntaxNode)(StructuredTriviaSyntax)(object)node).ParentTrivia);
|
||
|
|
}
|
||
|
|
int declarationDepth;
|
||
|
|
bool flag;
|
||
|
|
if (node.Parent != null)
|
||
|
|
{
|
||
|
|
if (node.Parent.IsKind(SyntaxKind.CompilationUnit))
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
declarationDepth = GetDeclarationDepth(node.Parent);
|
||
|
|
SyntaxKind syntaxKind = node.Parent.Kind();
|
||
|
|
if ((syntaxKind == SyntaxKind.GlobalStatement || syntaxKind == SyntaxKind.FileScopedNamespaceDeclaration) ? true : false)
|
||
|
|
{
|
||
|
|
return declarationDepth;
|
||
|
|
}
|
||
|
|
if (node.IsKind(SyntaxKind.IfStatement) && node.Parent.IsKind(SyntaxKind.ElseClause))
|
||
|
|
{
|
||
|
|
return declarationDepth;
|
||
|
|
}
|
||
|
|
if (node.Parent is BlockSyntax)
|
||
|
|
{
|
||
|
|
return declarationDepth + 1;
|
||
|
|
}
|
||
|
|
if (node != null)
|
||
|
|
{
|
||
|
|
SyntaxNode parent = node.Parent;
|
||
|
|
if (parent is InitializerExpressionSyntax || parent is AnonymousObjectMemberDeclaratorSyntax)
|
||
|
|
{
|
||
|
|
flag = true;
|
||
|
|
goto IL_00c2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
flag = false;
|
||
|
|
goto IL_00c2;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
IL_00c2:
|
||
|
|
if ((flag || (node is AssignmentExpressionSyntax assignmentExpressionSyntax && assignmentExpressionSyntax.Parent is InitializerExpressionSyntax)) && !IsSingleLineInitializerContext(node.Parent))
|
||
|
|
{
|
||
|
|
return declarationDepth + 1;
|
||
|
|
}
|
||
|
|
if (node is StatementSyntax && !(node is BlockSyntax))
|
||
|
|
{
|
||
|
|
if (node is UsingStatementSyntax usingStatementSyntax && usingStatementSyntax.Parent is UsingStatementSyntax)
|
||
|
|
{
|
||
|
|
return declarationDepth;
|
||
|
|
}
|
||
|
|
if (node is FixedStatementSyntax fixedStatementSyntax && fixedStatementSyntax.Parent is FixedStatementSyntax)
|
||
|
|
{
|
||
|
|
return declarationDepth;
|
||
|
|
}
|
||
|
|
return declarationDepth + 1;
|
||
|
|
}
|
||
|
|
if (node is MemberDeclarationSyntax || node is AccessorDeclarationSyntax || node is TypeParameterConstraintClauseSyntax || node is SwitchSectionSyntax || node is SwitchExpressionArmSyntax || node is UsingDirectiveSyntax || node is ExternAliasDirectiveSyntax || node is QueryExpressionSyntax || node is QueryContinuationSyntax)
|
||
|
|
{
|
||
|
|
return declarationDepth + 1;
|
||
|
|
}
|
||
|
|
return declarationDepth;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsSingleLineInitializerContext(SyntaxNode? node)
|
||
|
|
{
|
||
|
|
if (node == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
for (SyntaxNode parent = node.Parent; parent != null; parent = parent.Parent)
|
||
|
|
{
|
||
|
|
if ((parent is InterpolationSyntax || parent is AttributeArgumentSyntax || parent is ArgumentSyntax) ? true : false)
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
if ((parent is StatementSyntax || parent is MemberDeclarationSyntax) ? true : false)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsInitializerInSingleLineContext(SyntaxNode? node)
|
||
|
|
{
|
||
|
|
if ((!(node is InitializerExpressionSyntax) && !(node is AnonymousObjectCreationExpressionSyntax)) || 1 == 0)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return IsSingleLineInitializerContext(node);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static bool IsSingleLineProperty(PropertyDeclarationSyntax property)
|
||
|
|
{
|
||
|
|
if (property.AccessorList != null)
|
||
|
|
{
|
||
|
|
return IsAccessorListWithoutAccessorsWithBlockBody((SyntaxNode?)(object)property.AccessorList);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override SyntaxNode? VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax node)
|
||
|
|
{
|
||
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (node.StringStartToken.Kind() == SyntaxKind.InterpolatedStringStartToken)
|
||
|
|
{
|
||
|
|
bool inSingleLineInterpolation = _inSingleLineInterpolation;
|
||
|
|
_inSingleLineInterpolation = true;
|
||
|
|
try
|
||
|
|
{
|
||
|
|
return base.VisitInterpolatedStringExpression(node);
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
_inSingleLineInterpolation = inSingleLineInterpolation;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return base.VisitInterpolatedStringExpression(node);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override SyntaxNode? VisitXmlTextAttribute(XmlTextAttributeSyntax node)
|
||
|
|
{
|
||
|
|
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
XmlTextAttributeSyntax xmlTextAttributeSyntax = (XmlTextAttributeSyntax)(object)base.VisitXmlTextAttribute(node);
|
||
|
|
if ((xmlTextAttributeSyntax == null || ((SyntaxNode)xmlTextAttributeSyntax).HasTrailingTrivia) ? true : false)
|
||
|
|
{
|
||
|
|
return (SyntaxNode?)(object)xmlTextAttributeSyntax;
|
||
|
|
}
|
||
|
|
SyntaxKind syntaxKind = GetNextRelevantToken(node.EndQuoteToken).Kind();
|
||
|
|
if (syntaxKind == SyntaxKind.GreaterThanToken || syntaxKind == SyntaxKind.SlashGreaterThanToken)
|
||
|
|
{
|
||
|
|
return (SyntaxNode?)(object)xmlTextAttributeSyntax;
|
||
|
|
}
|
||
|
|
return (SyntaxNode?)(object)SyntaxNodeExtensions.WithTrailingTrivia<XmlTextAttributeSyntax>(xmlTextAttributeSyntax, (SyntaxTrivia[])(object)new SyntaxTrivia[1] { GetSpace() });
|
||
|
|
}
|
||
|
|
}
|