コード例 #1
0
        private void editQueryObjectInfo(string objectName, string objInfo, int objType)
        {                        //TODO: �������� objType
            int countOfCase = 0; // ���� 1 ������ ����� ��� ���� 2 ������ ����� ������ ������

            for (int j = 1; j <= codeModule.CountOfLines; j++)
            {
                string bufString = codeModule.get_Lines(j, 1);
                if (bufString.IndexOf(string.Format("Case \"{0}\"", objectName)) > 0)
                {
                    countOfCase++; // ����� ���
                }
                if (countOfCase > 0)
                {
                    if (bufString.IndexOf("objInfo") > 0)
                    {
                        countOfCase++; // ����� ������ � objInfo
                    }
                }
                if (countOfCase > 1)
                {
                    // �������� ������
                    string[] array = bufString.Split(new char[] { '"' });
                    array[1] = objInfo;
                    codeModule.ReplaceLine(j, string.Join("\"", array));
                    return;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns all of the code in a Module as a string.
        /// </summary>
        public static string Lines(this CodeModule module)
        {
            if (module.CountOfLines == 0)
            {
                return(string.Empty);
            }

            return(module.get_Lines(1, module.CountOfLines));
        }
コード例 #3
0
        private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false)
        {
            var line = module.get_Lines(selection.StartLine, 1);

            var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint];
            var pattern      = "\\b" + _declaration.IdentifierName + "\\" + hint;
            var fix          = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty));

            module.ReplaceLine(selection.StartLine, fix);
        }
コード例 #4
0
        private void FixTypeHintUsage(string hint, CodeModule module, Selection selection, bool isDeclaration = false)
        {
            var line = module.get_Lines(selection.StartLine, 1);

            var asTypeClause = ' ' + Tokens.As + ' ' + TypeHints[hint];
            var pattern = "\\b" + _declaration.IdentifierName + "\\" + hint;
            var fix = Regex.Replace(line, pattern, _declaration.IdentifierName + (isDeclaration ? asTypeClause : string.Empty));

            module.ReplaceLine(selection.StartLine, fix);
        }
コード例 #5
0
        /// <summary>
        /// Gets an array of strings where each element is a line of code in the Module.
        /// </summary>
        public static string[] Code(this CodeModule module)
        {
            var lines = module.CountOfLines;

            if (lines == 0)
            {
                return(new string[] { });
            }

            return(module.get_Lines(1, lines).Replace("\r", string.Empty).Split('\n'));
        }
コード例 #6
0
        /// <summary>
        /// Gets an array of strings where each element is a line of code in the Module,
        /// with line numbers stripped and any other pre-processing that needs to be done.
        /// </summary>
        public static string[] GetSanitizedCode(this CodeModule module)
        {
            var lines = module.CountOfLines;

            if (lines == 0)
            {
                return(new string[] { });
            }

            var code = module.get_Lines(1, lines).Replace("\r", string.Empty).Split('\n');

            StripLineNumbers(code);
            return(code);
        }
コード例 #7
0
        private Selection GetSelection()
        {
            int startLine;
            int endLine;
            int startColumn;
            int endColumn;

            if (_codePane == null)
            {
                return(new Selection());
            }

            GetSelection(out startLine, out startColumn, out endLine, out endColumn);

            if (endLine > startLine && endColumn == 1)
            {
                endLine--;
                endColumn = CodeModule.get_Lines(endLine, 1).Length;
            }

            return(new Selection(startLine, startColumn, endLine, endColumn));
        }
コード例 #8
0
 public string get_Lines(int StartLine, int Count)
 {
     return(_codeModule.get_Lines(StartLine, Count));
 }
