예제 #1
0
        public void TestFindMethodCalls_Nested()
        {
            File.Copy(@"..\..\TestInputs\nested_method_calls.cpp", Path.Combine(TestDir, "nested_method_calls.cpp"));

            using (var dataProj = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodCall[]        expected;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    expected = new[] {
                        globalScope.FindExpressions <MethodCall>(true).First(mc => mc.Name == "ToString"),
                        globalScope.FindExpressions <MethodCall>(true).First(mc => mc.Name == "SomeMethodCall"),
                        globalScope.FindExpressions <MethodCall>(true).First(mc => mc.Name == "printf")
                    };
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query    = new FindMethodCallsAtLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "nested_method_calls.cpp"));
                var actual   = query.Execute(new SourceLocation(testFile, 4, 41));
                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Length, actual.Count);
                for (int i = 0; i < expected.Length; i++)
                {
                    Assert.AreSame(expected[i], actual[i]);
                }
            }
        }
        public void CalculateSimpleProjectStats()
        {
            var dataProject = new DataProject<CompleteWorkingSet>("npp_6.2.3",
                Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
                "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

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

            Debug.WriteLine(dataProject.Data.GetFiles().Count() + " files");
            Debug.WriteLine(globalNamespace.GetDescendants<NamespaceDefinition>().Count() + " namespaces");
            Debug.WriteLine(globalNamespace.GetDescendants<TypeDefinition>().Count() + " types");
            Debug.WriteLine(globalNamespace.GetDescendants<MethodDefinition>().Count() + " methods");
            Debug.WriteLine("");

            var orderedMethodList = from method in globalNamespace.GetDescendants<MethodDefinition>()
                let loc = method.GetDescendants().Count()
                orderby loc descending
                select method;

            var top10 = orderedMethodList.Take(10);
            foreach (var m in top10)
            {
                Debug.WriteLine(m.GetFullName() + " - " + m.GetDescendants().Count());
            }
        }
예제 #3
0
        public void TestFindMethodCalls_Nested() {
            File.Copy(@"..\..\TestInputs\nested_method_calls.cpp", Path.Combine(TestDir, "nested_method_calls.cpp"));

            using(var dataProj = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodCall[] expected;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    expected = new[] {
                        globalScope.FindExpressions<MethodCall>(true).First(mc => mc.Name == "ToString"),
                        globalScope.FindExpressions<MethodCall>(true).First(mc => mc.Name == "SomeMethodCall"),
                        globalScope.FindExpressions<MethodCall>(true).First(mc => mc.Name == "printf")
                    };
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query = new FindMethodCallsAtLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "nested_method_calls.cpp"));
                var actual = query.Execute(new SourceLocation(testFile, 4, 41));
                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.Length, actual.Count);
                for(int i = 0; i < expected.Length; i++) {
                    Assert.AreSame(expected[i], actual[i]);
                }

            }
        }
예제 #4
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());
        }
예제 #5
0
        public void CalculateSimpleProjectStats()
        {
            var dataProject = new DataProject <CompleteWorkingSet>("npp_6.2.3",
                                                                   Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
                                                                   "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            NamespaceDefinition globalNamespace;

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

            Debug.WriteLine(dataProject.Data.GetFiles().Count() + " files");
            Debug.WriteLine(globalNamespace.GetDescendants <NamespaceDefinition>().Count() + " namespaces");
            Debug.WriteLine(globalNamespace.GetDescendants <TypeDefinition>().Count() + " types");
            Debug.WriteLine(globalNamespace.GetDescendants <MethodDefinition>().Count() + " methods");
            Debug.WriteLine("");

            var orderedMethodList = from method in globalNamespace.GetDescendants <MethodDefinition>()
                                    let loc = method.GetDescendants().Count()
                                              orderby loc descending
                                              select method;

            var top10 = orderedMethodList.Take(10);

            foreach (var m in top10)
            {
                Debug.WriteLine(m.GetFullName() + " - " + m.GetDescendants().Count());
            }
        }
예제 #6
0
        public static List <DataProject> QueryDataProjectList(IProxy psc, int cityId, int AreaId, string tableName)
        {
            var projects = psc.QueryDataProjectList(cityId, AreaId, tableName).ValidateStatus <DataProjectResponseModel>().DataProjects;

            #region 循环获取每个城市对应的区域数据,并将成City对象存入List集合中
            List <DataProject> list_projects = new List <DataProject>();
            foreach (DataProject item in projects)
            {
                DataProject item_tmp = new DataProject()
                {
                    CityID      = item.CityID,
                    OtherName   = item.OtherName,
                    PinYin      = item.PinYin,
                    PinYinAll   = item.PinYinAll,
                    ProjectId   = item.ProjectId,
                    ProjectName = item.ProjectName
                };

                //projectName
                //if ("".Equals(item.PinYinAll) || "".Equals(item.PinYin))
                //{
                string tmp_all = "";
                //if (item.ProjectName.Length >= 3)
                //{
                //    tmp_all = Chinese2Spell.Convert(item_tmp.ProjectName.Substring(0, 3));
                //}
                //else
                //{
                tmp_all = Chinese2Spell.Convert(item_tmp.ProjectName);
                //}

                item_tmp.PinYinAll = tmp_all.ToUpper();                     //ShenZhen
                item_tmp.PinYin    = Chinese2Spell.getFirstLetter(tmp_all); //SZ
                //}

                //otherName
                if (!string.IsNullOrEmpty(item_tmp.OtherName))
                //if (!"".Equals(Convert.ToString(item_tmp.OtherName)))
                {
                    //if (item_tmp.OtherName.Length >= 3)
                    //{
                    //    tmp_all = Chinese2Spell.Convert(item_tmp.OtherName.Substring(0, 3));
                    //}
                    //else
                    //{
                    tmp_all = Chinese2Spell.Convert(item_tmp.OtherName);
                    //}

                    item_tmp.OtherPinyinAll = tmp_all.ToUpper();                  //ShenZhen

                    item_tmp.OtherPinyin = Chinese2Spell.getFirstLetter(tmp_all); //SZ
                }

                list_projects.Add(item_tmp);
            }
            #endregion
            return(list_projects);
        }
예제 #7
0
 public ActionResult CreateDATAProject(DataProject data)
 {
     using (FxtAPIClient client = new FxtAPIClient())
     {
         JObject _obj = new JObject();
         _obj.Add("dataProject", Utils.Serialize(data));
         result = client.Entrance(Utils.CommonKey, Utils.GetWcfCode(Utils.CommonKey), "C", _DATAProjectAdd, Utils.Serialize(_obj));
         return(Json(ResultServerJson(result.ToString())));
     }
 }
예제 #8
0
        public async Task RunAsync(DataProject project)
        {
            logger.LogDebug("Loading DSL mapping file {Path}.", Path);

            // Parse the mapping document
            var dataMap = await parser.ParseAsync(Path, project.Models);

            // Add the mapping to the project
            project.ExpressiveMaps.Add(dataMap);
        }
예제 #9
0
        public DataProjectViewModel(
            DataProject dataProject,
            IDataApiClient dataApiClient,
            IClipboard clipboard)
        {
            this.dataApiClient = dataApiClient;
            this.clipboard     = clipboard;

            Model = dataProject;
            var projectDatabase = new GenericDatabase <DataProject>(dataApiClient);

            ParameterResponsesViewModel = new ProjectParameterResponsesViewModel(dataApiClient, projectDatabase, dataProject);
        }
예제 #10
0
        public static async Task CreateDataProject(
            IDataApiClient dataApiClient,
            string dataProjectId,
            string projectSourceSystem,
            string protocolName,
            Dictionary <string, string> protocolParameterResponses)
        {
            var protocol = await dataApiClient.GetAsync <DataCollectionProtocol>(protocolName);

            var mandatoryResponses = protocol.Parameters
                                     .Where(x => x.IsMandatory);
            var missingResponses = mandatoryResponses
                                   .Where(x => !protocolParameterResponses.ContainsKey(x.Name))
                                   .ToList();

            if (missingResponses.Any())
            {
                var aggregatedMissingParameters = string.Join(", ", missingResponses.Select(x => x.Name));
                throw new ArgumentException($"You are missing parameter responses for the following mandatory parameters: {aggregatedMissingParameters}");
            }


            var globalizedProjectId = dataProjectId;

            try
            {
                var detectedSourceSystem = IdGenerator.GetSourceSystem(dataProjectId);
                if (detectedSourceSystem != projectSourceSystem)
                {
                    throw new ArgumentException($"The provided data project ID has a prefix that is associated with "
                                                + $"source system '{detectedSourceSystem}', but '{projectSourceSystem}' was specified. "
                                                + $"This either means that the '{projectSourceSystem}' system uses an ID-pattern that "
                                                + $"clashes with the ID-convention (PREFIX.<LocalID>)"
                                                + $"or you specified the wrong ID/source system.");
                }
            }
            catch (KeyNotFoundException)
            {
                if (projectSourceSystem != "SelfAssigned")
                {
                    globalizedProjectId = IdGenerator.GlobalizeLocalId(projectSourceSystem, dataProjectId);
                }
            }
            var dataProject = new DataProject(
                globalizedProjectId,
                projectSourceSystem,
                protocol,
                protocolParameterResponses);
            await dataApiClient.InsertAsync(dataProject, dataProjectId);
        }
예제 #11
0
        public void TestOverloadedMethodCallResolutionWithCallingObject()
        {
            File.Copy(@"..\..\TestInputs\csharp_overload_callingobj.cs", Path.Combine(TestDir, "csharp_overload_callingobj.cs"));
            File.Copy(@"..\..\TestInputs\csharp_overload_calls.cs", Path.Combine(TestDir, "csharp_overload_calls.cs"));
            using (var project = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                project.Update();

                var query = new StatementForLocationQuery <MethodDefinition>(project.WorkingSet, Timeout.Infinite);

                var startOffoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 11, 25);
                var startOffoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 13, 25);

                var startOfRunFoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 5, 25);
                var startOfRunFoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 7, 25);

                var foo0 = query.Execute(startOffoo0);
                Assert.AreEqual("foo", foo0.Name);
                Assert.AreEqual(0, foo0.Parameters.Count);

                var foo1 = query.Execute(startOffoo1);
                Assert.AreEqual("foo", foo1.Name);
                Assert.AreEqual(1, foo1.Parameters.Count);

                var runFoo0 = query.Execute(startOfRunFoo0);
                Assert.AreEqual("runFoo0", runFoo0.Name);

                var runFoo1 = query.Execute(startOfRunFoo1);
                Assert.AreEqual("runFoo1", runFoo1.Name);

                Assert.That(runFoo0.ContainsCallTo(foo0));
                Assert.That(!runFoo0.ContainsCallTo(foo1));

                Assert.That(runFoo1.ContainsCallTo(foo1));
                Assert.That(!runFoo1.ContainsCallTo(foo0));

                var callNoParams = runFoo0.FindExpressions <MethodCall>(true).FirstOrDefault();
                var matches      = callNoParams.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo0, matches[0]);

                var callWithParam = runFoo1.FindExpressions <MethodCall>(true).FirstOrDefault();
                matches = callWithParam.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo1, matches[0]);
            }
        }
