public void TestTagAllParents() { SyntaxTree tree = CSharpSyntaxTree.ParseText(@"namespace Test{public class TestClass{}}"); TaggedSyntaxTree fTree = new TaggedSyntaxTree(tree); SyntaxNode root = tree.GetRootAsync().Result; NamespaceDeclarationSyntax testNs = root.DescendantNodes().OfType <NamespaceDeclarationSyntax>().First(); ClassDeclarationSyntax testClass = root.DescendantNodes().OfType <ClassDeclarationSyntax>().First(); bool succes = fTree.TagNode(testClass); fTree.TagAllParents(); Assert.IsTrue(fTree.IsTagged(root), "HasNode returns true for added root"); Assert.IsTrue(fTree.IsTagged(testNs), "HasNode returns true for namespace"); Assert.IsTrue(fTree.IsTagged(testClass), "HasNode returns true for class node"); }
public void TestIsTagged() { SyntaxTree tree = CSharpSyntaxTree.ParseText(@"namespace Test{public class TestClass{}}"); TaggedSyntaxTree fTree = new TaggedSyntaxTree(tree); SyntaxNode node = SyntaxFactory.ClassDeclaration("test2"); SyntaxNode root = tree.GetRootAsync().Result; NamespaceDeclarationSyntax testNs = root.DescendantNodes().OfType <NamespaceDeclarationSyntax>().First(); ClassDeclarationSyntax unknown = SyntaxFactory.ClassDeclaration("test2"); bool succes = fTree.TagNode(root); Assert.IsTrue(fTree.IsTagged(root), "HasNode returns true for added root"); Assert.IsFalse(fTree.IsTagged(testNs), "HasNode returns false for not added node (although its in the original tree)"); Assert.IsFalse(fTree.IsTagged(unknown), "HasNode returns false for unknown node"); }
public List <SyntaxNode> GetSyntaxNodesFromClass(ClassDeclarationSyntax node, TaggedSyntaxLibrary lib) { List <SyntaxNode> nodes = new List <SyntaxNode>(); INamedTypeSymbol classSymbol = this.symbolHelper.GetSymbol(node) as INamedTypeSymbol; if (classSymbol != null) { List <ISymbol> symbols = new List <ISymbol>(); INamedTypeSymbol baseType = classSymbol.BaseType; if (baseType != null) { symbols.Add(baseType); } ImmutableArray <INamedTypeSymbol> interfaces = classSymbol.Interfaces; if (interfaces != null && interfaces.Count() > 0) { foreach (INamedTypeSymbol inter in interfaces) { if (inter != null) { symbols.Add(inter); } } } // check for override methods List <IMethodSymbol> oMethods = this.getOverrideMethodSymbolsFromClass(node); if (oMethods != null && oMethods.Count() > 0) { foreach (IMethodSymbol oMethod in oMethods) { IMethodSymbol overridden = oMethod.OverriddenMethod; if (overridden != null) { List <SyntaxNode> oNodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(overridden); if (oNodes != null && oNodes.Count() > 0) { MethodDeclarationSyntax oNode = oNodes.First() as MethodDeclarationSyntax; if (oNode != null) { TaggedSyntaxTree tTree = lib.GetTreeFromNode(oNode); if (tTree != null && tTree.IsTagged(oNode)) { symbols.Add(oMethod); } } } } } } nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbols(symbols); } return(nodes); }
public void TestTagNode() { TaggedSyntaxLibrary lib = new TaggedSyntaxLibrary(); ClassDeclarationSyntax node = SyntaxFactory.ClassDeclaration("test"); bool result = lib.TagNode(node); Assert.IsTrue(result, "Expect result to be true"); Assert.IsNotNull(lib.TaggedSyntaxTrees, "Has created list of tagged syntax trees"); Assert.AreEqual(1, lib.TaggedSyntaxTrees.Count(), "List has one tagged tree"); TaggedSyntaxTree tree = lib.TaggedSyntaxTrees.First(); Assert.AreEqual(node.SyntaxTree, tree.OriginalTree, "Tagged Syntax tree has the correct syntaxtree"); Assert.IsTrue(tree.IsTagged(node), "The node is tagged on the tree"); }