コード例 #9
0
ファイル: RenamePresenter.cs プロジェクト: igor-bu/Rubberduck
        private string GetReplacementLine(CodeModule module, Declaration target, string newName)
        {
            var targetModule = _parseResult.ComponentParseResults.SingleOrDefault(m => m.QualifiedName == _view.Target.QualifiedName.QualifiedModuleName);

            if (targetModule == null)
            {
                return(null);
            }

            var content = module.get_Lines(_view.Target.Selection.StartLine, 1);

            if (target.DeclarationType == DeclarationType.Parameter)
            {
                var argContext = (VBAParser.ArgContext)_view.Target.Context;
                targetModule.Rewriter.Replace(argContext.ambiguousIdentifier().Start.TokenIndex, _view.NewName);

                // Target.Context is an ArgContext, its parent is an ArgsListContext;
                // the ArgsListContext's parent is the procedure context and it includes the body.
                var context         = (ParserRuleContext)_view.Target.Context.Parent.Parent;
                var firstTokenIndex = context.Start.TokenIndex;
                var lastTokenIndex  = -1; // will blow up if this code runs for any context other than below

                var subStmtContext = context as VBAParser.SubStmtContext;
                if (subStmtContext != null)
                {
                    lastTokenIndex = subStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                var functionStmtContext = context as VBAParser.FunctionStmtContext;
                if (functionStmtContext != null)
                {
                    lastTokenIndex = functionStmtContext.asTypeClause() != null
                        ? functionStmtContext.asTypeClause().Stop.TokenIndex
                        : functionStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                var propertyGetStmtContext = context as VBAParser.PropertyGetStmtContext;
                if (propertyGetStmtContext != null)
                {
                    lastTokenIndex = propertyGetStmtContext.asTypeClause() != null
                        ? propertyGetStmtContext.asTypeClause().Stop.TokenIndex
                        : propertyGetStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                var propertyLetStmtContext = context as VBAParser.PropertyLetStmtContext;
                if (propertyLetStmtContext != null)
                {
                    lastTokenIndex = propertyLetStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                var propertySetStmtContext = context as VBAParser.PropertySetStmtContext;
                if (propertySetStmtContext != null)
                {
                    lastTokenIndex = propertySetStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                var declareStmtContext = context as VBAParser.DeclareStmtContext;
                if (declareStmtContext != null)
                {
                    lastTokenIndex = declareStmtContext.STRINGLITERAL().Last().Symbol.TokenIndex;
                    if (declareStmtContext.argList() != null)
                    {
                        lastTokenIndex = declareStmtContext.argList().RPAREN().Symbol.TokenIndex;
                    }
                    if (declareStmtContext.asTypeClause() != null)
                    {
                        lastTokenIndex = declareStmtContext.asTypeClause().Stop.TokenIndex;
                    }
                }

                var eventStmtContext = context as VBAParser.EventStmtContext;
                if (eventStmtContext != null)
                {
                    lastTokenIndex = eventStmtContext.argList().RPAREN().Symbol.TokenIndex;
                }

                return(targetModule.Rewriter.GetText(new Interval(firstTokenIndex, lastTokenIndex)));
            }
            else
            {
                return(GetReplacementLine(content, target.IdentifierName, newName));
            }
        }
コード例 #10
0
        ///<summary>
        /// ����������� �������������, �������� ����� �� ����������, ����� ��������.
        ///</summary>
        private void getAVEAlarmObject()
        {
            try
            {
                for (int i = 1; i <= ((VBE)m_App.VBE).VBProjects.Count; i++)
                {
                    VBProject bufProject = ((VBE)m_App.VBE).VBProjects.Item(i);
                    if (bufProject.FileName.ToLower() == m_App.ActiveDisplay.Path.ToLower()) // ���� �� ��������� ����� ������
                    {
                        project = bufProject;
                        break;
                    }
                }

                if (project == null)
                {
                    MessageBox.Show("VBProject not found");
                    return;
                }
                List <string> listOfCase      = new List <string>();
                string        procQueryText   = "";
                string        procDisplayText = "";

                codeModule = project.VBComponents.Item("ThisDisplay").CodeModule;
                //TODO: ��� ������� ����� ����� �� "�������� �������", ���� ������� AVExtension1_QueryObjectInfo. �� �������� ��������!
                try
                {
                    string procName      = "AVExtension1_QueryObjectInfo";
                    int    procStart     = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc);
                    int    procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc);

                    procQueryText = codeModule.get_Lines(procStart, procCountLine);
                    if (procQueryText.IndexOf("Select Case") > 0)
                    {
                        int startSelect = procQueryText.IndexOf("Select Case") + ("End Select").Length + 1;
                        int EndSelect   = procQueryText.IndexOf("End Select");
                        procQueryText = procQueryText.Substring(startSelect, EndSelect - startSelect);
                        string[] sfd = procQueryText.Split(new string[] { "Case " }, StringSplitOptions.None);
                        ListOfAVESymbol.Clear();
                        for (int i = 0; i < sfd.Length; i++)
                        {
                            if (sfd[i].IndexOf("objInfo") >= 0)
                            {
                                string objName = sfd[i].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries)[0];
                                string mdbPath = sfd[i].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries)[2];
                                Symbol symbol  = getSymbolByName(objName);

                                ListOfAVESymbol.Add(new AVEAlarmObject(objName, mdbPath, symbol));
                            }
                        }
                    }
                }
                catch {
                    string s = string.Format(Res2.DefaultQueryProc, "AVExtension1");
                    codeModule.AddFromString(s);
                    procQueryText = s;
                }

                try
                {
                    string procName      = "Display_Open";
                    int    procStart     = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc);
                    int    procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc);

                    procDisplayText = codeModule.get_Lines(procStart, procCountLine);

                    for (int j = procStart; j <= procCountLine; j++)
                    {
                        listOfCase.Add(codeModule.get_Lines(j, 1));
                    }
                    procDisplayText = procDisplayText.Substring(procDisplayText.IndexOf("Initialize") + ("Initialize").Length + 1);
                    procDisplayText = procDisplayText.Substring(0, procDisplayText.IndexOf('\n'));
                    string[] prop = procDisplayText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    ServerName = prop[0].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    ModuleRoot = prop[1].Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries)[0];
                }
                catch {
                    string s = string.Format(Res2.DefaultDisplyaOpen, "AVExtension1");
                    codeModule.AddFromString(s);
                    procDisplayText = s;
                }
            }
            catch { }
        }