예제 #12
0
        public static IEnumerable<MethodDefinition> ExtractAllMethodsFromDirectory(string directoryPath)
        {
            var currentDirectory = Path.GetFullPath(Assembly.GetExecutingAssembly().Location);
            var srcmlDirectory = Path.GetFullPath(Path.Combine(currentDirectory, @"..\..\..\..\External\SrcML"));

            var dataProject = new DataProject<CompleteWorkingSet>(
                        Path.GetDirectoryName(directoryPath),       // name for base directory
                        directoryPath,                              // path to source files to extract
                        srcmlDirectory);                            // path to srcml executables

            dataProject.UpdateAsync().Wait();
            NamespaceDefinition globalNamespace;
            dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace);

            var methods = globalNamespace.GetDescendants<MethodDefinition>();

            return methods;
        }
예제 #13
0
        public void GenerateSwumForAnyOccassion()
        {
            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));

            //find an example method
            var sampleMethod = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == methodName).First();

            foreach (var line in sampleMethod.GetDescendants())                     //goes through lines (Statement class) in method
            {
                var sampleMethod_MethodCalls = line.FindExpressions <MethodCall>(); //represents all of the method calls within the method

                foreach (var methodCall in sampleMethod_MethodCalls)                //goes through each method call
                {
                    var swummedMdn = FromMethodCallToSWUM(methodCall, globalNamespace, dataProject);

                    if (swummedMdn != null)
                    {
                        Console.WriteLine("VOID RETURN");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }

                //return statement
                if (line is ReturnStatement)
                {
                    var returnMCall = line.FindExpressions <MethodCall>().First();
                    var swummedMdn  = FromMethodCallToSWUM(returnMCall, globalNamespace, dataProject);
                    if (swummedMdn != null)
                    {
                        Console.WriteLine("RETURN STMT");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }
            }
        }
예제 #14
0
        public void TestFindScopeForAdjacentMethods()
        {
            File.Copy(@"..\..\TestInputs\adjacent_methods.cpp", Path.Combine(TestDir, "adjacent_methods.cpp"));

            using (var dataProj = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodDefinition    mainMethod;
                MethodDefinition    fooMethod;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    mainMethod = globalScope.GetDescendants <MethodDefinition>().First(md => md.Name == "main");
                    fooMethod  = globalScope.GetDescendants <MethodDefinition>().First(md => md.Name == "Foo");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query    = new StatementForLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "adjacent_methods.cpp"));

                var startOfMain    = new SourceLocation(testFile, 1, 1);
                var locationInMain = new SourceLocation(testFile, 1, 11);
                Assert.That(mainMethod.PrimaryLocation.Contains(startOfMain));
                Assert.That(mainMethod.PrimaryLocation.Contains(locationInMain));

                Assert.AreSame(mainMethod, query.Execute(startOfMain));
                Assert.AreSame(mainMethod, query.Execute(locationInMain));

                var startOfFoo    = new SourceLocation(testFile, 3, 1);
                var locationInFoo = new SourceLocation(testFile, 3, 11);
                Assert.That(fooMethod.PrimaryLocation.Contains(startOfFoo));
                Assert.That(fooMethod.PrimaryLocation.Contains(locationInFoo));

                Assert.AreSame(fooMethod, query.Execute(startOfFoo));
                Assert.AreSame(fooMethod, query.Execute(locationInFoo));

                var lineBetweenMethods = new SourceLocation(testFile, 2, 1);
                Assert.That(mainMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.IsFalse(fooMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.AreSame(mainMethod, query.Execute(lineBetweenMethods));
            }
        }
예제 #15
0
        public void TestCompleteWorkingSet_SingleCore(RealWorldTestProject testData)
        {
            CheckThatProjectExists(testData);
            Console.WriteLine("{0} {1} Project Summary", testData.ProjectName, testData.Version);
            Console.WriteLine("============================");
            using (var project = new DataProject <CompleteWorkingSet>(new LimitedConcurrencyLevelTaskScheduler(1), new FileSystemFolderMonitor(testData.FullPath, testData.DataDirectory), new SrcMLGenerator("SrcML"))) {
                string   unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;
                using (var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                NamespaceDefinition globalScope;
                Assert.That(project.WorkingSet.TryObtainReadLock(5000, out globalScope));
                Assert.IsNotNull(globalScope);
            }
        }
예제 #16
0
        public static IEnumerable <MethodDefinition> ExtractAllMethodsFromDirectory(string directoryPath)
        {
            var currentDirectory = Path.GetFullPath(Assembly.GetExecutingAssembly().Location);
            var srcmlDirectory   = Path.GetFullPath(Path.Combine(currentDirectory, @"..\..\..\..\External\SrcML"));

            var dataProject = new DataProject <CompleteWorkingSet>(
                Path.GetDirectoryName(directoryPath),               // name for base directory
                directoryPath,                                      // path to source files to extract
                srcmlDirectory);                                    // path to srcml executables

            dataProject.UpdateAsync().Wait();
            NamespaceDefinition globalNamespace;

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

            var methods = globalNamespace.GetDescendants <MethodDefinition>();

            return(methods);
        }
        public void GenerateSwumForAnyOccassion()
        {
            var dataProject = new DataProject <CompleteWorkingSet>("Swum.NET-master",
                                                                   Path.GetFullPath("..//..//..//projects//Swum.NET-master"),
                                                                   "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            //get srcml stuff in order
            NamespaceDefinition globalNamespace;

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

            //find an example method
            var sampleMethod = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == "TestConstructSwum").First();

            foreach (var line in sampleMethod.GetDescendants())
            {
                var sampleMethod_MethodCalls = line.FindExpressions <MethodCall>();

                foreach (var methodCall in sampleMethod_MethodCalls)
                {
                    var swummedMdn = FromMethodCallToSWUM(methodCall, globalNamespace, dataProject);
                    if (swummedMdn != null)
                    {
                        Console.WriteLine("VOID RETURN");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }

                //return statement
                if (line is ReturnStatement)
                {
                    var returnMCall = line.FindExpressions <MethodCall>().First();
                    var swummedMdn  = FromMethodCallToSWUM(returnMCall, globalNamespace, dataProject);
                    if (swummedMdn != null)
                    {
                        Console.WriteLine("RETURN STMT");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }
            }
        }
        public void TestQueryDuringUpdate()
        {
            var sourceFolder = "TestQueryDuringUpdate";
            var dataFolder   = "TestQueryDuringUpdate_Data";

            Directory.CreateDirectory(sourceFolder);
            string fooSourcePath = Path.Combine(sourceFolder, "foo.cpp");
            string barSourcePath = Path.Combine(sourceFolder, "bar.cpp");

            var fooRevisions = new string[] { "void foo() { }", "void foo() { bar(); }" };

            File.WriteAllText(fooSourcePath, fooRevisions[1]);
            File.WriteAllText(barSourcePath, "void bar() { }");

            int iterations = 1000;

            using (var project = new DataProject <CompleteWorkingSet>(dataFolder, sourceFolder, "SrcML")) {
                project.Update();
                project.StartMonitoring();

                var developer = new Task(() => {
                    for (int i = 0; i < iterations; i++)
                    {
                        File.WriteAllText(fooSourcePath, fooRevisions[i % 2]);
                    }
                });

                developer.Start();
                Assert.DoesNotThrow(() => {
                    for (int i = 0; i < iterations; i++)
                    {
                        var foo = GetMethodWithName(project.WorkingSet, 500, "foo");
                        var bar = GetMethodWithName(project.WorkingSet, 500, "bar");
                        foo.ContainsCallTo(bar);
                        if (i % 10 == 0 && i > 0)
                        {
                            Console.WriteLine("Finished {0} iterations", i);
                        }
                    }
                });
                developer.Wait();
            }
        }
        public void GenerateSwumForAnyOccassion()
        {
            var dataProject = new DataProject<CompleteWorkingSet>("Swum.NET-master",
                    Path.GetFullPath("..//..//..//projects//Swum.NET-master"),
                    "..//..//..//SrcML");

            dataProject.UpdateAsync().Wait();

            //get srcml stuff in order
            NamespaceDefinition globalNamespace;
            Assert.That(dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace));

            //find an example method
            var sampleMethod = globalNamespace.GetDescendants<MethodDefinition>().Where(m => m.Name == "TestConstructSwum").First();

            foreach(var line in sampleMethod.GetDescendants())
            {
                var sampleMethod_MethodCalls = line.FindExpressions<MethodCall>();

                foreach (var methodCall in sampleMethod_MethodCalls)
                {
                    var swummedMdn = FromMethodCallToSWUM(methodCall, globalNamespace, dataProject);
                    if (swummedMdn != null)
                    {
                        Console.WriteLine("VOID RETURN");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }

                //return statement
                if (line is ReturnStatement)
                {
                    var returnMCall = line.FindExpressions<MethodCall>().First();
                    var swummedMdn = FromMethodCallToSWUM(returnMCall, globalNamespace, dataProject);
                    if(swummedMdn != null)
                    {
                        Console.WriteLine("RETURN STMT");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }
            }
        }
예제 #20
0
        public void TestFindMethodCalls_Simple() {
            File.Copy(@"..\..\TestInputs\function_def.cpp", Path.Combine(TestDir, "function_def.cpp"));

            using(var dataProj = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodCall expected;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    expected = globalScope.FindExpressions<MethodCall>(true).First(mc => mc.Name == "MyFunction");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query = new FindMethodCallsAtLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "function_def.cpp"));
                var actual = query.Execute(new SourceLocation(testFile, 12, 20));
                Assert.IsNotNull(actual);
                Assert.AreEqual(1, actual.Count);
                Assert.AreSame(expected, actual[0]);
            }
        }
        public void TestQueryDuringUpdate() {
            var sourceFolder = "TestQueryDuringUpdate";
            var dataFolder = "TestQueryDuringUpdate_Data";
            Directory.CreateDirectory(sourceFolder);
            string fooSourcePath = Path.Combine(sourceFolder, "foo.cpp");
            string barSourcePath = Path.Combine(sourceFolder, "bar.cpp");

            var fooRevisions = new string[] { "void foo() { }", "void foo() { bar(); }" };

            File.WriteAllText(fooSourcePath, fooRevisions[1]);
            File.WriteAllText(barSourcePath, "void bar() { }");

            int iterations = 1000;
            using(var project = new DataProject<CompleteWorkingSet>(dataFolder, sourceFolder, "SrcML")) {
                project.Update();
                project.StartMonitoring();

                var developer = new Task(() => {
                    for(int i = 0; i < iterations; i++) {
                        File.WriteAllText(fooSourcePath, fooRevisions[i % 2]);
                    }
                });

                developer.Start();
                Assert.DoesNotThrow(() => {
                    for(int i = 0; i < iterations; i++) {
                        var foo = GetMethodWithName(project.WorkingSet, 500, "foo");
                        var bar = GetMethodWithName(project.WorkingSet, 500, "bar");
                        foo.ContainsCallTo(bar);
                        if(i % 10 == 0 && i > 0) {
                            Console.WriteLine("Finished {0} iterations", i);
                        }
                    }
                });
                developer.Wait();
            }
        }
예제 #22
0
        /// <summary>
        /// 分页查询楼盘信息
        /// </summary>
        /// <param name="psc"></param>
        /// <param name="cityId"></param>
        /// <param name="AreaId"></param>
        /// <param name="tableName"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static List <DataProject> PagingQueryDataProjectList(IProxy psc, int cityId, int AreaId, string tableName, int page)
        {
            var projects = psc.PagingQueryProjectList(cityId, AreaId, tableName, page).ValidateStatus <DataProjectResponseModel>().DataProjects;

            #region 循环获取每个城市对应的区域数据,并将成City对象存入List集合中
            List <DataProject> list_projects = new List <DataProject>();
            foreach (DataProject item in projects)
            {
                DataProject item_tmp = new DataProject()
                {
                    CityID      = item.CityID,
                    OtherName   = item.OtherName,
                    PinYin      = item.PinYin,
                    PinYinAll   = item.PinYinAll,
                    ProjectId   = item.ProjectId,
                    ProjectName = item.ProjectName
                };

                string tmp_all = "";
                tmp_all = Chinese2Spell.Convert(item_tmp.ProjectName);

                item_tmp.PinYinAll = tmp_all.ToUpper();                     //ShenZhen
                item_tmp.PinYin    = Chinese2Spell.getFirstLetter(tmp_all); //SZ

                if (!string.IsNullOrEmpty(item_tmp.OtherName))
                {
                    tmp_all = Chinese2Spell.Convert(item_tmp.OtherName);
                    item_tmp.OtherPinyinAll = tmp_all.ToUpper();                     //ShenZhen
                    item_tmp.OtherPinyin    = Chinese2Spell.getFirstLetter(tmp_all); //SZ
                }

                list_projects.Add(item_tmp);
            }
            #endregion
            return(list_projects);
        }
예제 #23
0
        public ProjectParameterResponsesViewModel(
            IDataApiClient dataApiClient,

            IObjectDatabase <DataProject> dataProjectDatabase,
            DataProject dataProject)
        {
            this.dataProjectDatabase = dataProjectDatabase;
            DataProject = dataProject;
            var valueViewModelFactory = new ParameterValueViewModelFactory(dataApiClient);

            ParameterResponses = dataProject.Protocol.Parameters
                                 .Select(parameter =>
            {
                var response = dataProject.ParameterResponse.ContainsKey(parameter.Name)
                        ? dataProject.ParameterResponse[parameter.Name]
                        : null;
                return(new ProtocolParameterResponseViewModel(parameter, valueViewModelFactory, response));
            })
                                 .ToList();
            ParameterResponses.ForEach(vm => vm.PropertyChanged += ParameterResponse_PropertyChanged);
            ShowParameters = !IsProtocolParametersCompleted;

            SaveCommand = new AsyncRelayCommand(Save, () => IsProtocolParametersCompleted);
        }
        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));

            //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);
            Console.WriteLine("InClass = " + rule.InClass(mdn));
            rule.ConstructSwum(mdn);
            Console.WriteLine(mdn.ToString());
        }
