public void TestCollectForExternalReference()
        {
            var projects = new List <Project> ();
            var solution = new Solution();

            for (int i = 0; i < 3; i++)
            {
                var project = new DotNetAssemblyProject {
                    FileName = String.Format("projectx{0}.csproj", i)
                };
                projects.Add(project);
                solution.RootFolder.AddItem(project);
                project.AddFile(new ProjectFile(String.Format("dummy{0}.cs", i)));
                project.AddReference(typeof(object).Assembly.Location);
                TypeSystemService.LoadProject(project);
                TypeSystemService.GetProjectContentWrapper(project).ReloadAssemblyReferences(project);
            }
            solution.RootFolder.AddItem(new UnknownProject {
                FileName = "test.csproj"
            });

            var compilation = TypeSystemService.GetCompilation(projects[0]);
            var intType     = compilation.GetAllTypeDefinitions().First(t => t.Name == "Int32");

            Assert.AreEqual(null, TypeSystemService.GetProject(intType));
            TestCollectProjects(solution, new [] { intType }, projects);
            TestCollectFiles(solution, new [] { intType }, projects.Select(CreateTestTuple));
        }
        internal static IParameterDataProvider CreateProvider(string text)
        {
            string parsedText;
            string editorText;
            int    cursorPosition = text.IndexOf('$');
            int    endPos         = text.IndexOf('$', cursorPosition + 1);

            if (endPos == -1)
            {
                parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }
            else
            {
                parsedText     = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1);
                editorText     = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
                cursorPosition = endPos - 1;
            }

            TestWorkbenchWindow tww     = new TestWorkbenchWindow();
            TestViewContent     sev     = new TestViewContent();
            DotNetProject       project = new DotNetAssemblyProject("C#");

            project.FileName = GetTempFile(".csproj");

            string file = GetTempFile(".cs");

            project.AddFile(file);

            ProjectDomService.Load(project);
//			ProjectDom dom = ProjectDomService.GetProjectDom (project);
            ProjectDomService.Parse(project, file, null, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, null, delegate { return(parsedText); });

            sev.Project        = project;
            sev.ContentName    = file;
            sev.Text           = editorText;
            sev.CursorPosition = cursorPosition;
            tww.ViewContent    = sev;
            Document doc = new Document(tww);

            doc.ParsedDocument = new NRefactoryParser().Parse(null, sev.ContentName, parsedText);
            CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion(doc);

            CodeCompletionContext ctx = new CodeCompletionContext();

            ctx.TriggerOffset = sev.CursorPosition;
            int line, column;

            sev.GetLineColumnFromPosition(sev.CursorPosition, out line, out column);
            ctx.TriggerLine       = line;
            ctx.TriggerLineOffset = column;

            IParameterDataProvider result = textEditorCompletion.HandleParameterCompletion(ctx, editorText[cursorPosition - 1]);

            ProjectDomService.Unload(project);
            return(result);
        }
        internal static RefactoringOptions CreateRefactoringOptions(string text)
        {
            int cursorPosition = -1;
            int endPos         = text.IndexOf('$');

            if (endPos >= 0)
            {
                cursorPosition = endPos;
                text           = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }

            int selectionStart = -1;
            int selectionEnd   = -1;
            int idx            = text.IndexOf("<-");

            if (idx >= 0)
            {
                selectionStart = idx;
                text           = text.Substring(0, idx) + text.Substring(idx + 2);
                selectionEnd   = idx = text.IndexOf("->");

                text = text.Substring(0, idx) + text.Substring(idx + 2);
                if (cursorPosition < 0)
                {
                    cursorPosition = selectionEnd - 1;
                }
            }

            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            TestViewContent     sev = new TestViewContent();
            //		return new RefactoringOptions ();

            DotNetProject project  = new DotNetAssemblyProject("C#");
            Solution      solution = new Solution();

            solution.RootFolder.Items.Add(project);
            project.FileName = GetTempFile(".csproj");
            string file = GetTempFile(".cs");

            project.AddFile(file);
            string parsedText = text;
            string editorText = text;

            ProjectDomService.Load(project);
            ProjectDom dom = ProjectDomService.GetProjectDom(project);

            dom.ForceUpdate(true);
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });
            ProjectDomService.Parse(project, file, delegate { return(parsedText); });

            sev.Project        = project;
            sev.ContentName    = file;
            sev.Text           = editorText;
            sev.CursorPosition = cursorPosition;

            tww.ViewContent = sev;
            var doc = new MonoDevelop.Ide.Gui.Document(tww);

            doc.Editor.Document.MimeType = "text/x-csharp";
            doc.Editor.Document.FileName = file;
            doc.ParsedDocument           = new McsParser().Parse(null, sev.ContentName, parsedText);
            foreach (var e in doc.ParsedDocument.Errors)
            {
                Console.WriteLine(e);
            }
            if (cursorPosition >= 0)
            {
                doc.Editor.Caret.Offset = cursorPosition;
            }
            if (selectionStart >= 0)
            {
                doc.Editor.SetSelection(selectionStart, selectionEnd);
            }

            NRefactoryResolver resolver = new NRefactoryResolver(dom,
                                                                 doc.ParsedDocument.CompilationUnit,
                                                                 sev.Data,
                                                                 file);

            ExpressionResult expressionResult;

            if (selectionStart >= 0)
            {
                expressionResult = new ExpressionResult(editorText.Substring(selectionStart, selectionEnd - selectionStart).Trim());
                endPos           = selectionEnd;
            }
            else
            {
                expressionResult = new NewCSharpExpressionFinder(dom).FindFullExpression(doc.Editor, cursorPosition + 1);
            }
            ResolveResult resolveResult = endPos >= 0 ? resolver.Resolve(expressionResult, new DomLocation(doc.Editor.Caret.Line, doc.Editor.Caret.Column)) : null;

            RefactoringOptions result = new RefactoringOptions {
                Document      = doc,
                Dom           = dom,
                ResolveResult = resolveResult,
                SelectedItem  = null
            };

            if (resolveResult is MemberResolveResult)
            {
                result.SelectedItem = ((MemberResolveResult)resolveResult).ResolvedMember;
            }
            if (resolveResult is LocalVariableResolveResult)
            {
                result.SelectedItem = ((LocalVariableResolveResult)resolveResult).LocalVariable;
            }
            if (resolveResult is ParameterResolveResult)
            {
                result.SelectedItem = ((ParameterResolveResult)resolveResult).Parameter;
            }
            result.TestFileProvider = new FileProvider(result);
            return(result);
        }
