The SrcML Generator class provides a convenient wrapper for multiple src2srcml runners, each targetted at a different language.
Inheritance: ABB.SrcML.AbstractGenerator
Esempio n. 1
0
 /// <summary>
 /// Creates a new project object
 /// </summary>
 /// <param name="scheduler">The task scheduler</param>
 /// <param name="monitor">The file monitor</param>
 ///<param name="generator">The SrcML generator to use</param>
 public SrcMLProject(TaskScheduler scheduler, AbstractFileMonitor monitor, SrcMLGenerator generator) {
     Scheduler = scheduler;
     Monitor = monitor;
     SetupMonitor(generator);
     SourceArchive.Generator.IsLoggingErrors = true;
     SourceArchive.Generator.ErrorLog = new StreamWriter(Path.Combine(StoragePath, "error.log"), false);
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new project object
 /// </summary>
 /// <param name="scheduler">The task scheduler</param>
 /// <param name="monitor">The file monitor</param>
 ///<param name="generator">The SrcML generator to use</param>
 public SrcMLProject(TaskScheduler scheduler, AbstractFileMonitor monitor, SrcMLGenerator generator)
 {
     Scheduler = scheduler;
     Monitor   = monitor;
     SetupMonitor(generator);
     SourceArchive.Generator.IsLoggingErrors = true;
     SourceArchive.Generator.ErrorLog        = new StreamWriter(Path.Combine(StoragePath, "error.log"), false);
 }
Esempio n. 3
0
        public void SetUp()
        {
            builder = new UnigramSwumBuilder { Splitter = new CamelIdSplitter() };
            var Generator = new SrcMLGenerator(@"..\..\External\SrcML");
            var file = Generator.GenerateSrcMLFileFromDirectory(@"..\..\", Path.GetTempFileName(), new List<string>(), Language.Any);

            functions = from func in file.GetXDocument().Descendants()
                            where _functionTypes.Contains(func.Name) && !func.Ancestors(SRC.Declaration).Any()
                            select func;
        }
Esempio n. 4
0
        /// <summary>
        /// Wires all of the properties together
        /// </summary>
        protected void SetupMonitor(SrcMLGenerator generator)
        {
            // setup the file monitor
            NonSourceArchive = new LastModifiedArchive(StoragePath, LastModifiedArchive.DEFAULT_FILENAME, Scheduler);
            var archiveDirectory = Path.Combine(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY);

            SourceArchive = new SrcMLArchive(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY, true, generator, new SrcMLFileNameMapping(archiveDirectory), Scheduler);
            Monitor.RegisterArchive(NonSourceArchive, true);
            Monitor.RegisterArchive(SourceArchive, false);
        }
        public Src2SrcMLPreviewWindow()
        {
            ToggleShowPositionCommand.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Alt));
            SelectSrcMLDirectoryCommand.InputGestures.Add(new KeyGesture(Key.D, ModifierKeys.Alt));

            binDirIsValid = true;
            directorySelector = new System.Windows.Forms.FolderBrowserDialog();
            directorySelector.ShowNewFolderButton = false;
            directorySelector.SelectedPath = SrcMLHelper.GetSrcMLDefaultDirectory();
            
            _language = ABB.SrcML.Language.CPlusPlus;
            InitializeComponent();
            XmlGenerator = new SrcMLGenerator(directorySelector.SelectedPath, _namespaceArguments);
        }
Esempio n. 6
0
 public void TestCSharpExpressionWithDefaultKeyword() {
     var generator = new SrcMLGenerator(TestConstants.SrcmlPath);
     generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithDefaultKeyword.cs", "external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml");
     var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml");
     var classB = fileUnit.Element(SRC.Class);
     Assert.IsNotNull(classB);
     Assert.AreEqual(2, classB.Descendants(SRC.Function).Count());
 }
Esempio n. 7
0
 public void TestCppStaticTypeModifier() {
     var generator = new SrcMLGenerator(TestConstants.SrcmlPath);
     generator.GenerateSrcMLFromFile("external\\TestCppTypeModifiers.cpp", "external_xml\\TestCppStaticModifier.cpp.xml");
     var fileUnit = SrcMLElement.Load("external_xml\\TestCppStaticModifier.cpp.xml");
     var typeWithStatic = fileUnit.Descendants(SRC.Type).LastOrDefault();
     Assert.IsNotNull(typeWithStatic);
     var staticModifier = typeWithStatic.Elements(SRC.Specifier).FirstOrDefault();
     Assert.IsNotNull(staticModifier);
     Assert.AreEqual("static", staticModifier.Value);
 }