예제 #25
0
        public void TestFindMethodCalls_Simple()
        {
            File.Copy(@"..\..\TestInputs\function_def.cpp", Path.Combine(TestDir, "function_def.cpp"));

            using (var dataProj = new DataProject <CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodCall          expected;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    expected = globalScope.FindExpressions <MethodCall>(true).First(mc => mc.Name == "MyFunction");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query    = new FindMethodCallsAtLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "function_def.cpp"));
                var actual   = query.Execute(new SourceLocation(testFile, 12, 20));
                Assert.IsNotNull(actual);
                Assert.AreEqual(1, actual.Count);
                Assert.AreSame(expected, actual[0]);
            }
        }
예제 #26
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());
                    }
                }
            }
        }
예제 #27
0
        /// <summary>
        /// Step 2 of DBScribeHibernate. 
        /// Build call graph for the target project. 
        /// Also, topologically sorted the methods in the call graph, for later bottom-up method description propagation.
        /// </summary>
        public void Step2_1_GenerateCallGraph()
        {
            // Get methods from SrcML.net
            //Console.Out.WriteLine("Invoke call graph generator ");
            string dataDir = @"TESTNAIVE_1.0";
            string localProj = TargetProjPath + "\\" + ProjName;
            using (var project = new DataProject<CompleteWorkingSet>(dataDir, localProj, Constants.SrcmlLoc))
            {
                string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;
                using (var unknownLog = new StreamWriter(unknownLogPath))
                {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try
                {
                    // return IEnumerable<MethodDefinition> type
                    methods = globalNamespace.GetDescendants<MethodDefinition>();
                    num_of_methods = globalNamespace.GetDescendants<MethodDefinition>().Count();
                    Console.WriteLine("# of methods = " + num_of_methods);

                    cgm = new CGManager();
                    cgm.BuildCallGraph(methods);

                    bottomUpSortedMethods = InvokeCGManager.GetBottomUpSortedMethodsFromCallGraph(methods, cgm);
                }
                finally
                {
                    project.WorkingSet.ReleaseReadLock();
                }
            }
        }
예제 #28
0
        public void TestOverloadedMethodCallResolutionWithCallingObject() {
            File.Copy(@"..\..\TestInputs\csharp_overload_callingobj.cs", Path.Combine(TestDir, "csharp_overload_callingobj.cs"));
            File.Copy(@"..\..\TestInputs\csharp_overload_calls.cs", Path.Combine(TestDir, "csharp_overload_calls.cs"));
            using(var project = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                project.Update();

                var query = new StatementForLocationQuery<MethodDefinition>(project.WorkingSet, Timeout.Infinite);

                var startOffoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 11, 25);
                var startOffoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_calls.cs")), 13, 25);

                var startOfRunFoo0 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 5, 25);
                var startOfRunFoo1 = new SourceLocation(Path.GetFullPath(Path.Combine(TestDir, "csharp_overload_callingobj.cs")), 7, 25);

                var foo0 = query.Execute(startOffoo0);
                Assert.AreEqual("foo", foo0.Name);
                Assert.AreEqual(0, foo0.Parameters.Count);

                var foo1 = query.Execute(startOffoo1);
                Assert.AreEqual("foo", foo1.Name);
                Assert.AreEqual(1, foo1.Parameters.Count);

                var runFoo0 = query.Execute(startOfRunFoo0);
                Assert.AreEqual("runFoo0", runFoo0.Name);

                var runFoo1 = query.Execute(startOfRunFoo1);
                Assert.AreEqual("runFoo1", runFoo1.Name);

                Assert.That(runFoo0.ContainsCallTo(foo0));
                Assert.That(!runFoo0.ContainsCallTo(foo1));

                Assert.That(runFoo1.ContainsCallTo(foo1));
                Assert.That(!runFoo1.ContainsCallTo(foo0));

                var callNoParams = runFoo0.FindExpressions<MethodCall>(true).FirstOrDefault();
                var matches = callNoParams.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo0, matches[0]);

                var callWithParam = runFoo1.FindExpressions<MethodCall>(true).FirstOrDefault();
                matches = callWithParam.FindMatches().ToList();
                Assert.AreEqual(1, matches.Count);
                Assert.AreSame(foo1, matches[0]);
            }
        }
예제 #29
0
        /// <summary>
        /// Command line testing
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DateTime dt = DateTime.Now;

            //args = new string[] { "hello" };
            //args = new string[] { "testcases", "--loc", LocalProj, "--srcmlPath", SrcmlLoc };
            args = new string[] { "summary", "--loc", LocalProj, "--srcmlPath", SrcmlLoc, "--outputLoc", outputLoc };
            var    options            = new Options();
            string invokedVerb        = null;
            object invokedVerbOptions = null;


            if (!CommandLine.Parser.Default.ParseArguments(args, options,
                                                           (verb, verbOptions) =>
            {
                invokedVerb = verb;
                invokedVerbOptions = verbOptions;
            }))
            {
                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }
            if (invokedVerb == "callgraph")
            {
                var callGraphOp = (CallgraphOptions)invokedVerbOptions;
                var generator   = new InvokeCallGraphGenerator(callGraphOp.LocationsPath, callGraphOp.SrcMLPath);
                generator.run();
            }
            else if (invokedVerb == "testcases")
            {
                var testCaseOp = (TestCaseDetectOptions)invokedVerbOptions;
                var detector   = new TestCaseDetector.TestCaseDetector(testCaseOp.LocationsPath, testCaseOp.SrcMLPath);
                detector.AnalyzeTestCases();
                Console.WriteLine("print testcases");
                foreach (var testCaseId in detector.AllTestCases)
                {
                    Console.WriteLine(testCaseId.NamespaceName + "  " + testCaseId.ClassName + "  " + testCaseId.MethodName);
                }
            }
            else if (invokedVerb == "summary")
            {
                var    SummaryOp = (SummarizeTestOptions)invokedVerbOptions;
                string execution = ConfigurationManager.AppSettings["Execution"];

                //steps should be run as indicated by the numbers below
                if (execution.Contains("CLONE") || execution.Contains("DETECT"))
                {
                    ProjectCloner projectCloner = new ProjectCloner(SrcmlLoc);
                    //1:clone repos clones a list of repos into the folder C:\grouped. Repos are grouped per ecosystem
                    //a CSV file called groupedProjectsList.csv is then created in the specified cloneprojectsfolder (check App config)

                    //projectCloner.cloneRepos();
                    //projectCloner.cloneMainGHRepos();
                    //projectCloner.appendProjectPathsToGHTorrentCSV();
                    //projectCloner.detectTestCasesFromGHMainProjects();
                    //projectCloner.updateProjectCreatedAtDateForTestCases();
                    //projectCloner.generateFinalMainlineGHProjectsCSV();
                    //==OBSOLETE==projectCloner.importCommitsCSV();
                    //projectCloner.importForksFromCSV();//these are detected using JAVA. See ANdroid Popularity project
                    //projectCloner.InsertTop10ForksWith5MoreCommits30DaysOld();
                    //==OBSLOTE==USING JAVA here.==projectCloner.cloneGHProjectsFromDB();
                    //projectCloner.UpdatePathsForClonedProjects();
                    //projectCloner.UpdateTotalCommitsPerProject();

                    //projectCloner.detectTestCasesFromFinalProjects();
                    //2: detect test cases reads the groupedProjectsList.csv file and for each project in their it exracts details of test cases, and UUTs (classes and methods)
                    //this emthod then generates a two CSV files in the cloneProjects Folder. One is called testsAndUUTs_allprojects.csv, the other is classesAndMethods_allprojects.csv

                    //projectCloner.detectTestCasesDB();
                }
                DataAnalyzer dataAnalyzer = new DataAnalyzer();
                if (execution.Contains("EXTRACTCLONES"))
                {
                    //3: extract clones reads all ecosystem projects and extract clone fragments. It reads from the groupedProjects CSV file saved in the "clonedProjectsFolder"
                    //for each ecosstem in the  groupedPrectsList.CSV it uses the clone detection tool Simian to generate clone pairs from all projects within the ecosystem
                    //to generate the cross-project clones we create one parent folder where we put all of an ecosystem's projects as sub-folders

                    //dataAnalyzer.extractClonesFromDB();

                    //update project comit details===OBSOLETE already done when extracting projects. see projectCloner.updateProjectCreatedAtDateForTestCases();
                    //dataAnalyzer.createProjectCommitDetails();

                    //generate clones pairs for defect prediction
                    //dataAnalyzer.ExtractClonesStandalone();
                }
                if (execution.Contains("UPDATEUUTPROJECTS"))
                {
                    //4. for each test case generated in step 2 (in the file testsAndUUTs_allprojects.csv), update it by indicating projects where it is present, missing, and targets for propagation

                    //dataAnalyzer.updateUUTsWithProjectListsDB();

                    //update the UUT projects from CSV into Database
                    //dataAnalyzer.InsertTestCaseUUTPairsFromCSV();
                    //SINCE MANY DULCATES EXIST from teh genrated project lists CSV, generate one CSV with unique records only
                    //dataAnalyzer.GenerateUniqueTestCaseUUTPairsFromCSV();
                }
                if (execution.Contains("STUDYREPORTS"))
                {
                    //5. Generate study reports
                    //these include: (1)project differences in commits i.e. for source projects of missing test cases and target projects
                    //(2) pairs of source UUTs for missing test cases and target UUTs
                    //dataAnalyzer.copyClonesToParentFolder();==OBSOLETE since when cloning projects we already group them by ecosystem

                    //DataAnalyzer.TestParseXML();
                    //5.1. Test case presence

                    //dataAnalyzer.generateTestCasePresence();

                    //5.2 Project differences between source and target projects for missing test cases
                    //These are mainly differences in number of commits and days since last commit.

                    //dataAnalyzer.getProjectDifferences();

                    //5.3 Test case UUT Target Pairs
                    //THis shows, for each missing test case, the source UUT and the possible target UUT matched from the clone pairs
                    //dataAnalyzer.createTestTargetUUTPairsWithMethodNames();
                    //5.4 Get unique test UUT pairs for files only so that we can get edit scripts at file level
                    //dataAnalyzer.createTestUUTPairsForEditScriptGeneration();
                    //5.5 NOw append editscripts generated to the large file with method pairs
                    //dataAnalyzer.appendEditScriptToLargeUUTPairs();
                }
                if (execution.Contains("CLEANDATA"))
                {
                    //UUTPairDataCleaner.CleanData();
                    UUTPairDataCleaner.createTokenCountFiles();
                }
                //dataAnalyzer.CountEcoSystems();
                //dataAnalyzer.CreateMappingOfMissingTestCases();



                //TestPropagator testPropagator = new TestPropagator(LocalProj, targetProject, SrcmlLoc);
                //testPropagator.propagate();
                //var summary = new SummaryGenerator(SummaryOp.LocationsPath, SummaryOp.SrcMLPath);
                //Console.WriteLine("This is summary");
                //summary.AnalyzeSummary();
                //summary.GenerateSummary(SummaryOp.OutputLoc);
                //Console.WriteLine("Done!!!!!!  Thanks.");
            }
            else if (invokedVerb == "hello")
            {
                Console.WriteLine("Hello");

                //string proPath = @"C:\Users\[email protected]\Documents\RunningTest\Input\ConsoleApplication1";
                //string proPath = @"C:\Users\[email protected]\Documents\RunningTest\Input\SrcML\ABB.SrcML";
                using (var project = new DataProject <CompleteWorkingSet>(LocalProj, LocalProj, SrcmlLoc))
                {
                    project.Update();
                    NamespaceDefinition globalNamespace;
                    project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                    try
                    {
                        // Step 1.   Build the call graph
                        Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                        Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                        Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                        Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());
                        Console.ReadLine();
                        var methods = globalNamespace.GetDescendants <MethodDefinition>();

                        // Step 2.   Testing
                        Console.WriteLine("======  test 1 ========= ");
                        foreach (MethodDefinition m in methods)
                        {
                            Console.WriteLine("Method Name : {0}", m.GetFullName());
                        }
                    }
                    finally
                    {
                        project.WorkingSet.ReleaseReadLock();
                    }
                }


                Console.ReadLine();
                Console.WriteLine("print hello");
            }
            TimeSpan ts = DateTime.Now - dt;

            Console.WriteLine(ts.ToString());
            Console.ReadLine();
        }
