public IToken GetUsingStopIndex(CSharpParser.Compilation_unitContext context) { return(context?.using_directive()?.LastOrDefault()?.Stop ?? context?.extern_alias_directive()?.LastOrDefault()?.Stop ?? context?.BYTE_ORDER_MARK()?.Symbol ?? context.Start); }
public IToken GetNamespaceStopIndex(CSharpParser.Compilation_unitContext context) { return(context?.namespace_member_declaration()?.LastOrDefault()?.Stop ?? context?.global_attributes()?.Stop ?? context?.using_directive()?.LastOrDefault()?.Stop ?? context?.extern_alias_directive()?.LastOrDefault()?.Stop ?? context?.BYTE_ORDER_MARK()?.Symbol ?? context.Start); }
public override object VisitCompilation_unit([NotNull] CSharpParser.Compilation_unitContext context) { HasServiceClass = false; Results.ServiceNamespace = _serviceNamespace; foreach (var usingDirective in context.using_directive()) { Results.UsingDirectives.Add( _cSharpParserService.GetTextWithWhitespaceMinifiedLite( Tokens, usingDirective.using_directive_inner())); } VisitChildren(context); return(null); }
public HashSet <string> GetUsingDirectivesNotInContext( CSharpParser.Compilation_unitContext context, List <string> usingDirectives) { var contextUsingDirectives = context?.using_directive(); var contextUsingSet = new HashSet <string>(); if (contextUsingDirectives != null) { foreach (var usingDir in contextUsingDirectives) { contextUsingSet.Add(_stringUtilService.MinifyString(usingDir.using_directive_inner().GetText())); } } return(_stringUtilService.GetMissingStrings(contextUsingSet, usingDirectives)); }
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); }