Example #1
0
        private void ConvertFunction(IInspectionResult result, VBAParser.FunctionStmtContext functionContext)
        {
            var rewriter = _state.GetRewriter(result.Target);

            var asTypeContext = functionContext.GetChild <VBAParser.AsTypeClauseContext>();

            if (asTypeContext != null)
            {
                rewriter.Remove(asTypeContext);
                rewriter.Remove(functionContext.children.ElementAt(functionContext.children.IndexOf(asTypeContext) - 1) as ParserRuleContext);
            }

            if (result.Target.TypeHint != null)
            {
                rewriter.Remove(functionContext.GetDescendent <VBAParser.TypeHintContext>());
            }

            rewriter.Replace(functionContext.FUNCTION(), Tokens.Sub);
            rewriter.Replace(functionContext.END_FUNCTION(), "End Sub");

            foreach (var returnStatement in GetReturnStatements(result.Target))
            {
                rewriter.Remove(returnStatement);
            }
        }