void RunSimpleTest(string definitions, string call, string expected)
        {
            editor.Document.Text = simpleStart + definitions + call + simpleEnd;
            editor.Caret.Offset  = simpleStart.Length + definitions.Length + 2;

            editor.CreateParseInformation();

            expressionFinder = new CSharpExpressionFinder(ParserService.GetParseInformation(editor.FileName));

            ExpressionResult expression = FindFullExpressionAtCaret(editor, expressionFinder);
            ResolveResult    rr         = ResolveExpressionAtCaret(editor, expression);

            //Ast.Expression ex = GenerateCode.GetExpressionInContext(rr as UnknownMethodResolveResult, editor);

            var introduceMethodAction = GenerateCode.GetContextAction(new EditorContext(editor));

            Assert.IsNotNull(introduceMethodAction);
            introduceMethodAction.Execute();            // .ExecuteIntroduceMethod(rr as UnknownMethodResolveResult, ex, editor, false, null);

            Assert.AreEqual(simpleStart + definitions + call + expected + simpleEnd, editor.Document.Text);
        }
        void RunInterfaceTest(string definitions, string call, string expected, string existingDefinitions)
        {
            editor.Document.Text = interfaceStart + existingDefinitions + interfaceEnd + simpleStart + definitions + call + simpleEnd;
            editor.Caret.Offset  = interfaceStart.Length + existingDefinitions.Length + interfaceEnd.Length + simpleStart.Length + definitions.Length + call.Length / 2;

            var line = editor.Document.GetLineForOffset(editor.Caret.Offset);

            Debug.Print("line: '" + line.Text + "'");

            editor.CreateParseInformation();

            expressionFinder = new CSharpExpressionFinder(ParserService.GetParseInformation(editor.FileName));

            ExpressionResult expression = FindFullExpressionAtCaret(editor, expressionFinder);
            ResolveResult    rr         = ResolveExpressionAtCaret(editor, expression);

            var introduceMethodAction = GenerateCode.GetContextAction(new EditorContext(editor));

            Assert.IsNotNull(introduceMethodAction);
            introduceMethodAction.Execute();             //ExecuteIntroduceMethod(rr as UnknownMethodResolveResult, ex, editor, false, null);

            Assert.AreEqual(interfaceStart + existingDefinitions + expected + interfaceEnd + simpleStart + definitions + call + simpleEnd, editor.Document.Text);
        }
Exemplo n.º 3
0
        public override IEnumerable <IContextAction> GetAvailableActions(EditorContext context)
        {
            if (string.IsNullOrEmpty(context.CurrentExpression.Expression))
            {
                yield break;
            }
            if (context.CurrentExpression.Region != null &&
                context.CurrentExpression.Region.EndLine > context.CurrentExpression.Region.BeginLine)
            {
                // do not yield the action for 2-line expressions like this, which are actually 2 different expressions
                //   variable.(*caret*)
                //   CallFooMethod();
                // this check is not correct for this case because it does not yield the action when it should:
                //   variable.Foo((*caret*)
                //                123);
                yield break;
            }
            var generateCodeAction = GenerateCode.GetContextAction(context);

            if (generateCodeAction != null)
            {
                yield return(generateCodeAction);
            }
        }