Exemple #4
0
 public void UpdateWithoutFileGetsRemoved()
 {
     _project.AddFile("somefile");
     DoUpdate();
     AssertProjectFilesEquals(new string[0]);
 }
Exemple #5
0
        static void TestInsertionPoints(string text)
        {
            TestWorkbenchWindow tww     = new TestWorkbenchWindow();
            TestViewContent     sev     = new TestViewContent();
            DotNetProject       project = new DotNetAssemblyProject("C#");

            project.FileName = GetTempFile(".csproj");

            string file = GetTempFile(".cs");

            project.AddFile(file);
            sev.Project     = project;
            sev.ContentName = file;
            tww.ViewContent = sev;
            var doc  = new MonoDevelop.Ide.Gui.Document(tww);
            var data = doc.Editor;
            List <InsertionPoint> loc = new List <InsertionPoint> ();

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text[i];
                if (ch == '@')
                {
                    i++;
                    ch = text[i];
                    NewLineInsertion insertBefore = NewLineInsertion.None;
                    NewLineInsertion insertAfter  = NewLineInsertion.None;

                    switch (ch)
                    {
                    case 'n':
                        break;

                    case 'd':
                        insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'D':
                        insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 'u':
                        insertBefore = NewLineInsertion.Eol;
                        break;

                    case 'U':
                        insertBefore = NewLineInsertion.BlankLine;
                        break;

                    case 's':
                        insertBefore = insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'S':
                        insertBefore = insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 't':
                        insertBefore = NewLineInsertion.Eol;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'T':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'v':
                        insertBefore = NewLineInsertion.BlankLine;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    case 'V':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    default:
                        Assert.Fail("unknown insertion point:" + ch);
                        break;
                    }
                    loc.Add(new InsertionPoint(data.Document.OffsetToLocation(data.Document.Length), insertBefore, insertAfter));
                }
                else
                {
                    data.Insert(data.Document.Length, ch.ToString());
                }
            }


            doc.ParsedDocument = new McsParser().Parse(null, "a.cs", data.Document.Text);

            var foundPoints = CodeGenerationService.GetInsertionPoints(doc, doc.ParsedDocument.CompilationUnit.Types[0]);

            Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
            for (int i = 0; i < loc.Count; i++)
            {
                Assert.AreEqual(loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
                Assert.AreEqual(loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                Assert.AreEqual(loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
            }
        }