예제 #30
0
        public void AnalyzeSummary()
        {
            Console.WriteLine("Hello");

            using (var project = new DataProject <CompleteWorkingSet>(LocalProj, LocalProj, SrcmlLoc))
            {
                project.Update();
                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try
                {
                    // Step 1.   Build the call graph
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());
                    //Console.Read();
                    var methods = globalNamespace.GetDescendants <MethodDefinition>();
                    int i       = 0;
                    // Step 2.   Testing
                    Console.WriteLine("======  test 1 ========= ");
                    foreach (MethodDefinition method in methods)
                    {
                        Console.WriteLine("Method Name : {0}", method.GetFullName());
                        //colect basic ID information
                        var declaringClass = method.GetAncestors <TypeDefinition>().FirstOrDefault();
                        var className      = "";
                        if (declaringClass != null)
                        {
                            className = declaringClass.Name;
                        }
                        var nameSpaceName = GetNamespaceByMethod(method);


                        //for testing
                        //if (className != "CPlusPlusCodeParserTests") {
                        //    continue;
                        //}
                        //if (className != "BuiltInTypeFactoryTests") {
                        //    continue;
                        //}

                        //if (i > 10)
                        //{
                        //    continue;
                        //}


                        //if (method.Name != "CreateRequest_ETag")
                        //{
                        //    continue;
                        //}

                        if (IsTestCase(method))
                        {
                            SwumSummary swumSummary = new SwumSummary(method);
                            swumSummary.BasicSummary();
                            TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
                            //analyzer.GetTestingObject();
                            string desc = swumSummary.Describe();
                            //writetext.WriteLine(method.Name + "  ,  " + desc);
                            Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

                            TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
                            tcSummary.NameSpaceName = nameSpaceName;
                            tcSummary.ClassName     = className;
                            tcSummary.MethodName    = method.Name;

                            AllTestSummary.Add(tcSummary);
                            var stmts = method.GetDescendants <Statement>();

                            //delete me
                            //using (StreamWriter sw = File.AppendText(@"D:\d.csv"))
                            //{
                            //   var number = stmts.Count() + 2;
                            //   sw.WriteLine(method.Name + "," + number);
                            //    sw.Close();
                            //}
                            i++;
                        }
                    }
                }
                finally
                {
                    project.WorkingSet.ReleaseReadLock();
                }
            }


            //Console.ReadLine();
            //string dataDir = @"TESTNAIVE_1.0";
            //using (var project = new DataProject<CompleteWorkingSet>(dataDir, this.LocalProj, this.SrcmlLoc)) {

            //    //Console.WriteLine("============================");
            //    //string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
            //    //DateTime start = DateTime.Now, end;
            //    //Console.WriteLine("============================");
            //    //using (var unknownLog = new StreamWriter(unknownLogPath)) {
            //    //    project.UnknownLog = unknownLog;
            //    //    project.UpdateAsync().Wait();

            //    //}
            //    //end = DateTime.Now;
            //    project.Update();
            //    NamespaceDefinition globalNamespace;
            //    project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
            //    try {

            //        // Step 1.   Build the call graph
            //        Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
            //        Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants<NamespaceDefinition>().Count());
            //        Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants<TypeDefinition>().Count());
            //        Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants<MethodDefinition>().Count());
            //        var methods = globalNamespace.GetDescendants<MethodDefinition>();
            //        int i = 0;
            //        StreamWriter writetext = new StreamWriter("write.csv");
            //        foreach (var method in methods) {
            //            //colect basic ID information
            //            var declaringClass = method.GetAncestors<TypeDefinition>().FirstOrDefault();
            //            var className = "";
            //            if (declaringClass != null) {
            //                className = declaringClass.Name;
            //            }
            //            var nameSpaceName = GetNamespaceByMethod(method);


            //            //for testing
            //            //if (className != "CPlusPlusCodeParserTests") {
            //            //    continue;
            //            //}
            //            //if (className != "BuiltInTypeFactoryTests") {
            //            //    continue;
            //            //}
            //            //if (className == "ProgamElementTests" || className == "CPlusPlusCodeParserTests") {
            //            //    continue;
            //            //}

            //            //if (className != "CPlusPlusCodeParserTests") {

            //            //    continue;
            //            //}


            //            //if (className != "SourceLocationTests") {
            //            //    continue;
            //            //}


            //            //if (method.Name != "TestContains_DifferentLines") {
            //            //    continue;
            //            //}


            //            //if (method.Name != "TestSiblingsBeforeSelf_MissingChild") {
            //            //    continue;
            //            //}

            //            //if (i > 30) {
            //            //    continue;
            //            //}

            //            if (IsTestCase(method)) {
            //                i++;
            //                SwumSummary swumSummary = new SwumSummary(method);
            //                swumSummary.BasicSummary();
            //                TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
            //                //analyzer.GetTestingObject();
            //                string desc = swumSummary.Describe();
            //                //writetext.WriteLine(method.Name + "  ,  " + desc);
            //                Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

            //                TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
            //                tcSummary.NameSpaceName = nameSpaceName;
            //                tcSummary.ClassName = className;
            //                tcSummary.MethodName = method.Name;

            //                AllTestSummary.Add(tcSummary);
            //                i++;
            //            }


            //        }
            //        writetext.Close();
            //        //Console.WriteLine("total i :" + i);



            //    } finally {
            //        project.WorkingSet.ReleaseReadLock();
            //    }
            //}
        }
예제 #31
0
        public void TestCompleteWorkingSet(RealWorldTestProject testData) {
            CheckThatProjectExists(testData);
            Console.WriteLine("{0} {1} Project Summary", testData.ProjectName, testData.Version);
            Console.WriteLine("============================");
            using(var project = new DataProject<CompleteWorkingSet>(testData.DataDirectory, testData.FullPath, "SrcML")) {
                string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;

                using(var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                Console.WriteLine("{0} to initialize complete working set", end - start);

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

                try {
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants<NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants<TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants<MethodDefinition>().Count());

                    var methodCalls = from statement in globalNamespace.GetDescendantsAndSelf()
                                      from expression in statement.GetExpressions()
                                      from call in expression.GetDescendantsAndSelf<MethodCall>()
                                      select call;
                    
                    int numMethodCalls = 0, numMatchedMethodCalls = 0, numMissedMethodCalls = 0;
                    Stopwatch sw = new Stopwatch();
                    TimeSpan elapsed = new TimeSpan(0),
                             matchedElapsed = new TimeSpan(0),
                             missedElapsed = new TimeSpan(0);

                    using(var callLog = new StreamWriter(Path.Combine(testData.DataDirectory, "call_log.csv"), false)) {

                        callLog.WriteLine("Location,Call Name,Successful,Time");
                        foreach(var call in methodCalls) {
                            INamedEntity match = null;
                            sw.Restart();
                            try {
                                match = call.FindMatches().FirstOrDefault();
                            } catch(Exception e) {
                                project.ErrorLog.WriteLine("{0}:{1}:{2}: Call Exception {3}", call.Location.SourceFileName, call.Location.StartingLineNumber, call.Location.StartingColumnNumber, e);
                            }
                            sw.Stop();
                            numMethodCalls++;
                            if(null != match) {
                                numMatchedMethodCalls++;
                                matchedElapsed += sw.Elapsed;
                            } else {
                                numMissedMethodCalls++;
                                missedElapsed += sw.Elapsed;
                            }
                            callLog.WriteLine(String.Join(",", String.Join(":", call.Location.SourceFileName, call.Location.StartingLineNumber, call.Location.StartingColumnNumber), call.Name, (match == null ? "0" : "1"), sw.ElapsedMilliseconds));
                            elapsed += sw.Elapsed;
                        }
                    }
                    Console.WriteLine("{0,10:N0} method calls", numMethodCalls);
                    Console.WriteLine("{0,10:P2} of method calls matched", (float) numMatchedMethodCalls / numMethodCalls);
                    Console.WriteLine("{0,10:N2} matches / millisecond ({1,7:N0} ms elapsed)", ((float) numMethodCalls) / elapsed.TotalMilliseconds, elapsed.TotalMilliseconds);
                    Console.WriteLine("{0,7:N3} ms / match", (float) matchedElapsed.TotalMilliseconds / numMatchedMethodCalls);
                    Console.WriteLine("{0,7:N3} ms / miss", (float) missedElapsed.TotalMilliseconds / numMissedMethodCalls);
                } finally {
                    project.WorkingSet.ReleaseReadLock();
                }
            }
        }