Esempio n. 8
0
        public void TestCSharpExpressionWithRemove() {
            var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation));
            generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithRemove.cs", "external_xml\\TestCSharpExpressionWithRemove.cs.xml");
            var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithRemove.cs.xml");

            var method = fileUnit.Descendants(SRC.Function).FirstOrDefault();
            Assert.IsNotNull(method);
            var methodBlock = method.Element(SRC.Block);
            Assert.IsNotNull(methodBlock);
            Assert.AreEqual(1, methodBlock.Elements(SRC.ExpressionStatement).Count());
        }
Esempio n. 9
0
        public void TestCSharpUsingStatement() {
            var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation));
            generator.GenerateSrcMLFromFile("external\\TestCSharpUsingStatement.cs", "external_xml\\TestCSharpUsingStatement.cs.xml");
            var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpUsingStatement.cs.xml");

            var usingBlock = fileUnit.Elements(SRC.Using_Stmt).FirstOrDefault();
            Assert.IsNotNull(usingBlock);

            Assert.AreEqual(1, usingBlock.Elements(SRC.Init).Count());
            Assert.AreEqual(1, usingBlock.Elements(SRC.Block).Count());
        }
Esempio n. 10
0
 public void TestSetup() {
     generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation));
 }
Esempio n. 11
0
 public void TestSetup() {
     generator = new SrcMLGenerator(TestConstants.SrcmlPath);
 }
 private void MenuItemShowPosition_Unchecked(object sender, RoutedEventArgs e) {
     _xmlGenerator = new SrcMLGenerator(directorySelector.SelectedPath, _namespaceArguments);
     if(sourceBox.Text.Length > 0) sourceBox_TextChanged(sender, null);
 }
Esempio n. 13
0
 /// <summary>
 /// Creates a new SrcMLArchive.
 /// </summary>
 /// <param name="baseDirectory">The parent of <paramref name="srcMLDirectory"/>. <see cref="AbstractArchive.ArchivePath"/> will be set to <c>Path.Combine(baseDirectory, srcMLDirectory)</c></param>
 /// <param name="srcMLDirectory">The directory to store the SrcML files in. This will be created as a subdirectory of <paramref name="baseDirectory"/></param>
 /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
 /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
 public SrcMLArchive(string baseDirectory, string srcMLDirectory, bool useExistingSrcML, SrcMLGenerator generator)
     : this(baseDirectory, srcMLDirectory, useExistingSrcML, generator,
            new ShortXmlFileNameMapping(Path.Combine(baseDirectory, srcMLDirectory)), TaskScheduler.Default)
 {
 }
