コード例 #1
0
        public override void Fix()
        {
            dynamic functionContext    = Context as VBAParser.FunctionStmtContext;
            dynamic propertyGetContext = Context as VBAParser.PropertyGetStmtContext;

            var context = functionContext ?? propertyGetContext;

            if (context == null)
            {
                throw new InvalidOperationException(string.Format(InspectionsUI.InvalidContextTypeInspectionFix, Context.GetType(), GetType()));
            }


            VBAParser.FunctionNameContext functionName = null;
            if (Context is VBAParser.FunctionStmtContext)
            {
                functionName = ((VBAParser.FunctionStmtContext)Context).functionName();
            }
            else
            {
                functionName = ((VBAParser.PropertyGetStmtContext)Context).functionName();
            }

            string token = functionContext != null
                ? Tokens.Function
                : Tokens.Property + ' ' + Tokens.Get;
            string endToken = token == Tokens.Function
                ? token
                : Tokens.Property;

            string visibility  = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
            string name        = ' ' + Identifier.GetName(functionName.identifier());
            bool   hasTypeHint = Identifier.GetTypeHintValue(functionName.identifier()) != null;

            string args   = context.argList().GetText();
            string asType = context.asTypeClause() == null ? string.Empty : ' ' + context.asTypeClause().GetText();

            string oldSignature = visibility + token + name + (hasTypeHint ? Identifier.GetTypeHintValue(functionName.identifier()) : string.Empty) + args + asType;
            string newSignature = visibility + Tokens.Sub + name + args;

            string procedure          = Context.GetText();
            string noReturnStatements = procedure;

            _returnStatements.ToList().ForEach(returnStatement =>
                                               noReturnStatements = Regex.Replace(noReturnStatements, @"[ \t\f]*" + returnStatement + @"[ \t\f]*\r?\n?", ""));
            string result = noReturnStatements.Replace(oldSignature, newSignature)
                            .Replace(Tokens.End + ' ' + endToken, Tokens.End + ' ' + Tokens.Sub)
                            .Replace(Tokens.Exit + ' ' + endToken, Tokens.Exit + ' ' + Tokens.Sub);

            CodeModule module    = Selection.QualifiedName.Component.CodeModule;
            Selection  selection = Context.GetSelection();

            module.DeleteLines(selection.StartLine, selection.LineCount);
            module.InsertLines(selection.StartLine, result);
        }
コード例 #2
0
        public IntPtr WindowProc(IntPtr hwnd, uint msg, IntPtr WParam, IntPtr LParam)
        {
            // WM_CHAR
            if (msg == 0x102)
            {
                int chr = WParam.ToInt32();

                if (chr == '\x9')
                {
                    //MessageBox.Show("Tab", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    int x, y, w, h;
                    _vbe.ActiveCodePane.GetSelection(out x, out y, out h, out w);

                    Debug.WriteLine(String.Format("x : {0}, y : {1}, h : {2}, w : {3}", x, y, h, w));
                    CodeModule cm   = _vbe.ActiveCodePane.CodeModule;
                    string     line = cm.Lines[x, 1];
                    Debug.WriteLine("the code :" + line);

                    line = line.TrimEnd();

                    string token = findTokenReverse(line);

                    if (token == "if")
                    {
                        // paste if stat
                        line = line.Substring(0, line.Length - 2);
                        String[] strs = new String[3];
                        var      l    = line.Length;

                        strs[0] = line + "If    Then";
                        strs[1] = "";
                        strs[2] = new String(' ', line.Length) + "End If";

                        cm.DeleteLines(x);
                        cm.InsertLines(x, String.Join("\r\n", strs));

                        // set pos
                        _vbe.ActiveCodePane.SetSelection(x, y, h, w);
                    }
                }

                Debug.WriteLine("the chr : " + Convert.ToChar(chr));
            }

            if (msg == 0x14)
            {
                Debug.WriteLine("EraseBackgroud");
            }

            if (msg == 0x85)
            {
                Debug.WriteLine("NC PAINT");
            }
            return(NativeMethods.CallWindowProc(oldProc, hwnd, msg, WParam, LParam));
        }
コード例 #3
0
 private void addQueryObjectInfo(string objectName, string objInfo, int objType)
 {
     if (getQueryObjectInfo(objectName) == null)
     {
         string procName      = string.Format("{0}_QueryObjectInfo", AVE.Name);
         int    procStart     = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc);
         int    procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc);
         for (int endLoop = procStart + procCountLine; procStart <= endLoop; procStart++)
         {
             if (codeModule.get_Lines(procStart, 1).IndexOf("Case Else") > 0)
             {
                 break;
             }
         }
         codeModule.InsertLines(procStart, string.Format(@"        Case ""{0}""
     objType = {1}
     objInfo = ""{2}""", objectName, objType, objInfo));
     }
 }
コード例 #4
0
        private void SetFieldToPrivate(CodeModule module)
        {
            if (_model.TargetDeclaration.Accessibility == Accessibility.Private)
            {
                return;
            }

            RemoveField(_model.TargetDeclaration);

            var newField = "Private " + _model.TargetDeclaration.IdentifierName + " As " +
                           _model.TargetDeclaration.AsTypeName;

            module.InsertLines(module.CountOfDeclarationLines + 1, newField);

            _editor.SetSelection(_model.TargetDeclaration.QualifiedSelection);
            for (var index = 1; index <= module.CountOfDeclarationLines; index++)
            {
                if (module.Lines[index, 1].Trim() == string.Empty)
                {
                    _editor.DeleteLines(new Selection(index, 0, index, 0));
                }
            }
        }
コード例 #5
0
        private void SetFieldToPrivate(CodeModule module)
        {
            if (_model.TargetDeclaration.Accessibility == Accessibility.Private)
            {
                return;
            }

            RemoveField(_model.TargetDeclaration);

            var newField = "Private " + _model.TargetDeclaration.IdentifierName + " As " +
                           _model.TargetDeclaration.AsTypeName;

            module.InsertLines(module.CountOfDeclarationLines + 1, newField);

            _vbe.ActiveCodePane.CodeModule.SetSelection(_model.TargetDeclaration.QualifiedSelection);
            for (var index = 1; index <= module.CountOfDeclarationLines; index++)
            {
                if (module.Lines[index, 1].Trim() == string.Empty)
                {
                    _vbe.ActiveCodePane.CodeModule.DeleteLines(new Selection(index, 0, index, 0));
                }
            }
        }
コード例 #6
0
 public void InsertLines(int Line, string String)
 {
     _codeModule.InsertLines(Line, String);
 }