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);
        }
Esempio n. 2
0
 public IToken GetClassInterfaceStopIndex(CSharpParser.Namespace_bodyContext context)
 {
     return(context?.namespace_member_declaration()?.LastOrDefault()?.Stop
            ?? context?.using_directive()?.LastOrDefault()?.Stop
            ?? context?.extern_alias_directive()?.LastOrDefault()?.Stop
            ?? context.OPEN_BRACE().Symbol);
 }
Esempio n. 3
0
        public static void Parse(this CSharpParser.Namespace_bodyContext context, NamespaceContext parent, string name)
        {
            if (context.extern_alias_directives() != null)
            {
                throw new NotSupportedException("Extern alias not supported");
            }

            IUsingStatement[] @using = context.using_directives() != null
                ? context.using_directives().Parse()
                : new IUsingStatement[0];

            NamespaceContext ns = parent.GetChildContext(name, @using);

            if (context.namespace_member_declarations() != null)
            {
                context.namespace_member_declarations().Parse(ns);
            }
        }