ABB.Swum.Nodes.MethodDeclarationNode.CreateEquivalenceFromUnknownArguments C# (CSharp) Метод

CreateEquivalenceFromUnknownArguments() публичный Метод

Creates a new EquivalenceNode containing the passed node and the specified nodes from the UnknownArguments list. The arguments are removed from the UnknownArguments list after being added to the EquivalenceNode.
equivalentNode is null. The length of equivalentUnknownArgs is not the same as the UnknownArguments property of the MethodDeclarationNode.
public CreateEquivalenceFromUnknownArguments ( Node equivalentNode, bool equivalentUnknownArgs ) : EquivalenceNode
equivalentNode Node The first node to add to the EquivalenceNode, i.e. the node that the unknown arguments are equivalent with.
equivalentUnknownArgs bool An array of booleans indicating which unknown arguments to include in the equivalence. /// This array must be the same length as the UnknownArguments list. /// For each element in the array, a value of True means to include the corresponding unknown argument, False means to not include it.
Результат EquivalenceNode
        public virtual EquivalenceNode CreateEquivalenceFromUnknownArguments(Node equivalentNode, bool[] equivalentUnknownArgs) {
            if(equivalentNode == null) { throw new ArgumentNullException("equivalentNode"); }
            if(equivalentUnknownArgs.Length != UnknownArguments.Count) {
                throw new ArgumentException("Length of equivalentUnknownArgs array not equal to length of UnknownArguments", "equivalentUnknownArgs");
            }

            //grab the specified UnknownArguments and put in a list
            List<Node> equivArgs = new List<Node>();
            for(int argIndex = 0; argIndex < equivalentUnknownArgs.Length; argIndex++) {
                if(equivalentUnknownArgs[argIndex]) {
                    equivArgs.Add(this.UnknownArguments[argIndex]);
                }
            }
            return CreateEquivalenceFromUnknownArguments(equivalentNode, equivArgs);
        }

Same methods

MethodDeclarationNode::CreateEquivalenceFromUnknownArguments ( Node equivalentNode, IEnumerable equivalentUnknownArgs ) : EquivalenceNode

Usage Example

Пример #1
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
            }
        }