예제 #32
0
        public static void analyzeProjectTestCases(string projectLocation, HashSet <TestCaseID> projectTestCases, DataController dc, string srcMLexeLocation, string testsAndUUTFile, string classesAndMethodsFile, string projectGitName, string parent, bool isFork)
        {
            Console.WriteLine($"Analysing project {projectGitName}");//Path.GetFileName(projectLocation)

            using (var project = new DataProject <CompleteWorkingSet>(projectLocation, projectLocation, srcMLexeLocation))
            {
                project.Update();
                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                //StreamWriter classesWriter = File.AppendText(classesAndMethodsFile);
                //StreamWriter testsWriter = File.AppendText(testsAndUUTFile);
                try
                {
                    // Step 1.   Build the call graph
                    Console.WriteLine("======  project summary ========= ");
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces/packages", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    var methods = globalNamespace.GetDescendants <MethodDefinition>();
                    int total   = methods.Count();
                    Console.WriteLine("{0,10:N0} methods", total);
                    //Console.Read();

                    //=====THIS IS JUST TO PRINT OUT METHODS AND CLASSES
                    int i = 0;
                    //foreach(MethodDefinition method in methods)
                    //{
                    //    var declaringClass = method.GetAncestors<TypeDefinition>().FirstOrDefault();
                    //    var className = "";
                    //    if (declaringClass != null)
                    //    {
                    //        className = declaringClass.Name;
                    //    }
                    //    var nameSpaceName = Utilities.GetNamespaceByMethod(method);
                    //    printMethod(classesWriter, projectGitName, parent, isFork, nameSpaceName, className, method);
                    //    Console.WriteLine($"{++i}/{total}");
                    //}
                    //return;
                    //==END PRINITNG
                    // Step 2.   Testing
                    Console.WriteLine("\n======  analysing methods and identifying UUTs ========= ");
                    foreach (MethodDefinition method in methods)
                    {
                        try
                        {
                            //colect basic ID information
                            var declaringClass = method.GetAncestors <TypeDefinition>().FirstOrDefault();
                            var className      = "";
                            if (declaringClass != null)
                            {
                                className = declaringClass.Name;
                            }
                            var nameSpaceName = Utilities.GetNamespaceByMethod(method);

                            dc.ProjectClassesInsert(projectGitName, parent, isFork, nameSpaceName, className, method.Name, method.ToString(), method.PrimaryLocation.SourceFileName, method.PrimaryLocation.StartingLineNumber, method.PrimaryLocation.EndingLineNumber, method.PrimaryLocation.StartingColumnNumber, method.PrimaryLocation.EndingColumnNumber);

                            //printMethod(dc, projectGitName, parent, isFork, nameSpaceName, className, method);
                            //printMethod(classesWriter, projectGitName, parent, isFork, nameSpaceName, className, method);

                            if (Utilities.IsTestCase(method, projectTestCases))
                            {
                                try
                                {
                                    //Console.WriteLine("Test Method Name : {0}", method.GetFullName());
                                    //SwumSummary swumSummary = new SwumSummary(method);
                                    //swumSummary.BasicSummary();
                                    TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
                                    //Console.WriteLine("Passed Analyzer for Test Method Name : {0}", method.GetFullName());
                                    ////analyzer.GetTestingObject();
                                    //string desc = swumSummary.Describe();
                                    ////writetext.WriteLine(method.Name + "  ,  " + desc);
                                    ////Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

                                    //TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
                                    //tcSummary.NameSpaceName = nameSpaceName;
                                    //tcSummary.ClassName = className;
                                    //tcSummary.MethodName = method.Name;

                                    //projectTestSummary.Add(tcSummary);

                                    //======For the test case propagation, we are interested in reusing an entire test case, hence we must know all methods referenced in the test case. Thus we use theinvoked methods case

                                    //Dictionary<Statement, List<Statement>> focalToAssert = Utilities.GetFocalToAssert(analyzer.ListAssertInfo);
                                    //if (focalToAssert != null && focalToAssert.Count > 0)
                                    //{
                                    //    foreach (Statement statement in focalToAssert.Keys)
                                    //    {
                                    //        printMethodDetails(testsWriter, projectGitName, parent, isFork, method, className, nameSpaceName, statement);
                                    //    }
                                    //}
                                    //else if (analyzer.ListAssertInfo != null && analyzer.ListAssertInfo.Count > 0)
                                    //{
                                    //    //print all methods in asserts
                                    //    foreach (AssertSTInfo info in analyzer.ListAssertInfo)
                                    //    {
                                    //        printMethodDetails(testsWriter, projectGitName, parent, isFork, method, className, nameSpaceName, info.AssertStatment);
                                    //    }
                                    //}
                                    //else
                                    //{
                                    //all external methods referenced by the test method
                                    HashSet <MethodDefinition> external = analyzer.InvokedExternalMethods;
                                    foreach (MethodDefinition definition in external)
                                    {
                                        if (definition == null)
                                        {
                                            continue;
                                        }
                                        var mdCall = definition;


                                        var decClass = mdCall.GetAncestors <TypeDefinition>().FirstOrDefault();
                                        var mdClass  = "";
                                        if (decClass != null)
                                        {
                                            mdClass = decClass.Name;
                                        }
                                        var mdPackage = GetNamespaceByMethod(mdCall);
                                        dc.TestUUTPairInsert(projectGitName, parent, isFork, nameSpaceName, className, method.Name, method.ToString(), method.PrimaryLocation.SourceFileName, method.PrimaryLocation.StartingLineNumber, method.PrimaryLocation.EndingLineNumber, method.PrimaryLocation.StartingColumnNumber, method.PrimaryLocation.EndingColumnNumber, mdPackage, mdClass, mdCall.Name, mdCall.ToString(), mdCall.PrimaryLocation.SourceFileName, mdCall.PrimaryLocation.StartingLineNumber, mdCall.PrimaryLocation.EndingLineNumber, mdCall.PrimaryLocation.StartingColumnNumber, mdCall.PrimaryLocation.EndingColumnNumber);

                                        //printMethodDetails(dc, projectGitName, parent, isFork, method, className, nameSpaceName, definition);
                                        //printMethodDetails(testsWriter, projectGitName, parent, isFork, method, className, nameSpaceName, definition);
                                    }
                                    //}
                                }catch (StackOverflowException ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                            }
                        }catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        i++;
                        Console.WriteLine($"{i}/{total}");
                    }
                }
                finally
                {
                    //if (classesWriter != null)
                    //{
                    //    classesWriter.Close();
                    //}
                    //if (testsWriter != null)
                    //{
                    //    testsWriter.Close();
                    //}
                    project.WorkingSet.ReleaseReadLock();
                }
            }
        }
예제 #33
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());
                    }
                }
            }
        }
예제 #34
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
            {
                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());
        }
예제 #35
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;
     }
 }
예제 #36
0
        public void analyzeProjectTestCases(string projectLocation, HashSet <TestCaseID> projectTestCases, HashSet <TestCaseSummary> projectTestSummary)
        {
            Console.WriteLine($"Analysing project {Path.GetFileName(projectLocation)}");

            using (var project = new DataProject <CompleteWorkingSet>(projectLocation, projectLocation, srcMLexeLocation))
            {
                project.Update();
                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try
                {
                    // Step 1.   Build the call graph
                    Console.WriteLine("======  project summary ========= ");
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces/packages", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());
                    //Console.Read();
                    var methods = globalNamespace.GetDescendants <MethodDefinition>();

                    ////print test cases
                    //StreamWriter wt = File.AppendText(@"C:\testpropagation\clones\testCases.csv");
                    //wt.WriteLine($"nameSpaceName;className;methodName");
                    //wt.Flush();
                    //foreach(TestCaseID id in projectTestCases)
                    //{
                    //    wt.WriteLine($"{id.NamespaceName};{id.ClassName};{id.MethodName}");
                    //    wt.Flush();
                    //}
                    //wt.Close();
                    ////print methods
                    //StreamWriter w = File.AppendText(@"C:\testpropagation\clones\budMethods.csv");
                    //w.WriteLine($"nameSpaceName;className;methodName");
                    //w.Flush();

                    int i = 0;
                    // Step 2.   Testing
                    Console.WriteLine("\n======  analysing methods and identifying UUTs ========= ");
                    foreach (MethodDefinition method in methods)
                    {
                        //colect basic ID information
                        var declaringClass = method.GetAncestors <TypeDefinition>().FirstOrDefault();
                        var className      = "";
                        if (declaringClass != null)
                        {
                            className = declaringClass.Name;
                        }
                        var nameSpaceName = Utilities.GetNamespaceByMethod(method);
                        //w.WriteLine($"{nameSpaceName};{className};{method.Name}");
                        //w.Flush();
                        //continue;

                        if (Utilities.IsTestCase(method, projectTestCases))
                        {
                            //Console.WriteLine("Method Name : {0}", method.GetFullName());
                            SwumSummary swumSummary = new SwumSummary(method);
                            swumSummary.BasicSummary();
                            TestCaseAnalyzer analyzer = new TestCaseAnalyzer(method);
                            //analyzer.GetTestingObject();
                            string desc = swumSummary.Describe();
                            //writetext.WriteLine(method.Name + "  ,  " + desc);
                            //Console.WriteLine(nameSpaceName + "," + className + "," + method.Name + "Swum Description : " + desc);

                            TestCaseSummary tcSummary = new TestCaseSummary(desc, analyzer.ListAssertInfo, method);
                            tcSummary.NameSpaceName = nameSpaceName;
                            tcSummary.ClassName     = className;
                            tcSummary.MethodName    = method.Name;

                            projectTestSummary.Add(tcSummary);

                            Dictionary <Statement, List <Statement> > focalToAssert = Utilities.GetFocalToAssert(analyzer.ListAssertInfo);
                            if (focalToAssert != null && focalToAssert.Count > 0)
                            {
                                foreach (Statement statement in focalToAssert.Keys)
                                {
                                    Utilities.printMethodDetails(method, className, nameSpaceName, statement);
                                }
                            }
                            else
                            {
                                //print all methods in asserts
                                foreach (AssertSTInfo info in analyzer.ListAssertInfo)
                                {
                                    Utilities.printMethodDetails(method, className, nameSpaceName, info.AssertStatment);
                                }
                            }
                            //Console.WriteLine(tcSummary.GetBodyDescriptions());
                            //var stmts = method.GetDescendants<Statement>();
                            //Console.WriteLine($"===Printing local methods tested by {method.GetFullName()}===");
                            //HashSet<MethodDefinition> local = analyzer.InvokedLocalMethods;
                            //foreach(MethodDefinition definition in local)
                            //{
                            //    if (definition == null)
                            //    {
                            //        continue;
                            //    }
                            //    Console.WriteLine(definition.GetFullName());
                            //}
                            //Console.WriteLine($"===Printing external methods tested by {method.GetFullName()}===");
                            //HashSet<MethodDefinition> external = analyzer.InvokedExternalMethods;
                            //foreach (MethodDefinition definition in external)
                            //{
                            //    if (definition == null)
                            //    {
                            //        continue;
                            //    }
                            //    Console.WriteLine(definition.GetFullName());
                            //}

                            //delete me
                            //using (StreamWriter sw = File.AppendText(@"D:\d.csv"))
                            //{
                            //   var number = stmts.Count() + 2;
                            //   sw.WriteLine(method.Name + "," + number);
                            //    sw.Close();
                            //}
                            i++;
                        }
                    }
                    //w.Close();
                }
                finally
                {
                    project.WorkingSet.ReleaseReadLock();
                }
            }
        }
