Esempio n. 1
0
        public void BasicTest()
        {
            if(!File.Exists(Helper.NppXmlPath)) {
                Assert.Ignore(String.Format("SrcML for Notepad++ is not available at {0}", Helper.NppXmlPath));
            }
            var document = new SrcMLFile(Helper.NppXmlPath);

            var newUses = from unit in document.FileUnits
                          from use in QueryForNew(unit)
                          select use;

            SyntaticCategoryDataModel model = new SyntaticCategoryDataModel();
            
            foreach (var element in newUses)
            {
                var occurrence = new SyntaticOccurance(model, element);
            }

            //Console.WriteLine("{0} uses of the \"new\" operator in {1} categories", newUses.Count(), model.SyntaticCategories.Keys.Count);
            
            foreach (var category in model.SyntaticCategories.Keys)
            {
                
                var xpath = model.SyntaticCategories[category].First().CategoryAsXPath;//.Substring(1);

                var results = from use in newUses
                              let occurrence = new SyntaticOccurance(model, use)
                              where occurrence.CategoryAsXPath == xpath
                              select use;

                //Console.WriteLine("{0,3} uses of the new operator in {1}", results.Count(), xpath);
                Assert.AreEqual(model.SyntaticCategories[category].Count, results.Count(), category);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor which is used to create an instance of this class
 /// however this constructor requiers that some specific properties
 /// be met. The dataModel is simply the class which owns this one
 /// and that should only ever be the class which creates an instance
 /// of this type. The element is the xml element from inside of a 
 /// srcml archive, which represents an instance of a match matched 
 /// by a search pattern. The VCFile is the file which contains 
 /// the matched pattern and is used so that it can be easily located 
 /// and opened if necessary.
 /// 
 /// TODO: in the future: make this into an interface
 /// and implement that interface inside of a different class which is
 /// private to this namespace.
 /// 
 /// Not sure if it's benificial but it may be necessary to use something
 /// other then VCFile but I'm not 100% sure what.
 /// </summary>
 /// <param name="dataModel">The data model which is owns this class.</param>
 /// <param name="node">The element which is used to </param>
 public SyntaticOccurance(SyntaticCategoryDataModel dataModel, XElement element)
 {
     Element = element;
     // SyntaticCategoryGenerationType = SyntaticCategoryPathTypes.OuterBlockCategory;
     mDataModel = dataModel;
     XElement translationUnitElem = GetTranslationUnit();
     mTranslationUnitName = translationUnitElem.Attributes().Where(
         new Func<XAttribute, bool>(
             (x) => x.Name == "filename"
         )
     ).First().Value;
     UpdateCategory();
 }
        /// <summary>
        /// Constructor which is used to create an instance of this class
        /// however this constructor requiers that some specific properties
        /// be met. The dataModel is simply the class which owns this one
        /// and that should only ever be the class which creates an instance
        /// of this type. The element is the xml element from inside of a
        /// srcml archive, which represents an instance of a match matched
        /// by a search pattern. The VCFile is the file which contains
        /// the matched pattern and is used so that it can be easily located
        /// and opened if necessary.
        ///
        /// TODO: in the future: make this into an interface
        /// and implement that interface inside of a different class which is
        /// private to this namespace.
        ///
        /// Not sure if it's benificial but it may be necessary to use something
        /// other then VCFile but I'm not 100% sure what.
        /// </summary>
        /// <param name="dataModel">The data model which is owns this class.</param>
        /// <param name="node">The element which is used to </param>
        public SyntaticOccurance(SyntaticCategoryDataModel dataModel, XElement element)
        {
            Element = element;
            // SyntaticCategoryGenerationType = SyntaticCategoryPathTypes.OuterBlockCategory;
            mDataModel = dataModel;
            XElement translationUnitElem = GetTranslationUnit();

            mTranslationUnitName = translationUnitElem.Attributes().Where(
                new Func <XAttribute, bool>(
                    (x) => x.Name == "filename"
                    )
                ).First().Value;
            UpdateCategory();
        }
        private void queryWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Object[] results = e.Result as Object[];

            this.selectedDoc = results[0] as SrcMLFile;
            this.data = results[1] as List<DataCell>;
            this.categories = results[2] as SyntaticCategoryDataModel;

            int count = 0;

            if (null != this.data)
            {
                dataGridView1.DataSource = this.data;
                count = this.data.Count;
            }

            if (null != this.categories)
            {
                CategoryTreeNode root = new CategoryTreeNode("All");
                
                categoryTreeView.BeginUpdate();
                categoryTreeView.Nodes.Clear();
                categoryTreeView.Nodes.Add(root);
                foreach (var category in categories.SyntaticCategories.Keys)
                {
                    var xpath = categories.SyntaticCategories[category].First().CategoryAsXPath;
                    var categoryCount = categories.SyntaticCategories[category].Count;
                    root.AddCategory(xpath, categoryCount);
                }
                categoryTreeView.SelectedNode = root;
                categoryTreeView.EndUpdate();
            }

            queryingXML = false;
            runQueryButton.Text = Resources.TestButton;
            progressBar.Value = 0;
            progressLabel.Text = "";
            messageLabel.Text = String.Format("Found {0} items.", count);
            setButtons();
        }
        private void queryWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Object[] args = e.Argument as Object[];

            SrcMLFile doc = new SrcMLFile(args[0] as string);
            ITransform transform = args[1] as ITransform;

            SyntaticCategoryDataModel categories = new SyntaticCategoryDataModel();
            List<DataCell> data = executeTransform(doc, transform, ref categories, sender as BackgroundWorker);
            Object[] results = { doc, data, categories };
            e.Result = results;
        }
        private static List<DataCell> executeTransform(SrcMLFile doc, ITransform transform, ref SyntaticCategoryDataModel categories, BackgroundWorker worker)
        {
            IEnumerable<XElement> elements;
            List<DataCell> data = null;

            if (null != transform)
            {
                try
                {
                    elements = doc.QueryEachUnit(transform);

                    if (null != elements)
                    {
                        float numElements = (float)elements.Count();
                        int i = 0, percentComplete = 0;
                        data = new List<DataCell>();
                        foreach (var node in elements)
                        {
                            var occurrence = new SyntaticOccurance(categories, node);
                            categories.AddOccurance(occurrence);
                            data.Add(new DataCell(doc, node, transform, occurrence));
                            percentComplete = (int)((float)++i / numElements * 100);
                            worker.ReportProgress(percentComplete);
                        }
                        foreach (var d in data)
                            d.Enabled = true;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(String.Format("{0}: {1}\n{2}", e.Source, e.Message, e.StackTrace));
                }
            }
            return data;
        }