Beispiel #1
0
        private MethodDeclarationNode FromMethodCallToSWUM(MethodCall mcall, NamespaceDefinition globalNamespace, DataProject <CompleteWorkingSet> dataProject)
        {
            var mdef = globalNamespace.GetDescendants <MethodDefinition>().Where(decl => mcall.SignatureMatches(decl));

            if (mdef.Count() > 0)
            {
                var                   mdefXml = DataHelpers.GetElement(dataProject.SourceArchive, mdef.First().PrimaryLocation);
                MethodContext         mc      = ContextBuilder.BuildMethodContext(mdefXml);
                MethodDeclarationNode mdn     = new MethodDeclarationNode(mcall.Name, mc);
                BaseVerbRule          rule    = new BaseVerbRule(posData, tagger, splitter);
                if (rule.InClass(mdn))
                {
                    rule.ConstructSwum(mdn);
                    return(mdn);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                Console.WriteLine(mcall.Name + " could not be found");
                return(null);
            }
        }
Beispiel #2
0
        public void GenerateSimpleSwum()
        {
            var dataProject = new DataProject <CompleteWorkingSet>("npp_6.2.3",
                                                                   Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
                                                                   "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            //get srcml stuff in order
            NamespaceDefinition globalNamespace;

            Assert.That(dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace));

            //initialize swum stuff
            splitter = new ConservativeIdSplitter();
            tagger   = new UnigramTagger();
            posData  = new PCKimmoPartOfSpeechData();

            //find an example method
            var guiMethod         = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == "saveGUIParams").First();
            var guiMethodXElement = DataHelpers.GetElement(dataProject.SourceArchive, guiMethod.PrimaryLocation);

            //generate swum for method declaration
            MethodContext         mc   = ContextBuilder.BuildMethodContext(guiMethodXElement);
            MethodDeclarationNode mdn  = new MethodDeclarationNode("saveGUIParams", mc);
            BaseVerbRule          rule = new BaseVerbRule(posData, tagger, splitter);

            rule.ConstructSwum(mdn);
            Console.WriteLine(mdn.ToString());
        }
        public void TestInClass()
        {
            string        testSrcML = "<function><type><name>int</name></type> <name><name>CBidMarkup</name><op:operator>::</op:operator><name>modifyBid</name></name><parameter_list>(<param><decl><type><name>bool</name></type> <name>Recalc</name></decl></param>)</parameter_list><block>{<return>return <expr><lit:literal type=\"number\">0</lit:literal></expr>;</return>}</block></function>";
            XElement      xml       = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace);
            MethodContext mc        = ContextBuilder.BuildMethodContext(xml.Descendants(SRC.Function).First());

            MethodDeclarationNode mdn  = new MethodDeclarationNode("modifyBid", mc);
            BaseVerbRule          rule = new BaseVerbRule(posData, tagger, splitter);

            Console.WriteLine("InClass(): {0}", rule.InClass(mdn));
            rule.ConstructSwum(mdn);
            Console.WriteLine(mdn.ToString());
        }
Beispiel #4
0
        public void GenerateVoidReturnSUnit()
        {
            var dataProject = new DataProject <CompleteWorkingSet>(folderName,
                                                                   Path.GetFullPath(fullFilePath),
                                                                   "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            //get srcml stuff in order
            NamespaceDefinition globalNamespace;

            Assert.That(dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace));

            //initialize swum stuff
            splitter = new ConservativeIdSplitter();
            tagger   = new UnigramTagger();
            posData  = new PCKimmoPartOfSpeechData();

            //find an example method
            var guiMethod         = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == methodName).First();
            var guiMethodXElement = DataHelpers.GetElement(dataProject.SourceArchive, guiMethod.PrimaryLocation);

            // forget that, find ALL the methods
            var methods = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == methodName);

            foreach (MethodDefinition method in methods)
            {
                //Console.WriteLine(method.ToString());
                var statements = method.ChildStatements;
                foreach (Statement statement in statements)
                {
                    var expressions = statement.GetExpressions();
                    foreach (Expression expression in expressions)
                    {
                        // Skip any expression that contains an assignment
                        if (expression.ToString().Contains(" =") || expression.ToString().Contains(" ->"))
                        {
                            continue;
                        }

                        // Print whatever's left. It should be a void return.
                        Console.WriteLine(expression.ToString());

                        // *** PoS tag it ***
                        // convert the string to 'PhraseNode' objects so we can feed them to SWUM
                        var pn = PhraseNode.Parse(new WordNode(expression.ToString()).ToString());

                        Console.WriteLine(pn.ToString());

                        // construct the "rule" to break up method names into sentences
                        BaseVerbRule thisrule = new BaseVerbRule(posData, tagger, splitter);

                        var methodNode = new MethodDeclarationNode(expression.ToString());

                        thisrule.ConstructSwum(methodNode);

                        Console.WriteLine(methodNode.ToString());
                    }
                }
            }
        }
Beispiel #5
0
        public void GenerateEndingSUnit()
        {
            /*var dataProject = new DataProject<CompleteWorkingSet>("npp_6.2.3",
             *  Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
             *  "..//..//..//SrcML");*/

            var dataProject = new DataProject <CompleteWorkingSet>(folderName,
                                                                   Path.GetFullPath(fullFilePath),
                                                                   "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            //get srcml stuff in order
            NamespaceDefinition globalNamespace;

            Assert.That(dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace));

            //initialize swum stuff
            splitter = new ConservativeIdSplitter();
            tagger   = new UnigramTagger();
            posData  = new PCKimmoPartOfSpeechData();

            //find an example method, uses global methodName variable
            var testMethod         = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == methodName).First();
            var testMethodXElement = DataHelpers.GetElement(dataProject.SourceArchive, testMethod.PrimaryLocation);

            //generate swum for method declaration
            MethodContext         mc  = ContextBuilder.BuildMethodContext(testMethodXElement);
            MethodDeclarationNode mdn = new MethodDeclarationNode(methodName, mc);

            //Console.WriteLine(mdn.ToString()); //returns nothing since it hasn't been written

            var exp = testMethod.GetDescendants();
            //var verb = mdn.Action.ToString();

            var expResult = exp.ElementAt(exp.Count() - 1);

            Console.WriteLine(expResult);
            MethodDeclarationNode expMDN = null;

            if (expResult is ReturnStatement)
            {
                Console.WriteLine("return");
            }
            else if (expResult.ToString().Contains(" = "))
            {
                Console.WriteLine("Ending S Unit contains '='");
            }
            else
            {
                var mCall = expResult.FindExpressions <MethodCall>().First();

                expMDN = new MethodDeclarationNode(mCall.Name, mc);
            }
            //MethodDeclarationNode mdn2 = new MethodDeclarationNode(expResult.ToString(), mc);

            //BaseVerbRule rule = new BaseVerbRule(posData, tagger, splitter);
            //Console.WriteLine("InClass = " + rule.InClass(mdn)); //REQUIRED in order for the ConstructSwum method to work
            //rule.ConstructSwum(mdn); //rewrites mdn.ToString to a SWUM breakdown
            //Console.WriteLine(mdn.Action.ToString());

            BaseVerbRule rule2 = new BaseVerbRule(posData, tagger, splitter);

            Console.WriteLine("InClass = " + rule2.InClass(expMDN)); //REQUIRED in order for the ConstructSwum method to work
            rule2.ConstructSwum(expMDN);                             //rewrites mdn.ToString to a SWUM breakdown
            Console.WriteLine(expMDN.Action.ToString());
            //Console.WriteLine(mdn.Action.ToString());
        }