private static RewriterInfo GetSeparateModuleConstantRemovalInfo(VBAParser.ModuleDeclarationsElementContext element)
        {
            var startIndex = element.Start.TokenIndex;
            var stopIndex  = FindStopTokenIndexForRemoval(element);

            return(new RewriterInfo(startIndex, stopIndex));
        }
 // determine whether an option is present
 public override void EnterModuleDeclarationsElement([NotNull] VBAParser.ModuleDeclarationsElementContext context)
 {
     // check whether an option is present
     if (context?.moduleOption() != null && !context.moduleOption().IsEmpty)
     {
         TokenImport = context.moduleOption().Stop;
     }
 }
Ejemplo n.º 3
0
 public override bool VisitModuleDeclarationsElement(VBAParser.ModuleDeclarationsElementContext context)
 {
     return(context.moduleVariableStmt() == null &&
            context.constStmt() == null &&
            context.enumerationStmt() == null &&
            context.udtDeclaration() == null &&
            context.eventStmt() == null &&
            context.implementsStmt() == null &&
            context.declareStmt() == null);
 }
 private static RewriterInfo GetModuleConstantRemovalInfo(
     VBAParser.ConstSubStmtContext target, VBAParser.ModuleDeclarationsElementContext element,
     int count, int itemIndex, IReadOnlyList <VBAParser.ConstSubStmtContext> items)
 {
     if (count == 1)
     {
         return(GetSeparateModuleConstantRemovalInfo(element));
     }
     return(GetRewriterInfoForTargetRemovedFromListStmt(target.Start, itemIndex, items));
 }
        private static RewriterInfo GetModuleVariableRemovalInfo(VBAParser.VariableSubStmtContext target,
                                                                 VBAParser.ModuleDeclarationsElementContext element,
                                                                 int count, int itemIndex, IReadOnlyList <VBAParser.VariableSubStmtContext> items)
        {
            var startIndex = element.Start.TokenIndex;
            var parent     = (VBAParser.ModuleDeclarationsContext)element.Parent;
            var elements   = parent.moduleDeclarationsElement();

            if (count == 1)
            {
                var stopIndex = FindStopTokenIndex(elements, element, parent);
                return(new RewriterInfo(startIndex, stopIndex));
            }
            return(GetRewriterInfoForTargetRemovedFromListStmt(target.Start, itemIndex, items));
        }
        protected static int FindStopTokenIndexForRemoval(VBAParser.ModuleDeclarationsElementContext element)
        {
            if (!element.TryGetFollowingContext <VBAParser.IndividualNonEOFEndOfStatementContext>(out var followingIndividualEndOfLineStatement))
            {
                return(element.Stop.TokenIndex);
            }

            //If the endOfStatement starts with a statement separator, it is safe to simply remove that.
            if (followingIndividualEndOfLineStatement.COLON() != null)
            {
                return(followingIndividualEndOfLineStatement.Stop.TokenIndex);
            }

            //Since there is no statement separator, the individual endOfStatement must contain an endOfLine.
            var endOfLine = followingIndividualEndOfLineStatement.endOfLine();

            //EndOfLines contain preceding comments. So, we cannot remove the line, if there is one.
            if (endOfLine.commentOrAnnotation() != null)
            {
                return(endOfLine.commentOrAnnotation().Start.TokenIndex - 1);
            }

            return(followingIndividualEndOfLineStatement.Stop.TokenIndex);
        }