Exemple #1
0
        /// <summary>
        /// Parses the source-code in the csharpFileText.
        /// </summary>
        /// <param name="vbFileText"></param>
        /// <returns></returns>
        public static CodeRoot ParseVbCode(string vbFileText)
        {
            var parser       = new CSharpParser();
            var parseResults = new ParseResults();

            parser.Reset();
            parser.ParseCode(vbFileText);

            return((CodeRoot)parser.CreatedCodeRoot);
        }
Exemple #2
0
        public static ParseResults ParseCSharpFiles(IEnumerable <string> csharpFiles)
        {
            var parser       = new CSharpParser();
            var parseResults = new ParseResults();

            foreach (var file in csharpFiles)
            {
                if (File.Exists(file) == false)
                {
                    continue;
                }

                parser.Reset();
                parser.ParseCode(file, File.ReadAllText(file));
                parseResults.AddParsedFile(file, parser.CreatedCodeRoot as CodeRoot);
            }

            return(parseResults);
        }
Exemple #3
0
        /// <summary>
        /// Performs an in depth diff by breaking code files into their constituent parts (functions, properties
        /// etc, so that these elements can be diffed without regard to their ordering.
        /// </summary>
        /// <remarks>
        /// I've put some Thread.Sleep(1) calls in here to ensure that this processing doesn't bring a single core machine
        /// to its knees. This should ensure that any GUI or other background threads can still get some CPU time,
        /// as there is not much in here that could cause a context switch.
        /// </remarks>
        public bool PerformSuperDiff()
        {
            SetupPerformDiff();

            try
            {
                switch (IntelliMerge)
                {
                case IntelliMergeType.CSharp:
                    CSharpParser formatter = new CSharpParser();

                    try
                    {
                        // Reset the DiffType
                        CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy;

                        if (diffCodeRootMap.PrevGenCodeRoot == null && PrevGenFile.HasContents || ReloadFiles)
                        {
                            formatter.Reset();
                            string filename = string.IsNullOrEmpty(PrevGenFile.FilePath) ? "Prev Gen File" : PrevGenFile.FilePath;
                            formatter.ParseCode(filename, PrevGenFile.GetContents());
                            if (formatter.ErrorOccurred)
                            {
                                return(false);
                            }

                            diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.PrevGen);
                        }
                        // Force a context switch
                        Thread.Sleep(1);

                        if (diffCodeRootMap.NewGenCodeRoot == null && NewGenFile.HasContents || ReloadFiles)
                        {
                            formatter.Reset();
                            string filename = string.IsNullOrEmpty(NewGenFile.FilePath) ? "New Gen File" : NewGenFile.FilePath;
                            formatter.ParseCode(filename, NewGenFile.GetContents());
                            if (formatter.ErrorOccurred)
                            {
                                return(false);
                            }
                            diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.NewGen);
                        }

                        // Force a context switch
                        Thread.Sleep(1);

                        if (diffCodeRootMap.UserCodeRoot == null && UserFile.HasContents || ReloadFiles)
                        {
                            formatter.Reset();
                            string filename = string.IsNullOrEmpty(UserFile.FilePath) ? "User File" : UserFile.FilePath;
                            formatter.ParseCode(filename, UserFile.GetContents());
                            if (formatter.ErrorOccurred)
                            {
                                return(false);
                            }
                            diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.User);
                        }

                        // Force a context switch
                        Thread.Sleep(1);

                        // Set this back to false. If it was true, we have reloaded the files, if it was already false this
                        // does nothing.
                        ReloadFiles = false;
                    }
                    catch (Exception ex)
                    {
                        CurrentDiffResult.ParserWarningDescription = ex.Message;
                        return(false);
                    }
                    finally
                    {
                        if (formatter.ErrorOccurred)
                        {
                            CurrentDiffResult.ParserWarningDescription = formatter.GetFormattedErrors();
                        }
                    }

                    if (string.IsNullOrEmpty(temporaryManifestFile) == false && manifestFileApplied == false)
                    {
                        CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor();
                        processor.LoadCustomMappings(ManifestConstants.LoadManifestDocument(temporaryManifestFile), diffCodeRootMap, Path.GetFileName(RelativeFilePath));
                        manifestFileApplied = true;
                    }

                    CurrentDiffResult.DiffType = diffCodeRootMap.Diff();

                    if (CurrentDiffResult.DiffType != TypeOfDiff.Conflict && CurrentDiffResult.DiffType != TypeOfDiff.Warning)
                    {
                        //mergedFile = new TextFile(CodeRootMap.GetMergedCodeRoot().ToString());
                        //    Slyce.Common.Utility.WriteToFile(newFile, userFile.GetContents());
                    }



                    break;

                default:
                    // No SuperDiff available for this type of file (no parser created yet).
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new DiffException(ex);
            }

            return(true);
        }