Beispiel #1
0
        private ClassDeclarationSyntax ParseClass(string apexClass)
        {
            var result = ApexSharpParser.GetApexAst(apexClass) as ClassDeclarationSyntax;

            Assert.NotNull(result);
            return(result);
        }
        public static bool IsRelated(string apexText, string apexClassName)
        {
            if (string.IsNullOrWhiteSpace(apexText) || string.IsNullOrWhiteSpace(apexClassName))
            {
                return(false);
            }

            try
            {
                // try to parse and analyze the file
                var ast = ApexSharpParser.GetApexAst(apexText);

                // ignore the class itself
                if (ast is ClassDeclarationSyntax @class && Comparer.Equals(@class.Identifier, apexClassName))
                {
                    return(false);
                }
                else if (ast is EnumDeclarationSyntax @enum && Comparer.Equals(@enum.Identifier, apexClassName))
                {
                    return(false);
                }

                // inspect the code structure
                var visitor = new RelatedClassHelper(apexClassName);
                ast.Accept(visitor);
                return(visitor.ClassIsRelated);
            }
Beispiel #3
0
        public static string FormatApex(string apexCode, Settings settings = null)
        {
            if (string.IsNullOrWhiteSpace(apexCode))
            {
                return(string.Empty);
            }

            var apexAst = ApexSharpParser.GetApexAst(apexCode);

            return(GenerateApex(apexAst, settings));
        }
Beispiel #4
0
        public CodeFormatTest()
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Dev\codeformat\src\classes\");
            //DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\DevSharp\ApexSharpFsb\FSB\ApexClasses\");
            List <FileFormatDto> results = ApexCodeFormater.FormatApexCode(directoryInfo);

            foreach (var result in results)
            {
                Console.WriteLine(result.ApexFileName);
                var apexAst = ApexSharpParser.GetApexAst(result.ApexFileAfterFormat);
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
 // Convert Apex Code to C# with custom options
 public static string ConvertToCSharp(string apexCode, ApexSharpParserOptions options)
 {
     return(ApexSharpParser.GetApexAst(apexCode).ToCSharp(options));
 }
Beispiel #7
0
 // Convert Apex Code to C#
 public static string ConvertToCSharp(string apexCode, string @namespace = null)
 {
     return(ApexSharpParser.GetApexAst(apexCode).ToCSharp(@namespace: @namespace));
 }
Beispiel #8
0
        public void DetectTestClassExample3()
        {
            var ast = ApexSharpParser.GetApexAst("@isTest enum Example2 { A, B, C }");

            Assert.IsFalse(IsTestClass(ast));
        }
Beispiel #9
0
        public void DetectTestClassExample2()
        {
            var ast = ApexSharpParser.GetApexAst("@isTest class Example2 {}");

            Assert.IsTrue(IsTestClass(ast));
        }
Beispiel #10
0
        public void DetectTestClassExample1()
        {
            var ast = ApexSharpParser.GetApexAst("class Example1 {}");

            Assert.IsFalse(IsTestClass(ast));
        }
Beispiel #11
0
        public static string NormalizeCode(string apexCode)
        {
            var apexAst = ApexSharpParser.GetApexAst(apexCode);

            return(GenerateApex(apexAst));
        }