protected virtual void VisitWorkspace(WorkspaceModel workspaceModel)
 {
     foreach(var child in _workspaceModel.Children)
     {
         VisitProjectItem(child);
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        public WorkspaceModel BuildWorkspaceModel(string repositoryRootPath)
        {
            var solutionName = Path.GetFileName(_solution.FilePath);
            WorkspaceModel workspaceModel = new WorkspaceModel(solutionName, repositoryRootPath);
            //Build document model for every file.
            foreach (var doc in _solution.Projects.SelectMany(n => n.Documents))
            {
                buildDocumentModel(workspaceModel, doc);
            }

            return workspaceModel;
        }
Ejemplo n.º 5
0
        private void buildDocumentModel(WorkspaceModel workspaceModel, Document document)
        {
            var syntaxRoot = document.GetSyntaxRootAsync().Result;
            var containingFolder = findDocumentParent(workspaceModel, document);
            if (containingFolder == null)
                return;
            var docWalker = WalkerSelector.GetWalker(containingFolder, document, _refsourceLinkProvider);
            docWalker.Visit(syntaxRoot);

            //Save it
            var documentModel = docWalker.GetDocumentModel();
            containingFolder.Children.Add(documentModel);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
 public virtual void Visit(WorkspaceModel workspaceModel)
 {
     _workspaceModel = workspaceModel;
     VisitProjectItem(_workspaceModel);
 }
        protected override void VisitWorkspace(WorkspaceModel workspaceModel)
        {
            using (var stringWriter = new StreamWriter(_savePath, false))
            using(_writer = new HtmlTextWriter(stringWriter))
            {
                _writer.AddAttribute(HtmlTextWriterAttribute.Id, "browserTree");
                _writer.AddAttribute(HtmlTextWriterAttribute.Class, "treeview");
                _writer.AddAttribute("data-role", "treeview");
                _writer.RenderBeginTag(HtmlTextWriterTag.Ul);

                depth++;
                base.VisitWorkspace(workspaceModel);
                depth--;

                _writer.RenderEndTag();
                _writer.WriteLine();
            }
        }