Beispiel #1
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var projectFile = (IProjectFile)_highlight.OffendingProjectItem;

            using (var cookie = solution.CreateTransactionCookie(DefaultAction.Rollback, this.GetType().Name, progress))
            {
                IProjectFolder newFolder = (IProjectFolder)_highlight.TargetProject.FindProjectItemByLocation(_highlight.TargetFolder)
                                           ?? _highlight.TargetProject.GetOrCreateProjectFolder(_highlight.TargetFolder, cookie);

                var            workflow     = new MoveToFolderWorkflow(solution, "ManualMoveToFolderQuickFix");
                IProjectFolder targetFolder = newFolder ?? _highlight.TargetProject;

                var dataProvider = new MoveToFolderDataProvider(true, false, targetFolder, new List <string>(), new List <string>());
                workflow.SetDataProvider(dataProvider);

                Lifetimes.Using(
                    (lifetime => WorkflowExecuter.ExecuteWithCustomHost(
                         Shell.Instance.GetComponent <IActionManager>()
                         .DataContexts.CreateWithoutDataRules(lifetime
                                                              , DataRules.AddRule(DataRules.AddRule("ManualMoveToFolderQuickFix"
                                                                                                    , JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.PROJECT_MODEL_ELEMENTS, new IProjectModelElement[] { projectFile })
                                                                                  , "ManualMoveToFolderQuickFix"
                                                                                  , JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.SOLUTION, solution))
                         , workflow, new SimpleWorkflowHost())));

                cookie.Commit(progress);
            }

            return(null);
        }
        public static Func <Lifetime, DataContexts, IDataContext> ToDataContext([NotNull] this ITextControl textControl)
        {
            if (textControl == null)
            {
                throw new ArgumentNullException("textControl");
            }

            return((lifetime, contexts) => contexts.CreateWithDataRules(lifetime, DataRules.AddRule("TextControl", DataConstants.TEXT_CONTROL, textControl)));
        }
        public static IDataContext CreateDataContext(IComponentContainer componentContainer, ISolution solution, ITextControl control)
        {
            var actionManager = componentContainer.GetComponent <IActionManager>();

            var dataRules = DataRules
                            .AddRule("Test", ProjectModelDataConstants.SOLUTION, x => solution)
                            .AddRule("Test", TextControlDataConstants.TEXT_CONTROL, x => control)
                            .AddRule("Test", DocumentModelDataConstants.DOCUMENT, x => control.Document)
#if WAVE07
                            .AddRule("Test", DocumentModelDataConstants.EDITOR_CONTEXT, x => new DocumentEditorContext(new DocumentOffset(control.Document, control.Caret.Position.Value.ToDocOffset())));
Beispiel #4
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 static IDataContext CreateDataContext(IComponentContainer componentContainer, ISolution solution, ITextControl control)
        {
            var actionManager = componentContainer.GetComponent <IActionManager>();

            var dataRules = DataRules
                            .AddRule("Test", ProjectModelDataConstants.SOLUTION, x => solution)
                            .AddRule("Test", TextControlDataConstants.TEXT_CONTROL, x => control)
                            .AddRule("Test", DocumentModelDataConstants.DOCUMENT, x => control.Document)
                            .AddRule("Test", DocumentModelDataConstants.EDITOR_CONTEXT, x => new DocumentEditorContext(new DocumentOffset(control.Document, control.Caret.Offset())));

            return(actionManager.DataContexts.CreateWithDataRules(control.Lifetime, dataRules));
        }
 public void CallRename(IDeclaredElement declaredElement, ITextControl textControl, string newName)
 {
     Lifetimes.Using(
         lifetime => _renameRefactoringService.ExcuteRename(
             _actionManager.DataContexts.CreateWithDataRules(
                 lifetime,
                 DataRules
                 .AddRule("ManualChangeNameFix", DataConstants.DECLARED_ELEMENTS, new [] { declaredElement })
                 .AddRule("ManualChangeNameFix", TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl)
                 .AddRule("ManualChangeNameFix", ProjectModel.DataContext.DataConstants.SOLUTION, _solution)
                 .AddRule("ManualChangeNameFix",
                          RenameWorkflow.RenameDataProvider, new SimpleRenameDataProvider(newName)))));
 }
Beispiel #7
0
        public void Execute(ISolution solution, ITextControl textControl)
        {
            IList <IDataRule> provider =
                DataRules.AddRule(
                    "ManualRenameRefactoringItem",
                    PsiDataConstants.DECLARED_ELEMENTS,
                    _declaration.DeclaredElement.ToDeclaredElementsDataConstant()
                    ).AddRule(
                    "ManualRenameRefactoringItem",
                    TextControlDataConstants.TEXT_CONTROL,
                    textControl
                    ).AddRule(
                    "ManualRenameRefactoringItem",
                    ProjectModelDataConstants.SOLUTION,
                    solution);

            /*
             * if (Shell.Instance.IsTestShell)
             *  provider.AddRule(
             *      "ManualRenameRefactoringItem",
             *      RenameWorkflow.RenameDataProvider,
             *      new RenameTestDataProvider("TestName", false, false)
             *  );
             */
            if (_targetName != null)
#if RESHARPER20172
            { provider.AddRule(
                  "ManualRenameRefactoringItem",
                  RenameRefactoringService.RenameDataProvider, new RenameDataProvider(_targetName)); }
#else
            { provider.AddRule(
                  "ManualRenameRefactoringItem",
                  RenameRefactoringService.RenameDataProvider, new SimpleRenameDataProvider(_targetName)); }
#endif

            Lifetimes.Using(
                (lifetime => {
                var actionManager = solution.GetComponent <IActionManager>();
                var context = actionManager.DataContexts.CreateWithDataRules(lifetime, provider);
#if RESHARPER20161
                RenameRefactoringService.Instance.ExecuteRename(context);
#else
                RenameRefactoringService.RenameFromContext(context);
#endif
            }));
        }
        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);
                });
            }
        }
        public void Execute(ISolution solution, ITextControl textControl)
        {
            IList <IDataRule> provider =
                DataRules.AddRule(
                    "ManualRenameRefactoringItem",
                    JetBrains.ReSharper.Psi.Services.DataConstants.DECLARED_ELEMENTS,
                    DataConstantsEx.ToDeclaredElementsDataConstant(this._declaration.DeclaredElement)
                    ).AddRule(
                    "ManualRenameRefactoringItem",
                    JetBrains.TextControl.DataContext.DataConstants.TEXT_CONTROL,
                    textControl
                    ).AddRule(
                    "ManualRenameRefactoringItem",
                    JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION,
                    solution);

            /*
             * if (Shell.Instance.IsTestShell)
             *  provider.AddRule(
             *      "ManualRenameRefactoringItem",
             *      RenameWorkflow.RenameDataProvider,
             *      new RenameTestDataProvider("TestName", false, false)
             *  );
             */
            if (_targetName != null)
            {
                provider.AddRule(
                    "ManualRenameRefactoringItem",
                    RenameWorkflow.RenameDataProvider, new SimpleRenameDataProvider(_targetName));
            }

            Lifetimes.Using(
                (lifetime =>
                 RenameRefactoringService.Instance.ExcuteRename(
                     JetBrains.ActionManagement.ShellComponentsEx.ActionManager(
                         Shell.Instance.Components).DataContexts.CreateWithDataRules(lifetime, provider))));
        }
