示例#1
0
        private string DeclareExplicitVariant(VBAParser.ArgContext context, out string instruction)
        {
            if (context == null)
            {
                instruction = null;
                return(null);
            }

            instruction = context.GetText();
            if (!context.children.Select(s => s.GetType()).Contains(typeof(VBAParser.ArgDefaultValueContext)))
            {
                return(instruction + ' ' + Tokens.As + ' ' + Tokens.Variant);
            }

            var fix = string.Empty;
            var hasArgDefaultValue = false;

            foreach (var child in context.children)
            {
                if (child.GetType() == typeof(VBAParser.ArgDefaultValueContext))
                {
                    fix += Tokens.As + ' ' + Tokens.Variant + ' ';
                    hasArgDefaultValue = true;
                }

                fix += child.GetText();
            }

            return(hasArgDefaultValue ? fix : fix + ' ' + Tokens.As + ' ' + Tokens.Variant);
        }
        private string DeclareExplicitVariant(VBAParser.ArgContext context, out string instruction)
        {
            if (context == null)
            {
                instruction = null;
                return(null);
            }

            instruction = context.GetText();
            return(instruction + ' ' + Tokens.As + ' ' + Tokens.Variant);
        }
        private void FixMethod(VBAParser.ArgContext context, QualifiedSelection qualifiedSelection)
        {
            var parameter = context.GetText();
            var argList   = context.parent.GetText();

            var module = qualifiedSelection.QualifiedName.Component.CodeModule;
            {
                string result;
                if (context.BYREF() != null)
                {
                    result = parameter.Replace(Tokens.ByRef, Tokens.ByVal);
                }
                else if (context.OPTIONAL() != null)
                {
                    result = parameter.Replace(Tokens.Optional, Tokens.Optional + ' ' + Tokens.ByVal);
                }
                else
                {
                    result = Tokens.ByVal + ' ' + parameter;
                }

                var startLine = 0;
                var stopLine  = 0;
                try
                {
                    dynamic proc = context.parent.parent;
                    startLine = proc.GetType().GetProperty("Start").GetValue(proc).Line;
                    stopLine  = proc.GetType().GetProperty("Stop").GetValue(proc).Line;
                }
                catch { return; }

                var code = module.GetLines(startLine, stopLine - startLine + 1);
                result = code.Replace(argList, argList.Replace(parameter, result));

                foreach (var line in result.Split(new[] { "\r\n" }, StringSplitOptions.None))
                {
                    module.ReplaceLine(startLine++, line);
                }
            }
        }