예제 #37
0
        public void TestCompleteWorkingSet(RealWorldTestProject testData)
        {
            CheckThatProjectExists(testData);
            Console.WriteLine("{0} {1} Project Summary", testData.ProjectName, testData.Version);
            Console.WriteLine("============================");
            using (var project = new DataProject <CompleteWorkingSet>(testData.DataDirectory, testData.FullPath, "SrcML")) {
                string   unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;

                using (var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                Console.WriteLine("{0} to initialize complete working set", end - start);

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

                try {
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());

                    var methodCalls = from statement in globalNamespace.GetDescendantsAndSelf()
                                      from expression in statement.GetExpressions()
                                      from call in expression.GetDescendantsAndSelf <MethodCall>()
                                      select call;

                    int       numMethodCalls = 0, numMatchedMethodCalls = 0, numMissedMethodCalls = 0;
                    Stopwatch sw             = new Stopwatch();
                    TimeSpan  elapsed        = new TimeSpan(0),
                              matchedElapsed = new TimeSpan(0),
                              missedElapsed  = new TimeSpan(0);

                    using (var callLog = new StreamWriter(Path.Combine(testData.DataDirectory, "call_log.csv"), false)) {
                        callLog.WriteLine("Location,Call Name,Successful,Time");
                        foreach (var call in methodCalls)
                        {
                            INamedEntity match = null;
                            sw.Restart();
                            try {
                                match = call.FindMatches().FirstOrDefault();
                            } catch (Exception e) {
                                project.ErrorLog.WriteLine("{0}:{1}:{2}: Call Exception {3}", call.Location.SourceFileName, call.Location.StartingLineNumber, call.Location.StartingColumnNumber, e);
                            }
                            sw.Stop();
                            numMethodCalls++;
                            if (null != match)
                            {
                                numMatchedMethodCalls++;
                                matchedElapsed += sw.Elapsed;
                            }
                            else
                            {
                                numMissedMethodCalls++;
                                missedElapsed += sw.Elapsed;
                            }
                            callLog.WriteLine(String.Join(",", String.Join(":", call.Location.SourceFileName, call.Location.StartingLineNumber, call.Location.StartingColumnNumber), call.Name, (match == null ? "0" : "1"), sw.ElapsedMilliseconds));
                            elapsed += sw.Elapsed;
                        }
                    }
                    Console.WriteLine("{0,10:N0} method calls", numMethodCalls);
                    Console.WriteLine("{0,10:P2} of method calls matched", (float)numMatchedMethodCalls / numMethodCalls);
                    Console.WriteLine("{0,10:N2} matches / millisecond ({1,7:N0} ms elapsed)", ((float)numMethodCalls) / elapsed.TotalMilliseconds, elapsed.TotalMilliseconds);
                    Console.WriteLine("{0,7:N3} ms / match", (float)matchedElapsed.TotalMilliseconds / numMatchedMethodCalls);
                    Console.WriteLine("{0,7:N3} ms / miss", (float)missedElapsed.TotalMilliseconds / numMissedMethodCalls);
                } finally {
                    project.WorkingSet.ReleaseReadLock();
                }
            }
        }
예제 #38
0
        public void TestCompleteWorkingSet_SingleCore(RealWorldTestProject testData) {
            CheckThatProjectExists(testData);
            Console.WriteLine("{0} {1} Project Summary", testData.ProjectName, testData.Version);
            Console.WriteLine("============================");
            using(var project = new DataProject<CompleteWorkingSet>(new LimitedConcurrencyLevelTaskScheduler(1), new FileSystemFolderMonitor(testData.FullPath, testData.DataDirectory), new SrcMLGenerator("SrcML"))) {
                string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;
                using(var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                NamespaceDefinition globalScope;
                Assert.That(project.WorkingSet.TryObtainReadLock(5000, out globalScope));
                Assert.IsNotNull(globalScope);
            }
        }
예제 #39
0
        public IEnumerable <IReportWorker> CreateWork(DataProject dataProject, AppSettings settings)
        {
            // Grab the output directory and make sure it exists
            var outDir = new DirectoryInfo(settings.ReportDir);

            if (!outDir.Exists)
            {
                logger.LogInformation("Creating report output directory: {Path}.", outDir.FullName);
                outDir.Create();
            }

            // Set up the razor engine and pre-compile the templates.
            logger.LogInformation("Setting up Razor and compiling templates.");

            var watch       = Stopwatch.StartNew();
            var razorConfig = new TemplateServiceConfiguration
            {
                TemplateManager = new RazorTemplateManager()
            };

            var razorService = RazorEngineService.Create(razorConfig);

            razorService.Compile("mapping-report", typeof(MappingReportViewModel));
            razorService.Compile("model-report", typeof(DataModel));
            razorService.Compile("index-page", typeof(IndexModel));

            Engine.Razor = razorService;

            logger.LogDebug("...razor setup complete, elapsed: {Time}.", watch.Elapsed.ToString(@"hh\:mm\:ss\.fff"));

            // Create the index data model, so we can add to it as we're planning out other stuff
            var indexModel = new IndexModel();

            // Copy static (embedded) files to the output directory
            yield return(serviceProvider.CopyEmbedded("style.css", outDir.FullName));

            // Create a model report for each model
            var section = indexModel.CreateSection("Models");

            foreach (var model in dataProject.Models)
            {
                var filename = $"{model.Id}.html";
                var path     = Path.Combine(outDir.FullName, filename);

                section.CreateEntry(model.Name, filename);

                yield return(serviceProvider.ModelReport(model, path));
            }

            // Create a mapping report for each mapping
            section = indexModel.CreateSection("Mappings");

            foreach (var map in dataProject.ExpressiveMaps)
            {
                var filename = Path.GetFileNameWithoutExtension(map.FileName) + ".html";
                var path     = Path.Combine(outDir.FullName, filename);

                section.CreateEntry(map.Name, filename);

                yield return(serviceProvider.MappingReport(map, path));
            }

            // Create the index page
            yield return(serviceProvider.IndexPage(indexModel, Path.Combine(outDir.FullName, "index.html")));
        }
        public void run()
        {
            Console.Out.WriteLine("Invoke call graph generator ");


            string dataDir = @"TESTNAIVE_1.0";

            //string proPath = @"C:\Users\[email protected]\Documents\RunningTest\Input\ConsoleApplication1";
            //string proPath = @"C:\Users\[email protected]\Documents\RunningTest\Input\SrcML\ABB.SrcML";
            using (var project = new DataProject <CompleteWorkingSet>(dataDir, this.LocalProj, this.SrcmlLoc)) {
                Console.WriteLine("============================");
                string   unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;
                Console.WriteLine("============================");
                using (var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();
                }
                end = DateTime.Now;

                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try {
                    // Step 1.   Build the call graph
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants <NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants <TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants <MethodDefinition>().Count());
                    var methods = globalNamespace.GetDescendants <MethodDefinition>();

                    CGManager cgm = new CGManager();
                    cgm.BuildCallGraph(methods);

                    // Step 2.   Testing
                    Console.WriteLine("======  test 1 ========= ");
                    foreach (MethodDefinition m in methods)
                    {
                        Console.WriteLine("Method Name : {0}", m.GetFullName());
                        List <List <MethodDefinition> > paths = cgm.FindCalleeList(m);
                        foreach (List <MethodDefinition> path in paths)
                        {
                            foreach (MethodDefinition mc in path)
                            {
                                Console.Write("{0}--->", mc.Name);
                            }
                            Console.WriteLine("");
                        }
                    }


                    Console.WriteLine("======  test 2 ========= ");
                    List <List <MethodDefinition> > paths2 = cgm.FindCalleeListByName("ConsoleApplication1.Class1.m1");
                    foreach (List <MethodDefinition> path in paths2)
                    {
                        foreach (MethodDefinition mc in path)
                        {
                            Console.Write("{0}--->", mc.Name);
                        }
                        Console.WriteLine("");
                    }


                    Console.WriteLine("======  test 3 ========= ");
                    int sum     = 0;
                    int pathNum = 0;
                    foreach (MethodDefinition m in methods)
                    {
                        Console.WriteLine("Method Name : {0}", m.GetFullName());
                        List <List <MethodDefinition> > paths = cgm.FindCallerList(m);
                        foreach (List <MethodDefinition> path in paths)
                        {
                            sum += path.Count;
                            pathNum++;
                            foreach (MethodDefinition mc in path)
                            {
                                Console.Write("{0}<---", mc.Name);
                            }
                            Console.WriteLine("");
                        }
                    }
                    Console.WriteLine("average level : " + (double)sum / pathNum);
                } finally {
                    project.WorkingSet.ReleaseReadLock();
                }
            }


            Console.ReadLine();
        }
예제 #41
0
        //This method is running after we generate the class and it contains two parts: 1. generating call graph of the target project; 2. calling GoThroughMethods to check taht does each method contain SQL local invocation or not.
        public void run()
        {
            Console.WriteLine("Invoke method sql extractor");
            string dataDir = @"TESTNAIVE_1.0";
            using (var project = new DataProject<CompleteWorkingSet>(dataDir, this.LocalProj, this.SrcmlLoc)) {

                Console.WriteLine("============================");
                string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");
                DateTime start = DateTime.Now, end;
                Console.WriteLine("============================");
                using (var unknownLog = new StreamWriter(unknownLogPath)) {
                   project.UnknownLog = unknownLog;
                   project.UpdateAsync().Wait();

                }
                end = DateTime.Now;

                NamespaceDefinition globalNamespace;
                project.WorkingSet.TryObtainReadLock(5000, out globalNamespace);
                try {
                    // Step 1.   Build the call graph
                    Console.WriteLine("{0,10:N0} files", project.Data.GetFiles().Count());
                    Console.WriteLine("{0,10:N0} namespaces", globalNamespace.GetDescendants<NamespaceDefinition>().Count());
                    Console.WriteLine("{0,10:N0} types", globalNamespace.GetDescendants<TypeDefinition>().Count());
                    Console.WriteLine("{0,10:N0} methods", globalNamespace.GetDescendants<MethodDefinition>().Count());

                    var methods = globalNamespace.GetDescendants<MethodDefinition>();
                    this.cgm = new CGManager();
                    cgm.BuildCallGraph(methods);

                    GoThroughMethods(methods);

                    Console.WriteLine("Method Analyzing Finished! Total SQLs found: " + sqlCount+ ", total methods: " + allDirectMethods.Count);
                } finally {
                    project.WorkingSet.ReleaseReadLock();
                }

            }
        }
