예제 #1
0
 public void ParseXAMLFile()
 {
     var parser = new TextFileParser();
     var elements = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\SearchViewControl.xaml.txt");
     Assert.IsNotNull(elements);
     Assert.AreEqual(elements.Count, 1);
     Assert.IsTrue(elements.ElementAt(0).RawSource.Contains("</UserControl>"));
 }
예제 #2
0
        public void Update(string filePath, XElement xElement)
        {
            var fileInfo = new FileInfo(filePath);
            try
            {
                var parsed = new List<ProgramElement>();
                var codeParser = ExtensionPointsRepository.Instance.GetParserImplementation(fileInfo.Extension);
                if (codeParser != null)
                {
                    parsed.AddRange(codeParser.Parse(filePath, xElement));
                }
                if (codeParser == null || !codeParser.GetType().Equals(typeof(TextFileParser)))
                {
                    //parses everything with the TextFileParser (double parsing things that were parsed with SrcML)
                    var textFileParser = new TextFileParser();
                    parsed.AddRange(textFileParser.Parse(filePath, xElement));
                }

                var unresolvedElements = parsed.FindAll(pe => pe is CppUnresolvedMethodElement);
                if (unresolvedElements.Count > 0)
                {
                    //first generate program elements for all the included headers
                    var headerElements = CppHeaderElementResolver.GenerateCppHeaderElements(filePath, unresolvedElements);

                    //then try to resolve
                    foreach (CppUnresolvedMethodElement unresolvedElement in unresolvedElements)
                    {
                        var document = CppHeaderElementResolver.GetDocumentForUnresolvedCppMethod(unresolvedElement, headerElements);
                        if (document != null)
                        {
                            //writeLog( "- DI.AddDocument()");
                            _currentIndexer.AddDocument(document);
                        }
                    }
                }

                foreach (var programElement in parsed)
                {
                    if (!(programElement is CppUnresolvedMethodElement))
                    {
                        var document = DocumentFactory.Create(programElement);
                        if (document != null)
                        {
                            //writeLog( "- DI.AddDocument()");
                            _currentIndexer.AddDocument(document);
                        }
                    }
                }
                if(indexUpdated!=null)
                    indexUpdated(parsed.AsReadOnly());
            }
            catch (Exception e)
            {
                LogEvents.UIIndexUpdateError(this, e);
            }
        }
예제 #3
0
        public void ParseTxtFile()
        {
            var parser = new TextFileParser();
            var elements = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\LongFile.txt");
            Assert.IsNotNull(elements);
            Assert.AreEqual(elements.Count, 709);
            Assert.IsTrue(elements.ElementAt(0).RawSource.Contains("the")); //first word
            Assert.IsTrue(elements.ElementAt(0).RawSource.Contains("16761152")); //second number

            //this file is too big, so a word near the end of it should not have been parsed
            Assert.IsFalse(elements.ElementAt(0).RawSource.Contains("aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz"));
        }
예제 #4
0
 public void ParseCodeMaidTxtFile()
 {
     var parser = new TextFileParser();
     var elements = parser.Parse("..\\..\\IntegrationTests\\TestFiles\\TextFilesTestFiles\\CodeMaidTest.txt");
     Assert.IsNotNull(elements);
     Assert.AreEqual(elements.Count, 5);
     bool found = false;
     foreach (var element in elements)
     {
         if (element.RawSource.Contains("IconUnlock"))
         {
             found = true;
             break;
         }
     }
     Assert.IsTrue(found, "didn't find 'IconUnlock', a word that exists at the end of this file"); // word at end of file
 }