// If lazy is true then treeview items are populated on-demand. In other words, when lazy is true
        // the children for any given item are only populated when the item is selected. If lazy is
        // false then the entire tree is populated at once (and this can result in bad performance when
        // displaying large trees).
        public void DisplaySyntaxTree(CommonSyntaxTree tree, string language, bool lazy = true)
        {
            if (tree != null && !string.IsNullOrEmpty(language))
            {
                SourceLanguage = language;
                IsLazy         = lazy;
                SyntaxTree     = tree;

                AddNode(root, SyntaxTree.GetRoot());
                if (SyntaxTreeLoaded != null && SyntaxTree != null)
                {
                    SyntaxTreeLoaded(this, new SyntaxLoadedArgs(SyntaxTree.GetRoot()));
                }
            }
        }
Example #2
0
        internal static void ReplaceBasic()
        {
            IProject proj = ProtoTestProj;

            foreach (var doc in proj.Documents)
            {
                CommonSyntaxTree syntax = doc.GetSyntaxTree();
                FileTree = syntax;
                FileRoot = (CompilationUnitSyntax)syntax.GetRoot();

                bool containingMethodToReplace = true;
                while (containingMethodToReplace)
                {
                    containingMethodToReplace = SearchAndReplaceMethodsForTextCSharp(doc, "thisTest.Verify");
                    FileTree = SyntaxTree.Create(FileRoot);
                    FileRoot = (CompilationUnitSyntax)FileTree.GetRoot();
                }
                var UsingStmtForDict = Syntax.QualifiedName(Syntax.IdentifierName("System.Collections"),
                                                            Syntax.IdentifierName("Generic"));
                FileRoot = FileRoot.AddUsings(Syntax.UsingDirective(UsingStmtForDict).NormalizeWhitespace()).NormalizeWhitespace();

                File.WriteAllText(doc.FilePath, FileRoot.ToString());

                //Console.WriteLine(result);
            }
        }
        public AnalysisResult Analyze(CommonSyntaxTree syntaxTree, SemanticModel semanticModel)
        {
            List<ClassDeclarationSyntax> classDeclarations = syntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>().ToList();

            List<ClassInfo> classInfos = InspectClassDeclarations(semanticModel, classDeclarations);

            List<Issue> issues = new List<Issue>();

            foreach (ClassInfo classInfo in classInfos)
            {
                foreach (IAnalysisRule rule in _ruleProvider.Rules)
                {
                    AnalysisResult result = rule.Analyze(syntaxTree, semanticModel, classInfo);

                    if (!result.Success)
                    {
                        issues.AddRange(result.Issues);
                    }
                }
            }

            if (issues.Count > 0)
            {
                return new AnalysisResult(issues);
            }
            else
            {
                return AnalysisResult.Succeeded;
            }
        }
Example #4
0
        internal SyntaxTransporter(CommonSyntaxTree tree)
        {
            SyntaxStream = new MemoryStream();
            if (tree is CSharp.SyntaxTree)
            {
                SourceLanguage = LanguageNames.CSharp;
                var csharpTree = (CSharp.SyntaxTree)tree;
                csharpTree.GetRoot().SerializeTo(SyntaxStream);
            }
            else
            {
                SourceLanguage = LanguageNames.VisualBasic;
                var vbTree = (VisualBasic.SyntaxTree)tree;
                vbTree.GetRoot().SerializeTo(SyntaxStream);
            }

            ItemSpan = tree.GetRoot().Span;
            ItemKind = tree.GetRoot().GetKind(SourceLanguage);
            ItemCategory = SyntaxCategory.SyntaxNode;
        }
 // If lazy is true then treeview items are populated on-demand. In other words, when lazy is true
 // the children for any given item are only populated when the item is selected. If lazy is
 // false then the entire tree is populated at once (and this can result in bad performance when
 // displaying large trees).
 public void DisplaySyntaxTree(CommonSyntaxTree tree, string language, bool lazy = true)
 {
     if (tree != null && !string.IsNullOrEmpty(language))
     {
         SourceLanguage = language;
         IsLazy         = lazy;
         SyntaxTree     = tree;
         AddNode(null, SyntaxTree.GetRoot());
         legendButton.Visibility = Visibility.Visible;
     }
 }
        internal SyntaxTransporter(CommonSyntaxTree tree)
        {
            SyntaxStream = new MemoryStream();
            if (tree is CSharp.SyntaxTree)
            {
                SourceLanguage = LanguageNames.CSharp;
                var csharpTree = (CSharp.SyntaxTree)tree;
                csharpTree.GetRoot().SerializeTo(SyntaxStream);
            }
            else
            {
                SourceLanguage = LanguageNames.VisualBasic;
                var vbTree = (VisualBasic.SyntaxTree)tree;
                vbTree.GetRoot().SerializeTo(SyntaxStream);
            }

            ItemSpan     = tree.GetRoot().Span;
            ItemKind     = tree.GetRoot().GetKind(SourceLanguage);
            ItemCategory = SyntaxCategory.SyntaxNode;
        }