public override object VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, object data)
        {
            bool isDefinedInsideCutRegion = CutRegion.Contains(variableDeclarationStatement.StartLocation.Line, variableDeclarationStatement.StartLocation.Column);

            foreach (var varDecl in variableDeclarationStatement.Variables)
            {
                var descr = new VariableDescriptor(varDecl.Name)
                {
                    IsDefinedInsideCutRegion = isDefinedInsideCutRegion,
                    Declaration = variableDeclarationStatement
                };
                if (varDecl.Initializer != null)
                {
                    if (isDefinedInsideCutRegion)
                    {
                        descr.UsedInCutRegion = true;
                    }
                    else if (variableDeclarationStatement.StartLocation < new AstLocation(CutRegion.Start.Line, CutRegion.Start.Column))
                    {
                        descr.UsedBeforeCutRegion = !varDecl.Initializer.IsNull;
                    }
                    else
                    {
                        descr.UsedAfterCutRegion = true;
                    }
                }
                variables[varDecl.Name] = descr;
            }
            return(base.VisitVariableDeclarationStatement(variableDeclarationStatement, data));
        }
예제 #2
0
        public ExtractMethodDialog(RefactoringOptions options, ExtractMethodRefactoring extractMethod, ExtractMethodRefactoring.ExtractMethodParameters properties)
        {
            this.Build();
            this.options       = options;
            this.properties    = properties;
            this.extractMethod = extractMethod;

            store = new ListStore(typeof(string), typeof(string));
            treeviewParameters.Model = store;
            treeviewParameters.AppendColumn("Type", new CellRendererText(), "text", 0);
            treeviewParameters.AppendColumn("Name", new CellRendererText(), "text", 1);
            FillStore();
            buttonPreview.Sensitive = buttonOk.Sensitive = false;
            entry.Changed          += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName(); };
            ValidateName();

            buttonOk.Clicked      += OnOKClicked;
            buttonCancel.Clicked  += OnCancelClicked;
            buttonPreview.Clicked += OnPreviewClicked;

            buttonUp.Clicked += delegate {
                List <int> indices = new List <int> ();
                foreach (TreePath path in treeviewParameters.Selection.GetSelectedRows())
                {
                    int index = Int32.Parse(path.ToString());
                    if (index > 0)
                    {
                        VariableDescriptor tmp = properties.Parameters [index - 1];
                        properties.Parameters [index - 1] = properties.Parameters [index];
                        properties.Parameters [index]     = tmp;
                        indices.Add(index - 1);
                    }
                }
                FillStore();
                treeviewParameters.Selection.SelectPath(new TreePath(indices.ToArray()));
            };
            buttonDown.Clicked += delegate {
                List <int> indices = new List <int> ();
                foreach (TreePath path in treeviewParameters.Selection.GetSelectedRows())
                {
                    int index = Int32.Parse(path.ToString());
                    if (index + 1 < properties.Parameters.Count)
                    {
                        VariableDescriptor tmp = properties.Parameters [index + 1];
                        properties.Parameters [index + 1] = properties.Parameters [index];
                        properties.Parameters [index]     = tmp;
                        indices.Add(index + 1);
                    }
                }
                FillStore();
                treeviewParameters.Selection.SelectPath(new TreePath(indices.ToArray()));
            };
            ListStore modifiers = new ListStore(typeof(string));

            modifiers.AppendValues("");
            modifiers.AppendValues("public");
            modifiers.AppendValues("private");
            modifiers.AppendValues("protected");
            modifiers.AppendValues("internal");
            comboboxModifiers.Model  = modifiers;
            comboboxModifiers.Active = PropertyService.Get <int> ("MonoDevelop.Refactoring.ExtractMethod.ExtractMethodDialog.DefaultModifier");
            entry.Activated         += delegate {
                if (buttonOk.Sensitive)
                {
                    buttonOk.Click();
                }
            };
        }