├── .editorconfig ├── .gitignore ├── ApexParser.Example ├── ApexApiAnalyzer │ ├── Analyzer.cs │ ├── AnalyzerTests.cs │ ├── ApiAnalyzer.cs │ ├── ClassReference.cs │ ├── CommandLineOptions.cs │ ├── ConstructorReference.cs │ ├── DictionaryExtensions.cs │ ├── MarkdownReporter.cs │ ├── MethodReference.cs │ ├── Program.cs │ ├── PropertyReference.cs │ ├── SalesForceClassInfo.cs │ ├── SimpleReporter.cs │ ├── SimpleReporterTests.cs │ └── TestBase.cs ├── ApexClasses │ ├── ApexString.cls │ ├── ApexStringTest.cls │ ├── Comparison.cls │ ├── Criterium.cls │ ├── Dx.cls │ ├── DxTestFour.cls │ ├── DxTestOne.cls │ ├── DxTestThree.cls │ ├── DxTestTwo.cls │ ├── FieldFilterQuery.cls │ ├── FieldFilterQueryElement.cls │ ├── Filter.cls │ ├── FilterQuery.cls │ ├── FilterResult.cls │ ├── FilterResultIterator.cls │ ├── FilterTest.cls │ ├── GroupBy.cls │ ├── GroupByTest.cls │ ├── LambdaException.cls │ ├── MatchingFilterQuery.cls │ ├── Optional.cls │ ├── OptionalTest.cls │ ├── Pick.cls │ ├── PickTest.cls │ ├── Pluck.cls │ ├── PluckTest.cls │ ├── PrimitiveComparer.cls │ ├── PrimitiveComparerTest.cls │ ├── TestUtility.cls │ └── TokenCriterium.cls ├── ApexCodeFormat │ ├── ApexCodeFormater.cs │ ├── CodeFormatTest.cs │ ├── CustomApexCodeGenerator.cs │ ├── CustomApexCodeGeneratorTests.cs │ └── Settings.cs ├── ApexParser.Example.csproj ├── ApexTestFind │ ├── ApexTestFinder.cs │ └── ApexTestFinderTest.cs ├── CaseClean │ ├── ApexCleanCodeGen.cs │ ├── ApexCleanCodeGenTests.cs │ ├── CaseCleaner.SalesForceNames.cs │ ├── CaseCleaner.cs │ └── words.pl ├── Data │ ├── AllApexClasses.json │ ├── ApexClassDb.cs │ ├── ApexClassDbTest.cs │ ├── ApexClassDto.cs │ ├── ReservedWords.cs │ ├── SalesForceClasses.csv │ ├── SalesForceClasses.json │ └── SoqlWords.cs ├── FindRelatedClasses │ ├── FindRelatedClasses.cs │ ├── RelatedClassHelper.cs │ └── RelatedClassHelperTests.cs ├── ListClassesAndMethods │ ├── ClassesAndMethodsDemo.cs │ ├── Demo.cs │ └── DemoSetup.cs ├── Program.cs ├── Properties │ └── launchSettings.json └── README.md ├── ApexParser.sln ├── ApexSharp.ApexParser.Tests ├── ApexCSharpClasses │ ├── ApexDemo.cls │ ├── ApexDemoTest.cls │ ├── ApexDemoTest_CSharp.cs │ ├── ApexDemoTest_Formatted.cls │ ├── ApexDemo_CSharp.cs │ ├── ApexDemo_Formatted.cls │ ├── JSONParse.cls │ ├── JSONParseTests.cls │ ├── JSONParseTests_CSharp.cs │ ├── JSONParseTests_Formatted.cls │ ├── JSONParse_CSharp.cs │ ├── JSONParse_Formatted.cls │ ├── fflib_Answer.cls │ ├── fflib_AnswerTest.cls │ ├── fflib_AnswerTest_CSharp.cs │ ├── fflib_AnswerTest_Formatted.cls │ ├── fflib_Answer_CSharp.cs │ ├── fflib_Answer_Formatted.cls │ ├── fflib_AnyOrder.cls │ ├── fflib_AnyOrderTest.cls │ ├── fflib_AnyOrderTest_CSharp.cs │ ├── fflib_AnyOrderTest_Formatted.cls │ ├── fflib_AnyOrder_CSharp.cs │ ├── fflib_AnyOrder_Formatted.cls │ ├── fflib_ApexMocks.cls │ ├── fflib_ApexMocksConfig.cls │ ├── fflib_ApexMocksConfig_CSharp.cs │ ├── fflib_ApexMocksConfig_Formatted.cls │ ├── fflib_ApexMocksTest.cls │ ├── fflib_ApexMocksTest_CSharp.cs │ ├── fflib_ApexMocksTest_Formatted.cls │ ├── fflib_ApexMocksUtils.cls │ ├── fflib_ApexMocksUtilsTest.cls │ ├── fflib_ApexMocksUtilsTest_CSharp.cs │ ├── fflib_ApexMocksUtilsTest_Formatted.cls │ ├── fflib_ApexMocksUtils_CSharp.cs │ ├── fflib_ApexMocksUtils_Formatted.cls │ ├── fflib_ApexMocks_CSharp.cs │ ├── fflib_ApexMocks_Formatted.cls │ ├── fflib_ArgumentCaptor.cls │ ├── fflib_ArgumentCaptorTest.cls │ ├── fflib_ArgumentCaptorTest_CSharp.cs │ ├── fflib_ArgumentCaptorTest_Formatted.cls │ ├── fflib_ArgumentCaptor_CSharp.cs │ ├── fflib_ArgumentCaptor_Formatted.cls │ ├── fflib_IDGenerator.cls │ ├── fflib_IDGeneratorTest.cls │ ├── fflib_IDGeneratorTest_CSharp.cs │ ├── fflib_IDGeneratorTest_Formatted.cls │ ├── fflib_IDGenerator_CSharp.cs │ ├── fflib_IDGenerator_Formatted.cls │ ├── fflib_IMatcher.cls │ ├── fflib_IMatcher_CSharp.cs │ └── fflib_IMatcher_Formatted.cls ├── ApexParserMasterTest.cs ├── ApexRoundtrip │ ├── ClassAbstract_CSharp.cs │ ├── ClassAbstract_Formatted.cls │ ├── ClassAbstract_Original.cls │ ├── ClassEnum_CSharp.cs │ ├── ClassEnum_Formatted.cls │ ├── ClassEnum_Original.cls │ ├── ClassException_CSharp.cs │ ├── ClassException_Formatted.cls │ ├── ClassException_Original.cls │ ├── ClassGlobal_CSharp.cs │ ├── ClassGlobal_Formatted.cls │ ├── ClassGlobal_Original.cls │ ├── ClassInitialization_CSharp.cs │ ├── ClassInitialization_Formatted.cls │ ├── ClassInitialization_Original.cls │ ├── ClassInterface_CSharp.cs │ ├── ClassInterface_Formatted.cls │ ├── ClassInterface_Original.cls │ ├── ClassInternal_CSharp.cs │ ├── ClassInternal_Formatted.cls │ ├── ClassInternal_Original.cls │ ├── ClassNoApex2_CSharp.cs │ ├── ClassNoApex2_Formatted.cls │ ├── ClassNoApex2_Original.cls │ ├── ClassNoApex_CSharp.cs │ ├── ClassNoApex_Formatted.cls │ ├── ClassNoApex_Original.cls │ ├── ClassRestTest_CSharp.cs │ ├── ClassRestTest_Formatted.cls │ ├── ClassRestTest_Original.cls │ ├── ClassRest_CSharp.cs │ ├── ClassRest_Formatted.cls │ ├── ClassRest_Original.cls │ ├── ClassUnitTestRunAs_CSharp.cs │ ├── ClassUnitTestRunAs_Formatted.cls │ ├── ClassUnitTestRunAs_Original.cls │ ├── ClassUnitTestSeeAllData_CSharp.cs │ ├── ClassUnitTestSeeAllData_Formatted.cls │ ├── ClassUnitTestSeeAllData_Original.cls │ ├── ClassUnitTest_CSharp.cs │ ├── ClassUnitTest_Converted.cls │ ├── ClassUnitTest_Formatted.cls │ ├── ClassUnitTest_Original.cls │ ├── ClassWithOutSharing_CSharp.cs │ ├── ClassWithOutSharing_Formatted.cls │ ├── ClassWithOutSharing_Original.cls │ ├── ClassWithSharing_CSharp.cs │ ├── ClassWithSharing_Formatted.cls │ ├── ClassWithSharing_Original.cls │ ├── Collections_CSharp.cs │ ├── Collections_Formatted.cls │ ├── Collections_Original.cls │ ├── Comments_CSharp.cs │ ├── Comments_Formatted.cls │ ├── Comments_Original.cls │ ├── CsvReaderTest_CSharp.cs │ ├── CsvReaderTest_Formatted.cls │ ├── CsvReaderTest_Original.cls │ ├── DemoControllerTests_CSharp.cs │ ├── DemoControllerTests_Formatted.cls │ ├── DemoControllerTests_Original.cls │ ├── DemoController_CSharp.cs │ ├── DemoController_Formatted.cls │ ├── DemoController_Original.cls │ ├── DemoTest_CSharp.cs │ ├── DemoTest_Formatted.cls │ ├── DemoTest_Original.cls │ ├── Demo_CSharp.cs │ ├── Demo_Formatted.cls │ ├── Demo_Original.cls │ ├── ExceptionDemo_CSharp.cs │ ├── ExceptionDemo_Formatted.cls │ ├── ExceptionDemo_Original.cls │ ├── ForIfWhile4_CSharp.cs │ ├── ForIfWhile4_Formatted.cls │ ├── ForIfWhile4_Original.cls │ ├── ForIfWhile_CSharp.cs │ ├── ForIfWhile_Formatted.cls │ ├── ForIfWhile_Original.cls │ ├── GetSetDemo_CSharp.cs │ ├── GetSetDemo_Formatted.cls │ ├── GetSetDemo_Original.cls │ ├── IClassInterfaceExt_CSharp.cs │ ├── IClassInterfaceExt_Formatted.cls │ ├── IClassInterfaceExt_Original.cls │ ├── IClassInterface_CSharp.cs │ ├── IClassInterface_Formatted.cls │ ├── IClassInterface_Original.cls │ ├── JsonExample_CSharp.cs │ ├── JsonExample_Formatted.cls │ ├── JsonExample_Original.cls │ ├── MethodAndConstructor_CSharp.cs │ ├── MethodAndConstructor_Formatted.cls │ ├── MethodAndConstructor_Original.cls │ ├── MethodComplex_CSharp.cs │ ├── MethodComplex_Formatted.cls │ ├── MethodComplex_Original.cls │ ├── PrimitiveTypes_CSharp.cs │ ├── PrimitiveTypes_Formatted.cls │ ├── PrimitiveTypes_Original.cls │ ├── PropertyAndField_CSharp.cs │ ├── PropertyAndField_Formatted.cls │ ├── PropertyAndField_Original.cls │ ├── RunAll_CSharp.cs │ ├── RunAll_Formatted.cls │ ├── RunAll_Original.cls │ ├── SoqlDemo_CSharp.cs │ ├── SoqlDemo_Formatted.cls │ ├── SoqlDemo_Original.cls │ ├── SwitchDemo_CSharp.cs │ ├── SwitchDemo_Formatted.cls │ └── SwitchDemo_Original.cls ├── ApexSharp.ApexParser.Tests.csproj ├── ApexTestClasses │ ├── ApplicationTest.apex │ ├── ClassAbstract.cls │ ├── ClassEnum.cls │ ├── ClassException.cls │ ├── ClassGlobal.cls │ ├── ClassInitialization.cls │ ├── ClassInterface.cls │ ├── ClassInternal.cls │ ├── ClassOne.cls │ ├── ClassOne_Formatted.cls │ ├── ClassRest.cls │ ├── ClassTwo.cls │ ├── ClassTwo_Formatted.cls │ ├── ClassUnitTest.cls │ ├── ClassUnitTestRunAs.cls │ ├── ClassUnitTestSeeAllData.cls │ ├── ClassUnitTest_CSharp.cs │ ├── ClassVirtual.cls │ ├── ClassWithComments.cls │ ├── ClassWithComments_Formatted.cls │ ├── ClassWithOutSharing.cls │ ├── ClassWithSharing.cls │ ├── CommentFail.cls │ ├── Comments.cls │ ├── CustomerDto.cls │ ├── CustomerDto_Formatted.cls │ ├── DataAccessDemo.cls │ ├── Demo.cls │ ├── Demo2.cls │ ├── ExceptionDemo.cls │ ├── ForIfWhile.cls │ ├── ForIfWhile2.cls │ ├── ForIfWhile3.cls │ ├── FormatDemo.cls │ ├── FormatDemo_Formatted.cls │ ├── GetSetDemo.cls │ ├── IClassInterface.cls │ ├── IClassInterfaceExt.cls │ ├── JsonExample.cls │ ├── ListAndArrayDemo.cls │ ├── MethodAndConstructor.cls │ ├── PrimitiveTypes.cls │ ├── PropertyAndField.cls │ ├── PropertyAndField2.cls │ ├── PropertyAndField3.cls │ ├── RunAll.cls │ ├── SoqlDemo.cls │ ├── SoqlDemo.cs │ └── SoqlDemo2.cls ├── ApexTestLibraries │ ├── Cumulus-master.zip │ ├── SalesForceApexSharp-master.zip │ ├── apex-lambda-master.zip │ ├── apex-sobjectdataloader-master.zip │ ├── ffhttp-core-master.zip │ ├── fflib-apex-common-master.zip │ ├── fflib-apex-common-samplecode-master.zip │ ├── fflib-apex-mocks-master.zip │ ├── salesforce-einstein-platform-apex-master.zip │ └── sfdx-dreamhouse-master.zip ├── CSharpParserTests.cs ├── GitHubHelper.cs ├── Parser │ ├── ApexGrammarTests.cs │ ├── ApexRegressionTests.cs │ ├── ApexResourceTests.cs │ ├── ApexSyntaxTests.cs │ └── MethodTestData.cs ├── Properties │ ├── Resources.Designer.cs │ └── Resources.resx ├── TestFixtureBase.cs ├── Toolbox │ ├── ApiPlaygroundTests.cs │ ├── GenericExpressionHelperTests.cs │ ├── IEnumerableExtensionTests.cs │ ├── ParseExtensionTests.cs │ └── SmartEnumerableTests.cs └── Visitors │ ├── ApexGeneratorTests.cs │ ├── ApexResourceTests.cs │ ├── ApexSyntaxBuilderTests.cs │ ├── CSharpGeneratorTests.cs │ ├── CSharpResourceTests.cs │ ├── RoundtripTests.cs │ └── SoqlExtractorTests.cs ├── ApexSharp.ApexParser ├── ApexSharp.ApexParser.csproj ├── ApexSharpParser.cs ├── ApexSharpParserOptions.cs ├── Parser │ ├── Apex.cs │ ├── ApexGrammar.cs │ ├── ApexKeywords.cs │ ├── keywords.pl │ ├── keywords_nonreserved.txt │ └── keywords_reserved.txt ├── Properties │ └── AssemblyInfo.cs ├── Syntax │ ├── AccessorDeclarationSyntax.cs │ ├── AnnotationSyntax.cs │ ├── ArrayCreationExpressionSyntax.cs │ ├── AssignmentExpressionSyntax.cs │ ├── BaseSyntax.cs │ ├── BaseSyntaxDebuggerProxy.cs │ ├── BinaryExpressionSyntax.cs │ ├── BlockSyntax.cs │ ├── BreakStatementSyntax.cs │ ├── CastExpressionSyntax.cs │ ├── CatchClauseSyntax.cs │ ├── ClassDeclarationSyntax.cs │ ├── ClassInitializerSyntax.cs │ ├── ClassOfExpressionSyntax.cs │ ├── ConditionalExpressionSyntax.cs │ ├── ConstructorDeclarationSyntax.cs │ ├── ContinueStatementSyntax.cs │ ├── DeleteStatementSyntax.cs │ ├── DoStatementSyntax.cs │ ├── ElementAccessExpressionSyntax.cs │ ├── EnumDeclarationSyntax.cs │ ├── EnumMemberDeclarationSyntax.cs │ ├── ExpressionSyntax.cs │ ├── FieldDeclarationSyntax.cs │ ├── FieldDeclaratorSyntax.cs │ ├── FinallyClauseSyntax.cs │ ├── ForEachStatementSyntax.cs │ ├── ForStatementSyntax.cs │ ├── IAnnotatedSyntax.cs │ ├── IfStatementSyntax.cs │ ├── InsertStatementSyntax.cs │ ├── InstanceOfExpressionSyntax.cs │ ├── InterfaceDeclarationSyntax.cs │ ├── InvocationExpressionSyntax.cs │ ├── LiteralExpressionSyntax.cs │ ├── LiteralType.cs │ ├── MemberAccessExpressionSyntax.cs │ ├── MemberDeclarationSyntax.cs │ ├── MethodDeclarationSyntax.cs │ ├── ObjectCreationExpressionSyntax.cs │ ├── ParameterSyntax.cs │ ├── ParenthesizedExpressionSyntax.cs │ ├── PostfixUnaryExpressionSyntax.cs │ ├── PrefixUnaryExpressionSyntax.cs │ ├── PropertyDeclarationSyntax.cs │ ├── ReturnStatementSyntax.cs │ ├── RunAsStatementSyntax.cs │ ├── StatementSyntax.cs │ ├── SuperExpressionSyntax.cs │ ├── SwitchStatementSyntax.cs │ ├── SyntaxExtensions.cs │ ├── SyntaxType.cs │ ├── ThisExpressionSyntax.cs │ ├── ThrowStatementSyntax.cs │ ├── TryStatementSyntax.cs │ ├── TypeSyntax.cs │ ├── UpdateStatementSyntax.cs │ ├── UpsertStatementSyntax.cs │ ├── VariableDeclarationSyntax.cs │ ├── VariableDeclaratorSyntax.cs │ ├── WhenClauseSyntax.cs │ ├── WhenElseClauseSyntax.cs │ ├── WhenExpressionsClauseSyntax.cs │ ├── WhenTypeClauseSyntax.cs │ └── WhileStatementSyntax.cs ├── Toolbox │ ├── Disposable.cs │ ├── GenericExpressionHelper.cs │ ├── ICommentParserProvider.cs │ ├── IEnumerableExtensions.cs │ ├── ParseExceptionCustom.cs │ ├── ParserExtensions.cs │ ├── SmartEnumerable.cs │ ├── SmartEnumerableExt.cs │ └── SmartEnumerableT.cs ├── Visitors │ ├── ApexCodeGenerator.cs │ ├── ApexCodeGeneratorBase.cs │ ├── ApexMethodBodyGenerator.cs │ ├── ApexSyntaxVisitor.cs │ ├── CodeGeneratorBase.cs │ ├── Extensions.cs │ └── SoqlExtractor.cs └── app.config ├── ApexSharp.ApexToCSharp ├── ApexSharp.ApexToCSharp.csproj ├── ApexToCSharpHelpers.cs ├── Properties │ └── AssemblyInfo.cs └── Visitors │ ├── CSharpCodeGenerator.cs │ └── Extensions.cs ├── ApexSharp.CSharpToApex ├── ApexSharp.CSharpToApex.csproj ├── CSharpToApexHelpers.cs ├── Properties │ └── AssemblyInfo.cs └── Visitors │ ├── ApexSyntaxBuilder.cs │ └── SampleWalker.cs ├── ApexSharp.ruleset ├── LICENSE ├── Nuget └── BuildNugetPackage.bat ├── README.md └── appveyor.yml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: http://EditorConfig.org 2 | # VS extension: https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328 3 | 4 | # tab indentation 5 | [*.cs] 6 | indent_style = space 7 | indent_size = 4 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Visual Studio 3 | ################# 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | .vs/ 18 | 19 | # Visual Studio profiler 20 | *.psess 21 | *.vsp 22 | *.vspx 23 | 24 | # Guidance Automation Toolkit 25 | *.gpState 26 | 27 | # ReSharper is a .NET coding add-in 28 | _ReSharper*/ 29 | *.[Rr]e[Ss]harper 30 | 31 | # TeamCity is a build add-in 32 | _TeamCity* 33 | 34 | # DotCover is a Code Coverage Tool 35 | *.dotCover 36 | 37 | # axoCover is a Unit Test Runner / Code Coverage Tool 38 | .axoCover 39 | 40 | # NCrunch 41 | *.ncrunch* 42 | .*crunch*.local.xml 43 | 44 | 45 | # NuGet Packages Directory 46 | packages/ 47 | 48 | 49 | # Others 50 | config.json 51 | /*.bak 52 | .sfdx 53 | /JayPrivate 54 | ApexSharpPrivate.sln 55 | /Nuget/*.nupkg 56 | /TestResult.xml 57 | /.temp 58 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/ClassReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ApexApiAnalyzer 5 | { 6 | public class ClassReference 7 | { 8 | public string Namespace { get; set; } 9 | 10 | public string Name { get; set; } 11 | 12 | public bool HasImplementation { get; set; } 13 | 14 | public Dictionary Constructors { get; set; } = 15 | new Dictionary(StringComparer.InvariantCultureIgnoreCase); 16 | 17 | public Dictionary Methods { get; set; } = 18 | new Dictionary(StringComparer.InvariantCultureIgnoreCase); 19 | 20 | public Dictionary Properties { get; set; } = 21 | new Dictionary(StringComparer.InvariantCultureIgnoreCase); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/CommandLineOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using CommandLine; 3 | 4 | namespace ApexApiAnalyzer 5 | { 6 | public class CommandLineOptions 7 | { 8 | [Value(0, Required = true, HelpText = "Directories, ZIP files, Github project URLs to be processed")] 9 | public IEnumerable InputItems { get; set; } 10 | 11 | [Option('m', "markdown", Default = false, Required = false, HelpText = "Generate reports in Markdown format")] 12 | public bool Markdown { get; set; } 13 | 14 | [Option('n', "noimpl", Required = false, HelpText = "Report only classes that have no implementation")] 15 | public bool NotImplementedOnly { get; set; } 16 | 17 | [Option('o', "output", Required = false, HelpText = "Save the report to the output file instead of printing to STDOUT")] 18 | public string OutputFile { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/ConstructorReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexApiAnalyzer 8 | { 9 | public class ConstructorReference 10 | { 11 | public string Name { get; set; } 12 | 13 | public string Signature { get; set; } 14 | 15 | public string FullSignature { get; set; } 16 | 17 | public ClassReference Class { get; set; } 18 | 19 | public bool IsStatic { get; set; } 20 | 21 | public override string ToString() => Signature; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexApiAnalyzer 8 | { 9 | public static class DictionaryExtensions 10 | { 11 | public static V GetOrAdd(this IDictionary self, K key, Func factory) 12 | { 13 | if (self.TryGetValue(key, out var value)) 14 | { 15 | return value; 16 | } 17 | 18 | var created = factory(key); 19 | self[key] = created; 20 | return created; 21 | } 22 | 23 | public static V GetOrDefault(this IDictionary self, K key, V defaultValue = default(V)) 24 | { 25 | if (self.TryGetValue(key, out var value)) 26 | { 27 | return value; 28 | } 29 | 30 | return defaultValue; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/MethodReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexApiAnalyzer 8 | { 9 | public class MethodReference 10 | { 11 | public string Name { get; set; } 12 | 13 | public string Signature { get; set; } 14 | 15 | public string FullSignature { get; set; } 16 | 17 | public ClassReference Class { get; set; } 18 | 19 | public bool IsStatic { get; set; } 20 | 21 | public override string ToString() => Signature; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/PropertyReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexApiAnalyzer 8 | { 9 | public class PropertyReference 10 | { 11 | public string Name { get; set; } 12 | 13 | public string Signature { get; set; } 14 | 15 | public string FullSignature { get; set; } 16 | 17 | public ClassReference Class { get; set; } 18 | 19 | public bool IsStatic { get; set; } 20 | 21 | public override string ToString() => Signature; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexApiAnalyzer/SalesForceClassInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexApiAnalyzer 8 | { 9 | public class SalesForceClassInfo 10 | { 11 | // Is this a SF class or class created by the user. 12 | public bool IsCustom { get; set; } 13 | public string ClassName { get; set; } 14 | public string MethodName { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/Comparison.cls: -------------------------------------------------------------------------------- 1 | public enum Comparison 2 | { 3 | LESS_THAN, 4 | GREATER_THAN, 5 | EQUALS, 6 | NOT_EQUALS, 7 | LESS_THAN_OR_EQUALS, 8 | GREATER_THAN_OR_EQUALS, 9 | IS_IN, 10 | NOT_IN 11 | } 12 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/Criterium.cls: -------------------------------------------------------------------------------- 1 | public class Criterium 2 | { 3 | public String field { get; set; } 4 | 5 | public Comparison criterium { get; set; } 6 | 7 | public Object value { get; set; } 8 | 9 | public Criterium(String field, Comparison criterium, Object value) 10 | { 11 | this.field = field; 12 | this.criterium = criterium; 13 | this.value = value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/Dx.cls: -------------------------------------------------------------------------------- 1 | public with sharing class Dx 2 | { 3 | public static String updatePhone(String email, String newPhone) 4 | { 5 | List contacts = getContactByEMail(email); 6 | if (contacts.isEmpty()) 7 | { 8 | return 'Not Found'; 9 | } 10 | else 11 | { 12 | contacts[0].Phone = newPhone; 13 | updateContacts(contacts); 14 | return 'Phone Number Updated'; 15 | } 16 | } 17 | 18 | public static List getContactByEMail(String email) 19 | { 20 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email]; 21 | return contacts; 22 | } 23 | 24 | public static void updateContacts(List contacts) 25 | { 26 | update contacts; 27 | } 28 | 29 | public String updatePhoneNonStatic(String email, String newPhone) 30 | { 31 | List contacts = getContactByEMail(email); 32 | if (contacts.isEmpty()) 33 | { 34 | return 'Not Found'; 35 | } 36 | else 37 | { 38 | contacts[0].Phone = newPhone; 39 | update contacts; 40 | return 'Phone Number Updated'; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/DxTestFour.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | private class DxTestFour 3 | { 4 | @TestSetup 5 | public static void setup() 6 | { 7 | Contact contactNew = new Contact(); 8 | contactNew.LastName = 'Jay'; 9 | contactNew.Email = 'jay@jay.com'; 10 | insert contactNew; 11 | } 12 | 13 | @IsTest 14 | public static void updatePhoneTestValidEmail() 15 | { 16 | String Dx = 'This should not work'; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/DxTestOne.cls: -------------------------------------------------------------------------------- 1 | Private Class DxTestOne 2 | { 3 | Public Static void setup() 4 | { 5 | Contact contactNew = new Contact(); 6 | contactNew.LastName = 'Jay'; 7 | contactNew.Email = 'jay@jay.com'; 8 | insert contactNew; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/DxTestThree.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | private class DxTestThree 3 | { 4 | @TestSetup 5 | public static void setup() 6 | { 7 | Contact contactNew = new Contact(); 8 | contactNew.LastName = 'Jay'; 9 | contactNew.Email = 'jay@jay.com'; 10 | insert contactNew; 11 | } 12 | 13 | @IsTest 14 | public static void updatePhoneTestValidEmail() 15 | { 16 | // Dx.updatePhone('jay@jay.com', '555-1212'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/DxTestTwo.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | private class DxTestTwo 3 | { 4 | @TestSetup 5 | public static void setup() 6 | { 7 | Contact contactNew = new Contact(); 8 | contactNew.LastName = 'Jay'; 9 | contactNew.Email = 'jay@jay.com'; 10 | insert contactNew; 11 | } 12 | 13 | @IsTest 14 | public static void updatePhoneTestValidEmail() 15 | { 16 | Dx dx = new Dx(); 17 | dx.updatePhoneNonStatic('jay@jay.com', '555-1212'); 18 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'jay@jay.com']; 19 | System.assertEquals(contacts[0].Phone, '555-1212'); 20 | } 21 | 22 | @IsTest 23 | public static void updatePhoneTestNotValidEmail() 24 | { 25 | Dx dx = new Dx(); 26 | dx.updatePhoneNonStatic('jay@jay.com', '555-1212'); 27 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com']; 28 | System.assertEquals(contacts.size(), 0); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/Filter.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * Starting class for filtering queries on the list 3 | */ 4 | public class Filter 5 | { 6 | /** 7 | * Initiates a matching filtering query 8 | * @param obj Object to compare to in a query 9 | */ 10 | public static MatchingFilterQuery match(sObject prototype) 11 | { 12 | return new MatchingFilterQuery(prototype); 13 | } 14 | 15 | /** 16 | * Initiates a field token filtering query 17 | * @param token Field token to query 18 | */ 19 | public static FieldFilterQueryElement field(Schema.SObjectField field) 20 | { 21 | return new FieldFilterQueryElement(new FieldFilterQuery(), field); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/FilterResult.cls: -------------------------------------------------------------------------------- 1 | public class FilterResult implements Iterable 2 | { 3 | private FilterQuery query; 4 | 5 | private Iterable objects; 6 | 7 | public FilterResult(FilterQuery query, Iterable records) 8 | { 9 | this.query = query; 10 | this.records = records; 11 | } 12 | 13 | public Iterator iterator() 14 | { 15 | return new FilterResultIterator(query, records.iterator()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/FilterResultIterator.cls: -------------------------------------------------------------------------------- 1 | public class FilterResultIterator implements Iterator 2 | { 3 | private FilterQuery query; 4 | 5 | private Iterator objectsIterator; 6 | 7 | private sObject next; 8 | 9 | public FilterResultIterator(FilterQuery query, Iterator objectsIterator) 10 | { 11 | this.query = query; 12 | this.objectsIterator = objectsIterator; 13 | findNext(); 14 | } 15 | 16 | public Boolean hasNext() 17 | { 18 | return next != null; 19 | } 20 | 21 | private void findNext() 22 | { 23 | while (objectsIterator.hasNext()) 24 | { 25 | sObject obj = objectsIterator.next(); 26 | if (query.isValid(obj)) 27 | { 28 | next = obj; 29 | return; 30 | } 31 | } 32 | 33 | next = null; 34 | } 35 | 36 | public SObject next() 37 | { 38 | if (next == null) 39 | { 40 | throw new NoSuchElementException(); 41 | } 42 | 43 | SObject current = next; 44 | findNext(); 45 | return current; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/LambdaException.cls: -------------------------------------------------------------------------------- 1 | public class LambdaException extends Exception 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/MatchingFilterQuery.cls: -------------------------------------------------------------------------------- 1 | public class MatchingFilterQuery extends FilterQuery 2 | { 3 | private sObject obj; 4 | 5 | private Map availableFields = new Map(); 6 | 7 | /** 8 | * Constructor. Takes a comparison sObject to compare list elements with. 9 | * The comparison checks for equality with the comparison object and only 10 | * non-null fields are considered. 11 | * @param obj Comparison sObject 12 | */ 13 | public MatchingFilterQuery(sObject obj) 14 | { 15 | this.obj = obj; 16 | for (String field : obj.getSObjectType().getDescribe().fields.getMap().keyset()) 17 | { 18 | if (obj.get(field)!= null) 19 | { 20 | availableFields.put(field, obj.get(field)); 21 | } 22 | } 23 | } 24 | 25 | public override Boolean isValid(sObject o) 26 | { 27 | Boolean isValid = true; 28 | for (String field : availableFields.keySet()) 29 | { 30 | if (obj.get(field)!= o.get(field)) 31 | { 32 | isValid = false; 33 | break; 34 | } 35 | } 36 | 37 | return isValid; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/OptionalTest.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | private class OptionalTest 3 | { 4 | @IsTest 5 | public static void testOptionalRoundtrip() 6 | { 7 | Optional opt = Optional.of('foo'); 8 | System.assertEquals('foo', opt.get()); 9 | } 10 | 11 | @IsTest 12 | public static void testOptionalPresenceChecking() 13 | { 14 | Optional opt = Optional.of('foo'); 15 | System.assertEquals(true, opt.isPresent()); 16 | opt = Optional.ofNullable(null); 17 | System.assertEquals(false, opt.isPresent()); 18 | opt = Optional.empty(); 19 | System.assertEquals(false, opt.isPresent()); 20 | } 21 | 22 | @IsTest 23 | public static void testEmptyOptionalReferentialEquality() 24 | { 25 | Optional opt1 = Optional.ofNullable(null); 26 | Optional opt2 = Optional.empty(); 27 | System.assert(opt1 == opt2); 28 | } 29 | 30 | @IsTest 31 | public static void testOptionalOfThrowsExceptionOnNull() 32 | { 33 | try 34 | { 35 | Optional opt = Optional.of(null); 36 | System.assert(false, 'Exception was not thrown'); 37 | } 38 | catch (LambdaException e) 39 | { 40 | System.assert(true); 41 | } 42 | } 43 | 44 | @IsTest 45 | public static void testOrElse() 46 | { 47 | Optional o = Optional.empty(); 48 | Object result = o.orElse('other'); 49 | System.assertEquals('other', result); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/TestUtility.cls: -------------------------------------------------------------------------------- 1 | public class TestUtility 2 | { 3 | private static final Double DEFAULT_EPSILON = 0.0001; 4 | 5 | static Integer counter = 1; 6 | 7 | public static String getTestId(Schema.SObjectType sot) 8 | { 9 | String numberString = String.valueOf(counter++); 10 | String prefix = sot.getDescribe().getKeyPrefix(); 11 | return prefix + '0'.repeat(12 - numberString.length())+ numberString; 12 | } 13 | 14 | public static void assertEqualsEpsilon(Double expected, Double actual) 15 | { 16 | assertEqualsEpsilon(expected, actual, DEFAULT_EPSILON); 17 | } 18 | 19 | public static void assertEqualsEpsilon(Double expected, Double actual, Double epsilon) 20 | { 21 | Double delta = Math.abs(expected - actual); 22 | System.assert(delta < epsilon); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexClasses/TokenCriterium.cls: -------------------------------------------------------------------------------- 1 | public class TokenCriterium 2 | { 3 | public Schema.SObjectField field { get; set; } 4 | 5 | public Comparison criterium { get; set; } 6 | 7 | public Object value { get; set; } 8 | 9 | public TokenCriterium(Schema.SObjectField field, Comparison criterium, Object value) 10 | { 11 | this.field = field; 12 | this.criterium = criterium; 13 | this.value = value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexCodeFormat/CodeFormatTest.cs: -------------------------------------------------------------------------------- 1 | using ApexSharp.ApexParser; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace ApexSharpDemo.ApexCodeFormat 9 | { 10 | public class CodeFormatTest 11 | { 12 | public CodeFormatTest() 13 | { 14 | DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Dev\codeformat\src\classes\"); 15 | //DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\DevSharp\ApexSharpFsb\FSB\ApexClasses\"); 16 | List results = ApexCodeFormater.FormatApexCode(directoryInfo); 17 | 18 | foreach (var result in results) 19 | { 20 | Console.WriteLine(result.ApexFileName); 21 | var apexAst = ApexSharpParser.GetApexAst(result.ApexFileAfterFormat); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexCodeFormat/Settings.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCodeFormat 2 | { 3 | public class Settings 4 | { 5 | // The { and } brackets will start on a new line except for {get;set;} 6 | public bool OpenCloseBracesInNewLine { get; set; } = true; 7 | 8 | // Code will be on a single line until the end of ';' 9 | public bool SingleLine { get; set; } = true; 10 | 11 | // What should be in the indent 12 | public int TabIndentSize { get; set; } = 4; 13 | 14 | // Annotation TestMethod is being depreciated by @isTest, thus replace it 15 | public bool ReplaceTestMethod { get; set; } = true; 16 | 17 | /* 18 | * SOQL Formatting 19 | * Each statement should be on its own line 20 | * 21 | * SELECT Id, Name 22 | * FROM Account 23 | * WHERE Name = 'Sandy' 24 | */ 25 | public bool SoqlFormat { get; set; } = true; 26 | 27 | // Other items by default. 28 | // Comments between statements will show up in the top of the statements. 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexParser.Example/ApexParser.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ApexParser.Example/CaseClean/words.pl: -------------------------------------------------------------------------------- 1 | #!perl 2 | 3 | # Extracts the unique words from the given text 4 | # Usage: perl -w words.pl SalesForceClasses.txt >CaseCleaner.SalesForceClasses.cs 5 | # Written by Y [25-06-18] 6 | 7 | use strict; 8 | use warnings; 9 | 10 | my %count; 11 | #my @blacklist = ("ANY", "APEX_OBJECT", "CURRENCY", "LIST"); # let's avoid these 12 | #my %list = map { $_ => 1 } @blacklist; 13 | 14 | while (<>) { 15 | while (/([a-zA-Z]([\-\']?[\w]+)*)/g) { 16 | $count{$1}++ if length($1) > 1 && uc($1) ne $1; # !exists($list{$1}) 17 | } 18 | } 19 | 20 | # report statistics 21 | #foreach my $str (sort keys %count) { 22 | # printf "%-31s %s\n", $str, $count{$str}; 23 | #} 24 | 25 | print "using System; 26 | using System.Collections.Generic; 27 | 28 | namespace ApexSharpDemo.CaseClean 29 | { 30 | public partial class CaseCleaner 31 | { 32 | // generated by $0 33 | public static HashSet SalesForceNames { get; } = new HashSet(new[] 34 | {"; 35 | 36 | # generate C# list 37 | foreach my $str (sort keys %count) { 38 | printf " 39 | %-54s // %s", "\"" . $str . "\",", $count{$str}; 40 | } 41 | 42 | print " 43 | }, StringComparer.InvariantCultureIgnoreCase); 44 | } 45 | } 46 | "; 47 | -------------------------------------------------------------------------------- /ApexParser.Example/Data/ApexClassDto.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.Data 2 | { 3 | 4 | public class ApexClassDto 5 | { 6 | public string NameSpace { get; set; } 7 | public string ClassName { get; set; } 8 | public object[] constructors { get; set; } 9 | public Method[] methods { get; set; } 10 | public object[] properties { get; set; } 11 | } 12 | 13 | public class Method 14 | { 15 | public string[] argTypes { get; set; } 16 | public bool isStatic { get; set; } 17 | public object methodDoc { get; set; } 18 | public string name { get; set; } 19 | public Parameter[] parameters { get; set; } 20 | public object[] references { get; set; } 21 | public string returnType { get; set; } 22 | } 23 | 24 | public class Parameter 25 | { 26 | public string name { get; set; } 27 | public string type { get; set; } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ApexParser.Example/Data/SoqlWords.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ApexSharpDemo.Data 6 | { 7 | class SoqlWords 8 | { 9 | 10 | //SELECT 11 | //TYPEOF 12 | //FROM 13 | //USING SCOPE 14 | //WHERE 15 | //WITH 16 | //DATA CATEGORY 17 | //GROUP BY 18 | //ROLLUP 19 | //CUBE 20 | //HAVING 21 | //ORDER BY 22 | //ASC 23 | //DESC 24 | //NULLS 25 | //FIRST 26 | //LAST 27 | //LIMIT 28 | //OFFSET 29 | //FOR 30 | //VIEW 31 | //REFERENCE 32 | //UPDATE 33 | //RACKING 34 | //VIEWSTAT 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApexParser.Example/ListClassesAndMethods/Demo.cs: -------------------------------------------------------------------------------- 1 |  2 | using Apex.System; 3 | 4 | namespace ApexSharpDemo.ListClassesAndMethods 5 | { 6 | public class Demo 7 | { 8 | public void MethodOne() 9 | { 10 | HttpRequest demo = new HttpRequest(); 11 | demo.toString(); 12 | } 13 | public void MethodTwo() 14 | { 15 | Http demo = new Http(); 16 | demo.toString(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ApexParser.Example/ListClassesAndMethods/DemoSetup.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ListClassesAndMethods 2 | { 3 | public class DemoSetup 4 | { 5 | public static void StaticMethod() 6 | { 7 | 8 | } 9 | 10 | public static DemoSetup StaticMethodTwo() 11 | { 12 | return new DemoSetup(); 13 | } 14 | 15 | public void InstanceMethod() 16 | { 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /ApexParser.Example/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "ApexSharpDemo": { 4 | "commandName": "Project", 5 | "commandLineArgs": "-s apexcodeformat -d C:\\DevSharp\\ApexSharpFsb\\ApexSharpDemo\\ApexClasses " 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /ApexParser.Example/README.md: -------------------------------------------------------------------------------- 1 | # Apex Parser Demos 2 | 3 | Demos showing how to use the Apex Parser 4 | 5 | ## Syntax 6 | 7 | apexparserdemo.exe -service ApexTestFind -dir c:\apex\src -apex demo.cls 8 | 9 | apexparserdemo.exe -service ApexApiAnalyzer -dir c:\apex\src 10 | 11 | apexparserdemo.exe -service CaseClean -dir c:\apex\src 12 | 13 | apexparserdemo.exe -service NoAssert -dir c:\apex\src 14 | 15 | apexparserdemo.exe -service ApexCodeFormat -dir c:\apex\src 16 | 17 | 18 | 19 | ## Detail 20 | 21 | #### All the values are returnd as JSON so you can pipe these into other tools. 22 | 23 | 24 | ### ApexTestFind 25 | 26 | Given a apex classs, find all the unit test that calls the given class. 27 | 28 | ### ApexApiAnalyzer 29 | 30 | Find all the Apex classes and methods used on your code 31 | 32 | ### CaseClean 33 | 34 | Since apex is not case senstive you can write 35 | 36 | * System.debug (The Correct way) 37 | * system.debug 38 | * SYSTEM.DEBUG 39 | 40 | and all of the above are correct. CaseClean will clean up your code and make all the class and methods name to match what SF shows on the API docs 41 | 42 | ### No Assert 43 | 44 | List all the Test Classes and the methods that miss Assert 45 | 46 | ### Apex Code Format 47 | 48 | This will format all the settings based on Settings.cs (We will move this to JSON later) -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/ApexDemo.cls: -------------------------------------------------------------------------------- 1 | public class Demo 2 | { 3 | public Contact contact { get; set; } 4 | 5 | public Demo() { 6 | contact = new Contact(); 7 | } 8 | 9 | public PageReference Save() { 10 | try { 11 | insert contact; 12 | } catch(DMLException e) { 13 | ApexPages.AddMessages(e); 14 | 15 | } 16 | return null; 17 | } 18 | 19 | 20 | public static string UpdatePhone(string email, string newPhone) 21 | { 22 | List contacts = GetContactByEMail(email); 23 | if(contacts.IsEmpty()) { 24 | return 'Not Found'; 25 | } else { 26 | contacts[0].Phone = newPhone; 27 | UpdateContacts(contacts); 28 | return 'Phone Number Updated'; 29 | } 30 | } 31 | 32 | private static List GetContactByEMail(string email) 33 | { 34 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email]; 35 | return contacts; 36 | } 37 | 38 | 39 | public static List GetContacts() 40 | { 41 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 42 | return contacts; 43 | } 44 | 45 | private static void UpdateContacts(List contacts) 46 | { 47 | update contacts; 48 | } 49 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/ApexDemoTest.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class DemoTest { 3 | 4 | //:NoApex [OneTimeSetUp] 5 | //:NoApex public void NoApexSetup() 6 | //:NoApex { 7 | //:NoApex new ApexSharp().Connect("C:\\DevSharp\\connect.json"); 8 | //:NoApex } 9 | //:NoApex 10 | 11 | @testSetup 12 | public static void Setup() { 13 | Contact contactNew = new Contact(); 14 | contactNew.LastName = 'Jay'; 15 | contactNew.Email = 'jay@jay.com'; 16 | insert contactNew; 17 | } 18 | 19 | @IsTest 20 | public static void UpdatePhoneTestValidEmail() { 21 | Demo.UpdatePhone('jay@jay.com', '555-1212'); 22 | 23 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = 'jay@jay.com']; 24 | System.AssertEquals(contacts[0].Phone, '555-1212'); 25 | } 26 | 27 | @IsTest 28 | public static void UpdatePhoneTestNotValidEmail() { 29 | Demo.UpdatePhone('nojay@jay.com', '555-1212'); 30 | 31 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com']; 32 | System.AssertEquals(contacts.Size(), 0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/ApexDemoTest_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class DemoTest 13 | { 14 | [OneTimeSetUp] 15 | public void NoApexSetup() 16 | { 17 | new ApexSharp().Connect("C:\\DevSharp\\connect.json"); 18 | } 19 | 20 | [SetUp] 21 | public static void Setup() 22 | { 23 | Contact contactNew = new Contact(); 24 | contactNew.LastName = "Jay"; 25 | contactNew.Email = "jay@jay.com"; 26 | Soql.insert(contactNew); 27 | } 28 | 29 | [Test] 30 | public static void UpdatePhoneTestValidEmail() 31 | { 32 | Demo.UpdatePhone("jay@jay.com", "555-1212"); 33 | List contacts = Soql.query(@"SELECT Id, Email, Phone FROM Contact WHERE Email = 'jay@jay.com'"); 34 | System.AssertEquals(contacts[0].Phone, "555-1212"); 35 | } 36 | 37 | [Test] 38 | public static void UpdatePhoneTestNotValidEmail() 39 | { 40 | Demo.UpdatePhone("nojay@jay.com", "555-1212"); 41 | List contacts = Soql.query(@"SELECT Id, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com'"); 42 | System.AssertEquals(contacts.Size(), 0); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/ApexDemoTest_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class DemoTest 3 | { 4 | //:NoApex [OneTimeSetUp] 5 | //:NoApex public void NoApexSetup() 6 | //:NoApex { 7 | //:NoApex new ApexSharp().Connect("C:\\DevSharp\\connect.json"); 8 | //:NoApex } 9 | //:NoApex 10 | @TestSetup 11 | public static void Setup() 12 | { 13 | Contact contactNew = new Contact(); 14 | contactNew.LastName = 'Jay'; 15 | contactNew.Email = 'jay@jay.com'; 16 | insert contactNew; 17 | } 18 | 19 | @IsTest 20 | public static void UpdatePhoneTestValidEmail() 21 | { 22 | Demo.UpdatePhone('jay@jay.com', '555-1212'); 23 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = 'jay@jay.com']; 24 | System.AssertEquals(contacts[0].Phone, '555-1212'); 25 | } 26 | 27 | @IsTest 28 | public static void UpdatePhoneTestNotValidEmail() 29 | { 30 | Demo.UpdatePhone('nojay@jay.com', '555-1212'); 31 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com']; 32 | System.AssertEquals(contacts.Size(), 0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/ApexDemo_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class Demo 2 | { 3 | public Contact contact { get; set; } 4 | 5 | public Demo() 6 | { 7 | contact = new Contact(); 8 | } 9 | 10 | public PageReference Save() 11 | { 12 | try 13 | { 14 | insert contact; 15 | } 16 | catch (DMLException e) 17 | { 18 | ApexPages.AddMessages(e); 19 | } 20 | 21 | return null; 22 | } 23 | 24 | public static String UpdatePhone(String email, String newPhone) 25 | { 26 | List contacts = GetContactByEMail(email); 27 | if (contacts.IsEmpty()) 28 | { 29 | return 'Not Found'; 30 | } 31 | else 32 | { 33 | contacts[0].Phone = newPhone; 34 | UpdateContacts(contacts); 35 | return 'Phone Number Updated'; 36 | } 37 | } 38 | 39 | private static List GetContactByEMail(String email) 40 | { 41 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email]; 42 | return contacts; 43 | } 44 | 45 | public static List GetContacts() 46 | { 47 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 48 | return contacts; 49 | } 50 | 51 | private static void UpdateContacts(List contacts) 52 | { 53 | update contacts; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_Answer.cls: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 3 | */ 4 | 5 | /** 6 | * Interface for the answering framework. 7 | * This interface must be implemented inside the test class and implement the call back method answer. 8 | * @group Core 9 | */ 10 | public interface fflib_Answer 11 | { 12 | /** 13 | * Method to be implemented in the test class to implement the call back method. 14 | * @param invocation The invocation on the mock. 15 | * @throws The exception to be thrown. 16 | * @return The value to be returned. 17 | */ 18 | Object answer(fflib_InvocationOnMock invocation); 19 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_Answer_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | /* 11 | Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 12 | */ 13 | /** 14 | * Interface for the answering framework. 15 | * This interface must be implemented inside the test class and implement the call back method answer. 16 | * @group Core 17 | */ 18 | public interface fflib_Answer 19 | { 20 | /** 21 | * Method to be implemented in the test class to implement the call back method. 22 | * @param invocation The invocation on the mock. 23 | * @throws The exception to be thrown. 24 | * @return The value to be returned. 25 | */ 26 | object answer(fflib_InvocationOnMock invocation); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_Answer_Formatted.cls: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 3 | */ 4 | /** 5 | * Interface for the answering framework. 6 | * This interface must be implemented inside the test class and implement the call back method answer. 7 | * @group Core 8 | */ 9 | public interface fflib_Answer 10 | { 11 | /** 12 | * Method to be implemented in the test class to implement the call back method. 13 | * @param invocation The invocation on the mock. 14 | * @throws The exception to be thrown. 15 | * @return The value to be returned. 16 | */ 17 | Object answer(fflib_InvocationOnMock invocation); 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_ApexMocksConfig.cls: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 3 | */ 4 | @IsTest 5 | public class fflib_ApexMocksConfig 6 | { 7 | /** 8 | * When false, stubbed behaviour and invocation counts are shared among all test spies. 9 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedDependently 10 | * - This is the default for backwards compatibility. 11 | * When true, each test spy instance has its own stubbed behaviour and invocations. 12 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedIndependently 13 | */ 14 | public static Boolean HasIndependentMocks {get; set;} 15 | 16 | static 17 | { 18 | HasIndependentMocks = false; 19 | } 20 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_ApexMocksConfig_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | /* 12 | * Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 13 | */ 14 | [TestFixture] 15 | public class fflib_ApexMocksConfig 16 | { 17 | /** 18 | * When false, stubbed behaviour and invocation counts are shared among all test spies. 19 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedDependently 20 | * - This is the default for backwards compatibility. 21 | * When true, each test spy instance has its own stubbed behaviour and invocations. 22 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedIndependently 23 | */ 24 | public static bool HasIndependentMocks { get; set; } 25 | 26 | static fflib_ApexMocksConfig() 27 | { 28 | HasIndependentMocks = false; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexCSharpClasses/fflib_ApexMocksConfig_Formatted.cls: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 FinancialForce.com, inc. All rights reserved. 3 | */ 4 | @IsTest 5 | public class fflib_ApexMocksConfig 6 | { 7 | /** 8 | * When false, stubbed behaviour and invocation counts are shared among all test spies. 9 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedDependently 10 | * - This is the default for backwards compatibility. 11 | * When true, each test spy instance has its own stubbed behaviour and invocations. 12 | * - See fflib_ApexMocksTest.thatMultipleInstancesCanBeMockedIndependently 13 | */ 14 | public static Boolean HasIndependentMocks { get; set; } 15 | 16 | static 17 | { 18 | HasIndependentMocks = false; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassAbstract_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | // sample abstract class 11 | public abstract class ClassAbstract 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassAbstract_Formatted.cls: -------------------------------------------------------------------------------- 1 | // sample abstract class 2 | public abstract class ClassAbstract 3 | { 4 | } 5 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassAbstract_Original.cls: -------------------------------------------------------------------------------- 1 | // sample abstract class 2 | public abstract class ClassAbstract 3 | { 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassEnum_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public enum ClassEnum 11 | { 12 | America, 13 | Canada, 14 | Russia 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassEnum_Formatted.cls: -------------------------------------------------------------------------------- 1 | public enum ClassEnum 2 | { 3 | America, 4 | Canada, 5 | Russia 6 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassEnum_Original.cls: -------------------------------------------------------------------------------- 1 | public enum ClassEnum 2 | { 3 | America, 4 | Canada, 5 | Russia 6 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassException_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassException : Exception 11 | { 12 | [ApexSharpGenerated] 13 | public ClassException() : base() 14 | { 15 | } 16 | 17 | [ApexSharpGenerated] 18 | public ClassException(string message) : base(message) 19 | { 20 | } 21 | 22 | [ApexSharpGenerated] 23 | public ClassException(Exception e) : base(e) 24 | { 25 | } 26 | 27 | [ApexSharpGenerated] 28 | public ClassException(string message, Exception e) : base(message, e) 29 | { 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassException_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassException extends Exception 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassException_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassException extends Exception 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassGlobal_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [Global] 11 | public class ClassGlobal 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassGlobal_Formatted.cls: -------------------------------------------------------------------------------- 1 | global class ClassGlobal 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassGlobal_Original.cls: -------------------------------------------------------------------------------- 1 | global class ClassGlobal 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInitialization_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassInitialization 11 | { 12 | public List contactList; 13 | 14 | public ClassInitialization() 15 | { 16 | contactList = Soql.query(@"SELECT ID FROM Contact LIMIT 1"); 17 | } 18 | 19 | public static Map colorMap = new Map(); 20 | 21 | static ClassInitialization() 22 | { 23 | colorMap.Put("red", "255, 0, 0"); 24 | colorMap.Put("cyan", "0, 255, 255"); 25 | colorMap.Put("magenta", "255, 0, 255"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInitialization_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassInitialization 2 | { 3 | public List contactList; 4 | 5 | public ClassInitialization() 6 | { 7 | contactList = [SELECT ID FROM Contact LIMIT 1]; 8 | } 9 | 10 | public static Map colorMap = new Map(); 11 | 12 | static 13 | { 14 | colorMap.Put('red', '255, 0, 0'); 15 | colorMap.Put('cyan', '0, 255, 255'); 16 | colorMap.Put('magenta', '255, 0, 255'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInitialization_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassInitialization { 2 | 3 | public List contactList; 4 | public ClassInitialization() { 5 | contactList = [SELECT ID FROM Contact LIMIT 1]; 6 | } 7 | 8 | public static Map colorMap = new Map(); 9 | 10 | static { 11 | colorMap.Put('red', '255, 0, 0'); 12 | colorMap.Put('cyan', '0, 255, 255'); 13 | colorMap.Put('magenta', '255, 0, 255'); 14 | } 15 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInterface_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassInterface : IClassInterface 11 | { 12 | public string GetName(string name) 13 | { 14 | return name; 15 | } 16 | 17 | public string GetName() 18 | { 19 | return "Jay"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInterface_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassInterface implements IClassInterface 2 | { 3 | public String GetName(String name) 4 | { 5 | return name; 6 | } 7 | 8 | public String GetName() 9 | { 10 | return 'Jay'; 11 | } 12 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInterface_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassInterface implements IClassInterface 2 | { 3 | public string GetName(string name) 4 | { 5 | return name; 6 | } 7 | 8 | public string GetName() 9 | { 10 | return 'Jay'; 11 | } 12 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInternal_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassInternal 11 | { 12 | InternalClassOne classOne = new InternalClassOne(); 13 | 14 | ClassInternal.InternalClassTwo classTwo = new ClassInternal.InternalClassTwo(); 15 | 16 | public class InternalClassOne 17 | { 18 | } 19 | 20 | public class InternalClassTwo 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInternal_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassInternal 2 | { 3 | InternalClassOne classOne = new InternalClassOne(); 4 | 5 | ClassInternal.InternalClassTwo classTwo = new ClassInternal.InternalClassTwo(); 6 | 7 | public class InternalClassOne 8 | { 9 | } 10 | 11 | public class InternalClassTwo 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassInternal_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassInternal 2 | { 3 | InternalClassOne classOne = new InternalClassOne(); 4 | ClassInternal.InternalClassTwo classTwo = new ClassInternal.InternalClassTwo(); 5 | 6 | public class InternalClassOne 7 | { 8 | } 9 | 10 | public class InternalClassTwo 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex2_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassNoApex 11 | { 12 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 13 | public static void MethodOne() 14 | { 15 | NoApex.Serilog.LogInfo("Jay"); 16 | } 17 | 18 | public static List getContacts() 19 | { 20 | List contacts = Soql.query(@"SELECT Id, Email, Phone FROM Contact"); 21 | 22 | NoApex.Serilog.LogInfo(contacts.size().ToString()); 23 | return contacts; 24 | } 25 | 26 | public static void callingNonApexCode() 27 | { 28 | NoApex.Serilog.LogInfo("Hi"); 29 | } 30 | 31 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 32 | public static void NoApexMethodTwo() 33 | { 34 | NoApex.Serilog.LogInfo("Jay"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex2_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassNoApex 2 | { 3 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 4 | public static void MethodOne() 5 | { 6 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 7 | } 8 | 9 | public static List getContacts() 10 | { 11 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 12 | 13 | //:NoApex NoApex.Serilog.LogInfo(contacts.size().ToString()); 14 | return contacts; 15 | } 16 | 17 | public static void callingNonApexCode() 18 | { 19 | //:NoApex NoApex.Serilog.LogInfo("Hi"); 20 | } 21 | 22 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 23 | //:NoApex public static void NoApexMethodTwo() 24 | //:NoApex { 25 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 26 | //:NoApex } 27 | } 28 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex2_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassNoApex { 2 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 3 | public static void MethodOne() 4 | { 5 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 6 | } 7 | 8 | public static List getContacts() 9 | { 10 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 11 | //:NoApex NoApex.Serilog.LogInfo(contacts.size().ToString()); 12 | return contacts; 13 | } 14 | 15 | public static void callingNonApexCode() 16 | { 17 | //:NoApex NoApex.Serilog.LogInfo("Hi"); 18 | } 19 | 20 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 21 | //:NoApex public static void NoApexMethodTwo() 22 | //:NoApex { 23 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 24 | //:NoApex } 25 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassNoApex 11 | { 12 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 13 | public static void MethodOne() 14 | { 15 | NoApex.Serilog.LogInfo("Jay"); 16 | } 17 | 18 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 19 | public static void NoApexMethodTwo() 20 | { 21 | NoApex.Serilog.LogInfo("Jay"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassNoApex 2 | { 3 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 4 | public static void MethodOne() 5 | { 6 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 7 | } 8 | 9 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 10 | //:NoApex public static void NoApexMethodTwo() 11 | //:NoApex { 12 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 13 | //:NoApex } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassNoApex_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassNoApex { 2 | // Any classes in NoApex name space will be commented out in Apex and uncommented on c#. 3 | public static void MethodOne() 4 | { 5 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 6 | } 7 | 8 | 9 | // Any method in NoApex name space will be commented out in Apex and uncommented on c#. 10 | //:NoApex public static void NoApexMethodTwo() 11 | //:NoApex { 12 | //:NoApex NoApex.Serilog.LogInfo("Jay"); 13 | //:NoApex } 14 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassRestTest_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class ClassRestTest 13 | { 14 | [Test] 15 | public static void PostTest() 16 | { 17 | RestContext.Request = new RestRequest(); 18 | RestContext.Response = new RestResponse(); 19 | ClassRest.ContactDTO contact = new ClassRest.ContactDTO(); 20 | contact.LastName = "LastName"; 21 | RestContext.Request.RequestBody = Blob.ValueOf(JSON.Serialize(contact)); 22 | ClassRest.Post(); 23 | System.AssertEquals(200, RestContext.Response.StatusCode); 24 | List contacts = Soql.query(@"SELECT Id FROM Contact WHERE LastName = 'LastName'"); 25 | System.AssertEquals(1, contacts.Size()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassRestTest_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class ClassRestTest 3 | { 4 | @IsTest 5 | public static void PostTest() 6 | { 7 | RestContext.Request = new RestRequest(); 8 | RestContext.Response = new RestResponse(); 9 | ClassRest.ContactDTO contact = new ClassRest.ContactDTO(); 10 | contact.LastName = 'LastName'; 11 | RestContext.Request.RequestBody = Blob.ValueOf(JSON.Serialize(contact)); 12 | ClassRest.Post(); 13 | System.AssertEquals(200, RestContext.Response.StatusCode); 14 | List contacts = [SELECT Id FROM Contact WHERE LastName = 'LastName']; 15 | System.AssertEquals(1, contacts.Size()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassRestTest_Original.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class ClassRestTest { 3 | @isTest 4 | public static void PostTest() { 5 | 6 | RestContext.Request = new RestRequest(); 7 | RestContext.Response = new RestResponse(); 8 | 9 | ClassRest.ContactDTO contact = new ClassRest.ContactDTO(); 10 | contact.LastName = 'LastName'; 11 | 12 | RestContext.Request.RequestBody = Blob.ValueOf(JSON.Serialize(contact)); 13 | ClassRest.Post(); 14 | 15 | System.AssertEquals(200, RestContext.Response.StatusCode); 16 | 17 | List contacts = [SELECT Id FROM Contact WHERE LastName = 'LastName']; 18 | System.AssertEquals(1, contacts.Size()); 19 | } 20 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassRest_Formatted.cls: -------------------------------------------------------------------------------- 1 | @RestResource(urlMapping='/api/RestDemo') 2 | global class ClassRest 3 | { 4 | public class ContactDTO 5 | { 6 | public String LastName { get; set; } 7 | } 8 | 9 | @HttpPost 10 | global static void Post() 11 | { 12 | try 13 | { 14 | ContactDTO contact = (ContactDTO)JSON.Deserialize(RestContext.Request.RequestBody.ToString(), ContactDTO.class); 15 | InsertContact(contact); 16 | RestContext.Response.StatusCode = 200; 17 | } 18 | catch (Exception e) 19 | { 20 | RestContext.Response.StatusCode = 500; 21 | } 22 | } 23 | 24 | public static void InsertContact(ContactDTO contactToSave) 25 | { 26 | Contact contact = new Contact(); 27 | contact.LastName = contactToSave.LastName; 28 | insert contact; 29 | } 30 | 31 | @HttpGet 32 | global static String Get() 33 | { 34 | return 'Jay'; 35 | } 36 | 37 | @HttpPatch 38 | global static void Patch() 39 | { 40 | } 41 | 42 | @HttpPut 43 | global static void Put() 44 | { 45 | } 46 | 47 | @HttpDelete 48 | global static void DoDelete() 49 | { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassRest_Original.cls: -------------------------------------------------------------------------------- 1 | @RestResource(urlMapping='/api/RestDemo') 2 | global class ClassRest 3 | { 4 | public class ContactDTO { 5 | public String LastName {get;set;} 6 | } 7 | 8 | @httpPost 9 | global static void Post() { 10 | 11 | try { 12 | ContactDTO contact = (ContactDTO) JSON.Deserialize(RestContext.Request.RequestBody.ToString(), ContactDTO.class); 13 | InsertContact(contact); 14 | RestContext.Response.StatusCode = 200; 15 | } catch (Exception e) { 16 | RestContext.Response.StatusCode = 500; 17 | } 18 | } 19 | 20 | public static void InsertContact(ContactDTO contactToSave) { 21 | Contact contact = new Contact(); 22 | contact.LastName = contactToSave.LastName; 23 | insert contact; 24 | } 25 | 26 | @httpGet 27 | global static string Get() { 28 | return 'Jay'; 29 | } 30 | 31 | @httpPatch 32 | global static void Patch() { 33 | } 34 | 35 | @httpPut 36 | global static void Put() { 37 | } 38 | 39 | @httpDelete 40 | global static void DoDelete() { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestRunAs_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ClassUnitTestRunAs 11 | { 12 | static void RunAsExample() 13 | { 14 | User newUser = Soql.query(@"SELECT Id FROM User LIMIT 1"); 15 | using (System.runAs(newUser)) 16 | { 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestRunAs_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ClassUnitTestRunAs 2 | { 3 | static void RunAsExample() 4 | { 5 | User newUser = [SELECT Id FROM User LIMIT 1]; 6 | System.runAs(newUser) 7 | { 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestRunAs_Original.cls: -------------------------------------------------------------------------------- 1 | public class ClassUnitTestRunAs 2 | { 3 | static void RunAsExample() 4 | { 5 | User newUser = [SELECT Id FROM User LIMIT 1]; 6 | System.RunAs(newUser) 7 | { 8 | 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestSeeAllData_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture(SeeAllData=true)] 12 | public class ClassUnitTestSeeAllData 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestSeeAllData_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest(SeeAllData=true) 2 | public class ClassUnitTestSeeAllData 3 | { 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTestSeeAllData_Original.cls: -------------------------------------------------------------------------------- 1 | @isTest(SeeAllData=true) 2 | public class ClassUnitTestSeeAllData 3 | { 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTest_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class ClassUnitTest 13 | { 14 | [SetUp] 15 | public static void Setup() 16 | { 17 | System.Debug("One Time Setup Got Called"); 18 | } 19 | 20 | [Test] 21 | public static void Assert() 22 | { 23 | System.Assert(true, "Assert True"); 24 | } 25 | 26 | [Test] 27 | public static void AssertTestMethod() 28 | { 29 | System.Assert(true, "Assert True"); 30 | } 31 | 32 | [Test] 33 | public static void AssertEquals() 34 | { 35 | System.AssertEquals(5, 5, "Assert Equal"); 36 | } 37 | 38 | [Test] 39 | public static void AssertEqualsTestMethod() 40 | { 41 | System.AssertEquals(5, 5, "Assert Equal"); 42 | } 43 | 44 | [Test] 45 | public static void AssertNotEquals() 46 | { 47 | System.AssertNotEquals(5, 0, "Assert Not Equal"); 48 | } 49 | 50 | [Test] 51 | public static void AssertNotTestMethod() 52 | { 53 | System.AssertNotEquals(5, 0, "Assert Not Equal"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTest_Converted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class ClassUnitTest 3 | { 4 | @TestSetup 5 | public static void Setup() 6 | { 7 | System.Debug('One Time Setup Got Called'); 8 | } 9 | 10 | @IsTest 11 | public static void Assert() 12 | { 13 | System.Assert(true, 'Assert True'); 14 | } 15 | 16 | @IsTest 17 | public static void AssertTestMethod() 18 | { 19 | System.Assert(true, 'Assert True'); 20 | } 21 | 22 | @IsTest 23 | public static void AssertEquals() 24 | { 25 | System.AssertEquals(5, 5, 'Assert Equal'); 26 | } 27 | 28 | @IsTest 29 | public static void AssertEqualsTestMethod() 30 | { 31 | System.AssertEquals(5, 5, 'Assert Equal'); 32 | } 33 | 34 | @IsTest 35 | public static void AssertNotEquals() 36 | { 37 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 38 | } 39 | 40 | @IsTest 41 | public static void AssertNotTestMethod() 42 | { 43 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTest_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class ClassUnitTest 3 | { 4 | @TestSetup 5 | public static void Setup() 6 | { 7 | System.Debug('One Time Setup Got Called'); 8 | } 9 | 10 | @IsTest 11 | public static void Assert() 12 | { 13 | System.Assert(true, 'Assert True'); 14 | } 15 | 16 | public static testMethod void AssertTestMethod() 17 | { 18 | System.Assert(true, 'Assert True'); 19 | } 20 | 21 | @IsTest 22 | public static void AssertEquals() 23 | { 24 | System.AssertEquals(5, 5, 'Assert Equal'); 25 | } 26 | 27 | public static testMethod void AssertEqualsTestMethod() 28 | { 29 | System.AssertEquals(5, 5, 'Assert Equal'); 30 | } 31 | 32 | @IsTest 33 | public static void AssertNotEquals() 34 | { 35 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 36 | } 37 | 38 | public static testMethod void AssertNotTestMethod() 39 | { 40 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassUnitTest_Original.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class ClassUnitTest { 3 | @TestSetup 4 | public static void Setup() { 5 | System.Debug('One Time Setup Got Called'); 6 | } 7 | 8 | @isTest 9 | public static void Assert() { 10 | System.Assert(true, 'Assert True'); 11 | } 12 | public static testMethod void AssertTestMethod() { 13 | System.Assert(true, 'Assert True'); 14 | } 15 | 16 | @isTest 17 | public static void AssertEquals() { 18 | System.AssertEquals(5, 5, 'Assert Equal'); 19 | } 20 | public static testMethod void AssertEqualsTestMethod() { 21 | System.AssertEquals(5, 5, 'Assert Equal'); 22 | } 23 | 24 | @isTest 25 | public static void AssertNotEquals() { 26 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 27 | } 28 | 29 | public static testMethod void AssertNotTestMethod() { 30 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 31 | } 32 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithOutSharing_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [WithoutSharing] 11 | public class ClassWithOutSharing 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithOutSharing_Formatted.cls: -------------------------------------------------------------------------------- 1 | public without sharing class ClassWithOutSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithOutSharing_Original.cls: -------------------------------------------------------------------------------- 1 | public without sharing class ClassWithOutSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithSharing_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [WithSharing] 11 | public class ClassWithSharing 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithSharing_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassWithSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ClassWithSharing_Original.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassWithSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/Comments_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | /** 11 | * This comment belongs to the Class Syntax 12 | */ 13 | [WithSharing] 14 | public class Comments 15 | { 16 | // This comment belongs to the Method Syntax 17 | public static void DemoMethod() 18 | { 19 | int demoValue = 5; // Side Line Comment 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/Comments_Formatted.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * This comment belongs to the Class Syntax 3 | */ 4 | public with sharing class Comments 5 | { 6 | // This comment belongs to the Method Syntax 7 | public static void DemoMethod() 8 | { 9 | Integer demoValue = 5; // Side Line Comment 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/Comments_Original.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * This comment belongs to the Class Syntax 3 | */ 4 | public with sharing class Comments 5 | /** 6 | * This comment belongs to the Class Syntax 7 | */ 8 | // This comment belongs to the open bracket syntax 9 | { 10 | 11 | // This comment belongs to the Method Syntax 12 | public static void DemoMethod() { 13 | Integer demoValue = 5; // Side Line Comment 14 | } 15 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoControllerTests_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class DemoControllerTests 13 | { 14 | [Test] 15 | static void testConstructor() 16 | { 17 | // Contact contact = new Contact(LastName='Smith'); 18 | // insert contact; 19 | // Test.setCurrentPage(Page.DemoPage); 20 | // ApexPages.currentPage().getParameters().put('lastName', 'Smith'); 21 | // DemoController demo = new DemoController(new ApexPages.StandardController(contact)); 22 | // System.assertEquals(contact.Id, ApexPages.currentPage().getParameters().get('id')); 23 | } 24 | 25 | [Test] 26 | static void testGetAppVersion() 27 | { 28 | DemoController demo = new DemoController(); 29 | 30 | // System.assertEquals(demo.getAppVersion(), '1.0.0'); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoControllerTests_Formatted.cls: -------------------------------------------------------------------------------- 1 | 2 | @isTest 3 | public class DemoControllerTests { 4 | @isTest static void testConstructor() { 5 | // Contact contact = new Contact(LastName='Smith'); 6 | // insert contact; 7 | 8 | // Test.setCurrentPage(Page.DemoPage); 9 | // ApexPages.currentPage().getParameters().put('lastName', 'Smith'); 10 | 11 | // DemoController demo = new DemoController(new ApexPages.StandardController(contact)); 12 | // System.assertEquals(contact.Id, ApexPages.currentPage().getParameters().get('id')); 13 | } 14 | 15 | @isTest static void testGetAppVersion() { 16 | DemoController demo = new DemoController(); 17 | // System.assertEquals(demo.getAppVersion(), '1.0.0'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoControllerTests_Original.cls: -------------------------------------------------------------------------------- 1 | 2 | @isTest 3 | public class DemoControllerTests { 4 | @isTest static void testConstructor() { 5 | // Contact contact = new Contact(LastName='Smith'); 6 | // insert contact; 7 | 8 | // Test.setCurrentPage(Page.DemoPage); 9 | // ApexPages.currentPage().getParameters().put('lastName', 'Smith'); 10 | 11 | // DemoController demo = new DemoController(new ApexPages.StandardController(contact)); 12 | // System.assertEquals(contact.Id, ApexPages.currentPage().getParameters().get('id')); 13 | } 14 | 15 | @isTest static void testGetAppVersion() { 16 | DemoController demo = new DemoController(); 17 | // System.assertEquals(demo.getAppVersion(), '1.0.0'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoController_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [WithSharing] 11 | public class DemoController 12 | { 13 | /** 14 | * An empty constructor for the testing 15 | */ 16 | public DemoController() 17 | { 18 | } 19 | 20 | /** 21 | * Set the contact for the page using the lastName parameter, if there is one 22 | */ 23 | // public DemoController(ApexPages.StandardController controller) { 24 | // Get the last name from the url 25 | // String lastName = ApexPages.currentPage().getParameters().get('lastName'); 26 | // if (lastName != null) { 27 | // Query the object 28 | // Contact theContact = [SELECT ID FROM Contact WHERE LastName = :lastName LIMIT 1]; 29 | // this will set the Id, so now you can use the standard controller and just reference fields on the page 30 | // ApexPages.currentPage().getParameters().put('id', theContact.Id); 31 | // } 32 | // } 33 | /** 34 | * Get the version of the SFDX demo app 35 | */ 36 | public string getAppVersion() 37 | { 38 | return "1.0.0"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoController_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class DemoController 2 | { 3 | /** 4 | * An empty constructor for the testing 5 | */ 6 | public DemoController() 7 | { 8 | } 9 | 10 | /** 11 | * Set the contact for the page using the lastName parameter, if there is one 12 | */ 13 | // public DemoController(ApexPages.StandardController controller) { 14 | // Get the last name from the url 15 | // String lastName = ApexPages.currentPage().getParameters().get('lastName'); 16 | // if (lastName != null) { 17 | // Query the object 18 | // Contact theContact = [SELECT ID FROM Contact WHERE LastName = :lastName LIMIT 1]; 19 | // this will set the Id, so now you can use the standard controller and just reference fields on the page 20 | // ApexPages.currentPage().getParameters().put('id', theContact.Id); 21 | // } 22 | // } 23 | /** 24 | * Get the version of the SFDX demo app 25 | */ 26 | public String getAppVersion() 27 | { 28 | return '1.0.0'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoController_Original.cls: -------------------------------------------------------------------------------- 1 | public with sharing class DemoController { 2 | /** 3 | * An empty constructor for the testing 4 | */ 5 | public DemoController() {} 6 | 7 | /** 8 | * Set the contact for the page using the lastName parameter, if there is one 9 | */ 10 | // public DemoController(ApexPages.StandardController controller) { 11 | // Get the last name from the url 12 | // String lastName = ApexPages.currentPage().getParameters().get('lastName'); 13 | 14 | // if (lastName != null) { 15 | // Query the object 16 | // Contact theContact = [SELECT ID FROM Contact WHERE LastName = :lastName LIMIT 1]; 17 | 18 | // this will set the Id, so now you can use the standard controller and just reference fields on the page 19 | // ApexPages.currentPage().getParameters().put('id', theContact.Id); 20 | // } 21 | // } 22 | 23 | /** 24 | * Get the version of the SFDX demo app 25 | */ 26 | public String getAppVersion() { 27 | return '1.0.0'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoTest_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class DemoTest 13 | { 14 | [SetUp] 15 | public static void Setup() 16 | { 17 | Contact contactNew = new Contact(); 18 | contactNew.LastName = "Jay"; 19 | contactNew.Email = "jay@jay.com"; 20 | Soql.insert(contactNew); 21 | } 22 | 23 | [Test] 24 | public static void UpdatePhoneTestValidEmail() 25 | { 26 | Demo.UpdatePhone("jay@jay.com", "555-1212"); 27 | List contacts = Soql.query(@"SELECT ID, Email, Phone FROM Contact WHERE Email = 'jay@jay.com'"); 28 | System.AssertEquals(contacts[0].Phone, "555-1212"); 29 | } 30 | 31 | [Test] 32 | public static void UpdatePhoneTestNotValidEmail() 33 | { 34 | Demo.UpdatePhone("nojay@jay.com", "555-1212"); 35 | List contacts = Soql.query(@"SELECT ID, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com'"); 36 | System.AssertEquals(contacts.Size(), 0); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoTest_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class DemoTest 3 | { 4 | @TestSetup 5 | public static void Setup() 6 | { 7 | Contact contactNew = new Contact(); 8 | contactNew.LastName = 'Jay'; 9 | contactNew.Email = 'jay@jay.com'; 10 | insert contactNew; 11 | } 12 | 13 | @IsTest 14 | public static void UpdatePhoneTestValidEmail() 15 | { 16 | Demo.UpdatePhone('jay@jay.com', '555-1212'); 17 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'jay@jay.com']; 18 | System.AssertEquals(contacts[0].Phone, '555-1212'); 19 | } 20 | 21 | @IsTest 22 | public static void UpdatePhoneTestNotValidEmail() 23 | { 24 | Demo.UpdatePhone('nojay@jay.com', '555-1212'); 25 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com']; 26 | System.AssertEquals(contacts.Size(), 0); 27 | } 28 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/DemoTest_Original.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public class DemoTest 3 | { 4 | @TestSetup 5 | public static void Setup() 6 | { 7 | Contact contactNew = new Contact(); 8 | contactNew.LastName = 'Jay'; 9 | contactNew.Email = 'jay@jay.com'; 10 | insert contactNew; 11 | } 12 | @IsTest 13 | public static void UpdatePhoneTestValidEmail() 14 | { 15 | Demo.UpdatePhone('jay@jay.com', '555-1212'); 16 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'jay@jay.com']; 17 | System.AssertEquals(contacts[0].Phone, '555-1212'); 18 | } 19 | @IsTest 20 | public static void UpdatePhoneTestNotValidEmail() 21 | { 22 | Demo.UpdatePhone('nojay@jay.com', '555-1212'); 23 | List contacts = [SELECT ID, Email, Phone FROM Contact WHERE Email = 'nojay@jay.com']; 24 | System.AssertEquals(contacts.Size(), 0); 25 | } 26 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/Demo_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class Demo 2 | { 3 | public Contact contact { get; set; } 4 | 5 | public Demo() 6 | { 7 | contact = new Contact(); 8 | } 9 | 10 | public PageReference Save() 11 | { 12 | try 13 | { 14 | insert contact; 15 | } 16 | catch (DmlException e) 17 | { 18 | ApexPages.AddMessages(e); 19 | } 20 | 21 | return null; 22 | } 23 | 24 | public static String UpdatePhone(String email, String newPhone) 25 | { 26 | List contacts = GetContactByEMail(email); 27 | if (contacts.IsEmpty()) 28 | { 29 | return 'Not Found'; 30 | } 31 | else 32 | { 33 | contacts[0].Phone = newPhone; 34 | UpdateContacts(contacts); 35 | return 'Phone Number Updated'; 36 | } 37 | } 38 | 39 | public static List GetContactByEMail(String email) 40 | { 41 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email]; 42 | return contacts; 43 | } 44 | 45 | public static List GetContacts() 46 | { 47 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 48 | return contacts; 49 | } 50 | 51 | public static void UpdateContacts(List contacts) 52 | { 53 | update contacts; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/Demo_Original.cls: -------------------------------------------------------------------------------- 1 | public class Demo 2 | { 3 | public Contact contact { get; set; } 4 | 5 | public Demo() 6 | { 7 | contact = new Contact(); 8 | } 9 | 10 | public PageReference Save() 11 | { 12 | try 13 | { 14 | insert contact; 15 | } 16 | catch (DmlException e) 17 | { 18 | ApexPages.AddMessages(e); 19 | } 20 | 21 | return null; 22 | } 23 | 24 | public static string UpdatePhone(string email, string newPhone) 25 | { 26 | List contacts = GetContactByEMail(email); 27 | if (contacts.IsEmpty()) 28 | { 29 | return 'Not Found'; 30 | } 31 | else 32 | { 33 | contacts[0].Phone = newPhone; 34 | UpdateContacts(contacts); 35 | return 'Phone Number Updated'; 36 | } 37 | } 38 | 39 | public static List GetContactByEMail(string email) 40 | { 41 | List contacts = [SELECT Id, Email, Phone FROM Contact WHERE Email = :email]; 42 | return contacts; 43 | } 44 | 45 | public static List GetContacts() 46 | { 47 | List contacts = [SELECT Id, Email, Phone FROM Contact]; 48 | return contacts; 49 | } 50 | 51 | public static void UpdateContacts(List contacts) 52 | { 53 | update contacts; 54 | } 55 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ExceptionDemo_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class ExceptionDemo 11 | { 12 | public static void CatchDemo() 13 | { 14 | try 15 | { 16 | ThrowDemo(); 17 | } 18 | catch (MathException e) 19 | { 20 | System.Debug(e.GetMessage()); 21 | } 22 | finally 23 | { 24 | System.Debug("Finally"); 25 | } 26 | } 27 | 28 | public static void ThrowDemo() 29 | { 30 | throw new MathException("something bad happened!"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ExceptionDemo_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class ExceptionDemo 2 | { 3 | public static void CatchDemo() 4 | { 5 | try 6 | { 7 | ThrowDemo(); 8 | } 9 | catch (MathException e) 10 | { 11 | System.Debug(e.GetMessage()); 12 | } 13 | finally 14 | { 15 | System.Debug('Finally'); 16 | } 17 | } 18 | 19 | public static void ThrowDemo() 20 | { 21 | throw new MathException('something bad happened!'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/ExceptionDemo_Original.cls: -------------------------------------------------------------------------------- 1 | public class ExceptionDemo 2 | { 3 | public static void CatchDemo() 4 | { 5 | try 6 | { 7 | ThrowDemo(); 8 | } 9 | catch (MathException e) 10 | { 11 | System.Debug(e.GetMessage()); 12 | } 13 | finally 14 | { 15 | System.Debug('Finally'); 16 | } 17 | } 18 | 19 | public static void ThrowDemo() 20 | { 21 | throw new MathException('something bad happened!'); 22 | } 23 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/GetSetDemo_Original.cls: -------------------------------------------------------------------------------- 1 | public class GetSetDemo { 2 | public double MyReadWritePropPublic { get; set; } 3 | private Integer propPrvt; 4 | public Integer prop { 5 | get { 6 | return propPrvt; 7 | } 8 | set { 9 | propPrvt = value; 10 | } 11 | } 12 | public Integer MyReadOnlyProp { 13 | get; 14 | } 15 | 16 | private static Integer myStaticPropPrvt; 17 | public static Integer MyStaticProp { 18 | get { 19 | return myStaticPropPrvt; 20 | } 21 | } 22 | 23 | Integer MyReadOnlyPropPrvt { get;} 24 | double MyReadWritePropPrvt {get; set; 25 | } 26 | public string MyWriteOnlyProp {get; } 27 | protected string MyWriteOnlyPropPrvt { set; get; 28 | } 29 | 30 | private string namePrvt; 31 | 32 | public string getName { 33 | get { 34 | return namePrvt; 35 | } 36 | private set { 37 | namePrvt = value; 38 | } 39 | } 40 | public string Stubbing { 41 | private get { 42 | return namePrvt; 43 | } 44 | set { 45 | namePrvt = value; 46 | } 47 | } 48 | public string DoThrowWhenException { 49 | get { 50 | return namePrvt; 51 | } 52 | set { 53 | namePrvt = value; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterfaceExt_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public interface IClassInterfaceExt 11 | { 12 | // ID GetId(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterfaceExt_Formatted.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterfaceExt 2 | { 3 | // ID GetId(); 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterfaceExt_Original.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterfaceExt { 2 | // ID GetId(); 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterface_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public interface IClassInterface : IClassInterfaceExt 11 | { 12 | string GetName(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterface_Formatted.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterface extends IClassInterfaceExt 2 | { 3 | String GetName(); 4 | } 5 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/IClassInterface_Original.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterface extends IClassInterfaceExt { 2 | string GetName(); 3 | } 4 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/JsonExample_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class JsonExample 11 | { 12 | public void JsonExampleMethod() 13 | { 14 | Contact contact = new Contact(); 15 | contact.LastName = "Jay"; 16 | contact.Email = "jay@jay.com"; 17 | string jsonString = JSON.Serialize(contact); 18 | Contact newContact = (Contact)JSON.Deserialize(jsonString, typeof(Contact)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/JsonExample_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class JsonExample 2 | { 3 | public void JsonExampleMethod() 4 | { 5 | Contact contact = new Contact(); 6 | contact.LastName = 'Jay'; 7 | contact.Email = 'jay@jay.com'; 8 | String jsonString = JSON.Serialize(contact); 9 | Contact newContact = (Contact)JSON.Deserialize(jsonString, Contact.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/JsonExample_Original.cls: -------------------------------------------------------------------------------- 1 | public class JsonExample 2 | { 3 | public void JsonExampleMethod() 4 | { 5 | Contact contact = new Contact(); 6 | contact.LastName = 'Jay'; 7 | contact.Email = 'jay@jay.com'; 8 | 9 | String jsonString = JSON.Serialize(contact); 10 | Contact newContact = (Contact)JSON.Deserialize(jsonString, Contact.class); 11 | } 12 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/MethodComplex_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [WithSharing] 11 | public class MethodComplex 12 | { 13 | public static void MethodOne() 14 | { 15 | foreach (Account a in Soql.query(@"SELECT Id FROM Account")) 16 | { 17 | System.Debug(a.Id); 18 | } 19 | 20 | for (int i = 0; i<10; i++) 21 | { 22 | } 23 | } 24 | 25 | public Database.QueryLocator QueryLocator(Database.BatchableContext bc) 26 | { 27 | return Database.GetQueryLocator(Soql.query(@"SELECT Id FROM Contact")); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/MethodComplex_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class MethodComplex 2 | { 3 | public static void MethodOne() 4 | { 5 | for (Account a : [SELECT Id FROM Account]) 6 | { 7 | System.Debug(a.Id); 8 | } 9 | 10 | for (Integer i = 0; i<10; i++) 11 | { 12 | } 13 | } 14 | 15 | public Database.QueryLocator QueryLocator(Database.BatchableContext bc) 16 | { 17 | return Database.GetQueryLocator([SELECT Id FROM Contact]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/MethodComplex_Original.cls: -------------------------------------------------------------------------------- 1 | public with sharing class MethodComplex { 2 | public static void MethodOne() { 3 | 4 | for (Account a : [SELECT Id FROM Account]) { 5 | System.Debug(a.Id); 6 | } 7 | 8 | for (Integer i=0;i<10;i++) { 9 | 10 | } 11 | } 12 | 13 | public Database.QueryLocator QueryLocator(Database.BatchableContext bc) 14 | { 15 | return Database.GetQueryLocator([SELECT Id FROM Contact]); 16 | } 17 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/PrimitiveTypes_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class PrimitiveTypes 11 | { 12 | public Blob MyBlob = Blob.ValueOf("Jay"); 13 | 14 | public bool IsWinner = true; 15 | 16 | public Date MyDate = Date.today(); 17 | 18 | public Datetime MyDateTime = Datetime.now(); 19 | 20 | private Date AnotherDate = Date.today().date(); 21 | 22 | public decimal MyDecimal = 12.4567m; 23 | 24 | //public Double d=3.133433; 25 | public ID MyId = "006E0000004TquXIAS"; 26 | 27 | public int MyInteger = 1; 28 | 29 | public long MyLong = 23432424242L; 30 | 31 | public Time MyTime = Time.NewInstance(1, 2, 3, 4); 32 | 33 | public string MyString = "Jay"; 34 | 35 | public string abc, def, jkl; 36 | 37 | public void DemoMethod() 38 | { 39 | object obj = 10; 40 | int i = (int)obj; 41 | string abc1, def1, jkl1; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/PrimitiveTypes_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class PrimitiveTypes 2 | { 3 | public Blob MyBlob = Blob.ValueOf('Jay'); 4 | 5 | public Boolean IsWinner = true; 6 | 7 | public Date MyDate = Date.today(); 8 | 9 | public Datetime MyDateTime = Datetime.now(); 10 | 11 | private Date AnotherDate = Date.today().date(); 12 | 13 | public Decimal MyDecimal = 12.4567; 14 | 15 | //public Double d=3.133433; 16 | public ID MyId = '006E0000004TquXIAS'; 17 | 18 | public Integer MyInteger = 1; 19 | 20 | public Long MyLong = 23432424242L; 21 | 22 | public Time MyTime = Time.NewInstance(1, 2, 3, 4); 23 | 24 | public String MyString = 'Jay'; 25 | 26 | public String abc, def, jkl; 27 | 28 | public void DemoMethod() 29 | { 30 | Object obj = 10; 31 | Integer i = (Integer)obj; 32 | String abc1, def1, jkl1; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/PrimitiveTypes_Original.cls: -------------------------------------------------------------------------------- 1 | public class PrimitiveTypes 2 | { 3 | public Blob MyBlob = Blob.ValueOf('Jay'); 4 | public Boolean IsWinner = true; 5 | 6 | public Date MyDate = Date.today(); 7 | public Datetime MyDateTime = Datetime.now(); 8 | private Date AnotherDate = Date.today().date(); 9 | 10 | public Decimal MyDecimal = 12.4567; 11 | //public Double d=3.133433; 12 | public Id MyId = '006E0000004TquXIAS'; 13 | public Integer MyInteger = 1; 14 | public Long MyLong = 23432424242L; 15 | public Time MyTime = Time.NewInstance(1, 2, 3, 4); 16 | public String MyString = 'Jay'; 17 | 18 | public string abc, def, jkl; 19 | 20 | public void DemoMethod() 21 | { 22 | object obj = 10; 23 | Integer i = (Integer)obj; 24 | string abc1, def1, jkl1; 25 | } 26 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/PropertyAndField_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class PropertyAndField 2 | { 3 | public Datetime DateTimeGetSet { get; set; } 4 | 5 | public List DateTimeGetSetGeneric { get; set; } 6 | 7 | public Datetime[] DateTimeGetSetArray { get; set; } 8 | 9 | public Datetime DateTimeEmpty; 10 | 11 | public Datetime DateTimeInitialized = Datetime.Now(); 12 | 13 | public List DateTimeList = new List(); 14 | 15 | public Datetime[] DateTimeArray = new Datetime[5]; 16 | 17 | public String Name = 'jay'; 18 | 19 | public final String nameFinal = 'jay'; 20 | 21 | public static String NameStatic = 'jay'; 22 | 23 | public static final String NameStaticFinal = 'jay'; 24 | 25 | public List ContactList = [SELECT Id, Email FROM Contact]; 26 | 27 | public Set stringSet = new Set{}; 28 | 29 | public Boolean shouldRedirect { get; set; } 30 | 31 | // not supported yet, see issue #8 32 | // { 33 | // shouldRedirect = false; 34 | // } 35 | // 36 | public String[] newStringArray = new String[]{'Hi'}; 37 | 38 | public void MethodOne() 39 | { 40 | Datetime dateTimeEmpty; 41 | dateTimeEmpty = Datetime.Now(); 42 | Datetime dateTimeInitilized = Datetime.Now(); 43 | List dateTimeList = new List(); 44 | Datetime[] dateTimeArrary = new Datetime[5]; 45 | String name; 46 | name = 'Jay'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/PropertyAndField_Original.cls: -------------------------------------------------------------------------------- 1 | public class PropertyAndField 2 | { 3 | public DateTime DateTimeGetSet { get; set; } 4 | public List DateTimeGetSetGeneric { get; set; } 5 | public Datetime[] DateTimeGetSetArray { get; set; } 6 | public Datetime DateTimeEmpty; 7 | public Datetime DateTimeInitialized = Datetime.Now(); 8 | public List DateTimeList = new List(); 9 | public DateTime[] DateTimeArray = new DateTime[5]; 10 | public string Name = 'jay'; 11 | public final string nameFinal = 'jay'; 12 | public static string NameStatic = 'jay'; 13 | public static final string NameStaticFinal = 'jay'; 14 | 15 | public List ContactList = [SELECT Id, Email FROM Contact]; 16 | 17 | public Set stringSet = new Set{}; 18 | 19 | public boolean shouldRedirect { get;set; } 20 | 21 | // not supported yet, see issue #8 22 | // { 23 | // shouldRedirect = false; 24 | // } 25 | // 26 | public string[] newStringArray = new string[] {'Hi'}; 27 | 28 | public void MethodOne() 29 | { 30 | Datetime dateTimeEmpty; 31 | dateTimeEmpty = Datetime.Now(); 32 | Datetime dateTimeInitilized = Datetime.Now(); 33 | List dateTimeList = new List(); 34 | Datetime[] dateTimeArrary = new Datetime[5]; 35 | string name; 36 | name = 'Jay'; 37 | } 38 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/RunAll_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | [WithSharing] 13 | public class RunAll 14 | { 15 | [Test] 16 | public static void TestClassess() 17 | { 18 | System.Debug(ClassEnum.America); 19 | System.Debug(new ClassException()); 20 | System.Debug(new ClassGlobal()); 21 | ClassInitialization newClassInitialization = new ClassInitialization(); 22 | System.Debug(ClassInitialization.colorMap); 23 | System.Debug(newClassInitialization.contactList); 24 | ClassInterface classInterface = new ClassInterface(); 25 | System.Debug(classInterface.GetName()); 26 | System.Debug(new ClassInternal.InternalClassOne()); 27 | System.Debug(new ClassInternal.InternalClassTwo()); 28 | System.Debug(new ClassUnitTestSeeAllData()); 29 | System.Debug(new ClassWithOutSharing()); 30 | System.Debug(new ClassWithSharing()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/RunAll_Formatted.cls: -------------------------------------------------------------------------------- 1 | @IsTest 2 | public with sharing class RunAll 3 | { 4 | @IsTest 5 | public static void TestClassess() 6 | { 7 | System.Debug(ClassEnum.America); 8 | System.Debug(new ClassException()); 9 | System.Debug(new ClassGlobal()); 10 | ClassInitialization newClassInitialization = new ClassInitialization(); 11 | System.Debug(ClassInitialization.colorMap); 12 | System.Debug(newClassInitialization.contactList); 13 | ClassInterface classInterface = new ClassInterface(); 14 | System.Debug(classInterface.GetName()); 15 | System.Debug(new ClassInternal.InternalClassOne()); 16 | System.Debug(new ClassInternal.InternalClassTwo()); 17 | System.Debug(new ClassUnitTestSeeAllData()); 18 | System.Debug(new ClassWithOutSharing()); 19 | System.Debug(new ClassWithSharing()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/RunAll_Original.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | public with sharing class RunAll 3 | { 4 | @isTest 5 | public static void TestClassess() { 6 | System.Debug(ClassEnum.America); 7 | System.Debug(new ClassException()); 8 | System.Debug(new ClassGlobal()); 9 | 10 | ClassInitialization newClassInitialization = new ClassInitialization(); 11 | System.Debug(ClassInitialization.colorMap); 12 | System.Debug(newClassInitialization.contactList); 13 | 14 | ClassInterface classInterface = new ClassInterface(); 15 | System.Debug(classInterface.GetName()); 16 | 17 | System.Debug(new ClassInternal.InternalClassOne()); 18 | System.Debug(new ClassInternal.InternalClassTwo()); 19 | 20 | System.Debug(new ClassUnitTestSeeAllData()); 21 | 22 | System.Debug(new ClassWithOutSharing()); 23 | System.Debug(new ClassWithSharing()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/SwitchDemo_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | public class SwitchDemo 11 | { 12 | public static void Method() 13 | { 14 | int x = 123; 15 | switch (x) 16 | { 17 | case 5: 18 | case 6: 19 | case 7: 20 | System.debug("Cool!"); // 1 21 | break; 22 | 23 | case string c: 24 | switch (c) 25 | { 26 | // 2 27 | case "foo": 28 | System.debug("bar"); // 3 29 | break; 30 | 31 | default: 32 | System.debug("baz"); // 4 33 | break; // 5 34 | } 35 | 36 | System.debug("corge"); 37 | break; // 6 38 | 39 | default: 40 | return; // 7 41 | } 42 | 43 | while (true) 44 | { 45 | System.debug("quux"); // 8 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/SwitchDemo_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class SwitchDemo 2 | { 3 | public static void Method() 4 | { 5 | Integer x = 123; 6 | switch on x 7 | { 8 | when 5, 6, 7 9 | { 10 | System.debug('Cool!'); // 1 11 | } 12 | when String c 13 | { 14 | switch on c 15 | { 16 | // 2 17 | when 'foo' 18 | { 19 | System.debug('bar'); // 3 20 | } 21 | when else 22 | { 23 | System.debug('baz'); // 4 24 | } // 5 25 | } 26 | 27 | System.debug('corge'); 28 | } // 6 29 | when else 30 | { 31 | return; // 7 32 | } 33 | } 34 | 35 | while (true) 36 | { 37 | System.debug('quux'); // 8 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexRoundtrip/SwitchDemo_Original.cls: -------------------------------------------------------------------------------- 1 | public class SwitchDemo { 2 | public static void Method() { 3 | Integer x = 123; 4 | switch on x { 5 | when 5, 6, 7 { 6 | System.debug('Cool!'); // 1 7 | } 8 | when String c { 9 | switch on c { 10 | // 2 11 | when 'foo' { 12 | System.debug('bar'); // 3 13 | } 14 | when else { 15 | System.debug('baz'); // 4 16 | } // 5 17 | } 18 | 19 | System.debug('corge'); 20 | } // 6 21 | when else { 22 | return; // 7 23 | } 24 | } 25 | while (true) { 26 | System.debug('quux'); // 8 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ApplicationTest.apex: -------------------------------------------------------------------------------- 1 | @IsTest 2 | private class ApplicationTest 3 | { 4 | @IsTest 5 | private static void callingDomainFactoryShouldGiveRegisteredImplsAndMocks() 6 | { 7 | domainObjectAcct = 8 | Domain.newInstance( 9 | new List 10 | { new Account( 11 | Id = testAccountId, 12 | Name = 'Test Account') } 13 | , Account.SObjectType); 14 | 15 | try { 16 | Domain.newInstance(new List{ new Contact(LastName = 'TestContactLName') }); 17 | System.assert(false, 'Expected exception'); 18 | } catch (System.TypeException e) { 19 | System.assert(Pattern.Matches('Invalid conversion from runtime type \\w*\\.?fflib_ApplicationTest\\.ContactsConstructor to \\w*\\.?fflib_SObjectDomain\\.IConstructable', 20 | e.getMessage()), 'Exception message did not match the expected pattern: ' + e.getMessage()); 21 | } 22 | } 23 | 24 | @isTest //Tests all forms of the getDescribe static 25 | static void getAccountDescribes(){ 26 | System.assertEquals('Account', d.getDescribe().getName()); 27 | System.assert( (d === d2 && d2 === d3) ,'All three getDescribe calls should return the same cached instance.'); 28 | } 29 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassAbstract.cls: -------------------------------------------------------------------------------- 1 | // sample abstract class 2 | public abstract class ClassAbstract 3 | { 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassEnum.cls: -------------------------------------------------------------------------------- 1 | public enum ClassEnum 2 | { 3 | America, 4 | Canada, 5 | Russia 6 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassException.cls: -------------------------------------------------------------------------------- 1 | public class ClassException extends Exception 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassGlobal.cls: -------------------------------------------------------------------------------- 1 | global class ClassGlobal 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassInitialization.cls: -------------------------------------------------------------------------------- 1 | public class ClassInitialization { 2 | 3 | public List contactList; 4 | public ClassInitialization() { 5 | contactList = [SELECT ID FROM Contact LIMIT 1]; 6 | } 7 | 8 | public static Map colorMap = new Map(); 9 | 10 | static { 11 | colorMap.Put('red', '255, 0, 0'); 12 | colorMap.Put('cyan', '0, 255, 255'); 13 | colorMap.Put('magenta', '255, 0, 255'); 14 | } 15 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassInterface.cls: -------------------------------------------------------------------------------- 1 | public class ClassInterface implements IClassInterface 2 | { 3 | public Id GetId() { 4 | return ''; 5 | } 6 | public string GetName() 7 | { 8 | return 'Jay'; 9 | } 10 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassInternal.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassInternal 2 | { 3 | public class InternalClassOne 4 | { 5 | } 6 | public class InternalClassTwo 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassOne.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassOne { 2 | public void CallClassTwo() { 3 | ClassTwo classTwo = new ClassTwo(); 4 | System.debug('Test'); 5 | } 6 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassOne_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassOne 2 | { 3 | public void CallClassTwo() 4 | { 5 | ClassTwo classTwo = new ClassTwo(); 6 | System.debug('Test'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassRest.cls: -------------------------------------------------------------------------------- 1 | @RestResource(urlMapping='/api/v1/RestDemo') 2 | global class ClassRest 3 | { 4 | @httpDelete 5 | global static void DoDelete() { 6 | } 7 | 8 | @httpPost 9 | global static void Post() { 10 | } 11 | 12 | @httpGet 13 | global static string Get() { 14 | return 'Jay'; 15 | } 16 | 17 | @httpPatch 18 | global static void Patch() { 19 | } 20 | 21 | @httpPut 22 | global static void Put() { 23 | } 24 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassTwo.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassTwo { 2 | public ClassTwo() { 3 | System.debug('Test'); 4 | } 5 | 6 | public ClassTwo(String vin) { 7 | } 8 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassTwo_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassTwo 2 | { 3 | public ClassTwo() 4 | { 5 | System.debug('Test'); 6 | } 7 | 8 | public ClassTwo(String vin) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassUnitTest.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class ClassUnitTest 3 | { 4 | @TestSetup 5 | public static void Setup() 6 | { 7 | System.Debug('One Time Setup Got Called'); 8 | } 9 | @isTest 10 | public static void AssertTrue() 11 | { 12 | System.Assert(true, 'Assert True'); 13 | } 14 | @isTest 15 | public static void AssertEquals() 16 | { 17 | System.AssertEquals(5, 5, 'Assert Equal'); 18 | } 19 | @isTest 20 | public static void AssertNotEquals() 21 | { 22 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 23 | } 24 | testMethod public static void AssertNew() 25 | { 26 | System.Assert(true, 'Assert True'); 27 | } 28 | static testMethod public void AssertEqualsNew() 29 | { 30 | System.AssertEquals(5, 5, 'Assert Equal'); 31 | } 32 | static public testMethod void AssertNotEqualsNew() 33 | { 34 | System.AssertNotEquals(5, 0, 'Assert Not Equal'); 35 | } 36 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassUnitTestRunAs.cls: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class ClassUnitTestRunAs 3 | { 4 | static testMethod void RunAsExample() 5 | { 6 | User newUser = new User(); 7 | System.RunAs(newUser) 8 | { 9 | 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassUnitTestSeeAllData.cls: -------------------------------------------------------------------------------- 1 | @isTest(SeeAllData=true) 2 | public class ClassUnitTestSeeAllData 3 | { 4 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassUnitTest_CSharp.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.ApexSharp.NUnit; 8 | using Apex.System; 9 | using SObjects; 10 | 11 | [TestFixture] 12 | public class ClassUnitTest 13 | { 14 | [SetUp] 15 | public static void Setup() 16 | { 17 | System.Debug("One Time Setup Got Called"); 18 | } 19 | 20 | [Test] 21 | public static void AssertTrue() 22 | { 23 | System.Assert(true, "Assert True"); 24 | } 25 | 26 | [Test] 27 | public static void AssertEquals() 28 | { 29 | System.AssertEquals(5, 5, "Assert Equal"); 30 | } 31 | 32 | [Test] 33 | public static void AssertNotEquals() 34 | { 35 | System.AssertNotEquals(5, 0, "Assert Not Equal"); 36 | } 37 | 38 | [Test] 39 | public static void AssertNew() 40 | { 41 | System.Assert(true, "Assert True"); 42 | } 43 | 44 | [Test] 45 | static public void AssertEqualsNew() 46 | { 47 | System.AssertEquals(5, 5, "Assert Equal"); 48 | } 49 | 50 | [Test] 51 | static public void AssertNotEqualsNew() 52 | { 53 | System.AssertNotEquals(5, 0, "Assert Not Equal"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassVirtual.cls: -------------------------------------------------------------------------------- 1 | public virtual class ClassVirtual 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassWithComments.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassTwo { 2 | public ClassTwo() { // constructor 3 | System.debug('Test'); 4 | } 5 | 6 | public ClassTwo(String vin) { // another constructor 7 | // with a lot of misplaced comments 8 | } 9 | 10 | /* 11 | * This is a comment line one 12 | * This is a comment // line two 13 | */ 14 | public void Hello() { System.debug('Hello'); } 15 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassWithComments_Formatted.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassTwo 2 | { 3 | public ClassTwo() 4 | { 5 | // constructor 6 | System.debug('Test'); 7 | } 8 | 9 | public ClassTwo(String vin) 10 | { 11 | // another constructor 12 | // with a lot of misplaced comments 13 | } 14 | 15 | /* 16 | * This is a comment line one 17 | * This is a comment // line two 18 | */ 19 | public void Hello() 20 | { 21 | System.debug('Hello'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassWithOutSharing.cls: -------------------------------------------------------------------------------- 1 | public without sharing class ClassWithOutSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ClassWithSharing.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ClassWithSharing 2 | { 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/CommentFail.cls: -------------------------------------------------------------------------------- 1 | public with sharing class CommentFail 2 | { 3 | /* 4 | * ************************************************************************************************ 5 | * This is a general method for retrieving an sObject by it's id. selectFields is a list of fields 6 | * to return on the sObject. 7 | * ************************************************************************************************ 8 | */ 9 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/Comments.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * This comment belongs to the Class Syntax 3 | */ 4 | public with sharing class Comments 5 | // This comment belongs to the open bracket syntax 6 | { 7 | 8 | // This comment belongs to the Method Syntax 9 | public static void DemoMethod() { 10 | Integer demoValue = 5; // Side Line Comment 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/CustomerDto.cls: -------------------------------------------------------------------------------- 1 | public class CustomerDto 2 | { 3 | public String make {get;set;} 4 | public String year {get;set;} 5 | public CustomerDto.User user {get;set;} 6 | 7 | public class User { 8 | public string userName {get;set;} 9 | } 10 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/CustomerDto_Formatted.cls: -------------------------------------------------------------------------------- 1 | public class CustomerDto 2 | { 3 | public String make { get; set; } 4 | 5 | public String year { get; set; } 6 | 7 | public CustomerDto.User user { get; set; } 8 | 9 | public class User 10 | { 11 | public String userName { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/DataAccessDemo.cls: -------------------------------------------------------------------------------- 1 | public with sharing class DataAccessDemo 2 | { 3 | private DataAccessLayerI dl; 4 | 5 | public DataAccessDemo() 6 | { 7 | if (Test.isRunningTest()) 8 | { 9 | dl = (DataAccessLayerMok) MokProvider.createMokProvidor(DataAccessLayerMok.class); 10 | } 11 | else 12 | { 13 | dl = new DataAccessLayer(); 14 | } 15 | } 16 | 17 | public String UpdateContactEmailAddress(string firstName, string lastName, string email) 18 | { 19 | Contact contact = dl.GetContactByName(firstName, lastName); 20 | if (contact != null) 21 | { 22 | contact.Email = email; 23 | dl.UpdateContact(contact); 24 | return 'OK'; 25 | } 26 | else 27 | { 28 | return 'FAIL'; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/Demo.cls: -------------------------------------------------------------------------------- 1 | public class Demo 2 | { 3 | public static void RunContactDemo() 4 | { 5 | Contact contactNew = new Contact(LastName = 'Jay1', EMail = 'abc@abc.com'); 6 | insert contactNew; 7 | System.debug(contactNew.Id); 8 | 9 | List contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 10 | for (Contact c : contacts) 11 | { 12 | System.debug(c.Email); c.Email = 'new@new.com'; 13 | } 14 | update contacts; 15 | contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 16 | for (Contact c : contacts) 17 | { 18 | System.debug(c.Email); 19 | } 20 | delete contacts; 21 | contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 22 | if (contacts.isEmpty()) 23 | { 24 | System.debug('Del Worked'); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/Demo2.cls: -------------------------------------------------------------------------------- 1 | public class Demo2 2 | { 3 | public void MethodOne(int x) 4 | { 5 | if (x == 5) 6 | { 7 | Console.WriteLine(1); 8 | 9 | if (x == 8) 10 | { 11 | Console.WriteLine(8); 12 | } 13 | 14 | Console.WriteLine(2); 15 | Console.WriteLine(3); 16 | } else if (x == 6) 17 | { 18 | Console.WriteLine(6); 19 | } 20 | else 21 | { 22 | Console.WriteLine(7); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ExceptionDemo.cls: -------------------------------------------------------------------------------- 1 | public class ExceptionDemo 2 | { 3 | public static void CatchDemo() 4 | { 5 | try 6 | { 7 | ThrowDemo(); 8 | } 9 | catch (MathException e) 10 | { 11 | System.debug(e.getMessage()); 12 | } 13 | finally 14 | { 15 | System.debug('Finally'); 16 | } 17 | } 18 | 19 | public static void ThrowDemo() 20 | { 21 | throw new MathException('something bad happened!'); 22 | } 23 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ForIfWhile.cls: -------------------------------------------------------------------------------- 1 | public with sharing class ForIfWhile 2 | { 3 | public void MethodIfClean() 4 | { 5 | String medal_color ; 6 | Integer place ; 7 | if (place == 1) 8 | { 9 | medal_color = 'gold' ; 10 | } 11 | else if (place == 2) 12 | { 13 | medal_color = 'silver' ; 14 | } 15 | else if (place == 3) 16 | { 17 | medal_color = 'bronze' ; 18 | } 19 | else 20 | { 21 | medal_color = null ; 22 | } 23 | } 24 | public void MethodForTraditional() 25 | { 26 | for (Integer i = 0, j = 0; 27 | i < 10; 28 | i++) 29 | { 30 | System.debug (i + 1) ; 31 | } 32 | } 33 | public void MethodForIteration() 34 | { 35 | Integer[] myInts = new Integer[5] ; 36 | for (Integer i : myInts) 37 | { 38 | System.debug (i) ; 39 | } 40 | } 41 | public void MethodDo() 42 | { 43 | Integer count = 1 ; 44 | do 45 | { 46 | System.debug (count) ; 47 | count++ ; 48 | } 49 | while (count < 11) ; 50 | } 51 | public void MethodWhile() 52 | { 53 | Integer count = 1 ; 54 | while (count < 11) 55 | { 56 | System.debug (count) ; 57 | count++ ; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/FormatDemo.cls: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a comment line one 3 | * This is a comment // line two 4 | */ 5 | public with sharing class FormatDemo 6 | { 7 | public Integer 8 | dateOfBirth 9 | { get; set; } 10 | public void ForLoopTest() { 11 | for (Integer i = 0; i < 10; i++) { 12 | List contacts = 13 | [ 14 | SELECT Name, Email // This is a middle line comment 15 | From Contact 16 | Where Name = 'Jay' 17 | ]; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/FormatDemo_Formatted.cls: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a comment line one 3 | * This is a comment // line two 4 | */ 5 | public with sharing class FormatDemo 6 | { 7 | public Integer dateOfBirth { get; set; } 8 | 9 | public void ForLoopTest() 10 | { 11 | for (Integer i = 0; i < 10; i++) 12 | { 13 | List contacts = [SELECT Name, Email From Contact 14 | Where Name = 'Jay']; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/GetSetDemo.cls: -------------------------------------------------------------------------------- 1 | public class GetSetDemo { 2 | public double MyReadWritePropPublic { get; set; } 3 | private Integer propPrvt; 4 | public Integer prop { 5 | get { 6 | return propPrvt; 7 | } 8 | set { 9 | propPrvt = value; 10 | } 11 | } 12 | public Integer MyReadOnlyProp { 13 | get; 14 | } 15 | 16 | private static Integer myStaticPropPrvt; 17 | public static Integer MyStaticProp { 18 | get { 19 | return myStaticPropPrvt; 20 | } 21 | } 22 | 23 | Integer MyReadOnlyPropPrvt { get;} 24 | double MyReadWritePropPrvt {get; set; 25 | } 26 | public String MyWriteOnlyProp {get; } 27 | protected String MyWriteOnlyPropPrvt { set; get; 28 | } 29 | 30 | private string namePrvt; 31 | 32 | public string getName { 33 | get { 34 | return namePrvt; 35 | } 36 | private set { 37 | namePrvt = value; 38 | } 39 | } 40 | public string Stubbing { 41 | private get { 42 | return namePrvt; 43 | } 44 | set { 45 | namePrvt = value; 46 | } 47 | } 48 | public string DoThrowWhenException { 49 | get { 50 | return namePrvt; 51 | } 52 | set { 53 | namePrvt = value; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/IClassInterface.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterface extends IClassInterfaceExt { 2 | string GetName(); 3 | } 4 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/IClassInterfaceExt.cls: -------------------------------------------------------------------------------- 1 | public interface IClassInterfaceExt { 2 | Id GetId(); 3 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/JsonExample.cls: -------------------------------------------------------------------------------- 1 | public class JsonExample 2 | { 3 | public void JsonExampleMethod() 4 | { 5 | String name = 'Jay'; 6 | 7 | String jsonString = JSON.Serialize(name); 8 | 9 | String newName = (String)JSON.Deserialize(jsonString, String.class); 10 | } 11 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/ListAndArrayDemo.cls: -------------------------------------------------------------------------------- 1 | public class ListAndArrayDemo { 2 | public List StringList = new List { 'one', 'two' }; 3 | public Integer[] IntegerArray = new Integer[]{1, 2, 3}; 4 | 5 | public void Method() { 6 | List StringListLocal = new List { 'one', 'two' }; 7 | Integer[] IntegerArrayLocal = new Integer[]{1, 2, 3}; 8 | } 9 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/PrimitiveTypes.cls: -------------------------------------------------------------------------------- 1 | public class PrimitiveTypes 2 | { 3 | public Blob MyBlob = Blob.ValueOf('Jay'); 4 | public Boolean IsWinner = true; 5 | public Date MyDate = Date.Today(); 6 | public DateTime MyDateTime = DateTime.Now(); 7 | public Decimal MyDecimal = 12.4567; 8 | public Double d=3.133433; 9 | public Id MyId = '006E0000004TquXIAS'; 10 | public Integer MyInteger = 1; 11 | public Long MyLong = 23432424242L; 12 | public Time MyTime = Time.NewInstance(1, 2, 3, 4); 13 | public String MyString = 'Jay'; 14 | 15 | public void DemoMethod() 16 | { 17 | object obj = 10; 18 | Integer i = (Integer)obj; 19 | } 20 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/PropertyAndField.cls: -------------------------------------------------------------------------------- 1 | // ClassDeclaration 2 | public with sharing class PropertyAndField 3 | { 4 | // PropertyDeclarationSyntax 5 | public DateTime DateTimeGetSet { get; set; } 6 | // PropertyDeclarationSyntax 7 | public List DateTimeGetSetGeneric { get; set; } 8 | // PropertyDeclarationSyntax 9 | public DateTime[] DateTimeGetSetArray { get; set; } 10 | // FieldDeclarationSyntax 11 | public DateTime DateTimeEmpty; 12 | // FieldDeclarationSyntax 13 | public DateTime DateTimeInitilized = DateTime.now(); 14 | // FieldDeclarationSyntax 15 | public List DateTimeList = new List(); 16 | // FieldDeclarationSyntax 17 | public DateTime[] DateTimeArrary = new DateTime[5]; 18 | // FieldDeclarationSyntax 19 | public String Name = 'jay'; 20 | public final String nameFinal = 'jay'; 21 | public static String NameStatic = 'jay'; 22 | public static final String NameStaticFinal = 'jay'; 23 | 24 | public void MethodOne() 25 | { 26 | //FieldDeclaration 27 | DateTime dateTimeEmpty; 28 | //Expression 29 | dateTimeEmpty = DateTime.now(); 30 | //FieldDeclaration 31 | DateTime dateTimeInitilized = DateTime.now(); 32 | //FieldDeclaration 33 | List dateTimeList = new List(); 34 | //FieldDeclaration 35 | DateTime[] dateTimeArrary = new DateTime[5]; 36 | //ExpressionStatement 37 | System.debug('Hello World'); 38 | String Name; 39 | Name = 'Jay'; 40 | } 41 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/PropertyAndField2.cls: -------------------------------------------------------------------------------- 1 | public class PropertyAndField 2 | { 3 | transient Integer TransientInteger; 4 | public DateTime DateTimeGetSet { get; set; } 5 | public List DateTimeGetSetGeneric { get; set; } 6 | public DateTime[] DateTimeGetSetArray { get; set; } 7 | public DateTime DateTimeEmpty; 8 | public DateTime DateTimeInitialized = DateTime.now(); 9 | public List DateTimeList = new List(); 10 | public DateTime[] DateTimeArray = new DateTime[5]; 11 | public String Name = 'jay'; 12 | public final String nameFinal = 'jay'; 13 | public static String NameStatic = 'jay'; 14 | public static final String NameStaticFinal = 'jay'; 15 | 16 | public void MethodOne() 17 | { 18 | DateTime dateTimeEmpty; 19 | dateTimeEmpty = DateTime.now(); 20 | DateTime dateTimeInitilized = DateTime.now(); 21 | List dateTimeList = new List(); 22 | DateTime[] dateTimeArrary = new DateTime[5]; 23 | String name; 24 | name = 'Jay'; 25 | } 26 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/PropertyAndField3.cls: -------------------------------------------------------------------------------- 1 | public class PropertyAndField 2 | { 3 | transient Integer TransientInteger; 4 | public DateTime DateTimeGetSet { get; set; } 5 | public List DateTimeGetSetGeneric { get; set; } 6 | public DateTime[] DateTimeGetSetArray { get; set; } 7 | public DateTime DateTimeEmpty; 8 | public DateTime DateTimeInitialized = DateTime.now(); 9 | public List DateTimeList = new List(); 10 | public DateTime[] DateTimeArray = new DateTime[5]; 11 | public String Name = 'jay'; 12 | public final String nameFinal = 'jay'; 13 | public static String NameStatic = 'jay'; 14 | public static final String NameStaticFinal = 'jay'; 15 | 16 | public Set stringSet = new Set{}; 17 | 18 | public boolean shouldRedirect { get;set; } 19 | { 20 | shouldRedirect =false; 21 | } 22 | 23 | public String[] newStringArray = new String[] {'Hi'}; 24 | 25 | public void MethodOne() 26 | { 27 | DateTime dateTimeEmpty; 28 | dateTimeEmpty = DateTime.now(); 29 | DateTime dateTimeInitilized = DateTime.now(); 30 | List dateTimeList = new List(); 31 | DateTime[] dateTimeArrary = new DateTime[5]; 32 | String name; 33 | name = 'Jay'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/RunAll.cls: -------------------------------------------------------------------------------- 1 | public class RunAll 2 | { 3 | public RunAll() 4 | { 5 | //ClassAbstract classAbstract = new ClassAbstract(); 6 | //ClassEnum classEnum = ClassEnum.America; 7 | ClassException classException = new ClassException(); 8 | ClassGlobal classGlobal = new ClassGlobal(); 9 | ClassInterface classInterface = new ClassInterface(); 10 | 11 | ClassInternal classInternal = new ClassInternal(); 12 | ClassInternal.InternalClassOne internalClassOne = new ClassInternal.InternalClassOne(); 13 | ClassInternal.InternalClassTwo internalClassTwo = new ClassInternal.InternalClassTwo(); 14 | 15 | ClassRest classRest = new ClassRest(); 16 | 17 | ClassVirtual classVirtual = new ClassVirtual(); 18 | 19 | ClassWithOutSharing classWithOutSharing = new ClassWithOutSharing(); 20 | ClassWithSharing classWithSharing = new ClassWithSharing(); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/SoqlDemo.cls: -------------------------------------------------------------------------------- 1 | public with sharing class SoqlDemo { 2 | /** 3 | * A simple CRUD Example 4 | */ 5 | public static void CrudExample() 6 | { 7 | Contact contactNew = new Contact(LastName = 'Jay', EMail = 'abc@abc.com'); 8 | insert contactNew; 9 | 10 | System.debug(contactNew.Id); 11 | 12 | List contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 13 | for (Contact c : contacts) 14 | { 15 | System.debug(c.Email); c.Email = 'new@new.com'; 16 | } 17 | update contacts; 18 | 19 | contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 20 | for (Contact c : contacts) 21 | { 22 | System.debug(c.Email); 23 | } 24 | delete contacts; 25 | 26 | contacts = [SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id]; 27 | if (contacts.isEmpty()) 28 | { 29 | System.debug('Delete Worked'); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestClasses/SoqlDemo.cs: -------------------------------------------------------------------------------- 1 | namespace ApexSharpDemo.ApexCode 2 | { 3 | using Apex; 4 | using Apex.ApexSharp; 5 | using Apex.ApexSharp.ApexAttributes; 6 | using Apex.ApexSharp.Extensions; 7 | using Apex.System; 8 | using SObjects; 9 | 10 | [WithSharing] 11 | public class SoqlDemo 12 | { 13 | /** 14 | * A simple CRUD Example 15 | */ 16 | public static void CrudExample() 17 | { 18 | Contact contactNew = new Contact { LastName = "Jay", EMail = "abc@abc.com" }; 19 | Soql.insert(contactNew); 20 | System.debug(contactNew.Id); 21 | List contacts = Soql.query(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); 22 | foreach (Contact c in contacts) 23 | { 24 | System.debug(c.Email); 25 | c.Email = "new@new.com"; 26 | } 27 | 28 | Soql.update(contacts); 29 | contacts = Soql.query(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); 30 | foreach (Contact c in contacts) 31 | { 32 | System.debug(c.Email); 33 | } 34 | 35 | Soql.delete(contacts); 36 | contacts = Soql.query(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); 37 | if (contacts.isEmpty()) 38 | { 39 | System.debug("Delete Worked"); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/Cumulus-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/Cumulus-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/SalesForceApexSharp-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/SalesForceApexSharp-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/apex-lambda-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/apex-lambda-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/apex-sobjectdataloader-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/apex-sobjectdataloader-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/ffhttp-core-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/ffhttp-core-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-common-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-common-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-common-samplecode-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-common-samplecode-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-mocks-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/fflib-apex-mocks-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/salesforce-einstein-platform-apex-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/salesforce-einstein-platform-apex-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/ApexTestLibraries/sfdx-dreamhouse-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apexsharp/apexparser/4eb5983c657b0e6c49ed47bc42a0346e80f9e26d/ApexSharp.ApexParser.Tests/ApexTestLibraries/sfdx-dreamhouse-master.zip -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/TestFixtureBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Syntax; 7 | using ApexSharp.ApexParser.Visitors; 8 | using NUnit.Framework; 9 | using static System.Math; 10 | 11 | namespace ApexSharp.ApexParser.Tests 12 | { 13 | public class TestFixtureBase 14 | { 15 | protected void CompareLineByLine(string actual, string expected) 16 | { 17 | var actualList = actual.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 18 | var expectedList = expected.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 19 | 20 | for (int i = 0; i < Min(expectedList.Length, actualList.Length); i++) 21 | { 22 | Assert.AreEqual(expectedList[i].Trim(), actualList[i].Trim()); 23 | } 24 | 25 | if (Abs(expectedList.Length - actualList.Length) > 1) 26 | { 27 | Assert.Fail("Too many difference in lines: expected {0}, actual {1}", expectedList.Length, actualList.Length); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/Toolbox/IEnumerableExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Toolbox; 7 | using NUnit.Framework; 8 | 9 | namespace ApexSharp.ApexParser.Tests.Toolbox 10 | { 11 | [TestFixture] 12 | public class IEnumerableExtensionTests 13 | { 14 | [Test] 15 | public void EmptyIfNullReturnsEmptyEnumerableInsteadOfNull() 16 | { 17 | int[] x = null; 18 | var enumerable = x.EmptyIfNull(); 19 | Assert.NotNull(enumerable); 20 | Assert.False(enumerable.Any()); 21 | } 22 | 23 | [Test] 24 | public void AsSmartExtensionMethodReturnsSmartEnumerableForNullEnumerables() 25 | { 26 | int[] x = null; 27 | foreach (var t in x.AsSmart()) 28 | { 29 | Console.WriteLine("Hello!"); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser.Tests/Visitors/SoqlExtractorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | using NUnit.Framework; 8 | using static ApexSharp.ApexParser.Tests.Properties.Resources; 9 | 10 | namespace ApexSharp.ApexParser.Tests.Visitors 11 | { 12 | [TestFixture] 13 | public class SoqlExtractorTests 14 | { 15 | [Test] 16 | public void SoqlExtractorExtractsAllSoqlDemo2Queries() 17 | { 18 | var queries = SoqlExtractor.ExtractAllQueries(SoqlDemo2); 19 | Assert.AreEqual(23, queries.Length); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/ApexSharpParser.cs: -------------------------------------------------------------------------------- 1 | using ApexSharp.ApexParser.Parser; 2 | using ApexSharp.ApexParser.Toolbox; 3 | using ApexSharp.ApexParser.Visitors; 4 | using MemberDeclarationSyntax = ApexSharp.ApexParser.Syntax.MemberDeclarationSyntax; 5 | 6 | namespace ApexSharp.ApexParser 7 | { 8 | public class ApexSharpParser 9 | { 10 | private static ApexGrammar ApexGrammar { get; } = new ApexGrammar(); 11 | 12 | // Get the AST for a given APEX File 13 | public static MemberDeclarationSyntax GetApexAst(string apexCode) 14 | { 15 | return ApexGrammar.CompilationUnit.ParseEx(apexCode); 16 | } 17 | 18 | // Format APEX Code so each statement is in its own line 19 | public static string FormatApex(string apexCode) 20 | { 21 | return GetApexAst(apexCode).ToApex(tabSize: 0); 22 | } 23 | 24 | // Indent APEX code, Pass the Tab Size. If Tab size is set to 0, no indentions 25 | public static string IndentApex(string apexCode, int tabSize = 4) 26 | { 27 | return GetApexAst(apexCode).ToApex(tabSize); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/ApexSharpParserOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexSharp.ApexParser 8 | { 9 | public class ApexSharpParserOptions 10 | { 11 | public string Namespace { get; set; } = "ApexSharpDemo.ApexCode"; 12 | 13 | public int TabSize { get; set; } = 4; 14 | 15 | public bool UseLocalSObjectsNamespace { get; set; } = true; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Parser/Apex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Syntax; 7 | using ApexSharp.ApexParser.Toolbox; 8 | 9 | namespace ApexSharp.ApexParser.Parser 10 | { 11 | internal static class Apex 12 | { 13 | private static ApexGrammar ApexGrammar { get; } = new ApexGrammar(); 14 | 15 | public static MemberDeclarationSyntax ParseFile(string text) => 16 | ApexGrammar.CompilationUnit.ParseEx(text); 17 | 18 | public static ClassDeclarationSyntax ParseClass(string text) => 19 | ApexGrammar.ClassDeclaration.ParseEx(text); 20 | 21 | public static EnumDeclarationSyntax ParseEnum(string text) => 22 | ApexGrammar.EnumDeclaration.ParseEx(text); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Parser/keywords.pl: -------------------------------------------------------------------------------- 1 | # Sample usage: 2 | # perl -w keywords.pl keywords_reserved.txt > tmp1.cs 3 | # perl -w keywords.pl keywords_nonreserved.txt > tmp2.cs 4 | 5 | while (<>) 6 | { 7 | next if /http/; 8 | next if /^\s*$/; 9 | 10 | s/\s*$//; # strip newlines 11 | $reserved = s/\*// ? " // reserved for future use" : ""; # strip stars 12 | 13 | 14 | $name = ucfirst($_); 15 | $value = $_; 16 | print " public const string $name = \"$value\";$reserved\n"; 17 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Parser/keywords_nonreserved.txt: -------------------------------------------------------------------------------- 1 | https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reserved_words.htm 2 | 3 | after 4 | before 5 | count 6 | excludes 7 | first 8 | includes 9 | last 10 | order 11 | sharing 12 | with -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("ApexSharp.ApexParser.Tests")] 4 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/AccessorDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Toolbox; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class AccessorDeclarationSyntax : MemberDeclarationSyntax 12 | { 13 | public AccessorDeclarationSyntax(MemberDeclarationSyntax heading = null) 14 | : base(heading) 15 | { 16 | } 17 | 18 | public override SyntaxType Kind => SyntaxType.Accessor; 19 | 20 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitAccessor(this); 21 | 22 | public override IEnumerable ChildNodes => GetNodes(Body); 23 | 24 | public bool IsGetter { get; set; } 25 | 26 | public bool IsSetter => !IsGetter; 27 | 28 | public BlockSyntax Body { get; set; } 29 | 30 | public bool IsEmpty => Body == null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/AnnotationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Parser; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class AnnotationSyntax : BaseSyntax 12 | { 13 | public AnnotationSyntax(string identifier = null, string parameters = null) 14 | { 15 | Identifier = identifier; 16 | Parameters = parameters; 17 | } 18 | 19 | public override SyntaxType Kind => SyntaxType.Annotation; 20 | 21 | public string Identifier { get; set; } 22 | 23 | public string Parameters { get; set; } 24 | 25 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitAnnotation(this); 26 | 27 | public override IEnumerable ChildNodes => NoChildren; 28 | 29 | public bool IsTest => ApexKeywords.UnitTestKeywords.Contains(Identifier); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ArrayCreationExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ApexSharp.ApexParser.Toolbox; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ArrayCreationExpressionSyntax : ExpressionSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ArrayCreationExpression; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitArrayCreationExpression(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Type).Concat(Expressions.EmptyIfNull()); 15 | 16 | public TypeSyntax Type { get; set; } 17 | 18 | public List Expressions { get; set; } = new List(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/AssignmentExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class AssignmentExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.AssignmentExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitAssignmentExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Left, Right); 13 | 14 | public ExpressionSyntax Left { get; set; } 15 | 16 | public string Operator { get; } 17 | 18 | public ExpressionSyntax Right { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/BaseSyntaxDebuggerProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class BaseSyntaxDebuggerProxy 12 | { 13 | public BaseSyntaxDebuggerProxy(BaseSyntax content) => Content = content; 14 | 15 | private BaseSyntax Content { get; } 16 | 17 | public string NodeType => Content.GetType().Name; 18 | 19 | public string ApexCode => Content.ToApex(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/BinaryExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class BinaryExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.BinaryExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitBinaryExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Left, Right); 13 | 14 | public ExpressionSyntax Left { get; set; } 15 | 16 | public string Operator { get; } 17 | 18 | public ExpressionSyntax Right { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/BlockSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using ApexSharp.ApexParser.Toolbox; 8 | using ApexSharp.ApexParser.Visitors; 9 | 10 | namespace ApexSharp.ApexParser.Syntax 11 | { 12 | public class BlockSyntax : StatementSyntax, IEnumerable, IEnumerable 13 | { 14 | public BlockSyntax() 15 | { 16 | } 17 | 18 | public BlockSyntax(IEnumerable statements) 19 | { 20 | Statements.AddRange(statements.EmptyIfNull()); 21 | } 22 | 23 | public override SyntaxType Kind => SyntaxType.Block; 24 | 25 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitBlock(this); 26 | 27 | public override IEnumerable ChildNodes => Statements; 28 | 29 | public List Statements { get; set; } = new List(); 30 | 31 | public void Add(StatementSyntax statement) => Statements.Add(statement); 32 | 33 | public List InnerComments { get; set; } = new List(); 34 | 35 | public IEnumerator GetEnumerator() => ((IEnumerable)Statements).GetEnumerator(); 36 | 37 | IEnumerator IEnumerable.GetEnumerator() => Statements.GetEnumerator(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/BreakStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class BreakStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.BreakStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitBreakStatement(this); 15 | 16 | public override IEnumerable ChildNodes => NoChildren; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/CastExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class CastExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.CastExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitCastExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Type, Expression); 13 | 14 | public TypeSyntax Type { get; set; } 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/CatchClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class CatchClauseSyntax : BaseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.Catch; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitCatch(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Type, Block); 17 | 18 | public TypeSyntax Type { get; set; } 19 | 20 | public string Identifier { get; set; } 21 | 22 | public BlockSyntax Block { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ClassInitializerSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Parser; 7 | using ApexSharp.ApexParser.Toolbox; 8 | using ApexSharp.ApexParser.Visitors; 9 | 10 | namespace ApexSharp.ApexParser.Syntax 11 | { 12 | public class ClassInitializerSyntax : MemberDeclarationSyntax 13 | { 14 | public ClassInitializerSyntax(MemberDeclarationSyntax heading = null) 15 | : base(heading) 16 | { 17 | } 18 | 19 | public override SyntaxType Kind => SyntaxType.ClassInitializer; 20 | 21 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitClassInitializer(this); 22 | 23 | public override IEnumerable ChildNodes => 24 | base.ChildNodes.Concat(GetNodes(Body)); 25 | 26 | public BlockSyntax Body { get; set; } 27 | 28 | public bool IsStatic => Modifiers.EmptyIfNull().Any(m => m == ApexKeywords.Static); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ClassOfExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class ClassOfExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.ClassOfExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitClassOfExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Type); 13 | 14 | public TypeSyntax Type { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ConditionalExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class ConditionalExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.ConditionalExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitConditionalExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Condition, WhenTrue, WhenFalse); 13 | 14 | public ExpressionSyntax Condition { get; set; } 15 | 16 | public ExpressionSyntax WhenTrue { get; set; } 17 | 18 | public ExpressionSyntax WhenFalse { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ConstructorDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class ConstructorDeclarationSyntax : MethodDeclarationSyntax 11 | { 12 | public ConstructorDeclarationSyntax(MethodDeclarationSyntax method = null) 13 | : base(method) 14 | { 15 | if (method != null) 16 | { 17 | Body = method.Body; 18 | ReturnType = method.ReturnType; 19 | Identifier = method.Identifier; 20 | Parameters = method.Parameters; 21 | } 22 | } 23 | 24 | public override SyntaxType Kind => SyntaxType.Constructor; 25 | 26 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitConstructorDeclaration(this); 27 | 28 | public override MemberDeclarationSyntax WithTypeAndName(ParameterSyntax typeAndName) 29 | { 30 | Identifier = typeAndName.Identifier ?? typeAndName.Type.Identifier; 31 | return this; 32 | } 33 | 34 | public ExpressionSyntax ChainedConstructorCall { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ContinueStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ContinueStatementSyntax : StatementSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ContinueStatement; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitContinueStatement(this); 13 | 14 | public override IEnumerable ChildNodes => NoChildren; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/DeleteStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class DeleteStatementSyntax : StatementSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.DeleteStatement; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitDeleteStatement(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Expression); 13 | 14 | public ExpressionSyntax Expression { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/DoStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class DoStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.DoStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitDoStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression, Statement); 17 | 18 | public ExpressionSyntax Expression { get; set; } 19 | 20 | public StatementSyntax Statement { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ElementAccessExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ApexSharp.ApexParser.Toolbox; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ElementAccessExpressionSyntax : ExpressionSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ElementAccessExpression; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitElementAccessExpression(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Expression).Concat(Arguments.EmptyIfNull()); 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | 18 | public List Arguments { get; set; } = new List(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/EnumDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class EnumDeclarationSyntax : MemberDeclarationSyntax 11 | { 12 | public EnumDeclarationSyntax(MemberDeclarationSyntax heading = null) 13 | : base(heading) 14 | { 15 | } 16 | 17 | public override SyntaxType Kind => SyntaxType.Enum; 18 | 19 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitEnum(this); 20 | 21 | public override IEnumerable ChildNodes => 22 | base.ChildNodes.Concat(Members).Where(n => n != null); 23 | 24 | public string Identifier { get; set; } 25 | 26 | public List Members { get; set; } = new List(); 27 | 28 | public List InnerComments { get; set; } = new List(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/EnumMemberDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class EnumMemberDeclarationSyntax : MemberDeclarationSyntax 11 | { 12 | public EnumMemberDeclarationSyntax(MemberDeclarationSyntax heading = null) 13 | : base(heading) 14 | { 15 | } 16 | 17 | public override SyntaxType Kind => SyntaxType.EnumMember; 18 | 19 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitEnumMember(this); 20 | 21 | public string Identifier { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | using Sprache; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class ExpressionSyntax : BaseSyntax 12 | { 13 | public ExpressionSyntax() 14 | { 15 | } 16 | 17 | public ExpressionSyntax(string expr) => ExpressionString = expr; 18 | 19 | public static ExpressionSyntax CreateOrDefault(IOption expression) 20 | { 21 | if (expression.IsDefined) 22 | { 23 | return new ExpressionSyntax(expression.Get()); 24 | } 25 | 26 | return null; 27 | } 28 | 29 | public override SyntaxType Kind => SyntaxType.Expression; 30 | 31 | public override IEnumerable ChildNodes => NoChildren; 32 | 33 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitExpression(this); 34 | 35 | public string ExpressionString { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/FieldDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Toolbox; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class FieldDeclarationSyntax : MemberDeclarationSyntax 12 | { 13 | public FieldDeclarationSyntax(MemberDeclarationSyntax heading = null) 14 | : base(heading) 15 | { 16 | } 17 | 18 | public override SyntaxType Kind => SyntaxType.Field; 19 | 20 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitFieldDeclaration(this); 21 | 22 | public override IEnumerable ChildNodes => 23 | base.ChildNodes.Concat(GetNodes(Type)).Concat(Fields).Where(n => n != null); 24 | 25 | public override MemberDeclarationSyntax WithTypeAndName(ParameterSyntax typeAndName) 26 | { 27 | Type = typeAndName.Type; 28 | 29 | var identifier = typeAndName.Identifier ?? typeAndName.Type.Identifier; 30 | if (!Fields.IsNullOrEmpty()) 31 | { 32 | Fields[0].Identifier = identifier; 33 | } 34 | 35 | return this; 36 | } 37 | 38 | public TypeSyntax Type { get; set; } 39 | 40 | public List Fields { get; set; } = new List(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/FieldDeclaratorSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class FieldDeclaratorSyntax : BaseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.FieldDeclarator; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitFieldDeclarator(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression); 17 | 18 | public string Identifier { get; set; } 19 | 20 | public ExpressionSyntax Expression { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/FinallyClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class FinallyClauseSyntax : BaseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.Finally; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitFinally(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Block); 17 | 18 | public BlockSyntax Block { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ForEachStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class ForEachStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.ForEachStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitForEachStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Type, Expression, Statement); 17 | 18 | public TypeSyntax Type { get; set; } 19 | 20 | public string Identifier { get; set; } 21 | 22 | public ExpressionSyntax Expression { get; set; } 23 | 24 | public StatementSyntax Statement { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ForStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class ForStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.ForStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitForStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Declaration, Statement); 17 | 18 | public VariableDeclarationSyntax Declaration { get; set; } 19 | 20 | public ExpressionSyntax Condition { get; set; } 21 | 22 | public List Incrementors { get; set; } 23 | 24 | public StatementSyntax Statement { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/IAnnotatedSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ApexSharp.ApexParser.Syntax 6 | { 7 | public interface IAnnotatedSyntax 8 | { 9 | List Annotations { get; } 10 | 11 | List Modifiers { get; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/IfStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class IfStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.IfStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitIfStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression, ThenStatement, ElseStatement); 17 | 18 | public ExpressionSyntax Expression { get; set; } 19 | 20 | public StatementSyntax ThenStatement { get; set; } 21 | 22 | public StatementSyntax ElseStatement { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/InsertStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class InsertStatementSyntax : StatementSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.InsertStatement; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitInsertStatement(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Expression); 13 | 14 | public ExpressionSyntax Expression { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/InstanceOfExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class InstanceOfExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.InstanceOfExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitInstanceOfExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Expression, Type); 13 | 14 | public ExpressionSyntax Expression { get; set; } 15 | 16 | public TypeSyntax Type { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/InterfaceDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class InterfaceDeclarationSyntax : ClassDeclarationSyntax 11 | { 12 | public InterfaceDeclarationSyntax(MemberDeclarationSyntax heading = null) 13 | : base(heading) 14 | { 15 | } 16 | 17 | public InterfaceDeclarationSyntax(MemberDeclarationSyntax heading, ClassDeclarationSyntax classBody) 18 | : base(heading, classBody) 19 | { 20 | } 21 | 22 | public override SyntaxType Kind => SyntaxType.Interface; 23 | 24 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitInterfaceDeclaration(this); 25 | 26 | public override bool IsInterface => true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/InvocationExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ApexSharp.ApexParser.Toolbox; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class InvocationExpressionSyntax : ExpressionSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.InvocationExpression; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitInvocationExpression(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Expression).Concat(Arguments.EmptyIfNull()); 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | 18 | public List Arguments { get; set; } = new List(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/LiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class LiteralExpressionSyntax : ExpressionSyntax 7 | { 8 | public LiteralExpressionSyntax(string token = null, LiteralType type = LiteralType.Null) 9 | { 10 | Token = token; 11 | LiteralType = type; 12 | } 13 | 14 | public override SyntaxType Kind => SyntaxType.LiteralExpression; 15 | 16 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitLiteralExpression(this); 17 | 18 | public override IEnumerable ChildNodes => NoChildren; 19 | 20 | public string Token { get; set; } 21 | 22 | public LiteralType LiteralType { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/LiteralType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexSharp.ApexParser.Syntax 8 | { 9 | public enum LiteralType 10 | { 11 | Null, 12 | Boolean, 13 | Numeric, 14 | String, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/MemberAccessExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ApexSharp.ApexParser.Toolbox; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class MemberAccessExpressionSyntax : ExpressionSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.MemberAccessExpression; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitMemberAccessExpression(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Expression); 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | 18 | public string Name { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/MemberDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | using Sprache; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class MemberDeclarationSyntax : BaseSyntax, IAnnotatedSyntax 12 | { 13 | public MemberDeclarationSyntax(MemberDeclarationSyntax other = null) 14 | { 15 | this.WithProperties(other); 16 | } 17 | 18 | public override SyntaxType Kind => SyntaxType.ClassMember; 19 | 20 | public override void Accept(ApexSyntaxVisitor visitor) => throw new InvalidOperationException(); 21 | 22 | public override IEnumerable ChildNodes => 23 | Annotations.Where(n => n != null); 24 | 25 | public List Annotations { get; set; } = new List(); 26 | 27 | public List Modifiers { get; set; } = new List(); 28 | 29 | public virtual MemberDeclarationSyntax WithTypeAndName(ParameterSyntax typeAndName) 30 | { 31 | return this; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/MethodDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using ApexSharp.ApexParser.Visitors; 5 | using Sprache; 6 | 7 | namespace ApexSharp.ApexParser.Syntax 8 | { 9 | public class MethodDeclarationSyntax : MemberDeclarationSyntax 10 | { 11 | public MethodDeclarationSyntax(MemberDeclarationSyntax heading = null) 12 | : base(heading) 13 | { 14 | } 15 | 16 | public override SyntaxType Kind => SyntaxType.Method; 17 | 18 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitMethodDeclaration(this); 19 | 20 | public override IEnumerable ChildNodes => 21 | base.ChildNodes.Concat(GetNodes(ReturnType)).Concat(Parameters).Concat(GetNodes(Body)).Where(n => n != null); 22 | 23 | public TypeSyntax ReturnType { get; set; } 24 | 25 | public string Identifier { get; set; } 26 | 27 | public List Parameters { get; set; } = new List(); 28 | 29 | public BlockSyntax Body { get; set; } 30 | 31 | public bool IsAbstract => Body == null; 32 | 33 | public override MemberDeclarationSyntax WithTypeAndName(ParameterSyntax typeAndName) 34 | { 35 | ReturnType = typeAndName.Type; 36 | Identifier = typeAndName.Identifier ?? typeAndName.Type.Identifier; 37 | return this; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ObjectCreationExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ApexSharp.ApexParser.Toolbox; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ObjectCreationExpressionSyntax : ExpressionSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ObjectCreationExpression; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitObjectCreationExpression(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Type).Concat(Arguments.EmptyIfNull()); 15 | 16 | public TypeSyntax Type { get; set; } 17 | 18 | public List Arguments { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ParameterSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class ParameterSyntax : BaseSyntax, IAnnotatedSyntax 7 | { 8 | public ParameterSyntax(string type, string identifier) 9 | : this(new TypeSyntax(type), identifier) 10 | { 11 | } 12 | 13 | public ParameterSyntax(TypeSyntax type, string identifier) 14 | { 15 | Type = type; 16 | Identifier = identifier; 17 | } 18 | 19 | public override SyntaxType Kind => SyntaxType.Parameter; 20 | 21 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitParameter(this); 22 | 23 | public override IEnumerable ChildNodes => GetNodes(Type); 24 | 25 | public List Annotations { get; set; } = new List(); 26 | 27 | public List Modifiers { get; set; } = new List(); 28 | 29 | public TypeSyntax Type { get; set; } 30 | 31 | public string Identifier { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ParenthesizedExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class ParenthesizedExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.ParenthesizedExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitParenthesizedExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Expression); 13 | 14 | public ExpressionSyntax Expression { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/PostfixUnaryExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class PostfixUnaryExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.PostfixUnaryExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitPostfixUnaryExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Operand); 13 | 14 | public ExpressionSyntax Operand { get; set; } 15 | 16 | public string Operator { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/PrefixUnaryExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class PrefixUnaryExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.PrefixUnaryExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitPrefixUnaryExpression(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Operand); 13 | 14 | public ExpressionSyntax Operand { get; set; } 15 | 16 | public string Operator { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ReturnStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ReturnStatementSyntax : StatementSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ReturnStatement; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitReturnStatement(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Expression); 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/RunAsStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class RunAsStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.RunAsStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitRunAsStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression, Statement); 17 | 18 | public ExpressionSyntax Expression { get; set; } 19 | 20 | public StatementSyntax Statement { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/StatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class StatementSyntax : BaseSyntax 11 | { 12 | public StatementSyntax(string body = null) 13 | { 14 | Body = body; 15 | } 16 | 17 | public override SyntaxType Kind => SyntaxType.Statement; 18 | 19 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitStatement(this); 20 | 21 | public override IEnumerable ChildNodes => NoChildren; 22 | 23 | public bool IsEmpty => string.IsNullOrWhiteSpace(Body); 24 | 25 | public string Body { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/SuperExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class SuperExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.SuperExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitSuperExpression(this); 11 | 12 | public override IEnumerable ChildNodes => NoChildren; 13 | } 14 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/SwitchStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Toolbox; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class SwitchStatementSyntax : StatementSyntax 12 | { 13 | public override SyntaxType Kind => SyntaxType.SwitchStatement; 14 | 15 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitSwitchStatement(this); 16 | 17 | public override IEnumerable ChildNodes => 18 | GetNodes(Expression).Concat(WhenClauses.EmptyIfNull().Where(n => n != null)); 19 | 20 | public ExpressionSyntax Expression { get; set; } 21 | 22 | public List WhenClauses { get; set; } = new List(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ThisExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class ThisExpressionSyntax : ExpressionSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.ThisExpression; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitThisExpression(this); 11 | 12 | public override IEnumerable ChildNodes => NoChildren; 13 | } 14 | } -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/ThrowStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ApexSharp.ApexParser.Visitors; 5 | 6 | namespace ApexSharp.ApexParser.Syntax 7 | { 8 | public class ThrowStatementSyntax : StatementSyntax 9 | { 10 | public override SyntaxType Kind => SyntaxType.ThrowStatement; 11 | 12 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitThrowStatement(this); 13 | 14 | public override IEnumerable ChildNodes => GetNodes(Expression); 15 | 16 | public ExpressionSyntax Expression { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/TryStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class TryStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.TryStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitTryStatement(this); 15 | 16 | public override IEnumerable ChildNodes => 17 | GetNodes(Block).Concat(Catches).Concat(GetNodes(Finally)).Where(n => n != null); 18 | 19 | public BlockSyntax Block { get; set; } 20 | 21 | public List Catches { get; set; } = new List(); 22 | 23 | public FinallyClauseSyntax Finally { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/UpdateStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class UpdateStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.UpdateStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitUpdateStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression); 17 | 18 | public ExpressionSyntax Expression { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/UpsertStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ApexSharp.ApexParser.Visitors; 3 | 4 | namespace ApexSharp.ApexParser.Syntax 5 | { 6 | public class UpsertStatementSyntax : StatementSyntax 7 | { 8 | public override SyntaxType Kind => SyntaxType.UpsertStatement; 9 | 10 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitUpsertStatement(this); 11 | 12 | public override IEnumerable ChildNodes => GetNodes(Expression); 13 | 14 | public ExpressionSyntax Expression { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/VariableDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class VariableDeclarationSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.VariableDeclaration; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitVariableDeclaration(this); 15 | 16 | public override IEnumerable ChildNodes => 17 | GetNodes(Type).Concat(Variables).Where(n => n != null); 18 | 19 | public TypeSyntax Type { get; set; } 20 | 21 | public List Variables { get; set; } = new List(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/VariableDeclaratorSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class VariableDeclaratorSyntax : BaseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.VariableDeclarator; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitVariableDeclarator(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression); 17 | 18 | public string Identifier { get; set; } 19 | 20 | public ExpressionSyntax Expression { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/WhenClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public abstract class WhenClauseSyntax : StatementSyntax 11 | { 12 | public override IEnumerable ChildNodes => GetNodes(Block); 13 | 14 | public BlockSyntax Block { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/WhenElseClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class WhenElseClauseSyntax : WhenClauseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.WhenElseClause; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitWhenElseClauseSyntax(this); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/WhenExpressionsClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Toolbox; 7 | using ApexSharp.ApexParser.Visitors; 8 | 9 | namespace ApexSharp.ApexParser.Syntax 10 | { 11 | public class WhenExpressionsClauseSyntax : WhenClauseSyntax 12 | { 13 | public override SyntaxType Kind => SyntaxType.WhenExpressionsClause; 14 | 15 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitWhenExpressionsClauseSyntax(this); 16 | 17 | public override IEnumerable ChildNodes => 18 | Expressions.EmptyIfNull().Where(n => n != null).Concat(GetNodes(Block)); 19 | 20 | // note: Apex only allows literals here 21 | public List Expressions { get; set; } = new List(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/WhenTypeClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class WhenTypeClauseSyntax : WhenClauseSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.WhenTypeClause; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitWhenTypeClauseSyntax(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Type, Block); 17 | 18 | public TypeSyntax Type { get; set; } 19 | 20 | public string Identifier { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Syntax/WhileStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Visitors; 7 | 8 | namespace ApexSharp.ApexParser.Syntax 9 | { 10 | public class WhileStatementSyntax : StatementSyntax 11 | { 12 | public override SyntaxType Kind => SyntaxType.WhileStatement; 13 | 14 | public override void Accept(ApexSyntaxVisitor visitor) => visitor.VisitWhileStatement(this); 15 | 16 | public override IEnumerable ChildNodes => GetNodes(Expression, Statement); 17 | 18 | public ExpressionSyntax Expression { get; set; } 19 | 20 | public StatementSyntax Statement { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/Disposable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ApexSharp.ApexParser.Toolbox 8 | { 9 | public sealed class Disposable : IDisposable 10 | { 11 | public Disposable() 12 | { 13 | } 14 | 15 | public Disposable(params Action[] actions) 16 | { 17 | DisposeActions.AddRange(actions); 18 | } 19 | 20 | private List DisposeActions { get; } = new List(); 21 | 22 | public void Dispose() 23 | { 24 | var actions = DisposeActions.ToArray(); 25 | for (var i = actions.Length - 1; i >= 0; i--) 26 | { 27 | var action = actions[i]; 28 | DisposeActions.RemoveAt(i); 29 | action?.Invoke(); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/ICommentParserProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Sprache; 7 | 8 | namespace ApexSharp.ApexParser.Toolbox 9 | { 10 | public interface ICommentParserProvider 11 | { 12 | IComment CommentParser { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/IEnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using IEnumerable = System.Collections.IEnumerable; 7 | 8 | namespace ApexSharp.ApexParser.Toolbox 9 | { 10 | public static class IEnumerableExtensions 11 | { 12 | public static bool IsNullOrEmpty(this IEnumerable enumerable) 13 | { 14 | return enumerable == null || !enumerable.Any(); 15 | } 16 | 17 | public static IEnumerable EmptyIfNull(this IEnumerable enumerable) 18 | { 19 | return enumerable ?? Enumerable.Empty(); 20 | } 21 | 22 | public static IEnumerable Except(this IEnumerable enumerable, params T[] values) 23 | { 24 | return enumerable.Except(values.AsEnumerable()); 25 | } 26 | 27 | public static SmartEnumerable AsSmart(this IEnumerable enumerable) 28 | { 29 | return enumerable.EmptyIfNull().AsSmartEnumerable(); 30 | } 31 | 32 | public static IEnumerable OfExactType(this IEnumerable enumerable) 33 | { 34 | return enumerable.OfType().Where(t => t.GetType() == typeof(T)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/ParseExceptionCustom.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Sprache; 7 | 8 | namespace ApexSharp.ApexParser.Toolbox 9 | { 10 | public class ParseExceptionCustom : ParseException 11 | { 12 | public string[] Apexcode { get; set; } 13 | public int LineNumber { get; set; } 14 | public ParseExceptionCustom(string message, int lineNumber, string[] apexcode) 15 | : base(message) 16 | { 17 | LineNumber = lineNumber; 18 | Apexcode = apexcode; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/SmartEnumerable.cs: -------------------------------------------------------------------------------- 1 | // SmartEnumerable by Jon Skeet 2 | // http://msmvps.com/blogs/jon_skeet/archive/2007/07/27/smart-enumerations.aspx 3 | // namespace MiscUtil.Collections 4 | /*--------------------------------*/ 5 | 6 | using System; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | 10 | namespace ApexSharp.ApexParser.Toolbox 11 | { 12 | /// 13 | /// Static class to make creation easier. If possible though, use the extension 14 | /// method in SmartEnumerableExt. 15 | /// 16 | ////[CoverageExclude] 17 | public static class SmartEnumerable 18 | { 19 | /// 20 | /// Extension method to make life easier. 21 | /// 22 | /// Type of enumerable 23 | /// Source enumerable 24 | /// A new SmartEnumerable of the appropriate type 25 | public static SmartEnumerable Create(IEnumerable source) 26 | { 27 | return new SmartEnumerable(source); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Toolbox/SmartEnumerableExt.cs: -------------------------------------------------------------------------------- 1 | // SmartEnumerable by Jon Skeet 2 | // http://msmvps.com/blogs/jon_skeet/archive/2007/07/27/smart-enumerations.aspx 3 | // namespace MiscUtil.Collections 4 | /*--------------------------------*/ 5 | 6 | using System; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | 10 | namespace ApexSharp.ApexParser.Toolbox 11 | { 12 | /// 13 | /// Wrapper methods for SmartEnumerable[T]. 14 | /// 15 | ////[CoverageExclude] 16 | public static class SmartEnumerableExt 17 | { 18 | /// 19 | /// Extension method to make life easier. 20 | /// 21 | /// Type of enumerable 22 | /// Source enumerable 23 | /// A new SmartEnumerable of the appropriate type 24 | public static SmartEnumerable AsSmartEnumerable(this IEnumerable source) 25 | { 26 | return new SmartEnumerable(source); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Visitors/ApexCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Syntax; 7 | using ApexSharp.ApexParser.Toolbox; 8 | 9 | namespace ApexSharp.ApexParser.Visitors 10 | { 11 | public class ApexCodeGenerator : ApexCodeGeneratorBase 12 | { 13 | public static string GenerateApex(BaseSyntax ast, int tabSize = 4) 14 | { 15 | var generator = new ApexCodeGenerator { IndentSize = tabSize }; 16 | ast.Accept(generator); 17 | return generator.Code.ToString(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/Visitors/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser.Syntax; 7 | 8 | namespace ApexSharp.ApexParser.Visitors 9 | { 10 | public static class Extensions 11 | { 12 | public static string ToApex(this BaseSyntax node, int tabSize = 4) => 13 | ApexCodeGenerator.GenerateApex(node, tabSize); 14 | 15 | public static string GetCodeInsideMethod(this MethodDeclarationSyntax node, int tabSize = 4) => 16 | ApexMethodBodyGenerator.GenerateApex(node, tabSize); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ApexSharp.ApexParser/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ApexSharp.ApexToCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("ApexSharp.ApexParser.Tests")] 4 | -------------------------------------------------------------------------------- /ApexSharp.ApexToCSharp/Visitors/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ApexSharp.ApexParser; 7 | using ApexSharp.ApexParser.Syntax; 8 | 9 | namespace ApexSharp.ApexToCSharp.Visitors 10 | { 11 | public static class Extensions 12 | { 13 | public static string ToCSharp(this BaseSyntax node, int tabSize = 4, string @namespace = null) => 14 | CSharpCodeGenerator.GenerateCSharp(node, tabSize, @namespace); 15 | 16 | public static string ToCSharp(this BaseSyntax node, ApexSharpParserOptions options) => 17 | CSharpCodeGenerator.GenerateCSharp(node, options); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ApexSharp.CSharpToApex/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("ApexSharp.ApexParser.Tests")] 4 | -------------------------------------------------------------------------------- /ApexSharp.CSharpToApex/Visitors/SampleWalker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.CodeAnalysis; 5 | using Microsoft.CodeAnalysis.CSharp; 6 | 7 | namespace ApexSharp.CSharpToApex.Visitors 8 | { 9 | public class SampleWalker : CSharpSyntaxWalker 10 | { 11 | private int IndentLevel { get; set; } = 0; 12 | 13 | private StringBuilder Builder { get; } = new StringBuilder(); 14 | 15 | public override void Visit(SyntaxNode node) 16 | { 17 | var indents = new string('\t', IndentLevel); 18 | Builder.AppendLine(indents + node.Kind()); 19 | 20 | IndentLevel++; 21 | base.Visit(node); 22 | IndentLevel--; 23 | } 24 | 25 | public override string ToString() => Builder.ToString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2018 ApexSharp.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Nuget/BuildNugetPackage.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | dotnet pack --include-symbols -c Release ..\ApexSharp.ApexParser\ApexSharp.ApexParser.csproj -o ..\Nuget -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### A C# to APEX Converter AND a APEX to C# Converter 2 | 3 | [![appveyor](https://ci.appveyor.com/api/projects/status/github/apexsharp/apexparser?svg=true)](https://ci.appveyor.com/project/yallie/apexparser) 4 | [![tests](https://img.shields.io/appveyor/tests/yallie/apexparser.svg)](https://ci.appveyor.com/project/yallie/apexparser/build/tests) 5 | [![codecov](https://codecov.io/gh/apexsharp/apexparser/branch/master/graph/badge.svg)](https://codecov.io/gh/apexsharp/apexparser) 6 | [![NuGet](https://img.shields.io/nuget/v/ApexParser.svg)](https://nuget.org/packages/ApexParser) 7 | 8 | Apex ←→ C# - Two Way [Transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler). 9 | 10 | 11 | ApexSharp.ApexParser 12 | 13 | var ast = ApexSharpParser.GetApexAst(string apexCode) var apexCode = ApexSharpParser.GetApex(ast) 14 | 15 | ApexSharp.ApexToCSharp 16 | 17 | ApexToCSharp.convertToCSharp(apexparser ast) 18 | 19 | CSharpToApex 20 | 21 | SyntaxTree tree = CSharpSyntaxTree.ParseText(cSharpFile); var root = (CompilationUnitSyntax)tree.GetRoot(); var ast CSharpToApex.ConvertToApexAst(root) 22 | 23 | TApexSharp.CSharpToApex 24 | 25 | Var apexCode = ApexSharpParser.GetApex(ast) 26 | 27 | 28 | 29 | This is very early stage Beta Software use it at your own risk :-). 30 | 31 | Jay 32 | EMail: 33 | [LinkedIn](https://www.linkedin.com/in/jayonsoftware/) 34 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | image: Visual Studio 2019 3 | 4 | init: 5 | - git config --global core.autocrlf true 6 | 7 | before_build: 8 | - nuget restore ApexParser.sln 9 | - choco install opencover.portable 10 | - choco install codecov 11 | 12 | after_build: 13 | - dotnet pack -c Release ApexSharp.ApexParser 14 | - dotnet pack -c Release ApexSharp.ApexToCSharp 15 | - dotnet pack -c Release ApexSharp.CSharpToApex 16 | 17 | build: 18 | project: ApexParser.sln 19 | verbosity: minimal 20 | 21 | test_script: 22 | - OpenCover.Console.exe -register:user -target:"nunit3-console.exe" -targetargs:".\ApexSharp.ApexParser.Tests\bin\Debug\net462\ApexSharp.ApexParser.Tests.dll" -filter:"+[*]* -[Apex]* -[ApexSharpDemo]* -[ApexSharpApi]*" -output:".\ApexParser_coverage.xml" 23 | - codecov -f "ApexParser_coverage.xml" 24 | 25 | artifacts: 26 | - path: .\ApexSharp.*\**\*.nupkg 27 | --------------------------------------------------------------------------------