Beispiel #1
0
        public void TestCreateEquivalenceFromUnknownArguments_NullNode()
        {
            var arg1 = new VariableDeclarationNode("arg1");
            var mdn  = new MethodDeclarationNode("MyMethod");

            mdn.AddUnknownArguments(new VariableDeclarationNode[] { arg1 });
            EquivalenceNode equiv = mdn.CreateEquivalenceFromUnknownArguments(null, new bool[] { true });
        }
Beispiel #2
0
        public void TestCreateEquivalenceFromUnknownArguments_MissizedArray()
        {
            var arg1 = new VariableDeclarationNode("arg1");
            var mdn  = new MethodDeclarationNode("MyMethod");

            mdn.AddUnknownArguments(new VariableDeclarationNode[] { arg1 });
            EquivalenceNode equiv = mdn.CreateEquivalenceFromUnknownArguments(new PhraseNode(), new bool[] { true, false });
        }
Beispiel #3
0
        public void TestCreateEquivalenceFromUnknownArguments()
        {
            var arg1 = new VariableDeclarationNode("arg1");
            var arg2 = new VariableDeclarationNode("arg2");
            var arg3 = new VariableDeclarationNode("arg3");
            var arg4 = new VariableDeclarationNode("arg4");
            var mdn  = new MethodDeclarationNode("MyMethod");

            mdn.AddUnknownArguments(new VariableDeclarationNode[] { arg1, arg2, arg3, arg4 });
            Assert.AreEqual(4, mdn.UnknownArguments.Count);

            var             themeNode = new PhraseNode(new string[] { "Relevent", "Args" });
            EquivalenceNode equiv     = mdn.CreateEquivalenceFromUnknownArguments(themeNode, new bool[] { true, false, true, false });

            Assert.AreEqual(3, equiv.EquivalentNodes.Count);
            Assert.IsTrue(equiv.EquivalentNodes.Contains(themeNode));
            Assert.IsTrue(equiv.EquivalentNodes.Contains(arg1));
            Assert.IsTrue(equiv.EquivalentNodes.Contains(arg3));
            Assert.AreEqual(2, mdn.UnknownArguments.Count);
            Assert.IsTrue(mdn.UnknownArguments.Contains(arg2));
            Assert.IsTrue(mdn.UnknownArguments.Contains(arg4));
        }
Beispiel #4
0
        /// <summary>
        /// Checks for semantic overlaps between parts of the given method's name and its UnknownArguments.
        /// If overlaps are found, appropriate EquivalenceNodes are created.
        /// </summary>
        /// <param name="mdn">The MethodDeclarationNode to check for overlaps.</param>
        /// <param name="checkDO">Indicates whether the Direct Object was taken from the method name, and therefore the Theme must be checked for overlap with UnknownArguments.</param>
        /// <param name="checkIO">Indicates whether the Indirect Object was taken from the method name, and therefore the SecondaryArguments must be checked for overlap with UnknownArguments.</param>
        private void CheckOverlap(MethodDeclarationNode mdn, bool checkDO, bool checkIO)
        {
            if (mdn.ParsedName[0].Text.ToLower() == "set")
            {
                return; //special case
            }

            PhraseNode   theme = null;
            ArgumentNode arg   = null;

            //get DO word from name
            string wordDO = "";

            if (checkDO) //theme is in the method name
            {
                theme  = (PhraseNode)mdn.Theme;
                wordDO = theme.LastWord().Text;
            }

            //get IO word from name
            string wordIO = "";

            if (checkIO) //IO is in the method name
            {
                arg = mdn.SecondaryArguments[0];
                PhraseNode argn = (PhraseNode)arg.Argument;
                wordIO = argn.LastWord().Text;
                if (wordDO == wordIO)
                {
                    return; //no equivalence if multiple overlap
                }
            }

            //find overlap
            List <Node> unknownArgs       = mdn.UnknownArguments;
            List <Node> DOOverlappingArgs = new List <Node>();
            List <Node> IOOverlappingArgs = new List <Node>();

            for (int i = 0; i < unknownArgs.Count; i++)
            {
                if (unknownArgs[i] is VariableDeclarationNode)
                {
                    VariableDeclarationNode var = (VariableDeclarationNode)unknownArgs[i];
                    PhraseNode name             = var.ParsedName;
                    PhraseNode type             = var.Type.ParsedName;
                    bool       DOOverlaps       = false;
                    bool       IOOverlaps       = false;

                    if (checkDO)
                    {
                        DOOverlaps = HasOverlap(name, wordDO) || HasOverlap(type, wordDO);
                        if (DOOverlaps)
                        {
                            DOOverlappingArgs.Add(unknownArgs[i]);
                        }
                    }
                    if (checkIO)
                    {
                        IOOverlaps = HasOverlap(name, wordIO) || HasOverlap(type, wordIO);
                        if (IOOverlaps)
                        {
                            IOOverlappingArgs.Add(unknownArgs[i]);
                        }
                    }

                    if (DOOverlaps && IOOverlaps)
                    {
                        return; //no equivalence if multiple overlap
                    }
                }
            }

            //Create overlap in SWUM
            if (DOOverlappingArgs.Count > 0)
            {
                EquivalenceNode en = mdn.CreateEquivalenceFromUnknownArguments(theme, DOOverlappingArgs);
                mdn.Theme = en; //reset theme in MethodDeclarationNode to new equivalence node
            }
            if (IOOverlappingArgs.Count > 0)
            {
                EquivalenceNode en = mdn.CreateEquivalenceFromUnknownArguments(arg.Argument, IOOverlappingArgs);
                arg.Argument = en; //reset mdn.SecondaryArguments to point to new equivalence node
            }
        }