Esempio n. 1
0
        private IntentionAction TryCreateMoveFromLoopAction([NotNull] ICSharpExpression toMove)
        {
            ILoopStatement previousLoop = null;

            foreach (var node in toMove.ContainingNodes())
            {
                if (node is ICSharpClosure)
                {
                    break;
                }
                if (node is ILoopStatement loop)
                {
                    if (MonoBehaviourMoveUtil.IsAvailableToMoveFromLoop(toMove, loop))
                    {
                        previousLoop = loop;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (previousLoop != null)
            {
                return(new IntentionAction(new MoveFromLoopAction(toMove, previousLoop, FieldName),
                                           BulbThemedIcons.ContextAction.Id, IntentionsAnchors.ContextActionsAnchor));
            }

            return(null);
        }
Esempio n. 2
0
        public virtual IEnumerable <IntentionAction> CreateBulbItems()
        {
            Assertion.Assert(ToMove != null, "ToMove != null");
            Assertion.Assert(MonoBehaviourScript != null, "MonoBehaviourScript != null");

            var result = new List <IntentionAction>();

            if (MonoBehaviourMoveUtil.IsExpressionAccessibleInMethod(ToMove, "Start"))
            {
                result.Add(new IntentionAction(new MoveAction(MonoBehaviourScript, ToMove, "Start", FieldName),
                                               BulbThemedIcons.ContextAction.Id, IntentionsAnchors.ContextActionsAnchor));
            }

            if (MonoBehaviourMoveUtil.IsExpressionAccessibleInMethod(ToMove, "Awake"))
            {
                result.Add(new IntentionAction(new MoveAction(MonoBehaviourScript, ToMove, "Awake", FieldName),
                                               BulbThemedIcons.ContextAction.Id, IntentionsAnchors.ContextActionsAnchor));
            }

            var loopAction = TryCreateMoveFromLoopAction(ToMove);

            if (loopAction != null)
            {
                result.Add(loopAction);
            }

            return(result);
        }
Esempio n. 3
0
 protected override Action <ITextControl> ExecutePsiTransaction(
     ISolution solution, IProgressIndicator progress)
 {
     MonoBehaviourMoveUtil.MoveToMethodWithFieldIntroduction(myClassDeclaration, myExpression, myMethodName,
                                                             myFieldName);
     return(null);
 }
Esempio n. 4
0
            protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
            {
                var anchor = myLoopStatement as ICSharpStatement;

                var declaredElement = MonoBehaviourMoveUtil.GetDeclaredElementFromParentDeclaration(myToMove);
                var baseName        = myVariableName ?? MonoBehaviourMoveUtil.CreateBaseName(myToMove, declaredElement);
                var name            = NamingUtil.GetUniqueName(myToMove, baseName, NamedElementKinds.Locals,
                                                               collection => collection.Add(myToMove.Type(), new EntryOptions()),
                                                               de => !de.Equals(declaredElement));

                var factory        = CSharpElementFactory.GetInstance(myToMove);
                var originMyToMove = myToMove.CopyWithResolve();

                MonoBehaviourMoveUtil.RenameOldUsages(myToMove, declaredElement, name, factory);

                ICSharpStatement declaration = factory.CreateStatement("var $0 = $1;", name, originMyToMove);

                StatementUtil.InsertStatement(declaration, ref anchor, true);
                return(null);
            }