Ejemplo n.º 1
0
        public bool ContainsDefinitionData(AbstractSyntaxTreeNode node)
        {
            var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "DefinitionData");

            node.BreadthFirst(visitor);
            return(visitor.Found);
        }
Ejemplo n.º 2
0
        public AbstractSyntaxTreeNode GatherCallExpressions(MethodExtractorObj obj, AbstractSyntaxTreeNode methodNode, AbstractSyntaxTreeNode root, string methodHashCode)
        {
            var hasCodes = new List <string>();

            foreach (var callExpressionNode in obj.CallExpressions)
            {
                var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "MemberExpr");
                callExpressionNode.BreadthFirst(visitor);
                if (!visitor.Found)
                {
                    continue;
                }

                var hashCode = Splitter.Split(visitor.Node.Value).Last();

                if (hashCode.Equals(methodHashCode) || hasCodes.Contains(hashCode))
                {
                    continue;
                }

                hasCodes.Add(hashCode);

                var callNode = GetCallNodeOrDefault(root, hashCode);

                if (callNode == null)
                {
                    continue;
                }

                methodNode.Append(callNode);
            }
            return(methodNode);
        }
        public void Search_ShouldNotFindTwo()
        {
            var root = new AbstractSyntaxTreeNode("root");

            root.Append(new AbstractSyntaxTreeNode("1 one"));
            var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "two");

            root.PreOrder(visitor);
            Assert.IsNull(visitor.Node);
        }
        public void Search_ShouldFindTheNodeWithOne()
        {
            var root = new AbstractSyntaxTreeNode("root");

            root.Append(new AbstractSyntaxTreeNode("1 one"));
            var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "one");

            root.PreOrder(visitor);

            Assert.IsTrue(visitor.Node.Value.Contains("1"));
        }
Ejemplo n.º 5
0
        public string GetMethodHashCodeOrDefault(AbstractSyntaxTreeNode node, string type)
        {
            var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, type);

            node.BreadthFirst(visitor);

            if (!visitor.Found)
            {
                return(null);
            }

            var values = Splitter.Split(visitor.Node.Value);

            return(values.Length > 1 ? values[1] : null);
        }
Ejemplo n.º 6
0
        public bool IsDefinedClassMethod(AbstractSyntaxTreeNode node, string hashCode)
        {
            var values = Splitter.Split(node.Value);

            if (values.Length <= 4 || values[2] != "parent" || values[3] != hashCode)
            {
                return(false);
            }

            if (node.Value.EndsWith("default"))
            {
                return(true);
            }

            var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "CompoundStmt");

            node.BreadthFirst(visitor);
            return(visitor.Found);
        }
Ejemplo n.º 7
0
        public AbstractSyntaxTreeNode GetMethodOrDefault(MethodExtractorObj obj, MethodDeclaration methodDeclaration, out string hashCode)
        {
            var root = new AbstractSyntaxTreeNode("Root");

            foreach (var methodNode in obj.Methods)
            {
                if (!NodeIsMethod(methodNode, methodDeclaration))
                {
                    continue;
                }

                hashCode = GetMethodHashCodeOrDefault(methodNode, methodDeclaration.AstType);

                if (hashCode == null)
                {
                    continue;
                }

                if (methodNode.Value.EndsWith("default"))
                {
                    root.Append(methodNode);
                    return(root);
                }

                var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "CompoundStmt");
                methodNode.BreadthFirst(visitor);

                if (!visitor.Found)
                {
                    continue;
                }

                root.Append(methodNode);
                return(root);
            }
            hashCode = null;
            return(null);
        }