示例#1
0
        public void SanityCheck()
        {
            //Set up the absolute minimum
            var solution = base.Solution(
              Generate.Project(
                Generate.ProjectName("Project1"),
                Generate.Sign,
                Generate.Document(
                        @"
                        class C1
                        {
                            public void M1 () { }
                        }")));

            WorkspaceModel ws = new WorkspaceModel("Workspace1", "");
            FolderModel fm = new FolderModel(ws, "Project1");

            var document = solution.Projects.SelectMany(n => n.Documents).Where(n => n.Name == "Document1.cs").Single();
            var linkProvider = new ReferencesourceLinkProvider();

            var walker = SourceBrowser.Generator.DocumentWalkers.WalkerSelector.GetWalker(fm, document, linkProvider);

            walker.Visit(document.GetSyntaxRootAsync().Result);
            var documentModel = walker.GetDocumentModel();

            //Make sure there's 12 tokens
            Assert.IsTrue(documentModel.Tokens.Count == 12);

            //Make sure they're classified correctly
            Assert.IsTrue(documentModel.Tokens.Count(n => n.Type == CSharpTokenTypes.KEYWORD) == 3);
            Assert.IsTrue(documentModel.Tokens.Count(n => n.Type == CSharpTokenTypes.TYPE) == 1);
            Assert.IsTrue(documentModel.Tokens.Count(n => n.Type == CSharpTokenTypes.IDENTIFIER) == 1);
            Assert.IsTrue(documentModel.Tokens.Count(n => n.Type == CSharpTokenTypes.OTHER) == 7);
        }
 protected virtual void VisitFolder(FolderModel folderModel)
 {
     foreach(var child in folderModel.Children)
     {
         VisitProjectItem(child);
     }
 }
示例#3
0
        public void BasicLinking()
        {
            var solution = base.Solution(
              Generate.Project(
                Generate.ProjectName("Project1"),
                Generate.Sign,
                Generate.Document(
                    @"
                    class C1
                    {
                        public void Method1()
                        {
                            Method2();
                        }
                        public void Method2()
                        {
                            Method1();
                        }
                    }")));

            WorkspaceModel ws = new WorkspaceModel("Workspace1", "");
            FolderModel fm = new FolderModel(ws, "Project1");

            var document = solution.Projects.SelectMany(n => n.Documents).Where(n => n.Name == "Document1.cs").Single();
            var linkProvider = new ReferencesourceLinkProvider();

            var walker = SourceBrowser.Generator.DocumentWalkers.WalkerSelector.GetWalker(fm, document, linkProvider);
            walker.Visit(document.GetSyntaxRootAsync().Result);
            var documentModel = walker.GetDocumentModel();

            //Make sure there's two links
            var links = documentModel.Tokens.Select(n => n.Link).Where(n => n != null);
            Assert.IsTrue(links.Count() == 5);

            //Make sure they're all symbol links
            Assert.IsTrue(links.All(n => n is SymbolLink));

            //Make sure they link correctly
            Assert.IsTrue(links.Count(n => ((SymbolLink)(n)).ReferencedSymbolName == "C1.Method1()") == 2);
            Assert.IsTrue(links.Count(n => ((SymbolLink)(n)).ReferencedSymbolName == "C1.Method2()") == 2);
            Assert.IsTrue(links.Count(n => ((SymbolLink)(n)).ReferencedSymbolName == "C1") == 1);
        }
        protected override void VisitFolder(FolderModel folderModel)
        {
            // The clicable element with the folder name:
            _writer.AddAttribute(HtmlTextWriterAttribute.Class, "node collapsed");
            // ID will be used to programmatically show the underlying UL tag by removing "collapsed" class

            //NOTE: We need to correct the backslashes to forward slashes... Thanks Windows...
            var urlStylePath = folderModel.RelativePath.Replace('\\','/');
            _writer.AddAttribute(HtmlTextWriterAttribute.Id, urlStylePath);
            _writer.AddAttribute(HtmlTextWriterAttribute.Title, HttpUtility.HtmlEncode(folderModel.Name)); // Tooltip
            _writer.RenderBeginTag(HtmlTextWriterTag.Li);

            // Folder item is not a link. It is merely used to hide/show the underlying UL tag
            _writer.AddAttribute(HtmlTextWriterAttribute.Href, "#");
            _writer.AddAttribute(HtmlTextWriterAttribute.Style, "margin-left: " + depth * 10 + "px;");
            _writer.RenderBeginTag(HtmlTextWriterTag.A);

            // The expander:
            _writer.AddAttribute(HtmlTextWriterAttribute.Class, "node-toggle");
            _writer.RenderBeginTag(HtmlTextWriterTag.Span);
            _writer.RenderEndTag(); // span

            _writer.Write(HttpUtility.HtmlEncode(folderModel.Name));

            _writer.RenderEndTag(); // a

            // li end tag will be written later
            _writer.WriteLine();

            // The underlying tree branch:
            _writer.RenderBeginTag(HtmlTextWriterTag.Ul);

            depth++;
            base.VisitFolder(folderModel);
            depth--;

            _writer.RenderEndTag(); // ul
            _writer.WriteLine();

            _writer.RenderEndTag(); // li
            _writer.WriteLine();
        }
示例#5
0
        public void TestParameters()
        {
            var solution = base.Solution(
              Generate.Project(
                Generate.ProjectName("Project1"),
                Generate.Sign,
                Generate.Document(
                    @"
                    class C1
                    {
                        public void M1(string p1, int p2, C1 p3)
                        {
                            p1 = null;
                            p2 = 0;
                            p3 = null;
                        }
                    }")));

            WorkspaceModel ws = new WorkspaceModel("Workspace1", "");
            FolderModel fm = new FolderModel(ws, "Project1");

            var document = solution.Projects.SelectMany(n => n.Documents).Where(n => n.Name == "Document1.cs").Single();
            var linkProvider = new ReferencesourceLinkProvider();

            var walker = SourceBrowser.Generator.DocumentWalkers.WalkerSelector.GetWalker(fm, document, linkProvider);
            walker.Visit(document.GetSyntaxRootAsync().Result);
            var documentModel = walker.GetDocumentModel();

            var links = documentModel.Tokens.Select(n => n.Link).Where(n => n != null);
            var symbolLinks = links.Select(n => n as SymbolLink);

            Assert.IsTrue(links.Count() == 9);

            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1").Count() == 2);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1(string, int, C1)").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1(string, int, C1)::p1").Count() == 2);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1(string, int, C1)::p2").Count() == 2);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1(string, int, C1)::p3").Count() == 2);
        }
示例#6
0
        public void TestLocals()
        {
            var solution = base.Solution(
              Generate.Project(
                Generate.ProjectName("Project1"),
                Generate.Sign,
                Generate.Document(
                    @"
                    class C1
                    {
                        public void M1()
                        {
                            string l1 = ""hello""
                            l1 = l1 + "" world""

                            int l2 = 0;
                            l2 = l2 + 1;
                        }
                    }")));

            WorkspaceModel ws = new WorkspaceModel("Workspace1", "");
            FolderModel fm = new FolderModel(ws, "Project1");

            var document = solution.Projects.SelectMany(n => n.Documents).Where(n => n.Name == "Document1.cs").Single();
            var linkProvider = new ReferencesourceLinkProvider();

            var walker = SourceBrowser.Generator.DocumentWalkers.WalkerSelector.GetWalker(fm, document, linkProvider);
            walker.Visit(document.GetSyntaxRootAsync().Result);
            var documentModel = walker.GetDocumentModel();

            var links = documentModel.Tokens.Select(n => n.Link).Where(n => n != null);
            var symbolLinks = links.Select(n => n as SymbolLink);

            Assert.IsTrue(links.Count() == 8);

            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1()").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1()::l1").Count() == 3);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "C1.M1()::l2").Count() == 3);
        }
示例#7
0
        public void TestExtensionMethods()
        {
            var solution = base.Solution(
              Generate.Project(
                Generate.ProjectName("Project1"),
                Generate.Sign,
                Generate.Document(
                  @"
                    public static class MyExtensions
                    {
                        public string ExtensionMethod(this string myParam)
                        {
                        }
                    }

                    class MyClass
                    {
                        public void MyMethod()
                        {
                            ""string"".ExtensionMethod();
                        }
                    }
                   ")));

            WorkspaceModel ws = new WorkspaceModel("Workspace1", "");
            FolderModel fm = new FolderModel(ws, "Project1");

            var document = solution.Projects.SelectMany(n => n.Documents).Where(n => n.Name == "Document1.cs").Single();
            var linkProvider = new ReferencesourceLinkProvider();

            var walker = SourceBrowser.Generator.DocumentWalkers.WalkerSelector.GetWalker(fm, document, linkProvider);
            walker.Visit(document.GetSyntaxRootAsync().Result);
            var documentModel = walker.GetDocumentModel();

            var links = documentModel.Tokens.Select(n => n.Link).Where(n => n != null);
            var symbolLinks = links.Select(n => n as SymbolLink);

            Assert.IsTrue(symbolLinks.Count() == 6);

            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "MyExtensions").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "MyExtensions.ExtensionMethod(string)").Count() == 2);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "MyExtensions.ExtensionMethod(string)::myParam").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "MyClass").Count() == 1);
            Assert.IsTrue(symbolLinks.Where(n => n.ReferencedSymbolName == "MyClass.MyMethod()").Count() == 1);
        }
        private IProjectItem findDocumentParent(WorkspaceModel workspaceModel, Document document)
        {
            IProjectItem currentNode = workspaceModel;
            var rootPath = workspaceModel.BasePath ;
            var docPath = Directory.GetParent(document.FilePath).FullName;

            //If we can't find it, it's not located within our repo and we'll ignore it.
            if (!docPath.StartsWith(rootPath))
                return null;

            var relativePath = docPath.Remove(0, rootPath.Length);

            var folders = relativePath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

            string pathSoFar = rootPath;

            foreach (var folder in folders)
            {
                pathSoFar = Path.Combine(pathSoFar, folder);
                var childFolder = currentNode.Children.Where(n => n.Name == folder).SingleOrDefault();
                if (childFolder == null)
                {
                    childFolder = new FolderModel(currentNode, folder);
                    currentNode.Children.Add(childFolder);
                }
                currentNode = childFolder;
            }
            return currentNode;
        }