private void AdjustReferences(IEnumerable <IdentifierReference> references, Declaration method)
        {
            foreach (var reference in references.Where(item => item.Context != method.Context))
            {
                var module = reference.QualifiedModuleName.Component.CodeModule;
                VBAParser.ArgumentListContext argumentList = null;
                var callStmt = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(reference.Context);
                if (callStmt != null)
                {
                    argumentList = CallStatement.GetArgumentList(callStmt);
                }

                if (argumentList == null)
                {
                    var indexExpression = ParserRuleContextHelper.GetParent <VBAParser.IndexExprContext>(reference.Context);
                    if (indexExpression != null)
                    {
                        argumentList = ParserRuleContextHelper.GetChild <VBAParser.ArgumentListContext>(indexExpression);
                    }
                }

                if (argumentList == null)
                {
                    continue;
                }
                RemoveCallParameter(argumentList, module);
            }
        }
Ejemplo n.º 2
0
        private void ConvertPropertyGet(IInspectionResult result, VBAParser.PropertyGetStmtContext propertyGetContext)
        {
            var rewriter = _state.GetRewriter(result.Target);

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

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

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

            rewriter.Replace(propertyGetContext.PROPERTY_GET(), Tokens.Sub);
            rewriter.Replace(propertyGetContext.END_PROPERTY(), "End Sub");

            foreach (var returnStatement in GetReturnStatements(result.Target))
            {
                rewriter.Remove(returnStatement);
            }
        }
Ejemplo n.º 3
0
        private void UpdateCall(IdentifierReference reference, int argIndex)
        {
            var rewriter        = _state.GetRewriter(reference.QualifiedModuleName);
            var callStmtContext = ParserRuleContextHelper.GetParent <VBAParser.CallStmtContext>(reference.Context);
            var argListContext  = ParserRuleContextHelper.GetChild <VBAParser.ArgumentListContext>(callStmtContext);

            var arg     = argListContext.argument()[argIndex];
            var argName = arg.positionalArgument()?.argumentExpression() ?? arg.namedArgument().argumentExpression();

            rewriter.InsertBefore(callStmtContext.Start.TokenIndex, $"{argName.GetText()} = ");
            rewriter.Replace(callStmtContext.whiteSpace(), "(");
            rewriter.InsertAfter(argListContext.Stop.TokenIndex, ")");
        }