Beispiel #11
0
 /// <summary>
 /// Gets a DataRule given its id.
 /// </summary>
 /// <param name="id">The unique id of the DataRule</param>
 /// <returns>The DataRule</returns>
 public DataRule GetDataRuleById(int id)
 {
     return(DataRules.FirstOrDefault(r => r.Id == id));
 }
Beispiel #12
0
 /// <summary>
 /// Removes a DataRule given its id.
 /// </summary>
 /// <param name="id">The unique id of the DataRule</param>
 public void RemoveDataRuleById(int id)
 {
     DataRules.Remove(GetDataRuleById(id));
 }
        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, ProjectModel.DataContext.DataConstants.SOLUTION, solution)
                        .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document)
                        .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl);

            var settingsStore       = expression.GetSettingsStore();
            var multipleOccurrences = settingsStore.GetValue(PostfixSettingsAccessor.SearchVarOccurrences);

            var definition = Lifetimes.Define(EternalLifetime.Instance, actionId);

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

                if (multipleOccurrences && !Shell.Instance.IsTestShell)
                {
                    var introduceAction = new IntroVariableAction();
                    if (introduceAction.Update(dataContext, new ActionPresentation(), () => false))
                    {
                        introduceAction.Execute(dataContext, delegate { });

                        if (executeAfter != null)
                        {
                            SubscribeAfterExecute(executeAfter);
                        }
                    }
                }
                else
                {
                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    WorkflowExecuter.ExecuteBatch(dataContext, workflow);

#if RESHARPER8
                    if (executeAfter != null)
                    {
                        SubscribeAfterExecute(executeAfter);
                    }
#elif RESHARPER9
                    var finishedAction = executeAfter;
                    if (finishedAction != null)
                    {
                        workflow.SuccessfullyFinished += delegate { finishedAction(); }
                    }
                    ;
#endif
                }
            }
            finally
            {
                definition.Terminate();
            }
        }
Beispiel #14
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, ProjectModel.DataContext.DataConstants.SOLUTION, solution)
                        .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document)
                        .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl);

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

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

                // todo: introduce normal way to execute refactorings with occurences search
                if (multipleOccurrences && !Shell.Instance.IsTestShell)
                {
                    var introduceAction = new IntroVariableAction();
                    if (introduceAction.Update(dataContext, new ActionPresentation(), () => false))
                    {
                        introduceAction.Execute(dataContext, delegate { });

                        if (executeAfter != null)
                        {
                            IntroduceVariableTemplate.SubscribeAfterExecute(executeAfter);
                        }
                    }
                }
                else
                {
                    var workflow = new IntroduceVariableWorkflow(solution, actionId);
                    WorkflowExecuter.ExecuteBatch(dataContext, workflow);

                    var finishedAction = executeAfter;
                    if (finishedAction != null)
                    {
                        var currentSession = HotspotSessionExecutor.Instance.CurrentSession;
                        if (currentSession != null) // ugly hack
                        {
                            currentSession.HotspotSession.Closed.Advise(EternalLifetime.Definition, (e) =>
                            {
                                if (e.TerminationType == TerminationType.Finished)
                                {
                                    finishedAction();
                                }
                            });
                        }
                        else
                        {
                            finishedAction();
                        }
                    }
                }
            }
        }
 protected override IList <IDataRule> ProvideContextData(IProject testProject, ITextControl control)
 {
     return(DataRules.AddRule("Test", RenameRefactoringService.RenameDataProvider,
                              ctx => CreateRenameDataProvider(ctx, control)));
 }