public override object VisitNamespace_body([NotNull] CSharpParser.Namespace_bodyContext context) { var isServiceNamespace = GetCurrentNamespace() == _serviceFile.ServiceNamespace; if (isServiceNamespace) { _hasServiceNamespace = true; } VisitChildren(context); if (!_hasServiceInterface && isServiceNamespace) { var classInterfaceStopIndex = _cSharpParserService.GetClassInterfaceStopIndex(context); var preclassWhitespace = Tokens.GetHiddenTokensToLeft(context.Start.TokenIndex, Lexer.Hidden); int tabLevels = 1 + ((preclassWhitespace?.Count ?? 0) > 0 ? _stringUtilService.CalculateTabLevels(preclassWhitespace[0]?.Text ?? string.Empty, _tabString) : 0); var interfaceDeclaration = _cSharpParserService.GenerateClassInterfaceDeclaration( _serviceFile.ServiceDeclaration, tabLevels, _tabString); IsModified = true; Rewriter.InsertAfter(classInterfaceStopIndex, interfaceDeclaration); } return(null); }
public override object VisitNamespace_declaration([NotNull] CSharpParser.Namespace_declarationContext context) { _currentNamespace.Push(context.qualified_identifier().GetText()); var isBreadcrumbNamespace = false; if (GetCurrentNamespace() == _breadcrumbNamespace) { _usingSet.Remove(GetCurrentNamespace()); _hasBreadcrumbNamespace = true; isBreadcrumbNamespace = true; } VisitChildren(context); if (isBreadcrumbNamespace) { if (!_hasBreadcrumbClass) { var classStopIndex = _cSharpParserService.GetClassInterfaceStopIndex(context.namespace_body()); var prenamespaceWhitespace = Tokens.GetHiddenTokensToLeft(context.Start.TokenIndex, Lexer.Hidden); int tabLevels = 1 + ((prenamespaceWhitespace?.Count ?? 0) > 0 ? _stringUtilService.CalculateTabLevels(prenamespaceWhitespace[0]?.Text ?? string.Empty, _tabString) : 0); var breadcrumbClassString = _breadcrumbCommandParserService.GenerateBreadcrumbClassInterfaceDeclaration( _breadcrumbDeclaration, tabLevels, _tabString); IsModified = true; Rewriter.InsertAfter(classStopIndex, breadcrumbClassString); } } _ = _currentNamespace.Pop(); return(null); }