public override void Visit(SyntaxNode node) { if (_firstVisit) { _firstVisit = false; var leadingTabs = new String('\t', 2 + ClassDepth); _code = node.WithoutLeadingTrivia().WithTrailingTrivia().ToFullString() .Replace(leadingTabs, ""); var nodeLine = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; var line = _lineNumberOverride ?? nodeLine; var codeBlocks = Regex.Split(_code, @"\/\*\*.*?\*\/", RegexOptions.Singleline) .Select(b => b.TrimStart('\r', '\n').TrimEnd('\r', '\n', '\t')) .Where(b => !string.IsNullOrEmpty(b) && b != ";") .Select(b=>new CodeBlock(b, line)) .ToList(); base.Visit(node); var nodeHasLeadingTriva = node.HasLeadingTrivia && node.GetLeadingTrivia() .Any(c=>c.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia); var blocks = codeBlocks.Intertwine<IDocumentationBlock>(this.TextBlocks, swap: nodeHasLeadingTriva); this.Blocks.Add(new CombinedBlock(blocks, line)); return; } base.Visit(node); }
public override void Visit(SyntaxNode node) { if (_firstVisit) { _firstVisit = false; var repeatedTabs = 2 + ClassDepth; var language = Language.CSharp; _code = node.WithoutLeadingTrivia().WithTrailingTrivia().ToFullString(); _code = _code.RemoveNumberOfLeadingTabsAfterNewline(repeatedTabs); #if !DOTNETCORE if (_propertyOrMethodName == "ExpectJson" || _propertyOrMethodName == "QueryJson") { // try to get the json for the anonymous type. // Only supports system types and Json.Net LINQ objects e.g. JObject string json; if (_code.TryGetJsonForAnonymousType(out json)) { language = Language.JavaScript; _code = json; } } #endif // TODO: Can do this once we get the generic arguments from the Property declaration //if (_propertyName == "Fluent") //{ // // need to know what type we're operating on // _code += $"client.Search({_code});"; //} var nodeLine = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; var line = _lineNumberOverride ?? nodeLine; var codeBlocks = ParseCodeBlocks(_code, line, language, _propertyOrMethodName); base.Visit(node); var nodeHasLeadingTriva = node.HasLeadingTrivia && node.GetLeadingTrivia().Any(c => c.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia); var blocks = codeBlocks.Intertwine<IDocumentationBlock>(this.TextBlocks, swap: nodeHasLeadingTriva); this.Blocks.Add(new CombinedBlock(blocks, line)); return; } base.Visit(node); }