Ejemplo n.º 1
0
        public static List <ParsedMember> ParseSource(string code)
        {
            var options          = new Microsoft.CodeAnalysis.CSharp.CSharpParseOptions().WithPreprocessorSymbols("RHINO_SDK").WithDocumentationMode(Microsoft.CodeAnalysis.DocumentationMode.Parse);
            var tree             = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(code, options);
            SourceFileWalker sfw = new SourceFileWalker();

            sfw.Visit(tree.GetRoot());
            return(sfw._parsedMembers);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //string[] directories = Directory.GetDirectories(@"..\..\..\rhinocommon_versions\6");

            const string pathOld              = @"..\..\..\rhinocommon_versions\7.4\RhinoCommon.dll";
            const string sinceVersion         = "7.5";
            string       pathNew              = $"..\\..\\..\\rhinocommon_versions\\{sinceVersion}\\RhinoCommon.dll";
            var          modifiedMembersTask  = ModifiedMembersAsync(pathOld, pathNew);
            bool         fileWritten          = false;
            int          countFoundInSource   = 0;
            string       rhinocommonDirectory = @"C:\dev\github\mcneel\rhino\src4\DotNetSDK\rhinocommon\dotnet\";

            foreach (var sourceFile in AllSourceFiles(rhinocommonDirectory))
            {
                bool modified = false;
                //Console.WriteLine($"parse: {sourceFile}");
                string text        = System.IO.File.ReadAllText(sourceFile);
                var    parsedItems = SourceFileWalker.ParseSource(text);
                // Reverse so we walk backward through the source. This will allow us
                // to use proper character offets as we insert strings
                parsedItems.Reverse();
                var modifiedMembers = modifiedMembersTask.Result;
                foreach (var parsedItem in parsedItems)
                {
                    string signature = parsedItem.Signature.ToLower();

                    ReflectedItem modifiedMember;
                    if (!modifiedMembers.TryGetValue(signature, out modifiedMember))
                    {
                        continue;
                    }
                    modifiedMember.FoundInParsedCode = true;
                    countFoundInSource++;
                    //if (modifiedMember.AddedInNewVersion && modifiedMember.ObsoletedInNewVersion)
                    //    throw new Exception("This looks sketchy");

                    if (!parsedItem.HasSinceTag() && modifiedMember.AddedInNewVersion)
                    {
                        int           insertIndex = parsedItem.TagInsertIndex();
                        StringBuilder since       = new StringBuilder();
                        while (text[insertIndex - 1] == ' ')
                        {
                            since.Append(" ");
                            insertIndex--;
                        }
                        since.AppendLine($"/// <since>{sinceVersion}</since>");
                        text     = text.Insert(insertIndex, since.ToString());
                        modified = true;
                    }
                    if (!parsedItem.HasDeprecatedTag() && modifiedMember.ObsoletedInNewVersion)
                    {
                        int           insertIndex = parsedItem.TagInsertIndex();
                        StringBuilder deprecated  = new StringBuilder();
                        while (text[insertIndex - 1] == ' ')
                        {
                            deprecated.Append(" ");
                            insertIndex--;
                        }
                        deprecated.AppendLine($"/// <deprecated>{sinceVersion}</deprecated>");
                        text     = text.Insert(insertIndex, deprecated.ToString());
                        modified = true;
                    }
                }
                if (modified)
                {
                    System.IO.File.WriteAllText(sourceFile, text);
                    fileWritten = true;
                }
            }

            foreach (var kv in modifiedMembersTask.Result)
            {
                if (kv.Value.FoundInParsedCode == false)
                {
                    Console.WriteLine($"Missed {kv.Key}");
                }
            }

            Console.WriteLine($"{modifiedMembersTask.Result.Keys.Count} modified items");
            Console.WriteLine($"{countFoundInSource} found in source");
            Console.WriteLine($"Any files written = {fileWritten}");
            Console.ReadKey();
        }