예제 #42
0
        public void TestSerialization(RealWorldTestProject testData) {
            using(var project = new DataProject<NullWorkingSet>(testData.DataDirectory, testData.FullPath, "SrcML")) {
                string unknownLogPath = Path.Combine(project.StoragePath, "unknown.log");

                using(var unknownLog = new StreamWriter(unknownLogPath)) {
                    project.UnknownLog = unknownLog;
                    project.UpdateAsync().Wait();

                    long count = 0;
                    TextWriter output = StreamWriter.Synchronized(Console.Out),
                                 error = StreamWriter.Synchronized(Console.Error);

                    long parseElapsed = 0, deserializedElapsed = 0, compareElapsed = 0;
                    output.WriteLine("{0,-12} {1,-12} {2,-12} {3,-12}", "# Files", "Parse", "Deserialize", "Comparison");
                    Parallel.ForEach(project.Data.GetFiles(), (sourcePath) => {
                        DateTime start, end;
                        NamespaceDefinition data;
                        NamespaceDefinition serializedData;
                        try {
                            start = DateTime.Now;
                            var fileUnit = project.SourceArchive.GetXElementForSourceFile(sourcePath);
                            data = project.Data.Generator.Parse(fileUnit);
                            end = DateTime.Now;
                            Interlocked.Add(ref parseElapsed, (end - start).Ticks);
                        } catch(Exception ex) {
                            Console.Error.WriteLine(ex);
                            data = null;
                        }

                        try {
                            start = DateTime.Now;
                            serializedData = project.Data.GetData(sourcePath);
                            end = DateTime.Now;
                            Interlocked.Add(ref deserializedElapsed, (end - start).Ticks);
                        } catch(Exception ex) {
                            error.WriteLine(ex);
                            serializedData = null;
                        }

                        Assert.IsNotNull(data);
                        Assert.IsNotNull(serializedData);
                        start = DateTime.Now;
                        DataAssert.StatementsAreEqual(data, serializedData);
                        end = DateTime.Now;
                        Interlocked.Add(ref compareElapsed, (end - start).Ticks);

                        if(Interlocked.Increment(ref count) % 25 == 0) {
                            output.WriteLine("{0,12:N0} {1,12:ss\\.fff} {2,12:ss\\.fff} {3,12:ss\\.fff}", count,
                                    new TimeSpan(parseElapsed),
                                    new TimeSpan(deserializedElapsed),
                                    new TimeSpan(compareElapsed));
                        }
                    });
                    
                    Console.WriteLine("Project: {0} {1}", testData.ProjectName, testData.Version);
                    Console.WriteLine("{0,-15} {1,11:N0}", "# Files", count);
                    Console.WriteLine("{0,-15} {1:g}", "Parsing", new TimeSpan(parseElapsed));
                    Console.WriteLine("{0,-15} {1:g}", "Deserializing", new TimeSpan(deserializedElapsed));
                    Console.WriteLine("{0,-15} {1:g}", "Comparing", new TimeSpan(compareElapsed));
                    Console.WriteLine("{0,-15} {1:g}", "Total", new TimeSpan(parseElapsed + deserializedElapsed + compareElapsed));
                }
            }
        }
예제 #43
0
        public void TestFindScopeForAdjacentMethods() {
            File.Copy(@"..\..\TestInputs\adjacent_methods.cpp", Path.Combine(TestDir, "adjacent_methods.cpp"));

            using(var dataProj = new DataProject<CompleteWorkingSet>(DataDir, TestDir, SrcMLDir)) {
                dataProj.Update();

                NamespaceDefinition globalScope;
                MethodDefinition mainMethod;
                MethodDefinition fooMethod;
                Assert.That(dataProj.WorkingSet.TryObtainReadLock(Timeout.Infinite, out globalScope));
                try {
                    mainMethod = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "main");
                    fooMethod = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "Foo");
                } finally {
                    dataProj.WorkingSet.ReleaseReadLock();
                }

                var query = new StatementForLocationQuery(dataProj.WorkingSet, Timeout.Infinite);
                var testFile = Path.GetFullPath(Path.Combine(TestDir, "adjacent_methods.cpp"));

                var startOfMain = new SourceLocation(testFile, 1, 1);
                var locationInMain = new SourceLocation(testFile, 1, 11);
                Assert.That(mainMethod.PrimaryLocation.Contains(startOfMain));
                Assert.That(mainMethod.PrimaryLocation.Contains(locationInMain));

                Assert.AreSame(mainMethod, query.Execute(startOfMain));
                Assert.AreSame(mainMethod, query.Execute(locationInMain));

                var startOfFoo = new SourceLocation(testFile, 3, 1);
                var locationInFoo = new SourceLocation(testFile, 3, 11);
                Assert.That(fooMethod.PrimaryLocation.Contains(startOfFoo));
                Assert.That(fooMethod.PrimaryLocation.Contains(locationInFoo));

                Assert.AreSame(fooMethod, query.Execute(startOfFoo));
                Assert.AreSame(fooMethod, query.Execute(locationInFoo));

                var lineBetweenMethods = new SourceLocation(testFile, 2, 1);
                Assert.That(mainMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.IsFalse(fooMethod.PrimaryLocation.Contains(lineBetweenMethods));
                Assert.AreSame(mainMethod, query.Execute(lineBetweenMethods));
            }
        }
예제 #44
0
        public void GenerateSameActionSUnit()
        {
            //   var dataProject = new DataProject<CompleteWorkingSet>("npp_6.2.3",
            //     Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
            //   "..//..//..//SrcML");

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

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

            List<String> success = new List<String>();
            Dictionary<SwumRule, bool> inClasses = null;

            string methodName = arg;
            bool debug = false; ///////////////// DEBUGGING

            // Get SrcML stuff in order
            dataProject.UpdateAsync().Wait();
            NamespaceDefinition globalNamespace;
            Assert.That(dataProject.WorkingSet.TryObtainReadLock(1000, out globalNamespace));

            // Initialize Swum
            splitter = new ConservativeIdSplitter();
            tagger = new UnigramTagger();
            posData = new PCKimmoPartOfSpeechData();

            var methodList = globalNamespace.GetDescendants<MethodDefinition>().Where(m => m.Name == methodName);
            MethodDefinition topMethod = null;

            // Check if the method was found
            try
            {
                topMethod = methodList.First();
            }
            catch (System.InvalidOperationException)
            {
                Console.WriteLine("--ERROR: Method '" + methodName + "' Not Found--");
                Assert.Fail("Method '" + methodName + "' Not Found");
            }

            var guiMethodXElement = DataHelpers.GetElement(dataProject.SourceArchive, topMethod.PrimaryLocation);

            //generate swum for method declaration
            MethodContext mc = ContextBuilder.BuildMethodContext(guiMethodXElement);
            MethodDeclarationNode mdn = new MethodDeclarationNode(methodName, mc);
            BaseVerbRule rule = new BaseVerbRule(posData, tagger, splitter);
            Console.WriteLine("Method = \t" + methodName);
            Console.WriteLine("InClass = \t" + rule.InClass(mdn));

            // Get the action verb from the SWUM
            String methodVerb = GetMethodVerb(methodName, mc);
            Console.WriteLine("Verb = \t\t" + methodVerb);
            Console.WriteLine("============================");

            // Get all of the lines of code that contains the verb in any form
            var expr = topMethod.GetDescendants().Where(t => t.ToString().Contains(methodVerb)).ToArray();

            // Iterate each line
            foreach (Statement t in expr)
            {
                if (debug) Console.WriteLine("Line: " + t.ToString());
                // This finds any method calls in this line and finds the verb in that method - from GetCallsTo()
                var methods = t.FindExpressions<MethodCall>(true).Where(c => c.ToString().ToLower().Contains(methodVerb));//c.Name.Contains(methodVerb));

                // Iterate through a list of the method calls in a line and find ones that contain the verb
                foreach (MethodCall i in methods)
                {

                    if (debug) Console.WriteLine("===\n" + i.Name);

                    MethodDeclarationNode mdnNEW = new MethodDeclarationNode(i.Name, mc);

                    inClasses = InClassChecker(i.Name, mc);

                    String foundVerb = GetMethodVerb(i.Name, mc);
                    if (foundVerb.Equals("!NONE!"))
                    {
                        if (debug) Console.WriteLine("   Method does not contain verb");
                    }
                    else
                    {
                        if (debug) Console.WriteLine("GetMethodVerb= " + GetMethodVerb(i.Name, mc));

                        success.Add(i.Name);
                    }

                    if (debug) Console.WriteLine("CompareSwums= " + CompareSwums(i.Name, mc));

                    // Debugging
                    if (debug)
                    {
                        int numbtrue = 0;
                        foreach (KeyValuePair<SwumRule, bool> entry in inClasses)
                        {
                            if (entry.Value)
                            {
                                numbtrue++;
                                mdnNEW = new MethodDeclarationNode(i.Name, mc);
                                entry.Key.InClass(mdnNEW);
                                entry.Key.ConstructSwum(mdnNEW);

                                Console.WriteLine("\t" + entry.Key.GetType().ToString() + new String(' ', 30 - entry.Key.GetType().ToString().Length) + " = " + mdnNEW.ToString());

                                if (mdnNEW.Action.ToPlainString().Equals(methodVerb, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Console.WriteLine("\tMethod contains the verb");
                                }
                                else
                                {
                                    Console.WriteLine("\tMethod does not contain the verb" + "\n");
                                }

                            }

                        }
                        Console.WriteLine(" Inclasses  = " + numbtrue);

                    } //end if debug

                } // End Method Iteration
            } // End Line Iteration

            if (success.Count == 0)
            {
                Console.WriteLine("===== No Same-Action Methods Found =====");
                //Assert.Fail("No Same-Action Methods found");
            }
            else
            {
                Console.WriteLine("\n============= SUCCESSES ===============");
                foreach (String i in success)
                {
                    Console.WriteLine(i);
                }
                //Assert.Pass("Same-Action methods found, check Output");

            }

            dataProject.WorkingSet.ReleaseReadLock();
        }
예제 #45
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());
        }
예제 #46
0
        public void GenerateSwumForAnyOccassion()
        {
            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));

            //find an example method
            var sampleMethod = globalNamespace.GetDescendants<MethodDefinition>().Where(m => m.Name == methodName).First();

            foreach (var line in sampleMethod.GetDescendants()) //goes through lines (Statement class) in method
            {
                var sampleMethod_MethodCalls = line.FindExpressions<MethodCall>(); //represents all of the method calls within the method

                foreach (var methodCall in sampleMethod_MethodCalls) //goes through each method call
                {
                    var swummedMdn = FromMethodCallToSWUM(methodCall, globalNamespace, dataProject);

                    if (swummedMdn != null)
                    {
                        Console.WriteLine("VOID RETURN");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }

                //return statement
                if (line is ReturnStatement)
                {
                    var returnMCall = line.FindExpressions<MethodCall>().First();
                    var swummedMdn = FromMethodCallToSWUM(returnMCall, globalNamespace, dataProject);
                    if (swummedMdn != null)
                    {
                        Console.WriteLine("RETURN STMT");
                        Console.WriteLine(swummedMdn.ToString());
                    }
                }
            }
        }
