Ejemplo n.º 1
0
        private void MenuItemLanguage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var menuItem = (sender as MenuItem);

                if (null != menuItem && menuItem.IsChecked)
                {
                    menuItem.IsCheckable = false;
                    var otherMenuItems = from MenuItem item in MenuItemLanguage.Items.SourceCollection
                                         where item != menuItem
                                         select item;
                    foreach (var item in otherMenuItems)
                    {
                        item.IsChecked   = false;
                        item.IsCheckable = true;
                    }

                    this._language = SrcMLElement.GetLanguageFromString(menuItem.Header.ToString());
                    sourceBox_TextChanged(sender, null);
                }
            }
            catch (SrcMLException error)
            {
                PrintErrorInSrcmlBox(error.Message);
            }
        }
Ejemplo n.º 2
0
 private static IEnumerable <ExtensionLanguagePair> ParseLanguageMap(string languageMapping)
 {
     foreach (var segment in languageMapping.Split(';'))
     {
         var      parts     = segment.Split('=');
         var      extension = parts[0];
         Language language  = SrcMLElement.GetLanguageFromString(parts[1]);
         yield return(new ExtensionLanguagePair(extension, language));
     }
 }
Ejemplo n.º 3
0
        private void UpdateSupportedLanguages()
        {
            HashSet <Language> supportedLanguages = new HashSet <Language>(this.XmlGenerator.SupportedLanguages);

            foreach (var item in this.MenuItemLanguage.Items)
            {
                var menuItem = item as MenuItem;
                var language = SrcMLElement.GetLanguageFromString(menuItem.Header.ToString());
                menuItem.IsEnabled = supportedLanguages.Contains(language);
            }
        }
