Exemple #1
0
 void ExecuteRenameStep()
 {
     Lifetimes.Using(Lifetime => RefactoringActionUtil.ExecuteRefactoring
                     (
                         Shell.Instance.Components.ActionManager().DataContexts.Create(Lifetime, Rules),
                         new RenameStepWorkflow(Solution, null)
                     ));
 }
Exemple #2
0
            private static void ExecuteRefactoring(
                [NotNull] ITextControl textControl,
                [NotNull] ICSharpExpression expression,
                [CanBeNull] Action executeAfter = null)
            {
                const string actionId = IntroVariableAction.ACTION_ID;

                var solution = expression.GetSolution();
                var document = textControl.Document;

                var expressionRange = expression.GetDocumentRange()
                                      .TextRange;

                textControl.Selection.SetRange(expressionRange);

                var rules = DataRules
                            .AddRule(actionId, ProjectModelDataConstants.SOLUTION, solution)
                            .AddRule(actionId, DocumentModelDataConstants.DOCUMENT, document)
                            .AddRule(actionId, TextControlDataConstants.TEXT_CONTROL, textControl);

                var settingsStore       = expression.GetSettingsStoreWithEditorConfig();
                var multipleOccurrences = settingsStore.GetValue(PostfixTemplatesSettingsAccessor.SearchVarOccurrences);

                // note: uber ugly code down here
                using (var definition = Lifetime.Define(Lifetime.Eternal, actionId))
                {
                    var dataContexts = solution.GetComponent <DataContexts>();
                    var dataContext  = dataContexts.CreateWithDataRules(definition.Lifetime, rules);

                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    RefactoringActionUtil.ExecuteRefactoring(dataContext, workflow);

                    var finishedAction = executeAfter;
                    if (finishedAction != null)
                    {
                        var currentSession = HotspotSessionExecutor.Instance.CurrentSession;
                        if (currentSession != null) // ugly hack
                        {
                            currentSession.HotspotSession.Closed.Advise(Lifetime.Eternal,
                                                                        (e) =>
                            {
                                if (e.TerminationType == TerminationType.Finished)
                                {
                                    finishedAction();
                                }
                            });
                        }
                        else
                        {
                            finishedAction();
                        }
                    }
                }
            }
        private IList <BalloonOption> GetOptions(InplaceRefactoringInfo refactoringInfo)
        {
            var applyRefactoringMessage = "Apply refactoring";

            switch (refactoringInfo.Type)
            {
            case InplaceRefactoringType.Rename:
                applyRefactoringMessage = "Apply rename refactoring (Alt+Enter)";
                break;

            case InplaceRefactoringType.ChangeSignature:
                applyRefactoringMessage = "Apply change signature refactoring (Alt+Enter)";
                break;

            case InplaceRefactoringType.MoveStaticMembers:
                applyRefactoringMessage = "Apply move static members refactoring (Alt+Enter)";
                break;
            }

            // ReSharper disable ConvertToLambdaExpression
            Action applyRefactoringAction = () =>
            {
                ReadLockCookie.GuardedExecute(() =>
                {
                    Lifetimes.Using(l =>
                    {
                        // I think this will fail if the cursor moves out of the refactoring range
                        var dataRules = DataRules.AddRule("DoInplaceRefactoringContextActionBase",
                                                          DataConstants.SOLUTION, solution);
                        var dataContext = actionManager.DataContexts.CreateOnSelection(l, dataRules);
                        RefactoringActionUtil.ExecuteRefactoring(dataContext,
                                                                 refactoringInfo.CreateRefactoringWorkflow());
                    });
                });
            };
            // ReSharper restore ConvertToLambdaExpression

            var options = new List <BalloonOption>
            {
                new BalloonOption(applyRefactoringMessage, applyRefactoringAction),
                new BalloonOption("Just edit the code without help")
            };

            return(options);
        }
        public void Execute(ISolution solution, ITextControl textControl)
        {
            if (!MethodDeclaration.IsValid())
            {
                return;
            }
            var declared = MethodDeclaration.DeclaredElement;

            if (declared != null)
            {
                var suggests = AsyncMethodNameSuggestions.Get(MethodDeclaration);
                var workflow =
                    (IRefactoringWorkflow)
                    new MethodRenameWorkflow(suggests, solution.GetComponent <RenameRefactoringService>(), solution, "AsyncSuffixMethodRename");
                Lifetimes.Using(lifetime =>
                {
                    var dataRules   = DataRules.AddRule("DoAsyncMethodRenameWorkflow", ProjectModelDataConstants.SOLUTION, solution);
                    var dataContext = solution.GetComponent <IActionManager>().DataContexts.CreateOnSelection(lifetime, dataRules);
                    RefactoringActionUtil.ExecuteRefactoring(dataContext, workflow);
                });
            }
        }
        private void MoveToOuterFile()
        {
            var declaredElement = _sourceTypeDeclaration.DeclaredElement;
            var solution        = _sourceTypeDeclaration.GetSolution();

            var newName = RenameFileToMatchTypeNameAction.GetFileName(declaredElement, _sourceTypeDeclaration.GetProjectFile());

            if (newName == null)
            {
                return;
            }

            var dataProvider = new MoveMoFileMoveTypeDataProvider(newName, null, new[] { _sourceTypeDeclaration });
            var context      = new DataContext();

            context.SetData(MoveTypeWorkflow.DATA_PROVIDER, dataProvider);
            context.SetData(DataConstants.SOLUTION, solution);
            context.SetData(JetBrains.ReSharper.Psi.Services.DataConstants.PSI_LANGUAGE_TYPE, _sourceTypeDeclaration.Language);
            context.SetData(JetBrains.ReSharper.Psi.Services.DataConstants.DECLARED_ELEMENT, declaredElement);

            var workflow = new MoveTypeWorkflow(solution);

            RefactoringActionUtil.ExecuteRefactoring(context, workflow);
        }