コード例 #1
0
            private Action <ITextControl> ChangeParameters(ISolution solution)
            {
                var model = ClrChangeSignatureModel.CreateModel(myMethodDeclaration.DeclaredElement).NotNull();

                for (var i = 0; i < myExpectedMethodSignature.Parameters.Length; i++)
                {
                    var requiredParameter = myExpectedMethodSignature.Parameters[i];

                    var modelParameter = FindBestMatch(requiredParameter, model, i);
                    if (modelParameter != null)
                    {
                        // If the current index is correct, do nothing. If not, use the original index to find the item to move
                        if (modelParameter.ParameterIndex != i)
                        {
                            model.MoveTo(modelParameter.OriginalParameterIndex, i);
                        }
                    }
                    else
                    {
                        model.Add(i);
                        modelParameter = model.ChangeSignatureParameters[i];
                    }

                    modelParameter.ParameterName = requiredParameter.Name;
                    modelParameter.ParameterKind = ParameterKind.VALUE;
                    modelParameter.ParameterType = requiredParameter.Type;

                    // Reset everything else
                    modelParameter.IsOptional = false;
                    modelParameter.IsParams   = false;
                    modelParameter.IsThis     = false;
                    modelParameter.IsVarArg   = false;
                }

                for (var i = model.ChangeSignatureParameters.Length - 1;
                     i >= myExpectedMethodSignature.Parameters.Length;
                     i--)
                {
                    model.RemoveAt(i);
                }

                var refactoring = new ChangeSignatureRefactoring(model);

                refactoring.Execute(NullProgressIndicator.Create());

                // Ideally, we would now call InplaceRefactoringsManager.Reset to make sure we didn't have
                // an inplace refactoring highlight. But InplaceRefactoringsManager is internal, so we can't.
                // We don't want a highlight telling us to "apply signature change refactoring" because we
                // just have. The only way to remove it is to fire the Escape action
                return(tc =>
                {
                    var highlightingManager = solution.GetComponent <InplaceRefactoringsHighlightingManager>();
                    if (highlightingManager.GetHighlightersForTests(tc).Any())
                    {
                        var actionManager = solution.GetComponent <IActionManager>();
                        var escapeActionHandler = actionManager.Defs.GetActionDef <EscapeActionHandler>();
                        escapeActionHandler.EvaluateAndExecute(actionManager);
                    }
                });
            }
コード例 #2
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var changeSignature = LanguageManager.Instance.TryGetService <ChangeSignature>(myMethodDeclaration.Language);

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

            var model = changeSignature.CreateModel(myMethodDeclaration.DeclaredElement);

            for (var i = 0; i < myEventFunction.Parameters.Length; i++)
            {
                var requiredParameter = myEventFunction.Parameters[i];

                var modelParameter = FindBestMatch(requiredParameter, model, i);
                if (modelParameter != null)
                {
                    model.MoveTo(modelParameter.OriginalParameterIndex, i);
                }
                else
                {
                    model.Add(i);
                    modelParameter = model.ChangeSignatureParameters[i];
                }

                modelParameter.ParameterName = requiredParameter.Name;
                modelParameter.ParameterKind = ParameterKind.VALUE;
                modelParameter.ParameterType = CreateParameterType(requiredParameter);

                // Reset everything else
                modelParameter.DefaultValue = null;
                modelParameter.IsOptional   = false;
                modelParameter.IsParams     = false;
                modelParameter.IsThis       = false;
                modelParameter.IsVarArg     = false;
            }

            for (var i = model.ChangeSignatureParameters.Length - 1; i >= myEventFunction.Parameters.Length; i--)
            {
                model.Remove(i);
            }

            var refactoring = new ChangeSignatureRefactoring(model);

            refactoring.Execute(NullProgressIndicator.Instance);

            // Ideally, we would now call InplaceRefactoringsManager.Reset to make sure we didn't have
            // an inplace refactoring highlight. But InplaceRefactoringsManager is internal, so we can't.
            // We don't want a highlight telling us to "apply signature change refactoring" because we
            // just have. The only way to remove it is to fire the Escape action
            return(tc =>
            {
                var highlightingManager = solution.GetComponent <InplaceRefactoringsHighlightingManager>();
                if (highlightingManager.GetHighlightersForTests(tc).Any())
                {
                    var actionManager = solution.GetComponent <IActionManager>();
                    var escapeActionHandler = actionManager.Defs.GetActionDef <EscapeActionHandler>();
                    escapeActionHandler.EvaluateAndExecute(actionManager);
                }
            });
        }