Ejemplo n.º 4
0
        public static void Src2SrcML([Required(Description = "Source file or directory of source code to convert")] string source,
                                     [Optional(null, Description = @"The file to write SrcML to. By default, this is <Current Directory>\<Directory>-<Date>.xml
        For instance, if you run .\srcml.exe src2srcml c:\source\python, the resulting output file will be located at .\python-YYYMMDDHHMM.xml")] string outputFileName,
                                     [Optional("Any", Description = @"Language to use. Only files for this language will be included. The options are
        * Any (the default: indicates that all recognized languages should be included)
        * C
        * C++
        * Java
        * AspectJ")] string language,
                                     [Optional("", Description = @"Mapping of file extensions to languages.
        This is formatted like this: ""/languageMapping:ext1=LANG;ext2=LANG;ext3=LANG""
        For example, to map foo.h and foo.cxx to C++, we would use ""/languageMapping:h=C++;cxx=C++""
        All of the languages that are valid for the /language option are valid except for ""Any"".
")] string languageMapping,
                                     [Optional(null, Description = @"Folder with SrcML binaries. If this is not given, the following directories are checked: 
        1. %SRCMLBINDIR%
        2. c:\Program Files (x86)\SrcML\bin
        3. c:\Program Files\SrcML\bin (only checked if c:\Program Files (x86) does not exist)
        4. The current directory")] string binaryFolder)
        {
            if (null == outputFileName)
            {
                var name = source.Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();
                outputFileName = String.Format("{0}-{1}.xml", name, DateTime.Now.ToString("yyyyMMddHHmmss"));
            }

            SrcMLGenerator generator = null;

            if (null != binaryFolder)
            {
                try
                {
                    generator = GetGeneratorWithDirectory(binaryFolder);
                }
                catch (IOException e)
                {
                    Console.Error.WriteLine("Invalid binary directory: {0}", e.Message);
                    Environment.Exit(-1);
                }
            }
            else
            {
                //try
                //{
                // check all of the usual suspects
                generator = new SrcMLGenerator();
                //}
                //catch(IOException)
                //{
                //    generator = null;
                //}
            }

            Language lang = SrcMLElement.GetLanguageFromString(language);

            if (lang > Language.Any)
            {
                Console.WriteLine("Using {0} language", language);
            }

            if (String.Empty != languageMapping)
            {
                foreach (var pair in ParseLanguageMap(languageMapping))
                {
                    Console.WriteLine("Mapping {0} files to {1} language", pair.Extension, KsuAdapter.GetLanguage(pair.Language));
                    string ext = pair.Extension.StartsWith(".") ? pair.Extension : "." + pair.Extension;
                    generator.ExtensionMapping.Add(ext, pair.Language);
                }
            }
            SrcMLFile doc;

            if (Directory.Exists(source))
            {
                doc = generator.GenerateSrcMLFileFromDirectory(source, outputFileName, lang);
                Console.WriteLine("Created {0}, a srcML archive, from {1} files located at {2}", doc.FileName, doc.FileUnits.Count(), source);
            }
            else if (File.Exists(source))
            {
                generator.GenerateSrcMLFromFile(source, outputFileName, lang);
                Console.WriteLine("Converted {0} to a srcML document at {1}", source, outputFileName);
            }
            else
            {
                Console.Error.WriteLine("the input folder or directory ({0}) does not exist!", source);
                Environment.Exit(-2);
            }
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            string  archivePath = "srcml";
            string  outputPath  = null;
            Command command     = null;

            bool shouldShowHelp = false;
            Dictionary <string, Language> extensionMapping = new Dictionary <string, Language>();

            OptionSet options = new OptionSet()
            {
                { "a|archive=", "the location of the srcML {ARCHIVE}", a => archivePath = a },
                { "c|command=", "the {COMMAND} to use (print-methods|print-calls)", c => command = GetCommand(c) },
                { "o|output=", "the location of the {OUTPUT} file", o => outputPath = o },
                { "e|extension=", "an extension mapping of the form \"EXT=Language\" (for example -e cs=C#)", e => {
                      var parts = e.Split(':');
                      if (parts.Length == 2)
                      {
                          extensionMapping[parts[0]] = SrcMLElement.GetLanguageFromString(parts[1]);
                      }
                  } },
                { "h|?|help", o => shouldShowHelp = true }
            };

            var    sourceFolderPaths = options.Parse(args);
            string errorMessage      = String.Empty;

            if (sourceFolderPaths.Count == 0)
            {
                errorMessage   = "Provide a source folder";
                shouldShowHelp = true;
            }

            if (command == null)
            {
                errorMessage   = "Provide a command";
                shouldShowHelp = true;
            }

            if (shouldShowHelp)
            {
                if (!String.IsNullOrEmpty(errorMessage))
                {
                    Console.Error.WriteLine(errorMessage);
                }
                ShowHelp(options);
            }
            else
            {
                var archive = new SrcMLArchive(Path.GetDirectoryName(archivePath), Path.GetFileName(archivePath));
                foreach (var key in extensionMapping.Keys)
                {
                    var finalKey = (key[0] != '.' ? "." + key : key);
                    Console.WriteLine("Mapping {0} files to {1}", finalKey, extensionMapping[key]);
                    archive.XmlGenerator.ExtensionMapping[finalKey] = extensionMapping[key];
                }

                var sourceFolder = new SourceFolder(sourceFolderPaths.First(), archive);

                sourceFolder.UpdateArchive();
                using (TextWriter output = (outputPath == null ? Console.Out : new StreamWriter(outputPath))) {
                    command(sourceFolder, output);
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Read the XML attributes from the current <paramref name="reader"/> position
 /// </summary>
 /// <param name="reader">The XML reader</param>
 protected virtual void ReadXmlAttributes(XmlReader reader)
 {
     ProgrammingLanguage = SrcMLElement.GetLanguageFromString(reader.GetAttribute(LanguageXmlName));
 }
Ejemplo n.º 7
0
 private static IEnumerable <RealWorldTestProject> ReadProjectMap(string fileName)
 {
     if (File.Exists(fileName))
     {
         var projects = from line in File.ReadAllLines(fileName)
                        where !line.StartsWith("#")
                        let parts = line.Split(',')
                                    where 4 == parts.Length
                                    let projectName = parts[0]
                                                      let projectVersion = parts[1]
                                                                           let projectLanguage
                                                                               = SrcMLElement.GetLanguageFromString(parts[2])
                                                                                 let rootDirectory = parts[3]
                                                                                                     select new RealWorldTestProject(projectName, projectVersion, projectLanguage, rootDirectory);
         return(projects);
     }
     return(Enumerable.Empty <RealWorldTestProject>());
 }