예제 #47
0
        public void GenerateSameActionSUnit()
        {
            //   var dataProject = new DataProject<CompleteWorkingSet>("npp_6.2.3",
            //     Path.GetFullPath("..//..//..//projects//npp_6.2.3"),
            //   "..//..//..//SrcML");


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

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


            List <String> success = new List <String>();
            Dictionary <SwumRule, bool> inClasses = null;

            bool debug = false; ///////////////// DEBUGGING

            // Get SrcML stuff in order
            dataProject.UpdateAsync().Wait();
            NamespaceDefinition globalNamespace;

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


            // Initialize Swum
            splitter = new ConservativeIdSplitter();
            tagger   = new UnigramTagger();
            posData  = new PCKimmoPartOfSpeechData();



            var methodList             = globalNamespace.GetDescendants <MethodDefinition>().Where(m => m.Name == methodName);
            MethodDefinition topMethod = null;

            // Check if the method was found
            try
            {
                topMethod = methodList.First();
            }
            catch (System.InvalidOperationException)
            {
                Console.WriteLine("--ERROR: Method '" + methodName + "' Not Found--");
                Assert.Fail("Method '" + methodName + "' Not Found");
            }

            var guiMethodXElement = DataHelpers.GetElement(dataProject.SourceArchive, topMethod.PrimaryLocation);

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

            Console.WriteLine("Method = \t" + methodName);
            Console.WriteLine("InClass = \t" + rule.InClass(mdn));


            // Get the action verb from the SWUM
            String methodVerb = GetMethodVerb(methodName, mc);

            Console.WriteLine("Verb = \t\t" + methodVerb);
            Console.WriteLine("============================");

            // Get all of the lines of code that contains the verb in any form
            var expr = topMethod.GetDescendants().Where(t => t.ToString().Contains(methodVerb)).ToArray();

            // Iterate each line
            foreach (Statement t in expr)
            {
                if (debug)
                {
                    Console.WriteLine("Line: " + t.ToString());
                }
                // This finds any method calls in this line and finds the verb in that method - from GetCallsTo()
                var methods = t.FindExpressions <MethodCall>(true).Where(c => c.ToString().ToLower().Contains(methodVerb));//c.Name.Contains(methodVerb));

                // Iterate through a list of the method calls in a line and find ones that contain the verb
                foreach (MethodCall i in methods)
                {
                    if (debug)
                    {
                        Console.WriteLine("===\n" + i.Name);
                    }

                    MethodDeclarationNode mdnNEW = new MethodDeclarationNode(i.Name, mc);

                    inClasses = InClassChecker(i.Name, mc);


                    String foundVerb = GetMethodVerb(i.Name, mc);
                    if (foundVerb.Equals("!NONE!"))
                    {
                        if (debug)
                        {
                            Console.WriteLine("   Method does not contain verb");
                        }
                    }
                    else
                    {
                        if (debug)
                        {
                            Console.WriteLine("GetMethodVerb= " + GetMethodVerb(i.Name, mc));
                        }

                        success.Add(i.Name);
                    }


                    if (debug)
                    {
                        Console.WriteLine("CompareSwums= " + CompareSwums(i.Name, mc));
                    }

                    // Debugging
                    if (debug)
                    {
                        int numbtrue = 0;
                        foreach (KeyValuePair <SwumRule, bool> entry in inClasses)
                        {
                            if (entry.Value)
                            {
                                numbtrue++;
                                mdnNEW = new MethodDeclarationNode(i.Name, mc);
                                entry.Key.InClass(mdnNEW);
                                entry.Key.ConstructSwum(mdnNEW);

                                Console.WriteLine("\t" + entry.Key.GetType().ToString() + new String(' ', 30 - entry.Key.GetType().ToString().Length) + " = " + mdnNEW.ToString());

                                if (mdnNEW.Action.ToPlainString().Equals(methodVerb, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Console.WriteLine("\tMethod contains the verb");
                                }
                                else
                                {
                                    Console.WriteLine("\tMethod does not contain the verb" + "\n");
                                }
                            }
                        }
                        Console.WriteLine(" Inclasses  = " + numbtrue);
                    } //end if debug
                }     // End Method Iteration
            }         // End Line Iteration

            if (success.Count == 0)
            {
                Console.WriteLine("===== No Same-Action Methods Found =====");
                //Assert.Fail("No Same-Action Methods found");
            }
            else
            {
                Console.WriteLine("\n============= SUCCESSES ===============");
                foreach (String i in success)
                {
                    Console.WriteLine(i);
                }
                //Assert.Pass("Same-Action methods found, check Output");
            }



            dataProject.WorkingSet.ReleaseReadLock();
        } // End Same-Action main method
예제 #48
0
파일: Sync.cs 프로젝트: Chaiwa/hybrid
        public static void Synchronize()
        {
            ConnectionProperties
                remote = new ConnectionProperties(Settings.Default.RemoteServer, Settings.Default.RemoteDb),
                local  = new ConnectionProperties(Settings.Default.LocalServer, Settings.Default.LocalDb);

            using (var service = new SchemaServiceClient()) {
                //check for schema update
                byte version = service.GetSchemaVersion();
                if (version > Settings.Default.SchemaVersion)
                {
                    //synchronise schema
                    StructureProject structure = new StructureProject(remote, local);

                    structure.ComparisonOptions.IgnoreIdentitySeedAndIncrement = true;
                    structure.MappedObjects.ExcludeAllFromComparison();

                    //select the desired tables and triggers
                    var tables = Settings.Default.Tables.Split(',');
                    structure.MappedTables.IncludeInComparison(tables.Select(t => '^' + t + '$').ToArray());
                    structure.MappedTriggers.IncludeInComparison(tables.Select(t => '^' + t + "_TimeStamp$").ToArray());

                    structure.ComparedObjects.IncludeAllInSynchronization();
                    Synchronise(structure);

                    Settings.Default.SchemaVersion = version;
                    Settings.Default.Save();
                }

                //server to client
                DataProject down = new DataProject(remote, local);
#pragma warning disable 612
                down.ComparisonOptions.CompareAdditionalRows = false;
#pragma warning restore 612

                //only retrieve rows which have changed since last sync
                string timestamp = "TimeStamp > '" + Settings.Default.LastSync.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                foreach (MappedDataObject <Table> table in down.MappedTables)
                {
                    table.WhereClause.SourceFilter = timestamp;
                    table.WhereClause.UseSourceFilterForDestination = false;
                }

                down.ComparedObjects.IncludeAllInSynchronization();
                Synchronise(down);

                //client to server
                DataProject up = new DataProject(local, remote);
#pragma warning disable 612
                up.ComparisonOptions.CompareAdditionalRows = false;
#pragma warning restore 612

                using (var con = new SqlConnection(Settings.Default.Local))
                    foreach (MappedDataObject <Table> table in up.MappedTables)
                    {
                        StringBuilder ids = new StringBuilder("ID in (");
                        using (var com = new SqlCommand("select ID from " + table.SourceName + " where " + timestamp, con)) {
                            con.Open();
                            using (var results = com.ExecuteReader(CommandBehavior.CloseConnection))
                                while (results.Read())
                                {
                                    ids.Append(results[0]).Append(',');
                                }
                        }
                        if (ids[ids.Length - 1] == '(')
                        {
                            table.IncludeInComparison = false;
                        }
                        else
                        {
                            table.WhereClause.SourceFilter = ids.Remove(ids.Length - 1, 1).Append(')').ToString();
                        }
                    }

                try {
                    up.ComparedObjects.IncludeAllInSynchronization();
                    Synchronise(up);
                }
                catch (NoSelectedForOperationObjectsException) { }

                Settings.Default.LastSync = DateTime.Now;
                Settings.Default.Save();

                //do we have an ID range?
                if (Settings.Default.MaxID == 0)
                {
                    var range = service.GetIdRange(Environment.MachineName);
                    Settings.Default.MinID = range.Min;
                    Settings.Default.MaxID = range.Max;
                    Settings.Default.Save();
                }
            }

            //reseed the client
            using (var db = new SqlConnection(Settings.Default.Local))
                Repository.Repository.Reseed(Settings.Default.MinID, Settings.Default.MaxID, db);
        }
예제 #49
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);
            }
        }
예제 #50
0
파일: Sync.cs 프로젝트: accursoft/hybrid
        public static void Synchronize()
        {
            ConnectionProperties
                remote = new ConnectionProperties(Settings.Default.RemoteServer, Settings.Default.RemoteDb),
                local = new ConnectionProperties(Settings.Default.LocalServer, Settings.Default.LocalDb);

            using (var service = new SchemaServiceClient()) {

                //check for schema update
                byte version = service.GetSchemaVersion();
                if (version > Settings.Default.SchemaVersion) {
                    //synchronise schema
                    StructureProject structure = new StructureProject(remote, local);

                    structure.ComparisonOptions.IgnoreIdentitySeedAndIncrement = true;
                    structure.MappedObjects.ExcludeAllFromComparison();

                    //select the desired tables and triggers
                    var tables = Settings.Default.Tables.Split(',');
                    structure.MappedTables.IncludeInComparison(tables.Select(t => '^' + t + '$').ToArray());
                    structure.MappedTriggers.IncludeInComparison(tables.Select(t => '^' + t + "_TimeStamp$").ToArray());

                    structure.ComparedObjects.IncludeAllInSynchronization();
                    Synchronise(structure);

                    Settings.Default.SchemaVersion = version;
                    Settings.Default.Save();
                }

                //server to client
                DataProject down = new DataProject(remote, local);
            #pragma warning disable 612
                down.ComparisonOptions.CompareAdditionalRows = false;
            #pragma warning restore 612

                //only retrieve rows which have changed since last sync
                string timestamp = "TimeStamp > '" + Settings.Default.LastSync.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                foreach (MappedDataObject<Table> table in down.MappedTables) {
                    table.WhereClause.SourceFilter = timestamp;
                    table.WhereClause.UseSourceFilterForDestination = false;
                }

                down.ComparedObjects.IncludeAllInSynchronization();
                Synchronise(down);

                //client to server
                DataProject up = new DataProject(local, remote);
            #pragma warning disable 612
                up.ComparisonOptions.CompareAdditionalRows = false;
            #pragma warning restore 612

                using (var con = new SqlConnection(Settings.Default.Local))
                    foreach (MappedDataObject<Table> table in up.MappedTables) {
                        StringBuilder ids = new StringBuilder("ID in (");
                        using (var com = new SqlCommand("select ID from " + table.SourceName + " where " + timestamp, con)) {
                            con.Open();
                            using (var results = com.ExecuteReader(CommandBehavior.CloseConnection))
                                while (results.Read())
                                    ids.Append(results[0]).Append(',');
                        }
                        if (ids[ids.Length - 1] == '(')
                            table.IncludeInComparison = false;
                        else
                            table.WhereClause.SourceFilter = ids.Remove(ids.Length - 1, 1).Append(')').ToString();
                    }

                try {
                    up.ComparedObjects.IncludeAllInSynchronization();
                    Synchronise(up);
                }
                catch (NoSelectedForOperationObjectsException) { }

                Settings.Default.LastSync = DateTime.Now;
                Settings.Default.Save();

                //do we have an ID range?
                if (Settings.Default.MaxID == 0) {
                    var range = service.GetIdRange(Environment.MachineName);
                    Settings.Default.MinID = range.Min;
                    Settings.Default.MaxID = range.Max;
                    Settings.Default.Save();
                }
            }

            //reseed the client
            using (var db = new SqlConnection(Settings.Default.Local))
                Repository.Repository.Reseed(Settings.Default.MinID, Settings.Default.MaxID, db);
        }