/// <summary>
 /// Gets the filename stored in the unit element of <paramref name="targetPath"/>
 /// </summary>
 /// <param name="targetPath">The target srcML file</param>
 /// <returns>The file name stored in <paramref name="targetPath"/></returns>
 protected override string GetSourcePathFromTargetFile(string targetPath)
 {
     try {
         var unit = XmlHelper.StreamElements(targetPath, SRC.Unit, 0).FirstOrDefault();
         return(null != unit ? SrcMLElement.GetFileNameForUnit(unit) : null);
     } catch (XmlException) {
         return(null);
     }
 }
Пример #2
0
        /// <summary>
        /// Gets the local declaration corresponding to the given name.
        /// </summary>
        /// <param name="name">A <see cref="SRC"/> element.</param>
        /// <returns>The corresponding declaration, null if not found.</returns>
        public static XElement GetLocalDecl(this XElement name)
        {
            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            SrcMLElement.ThrowExceptionOnInvalidName(name, SRC.Name);

            var decls = from d in name.Ancestors(SRC.Function).First().Descendants(SRC.Declaration)
                        where d.Elements(SRC.Name).Any()
                        where d.IsBefore(name) && d.Element(SRC.Name).Value == name.Value
                        select d;

            return(decls.Last());
        }
Пример #3
0
        /// <summary>
        /// Gets the XElement for the specified source file. If the SrcML does not already exist in the archive, it will be created.
        /// </summary>
        /// <param name="sourceFilePath">The source file to get the root XElement for.</param>
        /// <returns>The root XElement of the source file.</returns>
        public virtual XElement GetXElementForSourceFile(string sourceFilePath)
        {
            if (!File.Exists(sourceFilePath))
            {
                return(null);
            }
            else
            {
                string xmlPath = GetArchivePath(sourceFilePath);

                if (!File.Exists(xmlPath))
                {
                    return(null);
                }
                return(SrcMLElement.Load(xmlPath));
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the XElement for the specified source file. If the SrcML does not already exist in the archive, it will be created.
        /// </summary>
        /// <param name="sourceFilePath">The source file to get the root XElement for.</param>
        /// <returns>The root XElement of the source file.</returns>
        public XElement GetXElementForSourceFile(string sourceFilePath)
        {
            if (!File.Exists(sourceFilePath))
            {
                return(null);
            }
            else
            {
                string xmlPath = GetXmlPath(sourceFilePath);

                if (!File.Exists(xmlPath))
                {
                    GenerateXmlForSource(sourceFilePath);
                }
                return(SrcMLElement.Load(xmlPath));
            }
        }
Пример #5
0
 /// <summary>
 /// Reads the mapping file in XmlDirectory. If this doesn't exist, it constructs a mapping
 /// from any existing SrcML files in the directory.
 /// </summary>
 protected void ReadMapping()
 {
     lock (mappingLock) {
         mapping.Clear();
         var mappingPath = Path.Combine(XmlDirectory, mappingFile);
         if (File.Exists(mappingPath))
         {
             //read mapping file
             foreach (var line in File.ReadLines(mappingPath))
             {
                 var paths = line.Split('|');
                 if (paths.Length != 2)
                 {
                     Debug.WriteLine(string.Format("Bad line found in mapping file. Expected 2 fields, has {0}: {1}", paths.Length, line));
                     continue;
                 }
                 ProcessMapFileEntry(paths[0].Trim(), paths[1].Trim());
             }
             //TODO: remove file from disk
         }
         else
         {
             //mapping file doesn't exist, so construct mapping from the xml files in the directory
             Debug.WriteLine(string.Format("Mapping file not found: {0}", mappingPath));
             if (Directory.Exists(XmlDirectory))
             {
                 foreach (var xmlFile in Directory.GetFiles(XmlDirectory, "*.xml"))
                 {
                     var unit = XmlHelper.StreamElements(xmlFile, SRC.Unit, 0).FirstOrDefault();
                     if (unit != null)
                     {
                         //should be a SrcML file
                         var sourcePath = SrcMLElement.GetFileNameForUnit(unit);
                         if (!string.IsNullOrWhiteSpace(sourcePath))
                         {
                             ProcessMapFileEntry(sourcePath, Path.GetFullPath(xmlFile));
                         }
                     }
                 }
             }
         }
     }
 }
Пример #6
0
        public string GetPathForUnit(XElement unit)
        {
            if (null == unit)
            {
                throw new ArgumentNullException("unit");
            }
            try {
                SrcMLElement.ThrowExceptionOnInvalidName(unit, SRC.Unit);
            } catch (SrcMLRequiredNameException e) {
                throw new ArgumentException(e.Message, "unit", e);
            }

            var fileName = unit.Attribute("filename");

            if (null != fileName)
            {
                return(fileName.Value);
            }

            return(null);
            //return fileName.Value;
        }