Esempio n. 14
0
        /// <summary>
        /// Creates a new SrcMLArchive.
        /// </summary>
        /// <param name="baseDirectory">The parent of <paramref name="srcMLDirectory"/>. <see cref="AbstractArchive.ArchivePath"/> will be set to <c>Path.Combine(baseDirectory, srcMLDirectory)</c></param>
        /// <param name="srcMLDirectory">The directory to store the SrcML files in. This will be created as a subdirectory of <paramref name="baseDirectory"/></param>
        /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
        /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
        public SrcMLArchive(string baseDirectory, string srcMLDirectory, bool useExistingSrcML, SrcMLGenerator generator)
            : this(baseDirectory, srcMLDirectory, useExistingSrcML, generator,
                   new ShortXmlFileNameMapping(Path.Combine(baseDirectory, srcMLDirectory)), TaskScheduler.Default) {

        }
 private void MenuItemSrcMLSelect_Click(object sender, RoutedEventArgs e)
 {
     var currentDirectory = this.directorySelector.SelectedPath;
     directorySelector.Description = String.Format("Select a directory that contains src2srcml.exe\nThe current directory is {0}", currentDirectory);
     if (directorySelector.ShowDialog() == Forms.DialogResult.OK)
     {
         this._xmlGenerator = new SrcMLGenerator(directorySelector.SelectedPath, _namespaceArguments);
         binDirIsValid = true;
         srcmlBox.Foreground = Brushes.Black;
         UpdateSupportedLanguages();
         if (sourceBox.Text.Length > 0)
             sourceBox_TextChanged(sender, null);
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a new SrcMLArchive. The archive is created in <c>"baseDirectory\srcML"</c>.
 /// </summary>
 /// <param name="baseDirectory">the base directory</param>
 /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
 /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
 /// <param name="xmlMapping">The XmlFileNameMapping to use to map source paths to xml file paths.</param>
 public SrcMLArchive(string baseDirectory, bool useExistingSrcML, SrcMLGenerator generator, XmlFileNameMapping xmlMapping)
     : this(baseDirectory, "srcML", useExistingSrcML, generator, xmlMapping, TaskScheduler.Default) {
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new SrcMLArchive. The archive is created in <c>"baseDirectory\srcML"</c>.
 /// </summary>
 /// <param name="baseDirectory">the base directory</param>
 /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
 /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
 public SrcMLArchive(string baseDirectory, bool useExistingSrcML, SrcMLGenerator generator)
     : this(baseDirectory, "srcML", useExistingSrcML, generator) {
 }
Esempio n. 18
0
        /// <summary>
        /// Creates a new SrcMLArchive.
        /// </summary>
        /// <param name="baseDirectory">The parent of <paramref name="srcMLDirectory"/>. <see cref="AbstractArchive.ArchivePath"/> will be set to <c>Path.Combine(baseDirectory, srcMLDirectory)</c></param>
        /// <param name="srcMLDirectory">The directory to store the SrcML files in. This will be created as a subdirectory of <paramref name="baseDirectory"/></param>
        /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
        /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
        /// <param name="xmlMapping">The XmlFileNameMapping to use to map source paths to xml file paths.</param>
        /// <param name="scheduler">The task scheduler to for asynchronous tasks</param>
        public SrcMLArchive(string baseDirectory, string srcMLDirectory, bool useExistingSrcML, SrcMLGenerator generator, XmlFileNameMapping xmlMapping, TaskScheduler scheduler) 
            : base(baseDirectory, srcMLDirectory, scheduler) {
            this.XmlGenerator = generator;
            this.xmlFileNameMapping = xmlMapping;

            if(!Directory.Exists(this.ArchivePath)) {
                Directory.CreateDirectory(this.ArchivePath);
            } else {
                if(!useExistingSrcML) {
                    foreach(var file in Directory.GetFiles(ArchivePath, "*.xml")) {
                        File.Delete(file);
                    }
                }
            }
        }
Esempio n. 19
0
        public void TestCSharpExpressionWithRemove() {
            var generator = new SrcMLGenerator(TestConstants.SrcmlPath);
            generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithRemove.cs", "external_xml\\TestCSharpExpressionWithRemove.cs.xml");
            var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithRemove.cs.xml");

            var method = fileUnit.Descendants(SRC.Function).FirstOrDefault();
            Assert.IsNotNull(method);
            var methodBlock = method.Element(SRC.Block);
            Assert.IsNotNull(methodBlock);
            Assert.AreEqual(1, methodBlock.Elements(SRC.ExpressionStatement).Count());
        }
 public void CreateArchive(string filesInThisDirectory)
 {
     var srcMlArchiveFolder = Path.Combine(_indexPath, "archive");
     var srcMLFolder = Path.Combine(".", "SrcML", "CSharp");
     Directory.CreateDirectory(srcMlArchiveFolder);
     var generator = new SrcMLGenerator(TestUtils.SrcMLDirectory);
     _srcMLArchive = new SrcMLArchive(_indexPath,  false, generator);
 }
Esempio n. 21
0
        public void TestCSharpUsingStatement() {
            var generator = new SrcMLGenerator(TestConstants.SrcmlPath);
            generator.GenerateSrcMLFromFile("external\\TestCSharpUsingStatement.cs", "external_xml\\TestCSharpUsingStatement.cs.xml");
            var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpUsingStatement.cs.xml");

            var usingBlock = fileUnit.Elements(SRC.Using).FirstOrDefault();
            Assert.IsNotNull(usingBlock);

            Assert.AreEqual(1, usingBlock.Elements(SRC.Declaration).Count());
            Assert.AreEqual(1, usingBlock.Elements(SRC.Block).Count());
        }
Esempio n. 22
0
 /// <summary>
 /// Creates a new SrcMLArchive. The archive is created in <c>"baseDirectory\srcML"</c>.
 /// </summary>
 /// <param name="baseDirectory">the base directory</param>
 /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
 /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
 public SrcMLArchive(string baseDirectory, bool useExistingSrcML, SrcMLGenerator generator)
     : this(baseDirectory, DEFAULT_ARCHIVE_DIRECTORY, useExistingSrcML, generator)
 {
 }
Esempio n. 23
0
 /// <summary>
 /// Wires all of the properties together
 /// </summary>
 protected void SetupMonitor(SrcMLGenerator generator) {
     // setup the file monitor
     NonSourceArchive = new LastModifiedArchive(StoragePath, LastModifiedArchive.DEFAULT_FILENAME, Scheduler);
     var archiveDirectory = Path.Combine(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY);
     SourceArchive = new SrcMLArchive(StoragePath, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY, true, generator, new SrcMLFileNameMapping(archiveDirectory), Scheduler);
     Monitor.RegisterArchive(NonSourceArchive, true);
     Monitor.RegisterArchive(SourceArchive, false);
 }
Esempio n. 24
0
        /// <summary>
        /// Creates a new SrcMLArchive.
        /// </summary>
        /// <param name="baseDirectory">The parent of <paramref name="srcMLDirectory"/>. <see cref="AbstractArchive.ArchivePath"/> will be set to <c>Path.Combine(baseDirectory, srcMLDirectory)</c></param>
        /// <param name="srcMLDirectory">The directory to store the SrcML files in. This will be created as a subdirectory of <paramref name="baseDirectory"/></param>
        /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
        /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
        /// <param name="xmlMapping">The XmlFileNameMapping to use to map source paths to xml file paths.</param>
        /// <param name="scheduler">The task scheduler to for asynchronous tasks</param>
        public SrcMLArchive(string baseDirectory, string srcMLDirectory, bool useExistingSrcML, SrcMLGenerator generator, XmlFileNameMapping xmlMapping, TaskScheduler scheduler)
            : base(baseDirectory, srcMLDirectory, scheduler)
        {
            this.XmlGenerator       = generator;
            this.xmlFileNameMapping = xmlMapping;

            if (!Directory.Exists(this.ArchivePath))
            {
                Directory.CreateDirectory(this.ArchivePath);
            }
            else
            {
                if (!useExistingSrcML)
                {
                    foreach (var file in Directory.GetFiles(ArchivePath, "*.xml"))
                    {
                        File.Delete(file);
                    }
                }
            }
        }
Esempio n. 25
0
 public SrcMLCppParser(SrcMLGenerator generator)
 {
     this.Generator = generator;
 }
Esempio n. 26
0
 /// <summary>
 /// Creates a new SrcMLArchive. The archive is created in <c>"baseDirectory\srcML"</c>.
 /// </summary>
 /// <param name="baseDirectory">the base directory</param>
 /// <param name="useExistingSrcML">If True, any existing SrcML files in <see cref="AbstractArchive.ArchivePath"/> will be used. If False, these files will be deleted and potentially recreated.</param>
 /// <param name="generator">The SrcMLGenerator to use to convert source files to SrcML.</param>
 /// <param name="xmlMapping">The XmlFileNameMapping to use to map source paths to xml file paths.</param>
 public SrcMLArchive(string baseDirectory, bool useExistingSrcML, SrcMLGenerator generator, XmlFileNameMapping xmlMapping)
     : this(baseDirectory, DEFAULT_ARCHIVE_DIRECTORY, useExistingSrcML, generator, xmlMapping, TaskScheduler.Default)
 {
 }
Esempio n. 27
0
 public void TestCSharpExpressionWithDefaultKeyword() {
     var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation));
     generator.GenerateSrcMLFromFile("external\\TestCSharpExpressionWithDefaultKeyword.cs", "external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml");
     var fileUnit = SrcMLElement.Load("external_xml\\TestCSharpExpressionWithDefaultKeyword.cs.xml");
     var classB = fileUnit.Element(SRC.Class);
     Assert.IsNotNull(classB);
     Assert.AreEqual(2, classB.Descendants(SRC.Function).Count());
 }
Esempio n. 28
0
 public void TestCppStaticTypeModifier() {
     var generator = new SrcMLGenerator(Path.Combine(SrcMLHelper.GetSrcMLRootDirectory(), SrcMLHelper.srcMLExecutableLocation));
     generator.GenerateSrcMLFromFile("external\\TestCppTypeModifiers.cpp", "external_xml\\TestCppStaticModifier.cpp.xml");
     var fileUnit = SrcMLElement.Load("external_xml\\TestCppStaticModifier.cpp.xml");
     var typeWithStatic = fileUnit.Descendants(SRC.Declaration).LastOrDefault();
     Assert.IsNotNull(typeWithStatic);
     var staticModifier = typeWithStatic.Elements(SRC.Specifier).FirstOrDefault();
     Assert.IsNotNull(staticModifier);
     Assert.AreEqual("static", staticModifier.Value);
 }
Esempio n. 29
0
 public void FixtureSetUp()
 {
     TestUtils.InitializeDefaultExtensionPoints();
     generator = new SrcMLGenerator(TestUtils.SrcMLDirectory);
 }
Esempio n. 30
0
 public MySrcMLCSharpParser(ABB.SrcML.SrcMLGenerator generator)
 {
     this.Generator = generator;
 }