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);
            }
        }
Example #2
0
 /// <summary>
 /// Takes an occurance and adds it into the syntatic categories
 /// dictionary.
 /// </summary>
 /// <param name="occurance"></param>
 private void AddToSyntaticCategory(SyntaticOccurance occurance)
 {
     if (!SyntaticCategories.ContainsKey(occurance.Category))
     {
         SyntaticCategories.Add(occurance.Category, new List <SyntaticOccurance>());
     }
     SyntaticCategories[occurance.Category].Add(occurance);
 }
 /// <summary>
 /// Takes an occurance and adds it into the syntatic categories 
 /// dictionary.
 /// </summary>
 /// <param name="occurance"></param>
 private void AddToSyntaticCategory(SyntaticOccurance occurance)
 {
     if (!SyntaticCategories.ContainsKey(occurance.Category))
     {
         SyntaticCategories.Add(occurance.Category,new List<SyntaticOccurance>());
     }
     SyntaticCategories[occurance.Category].Add(occurance);
 }
 /// <summary>
 /// Creates the syntatic occurance and adds it into the syntatic categories
 /// dictionary.
 /// </summary>
 /// <param name="searchInstance">An element represents a syntatic occurance of a pattern.</param>
 public void AddOccurance(XElement searchInstance)
 {
     SyntaticOccurance occurance = new SyntaticOccurance(this, searchInstance);
     AddOccurance(occurance);
 }
 /// <summary>
 /// Adds an instance of an occurance into the syntatic category list.
 /// </summary>
 /// <param name="occurance">An instance of a syntatic occurance.</param>
 public void AddOccurance(SyntaticOccurance occurance)
 {
     mSyntaticOccurances.Add(occurance);
     AddToSyntaticCategory(occurance);
 }
Example #6
0
        public DataCell(SrcMLFile doc, XElement xe, ITransform transform, SyntaticOccurance occurrence)
        {
            this.doc = doc;
            this.node = xe;
            this.transform = transform;
            this.occurrence = occurrence;

            this.Xml.AddAnnotation(new DataEnabledAnnotation());

            this.location = doc.RelativePath(node);
            this.lineNumber = xe.GetSrcLineNumber();
            if (xe.Descendants().Any())
            {
                this.endLineNumber = xe.Descendants().Last().GetSrcLineNumber();
            }
            else
            {
                this.endLineNumber = this.lineNumber;
            }

            if (null != this.Xml && null != this.Transform)
            {
                try
                {
                    this.text = Xml.ToSource(4);
                    var nodeCopy = new XElement(this.node);
                    var transformedNode = this.transform.Transform(nodeCopy);
                    this.Xml.AddAnnotation(new DataTransformAnnotation(transformedNode));
                    transformedText = transformedNode.ToSource(4);
                }
                catch (Exception e)
                {
                    error = String.Format("{0}: {1} ({2})", e.Source, e.Message, e.GetType().ToString());
                    this.Enabled = false;
                }
            }
        }
        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;
        }
Example #8
0
        /// <summary>
        /// Creates the syntatic occurance and adds it into the syntatic categories
        /// dictionary.
        /// </summary>
        /// <param name="searchInstance">An element represents a syntatic occurance of a pattern.</param>
        public void AddOccurance(XElement searchInstance)
        {
            SyntaticOccurance occurance = new SyntaticOccurance(this, searchInstance);

            AddOccurance(occurance);
        }
Example #9
0
 /// <summary>
 /// Adds an instance of an occurance into the syntatic category list.
 /// </summary>
 /// <param name="occurance">An instance of a syntatic occurance.</param>
 public void AddOccurance(SyntaticOccurance occurance)
 {
     mSyntaticOccurances.Add(occurance);
     AddToSyntaticCategory(occurance);
 }