示例#1
0
        public static CompilationUnitSyntax Reorganize(this CompilationUnitSyntax root)
        {
            var organizer = new SyntaxReorganizerRewriter();

            return(root.Accept(organizer) is CompilationUnitSyntax reorganizedRoot
                ? reorganizedRoot
                : throw new System.Exception("Reorganized root is null or not of type CompilationUnitSyntax."));
        }
示例#2
0
        private IEnumerable <LuaCompilationUnitSyntax> Create()
        {
            List <LuaCompilationUnitSyntax> luaCompilationUnits = new List <LuaCompilationUnitSyntax>();

            foreach (SyntaxTree syntaxTree in compilation_.SyntaxTrees)
            {
                SemanticModel         semanticModel         = GetSemanticModel(syntaxTree);
                CompilationUnitSyntax compilationUnitSyntax = (CompilationUnitSyntax)syntaxTree.GetRoot();
                LuaSyntaxNodeTransfor transfor = new LuaSyntaxNodeTransfor(this, semanticModel);
                var luaCompilationUnit         = (LuaCompilationUnitSyntax)compilationUnitSyntax.Accept(transfor);
                luaCompilationUnits.Add(luaCompilationUnit);
            }
            CheckExportEnums();
            CheckPartialTypes();
            CheckRefactorNames();
            return(luaCompilationUnits.Where(i => !i.IsEmpty));
        }
示例#3
0
        static void Transform(string filePath, CSharpSyntaxRewriter[] rewriters)
        {
            Console.Write($"  {filePath}");

            SourceText            text    = SourceText.From(File.ReadAllText(filePath));
            SyntaxTree            tree    = CSharpSyntaxTree.ParseText(text);
            CompilationUnitSyntax root    = tree.GetCompilationUnitRoot();
            CompilationUnitSyntax current = root;

            foreach (CSharpSyntaxRewriter rewriter in rewriters)
            {
                current = (CompilationUnitSyntax)current.Accept(rewriter);
            }

            if (!current.Equals(root))
            {
                Console.WriteLine("*");
                File.WriteAllText(filePath, current.ToFullString());
            }
            else
            {
                Console.WriteLine();
            }
        }