public override object VisitCompilation_unit([NotNull] CSharpParser.Compilation_unitContext context) { _isFoundConfigureServices = false; var usingNamespaceList = new List <string>(); foreach (var regInfo in _startupRegInfoList) { usingNamespaceList.Add(regInfo.ServiceNamespace); } var missingUsingDirectives = _cSharpParserService.GetUsingDirectivesNotInContext( context, usingNamespaceList); if (missingUsingDirectives.Count > 0) { var usingStopIndex = _cSharpParserService.GetUsingStopIndex(context); var usingDirectiveStr = _cSharpParserService.GenerateUsingDirectives( missingUsingDirectives.ToList(), usingStopIndex.Equals(context.Start)); IsModified = true; Rewriter.InsertAfter(usingStopIndex, usingDirectiveStr); } VisitChildren(context); return(null); }
public override object VisitCompilation_unit([NotNull] CSharpParser.Compilation_unitContext context) { var missingUsingDirectives = _cSharpParserService.GetUsingDirectivesNotInContext( context, new List <string>() { _serviceNamespace }); if (missingUsingDirectives.Count > 0) { var usingStopIndex = _cSharpParserService.GetUsingStopIndex(context); var usingDirectiveStr = _cSharpParserService.GenerateUsingDirectives( missingUsingDirectives.ToList(), usingStopIndex.Equals(context.Start)); _isRewritten = true; Rewriter.InsertAfter(usingStopIndex, usingDirectiveStr); } VisitChildren(context); IsModified = _isRewritten && _isConstructorClassFound; if (!_isConstructorClassFound) { _logger.LogWarning($"No class found called {_constructorClassName} in namespace " + $"{_constructorClassNamespace}. Failed to inject {_serviceInterfaceType} into class."); } return(null); }
public override object VisitCompilation_unit([NotNull] CSharpParser.Compilation_unitContext context) { VisitChildren(context); if (IsModified) { var missingUsingDirectives = _cSharpParserService.GetUsingDirectivesNotInContext( context, new List <string>() { _breadcrumbServiceNamespace }); if (missingUsingDirectives.Count > 0) { var usingStopIndex = _cSharpParserService.GetUsingStopIndex(context); var usingDirectiveStr = _cSharpParserService.GenerateUsingDirectives( missingUsingDirectives.ToList(), usingStopIndex.Equals(context.Start)); Rewriter.InsertAfter(usingStopIndex, usingDirectiveStr); } } return(null); }
public override object VisitCompilation_unit([NotNull] CSharpParser.Compilation_unitContext context) { var usingDirs = context?.using_directive(); if (usingDirs != null) { foreach (var usingDir in usingDirs) { var usingInner = usingDir.using_directive_inner().GetText(); if (_usingSet.Contains(usingInner)) { _usingSet.Remove(usingInner); } } } VisitChildren(context); if (_usingSet.Count > 0) { var usingStopIndex = _cSharpParserService.GetUsingStopIndex(context); var usingDirectivesStr = _cSharpParserService.GenerateUsingDirectives( _usingSet.ToList(), usingStopIndex.Equals(context.Start)); IsModified = true; Rewriter.InsertAfter(usingStopIndex, usingDirectivesStr); } if (!_hasBreadcrumbNamespace) { var namespaceStopIndex = _cSharpParserService.GetNamespaceStopIndex(context); var breadcrumbNamespaceDeclaration = _breadcrumbCommandParserService.GenerateBreadcrumbNamespaceDeclaration( _breadcrumbNamespace, _breadcrumbDeclaration); IsModified = true; Rewriter.InsertAfter(namespaceStopIndex, breadcrumbNamespaceDeclaration); } return(null); }