public AccessorBlockSyntax ConvertAccessor(AccessorDeclarationSyntax node, out bool isIterator) { SyntaxKind blockKind; AccessorStatementSyntax stmt; EndBlockStatementSyntax endStmt; SyntaxList <StatementSyntax> body; isIterator = false; var isIteratorState = new MethodBodyVisitor(_semanticModel, _nodesVisitor, _triviaConverter, this); body = ConvertBody(node.Body, node.ExpressionBody, isIteratorState); isIterator = isIteratorState.IsIterator; var attributes = SyntaxFactory.List(node.AttributeLists.Select(a => (AttributeListSyntax)a.Accept(_nodesVisitor))); var modifiers = ConvertModifiers(node.Modifiers, SyntaxKindExtensions.TokenContext.Local); var parent = (BasePropertyDeclarationSyntax)node.Parent.Parent; Microsoft.CodeAnalysis.VisualBasic.Syntax.ParameterSyntax valueParam; switch (CSharpExtensions.Kind(node)) { case Microsoft.CodeAnalysis.CSharp.SyntaxKind.GetAccessorDeclaration: blockKind = SyntaxKind.GetAccessorBlock; stmt = SyntaxFactory.GetAccessorStatement(attributes, modifiers, null); endStmt = SyntaxFactory.EndGetStatement(); break; case Microsoft.CodeAnalysis.CSharp.SyntaxKind.SetAccessorDeclaration: blockKind = SyntaxKind.SetAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.SetAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndSetStatement(); break; case Microsoft.CodeAnalysis.CSharp.SyntaxKind.AddAccessorDeclaration: blockKind = SyntaxKind.AddHandlerAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.AddHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndAddHandlerStatement(); break; case Microsoft.CodeAnalysis.CSharp.SyntaxKind.RemoveAccessorDeclaration: blockKind = SyntaxKind.RemoveHandlerAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.RemoveHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndRemoveHandlerStatement(); break; default: throw new NotSupportedException(); } return(SyntaxFactory.AccessorBlock(blockKind, stmt, body, endStmt)); }
public static SyntaxTokenList GetModifiers(this CSharpSyntaxNode member) { if (member != null) { switch (CSharpExtensions.Kind(member)) { case CSSyntaxKind.EnumDeclaration: return(((EnumDeclarationSyntax)member).Modifiers); case CSSyntaxKind.ClassDeclaration: case CSSyntaxKind.InterfaceDeclaration: case CSSyntaxKind.StructDeclaration: return(((TypeDeclarationSyntax)member).Modifiers); case CSSyntaxKind.DelegateDeclaration: return(((DelegateDeclarationSyntax)member).Modifiers); case CSSyntaxKind.FieldDeclaration: return(((FieldDeclarationSyntax)member).Modifiers); case CSSyntaxKind.EventFieldDeclaration: return(((EventFieldDeclarationSyntax)member).Modifiers); case CSSyntaxKind.ConstructorDeclaration: return(((ConstructorDeclarationSyntax)member).Modifiers); case CSSyntaxKind.DestructorDeclaration: return(((DestructorDeclarationSyntax)member).Modifiers); case CSSyntaxKind.PropertyDeclaration: return(((PropertyDeclarationSyntax)member).Modifiers); case CSSyntaxKind.EventDeclaration: return(((EventDeclarationSyntax)member).Modifiers); case CSSyntaxKind.IndexerDeclaration: return(((IndexerDeclarationSyntax)member).Modifiers); case CSSyntaxKind.OperatorDeclaration: return(((OperatorDeclarationSyntax)member).Modifiers); case CSSyntaxKind.ConversionOperatorDeclaration: return(((ConversionOperatorDeclarationSyntax)member).Modifiers); case CSSyntaxKind.MethodDeclaration: return(((MethodDeclarationSyntax)member).Modifiers); case CSSyntaxKind.GetAccessorDeclaration: case CSSyntaxKind.SetAccessorDeclaration: case CSSyntaxKind.AddAccessorDeclaration: case CSSyntaxKind.RemoveAccessorDeclaration: return(((AccessorDeclarationSyntax)member).Modifiers); } } return(default(SyntaxTokenList)); }
/// <summary> /// Returns all of the trivia to the left of this token up to the previous token (concatenates /// the previous token's trailing trivia and this token's leading trivia). /// </summary> public static IEnumerable <SyntaxTrivia> GetAllPrecedingTriviaToPreviousToken(this SyntaxToken token) { var prevToken = token.GetPreviousToken(includeSkipped: true); if (CSharpExtensions.Kind(prevToken) == CSSyntaxKind.None) { return(token.LeadingTrivia); } return(prevToken.TrailingTrivia.Concat(token.LeadingTrivia)); }
public static bool IsKind(this SyntaxNode node, CSSyntaxKind kind1, CSSyntaxKind kind2, CSSyntaxKind kind3, CSSyntaxKind kind4, CSSyntaxKind kind5) { if (node == null) { return(false); } var csharpKind = CSharpExtensions.Kind(node); return(csharpKind == kind1 || csharpKind == kind2 || csharpKind == kind3 || csharpKind == kind4 || csharpKind == kind5); }
public static bool IsContinuableConstruct(this SyntaxNode node) { switch (CSharpExtensions.Kind(node)) { case CSSyntaxKind.DoStatement: case CSSyntaxKind.WhileStatement: case CSSyntaxKind.ForStatement: case CSSyntaxKind.ForEachStatement: return(true); } return(false); }
private static string ConvertStopOrEndToCSharpStatementText(VBSyntax.StopOrEndStatementSyntax node) { switch (VBasic.VisualBasicExtensions.Kind(node.StopOrEndKeyword)) { case VBasic.SyntaxKind.StopKeyword: return("System.Diagnostics.Debugger.Break();"); case VBasic.SyntaxKind.EndKeyword: return("System.Environment.Exit(0);"); default: throw new NotImplementedException(CSharpExtensions.Kind(node.StopOrEndKeyword) + " not implemented!"); } }
public SyntaxToken ConvertIdentifier(SyntaxToken id) { CSharpSyntaxNode parent = (CSharpSyntaxNode)id.Parent; var idText = IsEventHandlerIdentifier(parent) && !IsEventHandlerAssignLhs(parent) ? id.ValueText + "Event" : id.ValueText; // Underscore is a special character in VB lexer which continues lines - not sure where to find the whole set of other similar tokens if any // Rather than a complicated contextual rename, just add an extra dash to all identifiers and hope this method is consistently used bool keywordRequiresEscaping = id.IsKind(CSSyntaxKind.IdentifierToken) && KeywordRequiresEscaping(id); switch (CSharpExtensions.Kind(id)) { case CSSyntaxKind.GlobalKeyword: idText = "Global"; break; } return(Identifier(idText, keywordRequiresEscaping)); }
public static bool IsReturnableConstruct(this SyntaxNode node) { switch (CSharpExtensions.Kind(node)) { case CSSyntaxKind.AnonymousMethodExpression: case CSSyntaxKind.SimpleLambdaExpression: case CSSyntaxKind.ParenthesizedLambdaExpression: case CSSyntaxKind.MethodDeclaration: case CSSyntaxKind.ConstructorDeclaration: case CSSyntaxKind.DestructorDeclaration: case CSSyntaxKind.GetAccessorDeclaration: case CSSyntaxKind.SetAccessorDeclaration: case CSSyntaxKind.OperatorDeclaration: case CSSyntaxKind.AddAccessorDeclaration: case CSSyntaxKind.RemoveAccessorDeclaration: return(true); } return(false); }
public SyntaxToken ConvertIdentifier(SyntaxToken id) { var parent = (CS.CSharpSyntaxNode)id.Parent; var idText = AdjustIfEventIdentifier(id, parent); // Underscore is a special character in VB lexer which continues lines - not sure where to find the whole set of other similar tokens if any // Rather than a complicated contextual rename, just add an extra dash to all identifiers and hope this method is consistently used bool keywordRequiresEscaping = id.IsKind(CSSyntaxKind.IdentifierToken) && KeywordRequiresEscaping(id); switch (CSharpExtensions.Kind(id)) { case CSSyntaxKind.GlobalKeyword: idText = "Global"; break; case CSSyntaxKind.ThisKeyword: idText = "Item"; break; } return(Identifier(idText, keywordRequiresEscaping).WithSourceMappingFrom(id)); }
public static bool IsKind(this SyntaxToken token, params SyntaxKind[] kinds) { return(kinds.Contains(CSharpExtensions.Kind(token))); }
private static SyntaxToken?ConvertModifier(SyntaxToken m, SyntaxKindExtensions.TokenContext context = SyntaxKindExtensions.TokenContext.Global) { var token = CSharpExtensions.Kind(m).ConvertToken(context); return(token == SyntaxKind.None ? null : new SyntaxToken?(SyntaxFactory.Token(token))); }
public static bool IsKind(this SyntaxToken token, SyntaxKind kind1, SyntaxKind kind2, SyntaxKind kind3) { return(CSharpExtensions.Kind(token) == kind1 || CSharpExtensions.Kind(token) == kind2 || CSharpExtensions.Kind(token) == kind3); }
static SyntaxTokenList ConvertModifiers(SyntaxTokenList modifiers, TokenContext context = SyntaxKindExtensions.TokenContext.Global) { return(SyntaxFactory.TokenList(ConvertModifiersCore(modifiers, context).Where(t => CSharpExtensions.Kind(t) != SyntaxKind.None))); }
private IEnumerable <SyntaxInfo> GetSyntaxInfos(int lineInfoOffset = 0) { #if DEBUG _debugFn?.Invoke($"{nameof(GetSyntaxInfos)} [{lineInfoOffset}]", 5); #endif SyntaxToken token1; if (lineInfoOffset != 0) { if (lineInfoOffset < Length) { var child = Node.ChildThatContainsPosition(lineInfoOffset); if (child.SpanStart > lineInfoOffset) { if (child.HasLeadingTrivia) { foreach (var syntaxTrivia in child.GetLeadingTrivia()) { yield return(new SyntaxInfo(syntaxTrivia, Node)); } } } // ReSharper disable once PossibleNullReferenceException token1 = child.IsToken ? child.AsToken() : child.AsNode().GetFirstToken(); } else { yield break; } } else { if (Node == null) { yield break; } if (Node.HasLeadingTrivia) { foreach (var syntaxTrivia in Node.GetLeadingTrivia()) { yield return(new SyntaxInfo(syntaxTrivia, Node)); } } token1 = Node.GetFirstToken(); } // ReSharper disable once InvokeAsExtensionMethod while (CSharpExtensions.Kind(token1) != SyntaxKind.None) { // ReSharper disable once InvokeAsExtensionMethod if (CSharpExtensions.Kind(token1) == SyntaxKind.EndOfFileToken) { yield break; } yield return(new SyntaxInfo(token1)); if (token1.HasTrailingTrivia) { foreach (var syntaxTrivia in token1.TrailingTrivia) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (false && syntaxTrivia.IsPartOfStructuredTrivia()) // ReSharper disable once HeuristicUnreachableCode { var syntaxNode = syntaxTrivia.GetStructure(); var n = syntaxTrivia.Token.Parent; if (n is StructuredTriviaSyntax sn) { var trail = sn.GetTrailingTrivia(); } // while (syntaxNode == null) // { // syntaxNode = n.ParentTrivia; // } // syntaxNode = syntaxTrivia.GetStructure(); var token2 = syntaxNode.GetFirstToken(true, true, true, true); while (CSharpExtensions.Kind(token2) != SyntaxKind.None) { if (token2.HasLeadingTrivia) { foreach (var syntaxTrivia2 in token2.LeadingTrivia) { yield return new SyntaxInfo(syntaxTrivia2, token2, TriviaPosition.Leading) { StructuredTrivia = syntaxNode } } } ; yield return(new SyntaxInfo(token2) { StructuredTrivia = syntaxNode }); if (token2.HasTrailingTrivia) { foreach (var syntaxTrivia2 in token2.TrailingTrivia) { yield return new SyntaxInfo(syntaxTrivia2, token2, TriviaPosition.Trailing) { StructuredTrivia = syntaxNode } } } ; token2 = token2.GetNextToken(true, true, true, true); } } else { yield return(new SyntaxInfo(syntaxTrivia, token1, TriviaPosition.Trailing)); } } } token1 = token1.GetNextToken(true, true, true, true); if (token1.HasLeadingTrivia) { foreach (var syntaxTrivia in token1.LeadingTrivia) { // if (syntaxTrivia.IsPartOfStructuredTrivia()) // { // var token2 = syntaxTrivia.GetStructure().GetFirstToken(true, true, true, true); // while (CSharpExtensions.Kind(token2) != SyntaxKind.None) // { // if (token2.HasLeadingTrivia) // { // foreach (var syntaxTrivia2 in token2.LeadingTrivia) // { // yield return new SyntaxInfo(syntaxTrivia2); // } // } // yield return new SyntaxInfo(token2); // if (token2.HasTrailingTrivia) // { // foreach (var syntaxTrivia2 in token2.TrailingTrivia) // { // yield return new SyntaxInfo(syntaxTrivia2); // } // } // token2 = token2.GetNextToken(true, true, true, true); // } // } // else // { yield return(new SyntaxInfo(syntaxTrivia, token1, TriviaPosition.Leading)); } } // } } }
private TextRun _GetTextRun(int textSourceCharacterIndex) { _charIndex = textSourceCharacterIndex; _debugFn?.Invoke($"GetTextRun(textSourceCharacterIndex = {textSourceCharacterIndex})", 5); if (textSourceCharacterIndex == 0) { #if DEBUG _debugFn?.Invoke($"Clearing runs because at beginning of text source", 4); #endif Runs.Clear(); SyntaxInfos = GetSyntaxInfos().GetEnumerator(); if (!SyntaxInfos.MoveNext()) { var endOfParagraph = new CustomTextEndOfParagraph(2) { Index = textSourceCharacterIndex }; Runs.Add(endOfParagraph); return(endOfParagraph); } } else { #if DEBUGRUNS foreach (var textRun in Runs) { _debugFn?.Invoke(" " + textRun.ToString(), 4); } #endif Runs = RunsBefore(textSourceCharacterIndex, Runs).ToList(); } var si = SyntaxInfos.Current; if (si == null) { var endOfParagraph = new CustomTextEndOfParagraph(2) { Index = textSourceCharacterIndex }; Runs.Add(endOfParagraph); return(endOfParagraph); } // ReSharper disable once PossibleNullReferenceException while (textSourceCharacterIndex > si.Span1.Start || /*|| si.Span1.End < textSourceCharacterIndex*/ si.Text.Length == 0) { if (!SyntaxInfos.MoveNext()) { if (textSourceCharacterIndex < Length) { var len = Length - textSourceCharacterIndex; var buf = new char[len]; Text.CopyTo(textSourceCharacterIndex, buf, 0, len); if (len == 2 && buf[0] == '\r' && buf[1] == '\n') { var eol = new CustomTextEndOfLine(2) { Index = textSourceCharacterIndex }; Runs.Add(eol); return(eol); } var t = string.Join("", buf); var customTextCharacters = new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t)) { Index = textSourceCharacterIndex }; Runs.Add(customTextCharacters); return(customTextCharacters); } var endOfParagraph = new CustomTextEndOfParagraph(2) { Index = textSourceCharacterIndex }; Runs.Add(endOfParagraph); return(endOfParagraph); } si = SyntaxInfos.Current; } if (textSourceCharacterIndex < si.Span1.Start) { var len = si.Span1.Start - textSourceCharacterIndex; var buf = new char[len]; Text.CopyTo(textSourceCharacterIndex, buf, 0, len); if (len == 2 && buf[0] == '\r' && buf[1] == '\n') { var eol = new CustomTextEndOfLine(2) { Index = textSourceCharacterIndex }; Runs.Add(eol); return(eol); } var t = string.Join("", buf); var nl = t.IndexOf("\r\n", StringComparison.Ordinal); if (nl != -1) { t = t.Substring(0, nl); if (t == "") { var eol = new CustomTextEndOfLine(2) { Index = textSourceCharacterIndex }; Runs.Add(eol); return(eol); } var ctc = new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t)) { Index = textSourceCharacterIndex }; Runs.Add(ctc); return(ctc); } var customTextCharacters = new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t)) { Index = textSourceCharacterIndex }; Runs.Add(customTextCharacters); return(customTextCharacters); } // while (textSourceCharacterIndex > si.Span1.Start) // { // if (!SyntaxInfos.MoveNext()) // { // } // } if (textSourceCharacterIndex != si.Span1.Start) { throw new InvalidOperationException("Character index does not match span start"); } if (si.SyntaxTrivia.HasValue) { var syntaxKind = CSharpExtensions.Kind(si.SyntaxTrivia.Value); if (syntaxKind == SyntaxKind.EndOfLineTrivia || syntaxKind == SyntaxKind.XmlTextLiteralNewLineToken) { var customTextEndOfLine = new CustomTextEndOfLine(2) { Index = textSourceCharacterIndex }; Runs.Add(customTextEndOfLine); return(customTextEndOfLine); } var p = PropsFor(si.SyntaxTrivia.Value, si.Text); var syntaxTriviaTextCharacters = new SyntaxTriviaTextCharacters(si.Text, p, si.Span1, si.SyntaxTrivia.Value, si.Node, si.Token, si.TriviaPosition, si.StructuredTrivia) { Index = si.Span1.Start }; Runs.Add(syntaxTriviaTextCharacters); return(syntaxTriviaTextCharacters); } if (si.SyntaxToken.HasValue) { if (CSharpExtensions.Kind(si.SyntaxToken.Value) == SyntaxKind.XmlTextLiteralNewLineToken) { var customTextEndOfLine = new CustomTextEndOfLine(2) { Index = textSourceCharacterIndex }; Runs.Add(customTextEndOfLine); return(customTextEndOfLine); } var syntaxTokenTextCharacters = new SyntaxTokenTextCharacters(si.Text, si.Text.Length, PropsFor(si.SyntaxToken.Value, si.Text), si.SyntaxToken.Value, si.SyntaxToken.Value.Parent) { Index = si.Span1.Start }; Runs.Add(syntaxTokenTextCharacters); return(syntaxTokenTextCharacters); } var textEndOfParagraph = new CustomTextEndOfParagraph(2) { Index = textSourceCharacterIndex }; Runs.Add(textEndOfParagraph); return(textEndOfParagraph); #if false Debug.WriteLine($"index: {textSourceCharacterIndex}"); TextSpan?TakeToken() { var includeDocumentationComments = true; var includeDirectives = true; var includeSkipped = true; var includeZeroWidth = true; token = token.HasValue ? token.Value.GetNextToken(includeZeroWidth, includeSkipped, includeDirectives, includeDocumentationComments) : Node?.GetFirstToken(includeZeroWidth, includeSkipped, includeDirectives, includeDocumentationComments); if (token.HasValue) { if (!_starts.Any() && token.Value.SpanStart != 0) { } var tuple = new StartInfo(token.Value.Span, token.Value); _starts.Add(tuple); DumpStarts(); return(token.Value.Span); } return(null); } TextSpan?span = null; if (textSourceCharacterIndex == 0) { if (Length == 0) { return(new TextEndOfParagraph(2)); } _curStart = 0; if (_starts.Any()) { var startInfo = _starts.First(); token = startInfo.Token; trivia = startInfo.SyntaxTrivia; span = startInfo.TextSpan; if (token.HasValue) { CheckToken(token); } } // _starts.Clear(); DumpStarts(); } else { var startInfo = _starts[_curStart]; token = startInfo.Token; trivia = startInfo.SyntaxTrivia; span = startInfo.TextSpan; if (token.HasValue) { CheckToken(token); } } try { var childInPos = Node.ChildThatContainsPosition(textSourceCharacterIndex); if (childInPos.IsNode) { var n = childInPos.AsNode(); if (textSourceCharacterIndex < n.SpanStart) { foreach (var syntaxTrivia in n.GetLeadingTrivia()) { if (textSourceCharacterIndex >= syntaxTrivia.SpanStart && textSourceCharacterIndex < syntaxTrivia.Span.End) { Debug.WriteLine("In trivia " + syntaxTrivia); if (textSourceCharacterIndex > syntaxTrivia.SpanStart) { Debug.WriteLine("In middle of trivia"); } var characterString = syntaxTrivia.ToFullString(); return(new SyntaxTriviaTextCharacters(characterString, PropsFor(syntaxTrivia, characterString), syntaxTrivia.FullSpan, syntaxTrivia, null, null, TriviaPosition.Leading)); } } } } } catch (Exception ex) { } var token1 = token; // Debug.WriteLine("Index = " + textSourceCharacterIndex); // if (!token1.HasValue) // { // span = TakeToken(); // if (!this.token.HasValue) return new TextEndOfParagraph(2); // token1 = this.token; // } // var token = token1.Value; if (!span.HasValue) { throw new InvalidOperationException(); } var k = span.Value; if (textSourceCharacterIndex < k.Start) { var len = k.Start - textSourceCharacterIndex; var buf = new char[len]; Text.CopyTo(textSourceCharacterIndex, buf, 0, len); if (len == 2 && buf[0] == '\r' && buf[1] == '\n') { return(new CustomTextEndOfLine(2)); } var t = string.Join("", buf); return(new CustomTextCharacters(t, MakeProperties(SyntaxKind.None, t))); } else if (textSourceCharacterIndex >= k.End && k.Length != 0) { TakeToken(); return(GetTextRun(textSourceCharacterIndex)); } else { if (trivia.HasValue) { var syntaxTrivia1 = trivia.Value; var q = syntaxTrivia1.Token.LeadingTrivia .SkipWhile(syntaxTrivia => syntaxTrivia != syntaxTrivia1) .Skip(1); if (q.Any()) { _curStart++; var startInfo = new StartInfo(q.First()); if (_starts.Count <= _curStart) { _starts.Add(startInfo); } else { _starts[_curStart] = startInfo; } } else { var t2 = syntaxTrivia1.Token.GetNextToken(true, true, true, true); if (t2.HasLeadingTrivia) { var st = new StartInfo(t2.LeadingTrivia.First()); _curStart++; if (_starts.Count <= _curStart) { _starts.Add(st); } else { _starts[_curStart] = st; } } else if (CSharpExtensions.Kind(t2) != SyntaxKind.None) { var st = new StartInfo(t2.Span, t2); _curStart++; if (_starts.Count <= _curStart) { _starts.Add(st); } else { _starts[_curStart] = st; } } } var t = syntaxTrivia1.ToFullString(); return(new SyntaxTriviaTextCharacters(t, PropsFor(trivia.Value, t), span.Value, syntaxTrivia1, null, null, TriviaPosition.Leading)); } if (token.HasValue && (CSharpExtensions.Kind(token.Value) == SyntaxKind.None || CSharpExtensions.Kind(token.Value) == SyntaxKind.EndOfFileToken)) { return(new TextEndOfParagraph(2)); } var token0 = token.Value; if (CSharpExtensions.Kind(token0) == SyntaxKind.EndOfLineTrivia) { return(new CustomTextEndOfLine(2)); } var len = k.Length; if (len == 0) { TakeToken(); return(GetTextRun(textSourceCharacterIndex)); } TakeToken(); if (token0.Text.Length != len) { } return(new CustomTextCharacters(token0.Text, MakeProperties(token, token0.Text))); } #endif }
public SyntaxTokenList ConvertModifiers(IEnumerable <SyntaxToken> modifiers, TokenContext context = TokenContext.Global, bool isVariableOrConst = false) { return(SyntaxFactory.TokenList(ConvertModifiersCore(modifiers, context, isVariableOrConst).Where(t => CSharpExtensions.Kind(t) != Microsoft.CodeAnalysis.CSharp.SyntaxKind.None))); }
public AccessorBlockSyntax ConvertAccessor(CSS.AccessorDeclarationSyntax node, out bool isIterator, bool isAutoImplementedProperty = false) { SyntaxKind blockKind; AccessorStatementSyntax stmt; EndBlockStatementSyntax endStmt; SyntaxList <StatementSyntax> body; isIterator = false; var accesorKind = CSharpExtensions.Kind(node); var isIteratorState = new MethodBodyExecutableStatementVisitor(_semanticModel, _nodesVisitor, this); body = ConvertBody(node.Body, node.ExpressionBody, accesorKind == CSSyntaxKind.GetAccessorDeclaration, isIteratorState); isIterator = isIteratorState.IsIterator; var attributes = SyntaxFactory.List(node.AttributeLists.Select(a => (AttributeListSyntax)a.Accept(_nodesVisitor))); var modifiers = ConvertModifiers(node.Modifiers, TokenContext.Local); var parent = (CSS.BasePropertyDeclarationSyntax)node.Parent.Parent; Microsoft.CodeAnalysis.VisualBasic.Syntax.ParameterSyntax valueParam; switch (accesorKind) { case CSSyntaxKind.GetAccessorDeclaration: blockKind = SyntaxKind.GetAccessorBlock; stmt = SyntaxFactory.GetAccessorStatement(attributes, modifiers, null); endStmt = SyntaxFactory.EndGetStatement(); if (isAutoImplementedProperty) { body = body.Count > 0 ? body : SyntaxFactory.SingletonList((StatementSyntax)SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName(GetVbPropertyBackingFieldName(parent)))); } break; case CSSyntaxKind.SetAccessorDeclaration: blockKind = SyntaxKind.SetAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.SetAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndSetStatement(); if (isAutoImplementedProperty) { body = body.Count > 0 ? body : SyntaxFactory.SingletonList((StatementSyntax)SyntaxFactory.AssignmentStatement(SyntaxKind.SimpleAssignmentStatement, SyntaxFactory.IdentifierName(GetVbPropertyBackingFieldName(parent)), SyntaxFactory.Token(VBUtil.GetExpressionOperatorTokenKind(SyntaxKind.SimpleAssignmentStatement)), SyntaxFactory.IdentifierName("value") )); } break; case CSSyntaxKind.AddAccessorDeclaration: blockKind = SyntaxKind.AddHandlerAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.AddHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndAddHandlerStatement(); break; case CSSyntaxKind.RemoveAccessorDeclaration: blockKind = SyntaxKind.RemoveHandlerAccessorBlock; valueParam = SyntaxFactory.Parameter(SyntaxFactory.ModifiedIdentifier("value")) .WithAsClause(SyntaxFactory.SimpleAsClause((TypeSyntax)parent.Type.Accept(_nodesVisitor, false))) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ByValKeyword))); stmt = SyntaxFactory.RemoveHandlerAccessorStatement(attributes, modifiers, SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParam))); endStmt = SyntaxFactory.EndRemoveHandlerStatement(); break; default: throw new NotSupportedException(); } return(SyntaxFactory.AccessorBlock(blockKind, stmt, body, endStmt).WithCsSourceMappingFrom(node)); }