Пример #1
0
        public static List <FileFormatDto> Clean(string apexFolderName)
        {
            var dtoList = new List <FileFormatDto>();
            var files   = Directory.GetFiles(apexFolderName, "*.cls", SearchOption.TopDirectoryOnly).ToArray();

            foreach (var sourceFile in files)
            {
                var apexFileInfo = new FileInfo(sourceFile);

                Console.WriteLine($"Normalizing file: {sourceFile}...");
                var backupFile = sourceFile + ".bak";

                File.Delete(backupFile);
                File.Move(sourceFile, backupFile);

                var apexCode   = File.ReadAllText(backupFile);
                var normalized = ApexCleanCodeGen.NormalizeCode(apexCode);
                File.WriteAllText(sourceFile, normalized);
                File.Delete(backupFile);

                dtoList.Add(new FileFormatDto
                {
                    ApexFileName         = apexFileInfo.Name,
                    ApexFileBeforeFormat = apexCode,
                    ApexFileAfterFormat  = normalized
                });
            }

            Console.WriteLine($"Done. Normalized {dtoList.Count} files.");
            return(dtoList);
        }
Пример #2
0
        public static string GenerateApex(BaseSyntax ast, int tabSize = 4)
        {
            var generator = new ApexCleanCodeGen {
                IndentSize = tabSize
            };

            ast.Accept(generator);
            return(generator.Code.ToString());
        }
Пример #3
0
        public void TestCodeGeneration()
        {
            var apex = @"
                class Something
                {
                    @IsTest
                    public static void testPluckDecimals()
                    {
                        List<Account> accounts = testData();
                        LIST<decimal> revenues = Pluck.decimals(accounts, Account.AnnualRevenue);
                        System.deBUG(4, revenues.size());
                        System.assertNOTequals(100.0, revenues[0]); // SYSTEM
                        system.assertEquals(60.0, revenues[1]); // 'deBUG'
                        SYSTEM.assertEquals(150.0, revenues[2]);
                        System.Debug(150.0, revenues[3]);
                    }
                }";

            var parsed    = ApexSharpParser.GetApexAst(apex);
            var generated = ApexCleanCodeGen.GenerateApex(parsed);

            Assert.NotNull(generated);
            Assert.AreEqual(@"class Something
{
    @IsTest
    public static void testPluckDecimals()
    {
        List<Account> accounts = testData();
        List<Decimal> revenues = Pluck.decimals(accounts, Account.AnnualRevenue);
        System.debug(4, revenues.size());
        System.assertNotEquals(100.0, revenues[0]); // SYSTEM
        System.assertEquals(60.0, revenues[1]); // 'deBUG'
        System.assertEquals(150.0, revenues[2]);
        System.debug(150.0, revenues[3]);
    }
}
", generated);
        }