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);
            }
        }
Exemple #2
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);
        }