public void JsonStringGeneratorIsGenerated() { var text = @" class TestClass { public void Test() { string reqBody = ''; reqBody = '{""size"":1,""application"":[{""id"":""com.gm.testxy111.pkg"",""version"":""1"",""action"":""Update"",""status"":{""code"":""success""}}]}'; reqBody = '{""size"":0,""application"":[]}'; reqBody = '{""size"":1,""application"":[{""id"":""com.gm.testxy111.pkg"",""version"":""1"",""action"":""Update"",""status"":{""code"":""success""}}]}'; } }"; var apex = Apex.ParseFile(text); Check(apex, @"class TestClass { public void Test() { String reqBody = ''; reqBody = '{""size"":1,""application"":[{""id"":""com.gm.testxy111.pkg"",""version"":""1"",""action"":""Update"",""status"":{""code"":""success""}}]}'; reqBody = '{""size"":0,""application"":[]}'; reqBody = '{""size"":1,""application"":[{""id"":""com.gm.testxy111.pkg"",""version"":""1"",""action"":""Update"",""status"":{""code"":""success""}}]}'; } }"); }
public void JsonStringGeneratorIsGenerated2() { var text = @" class TestClass { public void Test() { tmp.Some_Identifier__tmp = '{""category"":[{""name"":""L10N.Translations"",""details"":{""data"":[{""val"":""50"",""name"":""RecentDestinationsMax""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""6"",""name"":""HomeScreenPages""},{""val"":""2"",""name"":""HomeScreenRows""},{""val"":""4"",""name"":""HomeScreenCols""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""40"",""name"":""FavoritesAudioMax""},{""val"":""10"",""name"":""Unidentified""},'; tmp.Some_Identifier__tmp += '{""tmp"":""20"",""name"":""Something""},{""val"":""2"",""name"":""FavoriteBundleVersion""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""true"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""true"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""1920x1080"",""name"":""HMIResolution""},{""val"":""5.1.1"",""name"":""AndroidOS""},{""val"":""tmp"",""name"":""BuildVersion""},{""val"":""1"",""name"":""GMFrameworkVersion""},{""val"":""From CPUInfo"",""name"":""DeviceProcessor""}]}}]}'; } }"; var apex = Apex.ParseFile(text); Check(apex, @"class TestClass { public void Test() { tmp.Some_Identifier__tmp = '{""category"":[{""name"":""L10N.Translations"",""details"":{""data"":[{""val"":""50"",""name"":""RecentDestinationsMax""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""6"",""name"":""HomeScreenPages""},{""val"":""2"",""name"":""HomeScreenRows""},{""val"":""4"",""name"":""HomeScreenCols""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""40"",""name"":""FavoritesAudioMax""},{""val"":""10"",""name"":""Unidentified""},'; tmp.Some_Identifier__tmp += '{""tmp"":""20"",""name"":""Something""},{""val"":""2"",""name"":""FavoriteBundleVersion""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""true"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""true"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},{""val"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""},'; tmp.Some_Identifier__tmp += '{""tmp"":""false"",""name"":""IRQ_NOT_LESS_OR_EQUAL""}]}},{""name"":""L10N.Translations"",""metadata"":{""property"":[{""val"":""1920x1080"",""name"":""HMIResolution""},{""val"":""5.1.1"",""name"":""AndroidOS""},{""val"":""tmp"",""name"":""BuildVersion""},{""val"":""1"",""name"":""GMFrameworkVersion""},{""val"":""From CPUInfo"",""name"":""DeviceProcessor""}]}}]}'; } }"); }
public void RunAsStatementIsGenerated() { var text = @" class Test { @isTest public static void LogErrorExceptionWithMessage() { System.runAs(Info3TestFactory.getGatewayAdminUser()) { } } }"; var apex = Apex.ParseFile(text); Check(apex, @"class Test { @IsTest public static void LogErrorExceptionWithMessage() { System.runAs(Info3TestFactory.getGatewayAdminUser()) { } } }"); }
// コンストラクター internal LineGroup(LineGroupCollection parent, Polygon polygon, double transparency) { this.Parent = parent; this.Transparency = transparency; using (var e = polygon.Apexes.GetEnumerator()) { var lineList = new List <Line>(polygon.Apexes.Count); // 直線シェイプを作成する。 if (e.MoveNext()) { Apex first = e.Current; Apex prev = e.Current; while (e.MoveNext()) { Apex current = e.Current; var line = parent.Parent.CreateLine(this, prev, current); lineList.Add(line); prev = current; } { var line = parent.Parent.CreateLine(this, prev, first); lineList.Add(line); } } this.lines = lineList.ToArray(); } }
public void MapStringStringIsGeneratedProperly() { var apex = Apex.ParseClass( @"class Sample { public static Map<String, string> SomeMap { get; private set; } public Map<string, STRING> SomeMethod() { return new Map<String, string>(); } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { public static Map<string, string> SomeMap { get; private set; } public Map<string, string> SomeMethod() { return new Map<string, string>(); } } }"); }
void shellListView_OnShellItemAdded(object sender, Apex.WinForms.Controls.ListViewItemEventArgs args) { var shellItem = shellListView.GetShellItem(args.Item); // If the icon handler is associated with the the item, test it. if (IsServerAssociatedWithShellItem(TestIconHandler, shellItem)) DoTestIconHandler(args.Item); // If the info tip handler is associated with the item, test it. if (IsServerAssociatedWithShellItem(TestInfoTipHandler, shellItem)) DoTestInfoTipHandler(args.Item); // If the drop handler is associated with the item, test it. if (IsServerAssociatedWithShellItem(TestDropHandler, shellItem)) DoTestDropHandler(args.Item); // If the preview handler is associated with the item, test it. if (IsServerAssociatedWithShellItem(TestPreviewHandler, shellItem)) DoTestPreviewHandler(args.Item); // If a thumbnail handleris associated with the item, highlight it. if(IsServerAssociatedWithShellItem(TestThumbnailHandler, shellItem)) HighlightItem(args.Item); // If an icon overlay handler is associated with the item, highlight it. if(IsServerAssociatedWithShellItem(TestIconOverlayHandler, shellItem)) HighlightItem(args.Item); }
public XElement serialize(CFurMeshResource chunk) { var ret = NvidiaXML.CreateStructHeader("", "Ref", "HairSceneDescriptor", "1.0", checksum); ret.AddNvValue("numGuideHairs", "U32", chunk.BoneIndices.Count.ToString()); ret.AddNvValue("numVertices", "U32", chunk.Positions.Count.ToString()); ret.AddNvArray("vertices", "Vec3", "", Apex.FormatCoordinateArray(chunk.Positions)); //TODO: Check why this has wrong numbers. Its correct but the matrix needs to be changed somehow! var endindicies = chunk.EndIndices; ret.AddNvArray("endIndices", "U32", endindicies.Count.ToString(), endindicies.Aggregate("", (c, n) => c += " " + n)); ret.AddNvValue("numFaces", "U32", ""); //TODO var faceIndices = chunk.FaceIndices; ret.AddNvArray("faceIndices", "U32", faceIndices.Count.ToString(), faceIndices.Aggregate("", (c, n) => c += " " + n)); ret.AddNvArray("faceUVs", "Vec2", "", ""); //TODO ret.AddNvValue("numBones", "U32", chunk.BoneCount.ToString()); ret.AddNvArray("boneIndices", "Vec4", "", ""); //TODO ret.AddNvArray("boneWeights", "Vec4", "", ""); //TODO ret.AddNvArray("boneNames", "U8", "", ""); //TODO ret.AddNvArray("boneNameList", "String", "", ""); //TODO ret.AddNvArray("bindPoses", "Mat44", "", ""); //TODO ret.AddNvArray("boneParents", "I32", "", ""); //TODO ret.AddNvValue("numBoneSpheres", "U32", ""); //TODO ret.AddNvArray("boneSpheres", "Struct", "", ""); //TODO: Fix AddnVarray(); structElements?? ret.AddNvValue("numBoneCapsules", "U32", ""); //TODO ret.AddNvArray("boneCapsuleIndices", "U32", "", ""); //TODO ret.AddNvValue("numPinConstraints", "U32", ""); //TODO ret.AddNvArray("pinConstraints", "Struct", "", ""); //TODO: Fix AddnVarray(); structElements?? ret.AddNvValue("sceneUnit", "F32", ""); //TODO ret.AddNvValue("upAxis", "U32", ""); //TODO ret.AddNvValue("handedness", "U32", ""); //TODO return(ret); }
public void NewListExpressionIsGenerated() { var text = @" class TestClass { void Test() { objCtrl.deliverableTypesName = new List<String> { 'test1', 'test2' } ; objCtrl.deliverableTypesDescription = new List<String> { 'test1', 'test2' } ; } }"; var apex = Apex.ParseFile(text); Check(apex, @"class TestClass { void Test() { objCtrl.deliverableTypesName = new List<String>{'test1', 'test2'}; objCtrl.deliverableTypesDescription = new List<String>{'test1', 'test2'}; } }"); }
public void SingleStaticInitializerIsGeneratedAsStaticConstructor() { var apex = Apex.ParseClass(@" class SingleStaticInitializer { static { System.debug('Hello'); } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class SingleStaticInitializer { static SingleStaticInitializer() { System.debug(""Hello""); } } }"); }
public void AnnotationsWithMultipleParametersAreCommaSeparated() { var apex = Apex.ParseClass( @"class Sample { @InvocableMethod(label='Get Account Names' description='Returns the list of account names corresponding to the specified account IDs.') void SomeMethod() { } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { [InvocableMethod(label=""Get Account Names"", description=""Returns the list of account names corresponding to the specified account IDs."")] void SomeMethod() { } } }"); }
public void ApexInstanceOfIsConvertedToCSharpIs() { var apex = Apex.ParseClass( @"class Sample { static void SomeMethod() { bool t = Sample instanceof SObject; } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { static void SomeMethod() { bool t = Sample is SObject; } } }"); }
public void RunAsStatementIsGeneratedAsUsingSystemRunAs() { var apex = Apex.ParseClass( @"class Sample { public void SomeMethod() { System.runAs(me) { System.debug('Hi there!'); } } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { public void SomeMethod() { using (System.runAs(me)) { System.debug(""Hi there!""); } } } }"); }
public void GlobalModifierGeneratesPublicClassWithGlobalAttribute() { var apex = Apex.ParseClass( @"global class Sample { global static void SomeMethod() { } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; [Global] public class Sample { [Global] public static void SomeMethod() { } } }"); }
public void StringValueOfXIsReplacedWithXToString() { var apex = Apex.ParseClass( @"class Sample { public Date SomeMethod() { String x = string.valueOf(123); String y = String.valueOf(10 + 20); return Date.Today(); } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { public Date SomeMethod() { string x = 123.ToString(); string y = (10 + 20).ToString(); return Date.Today(); } } }"); }
public void AnnotationWithParametersIsConvertedProperly() { var apex = Apex.ParseClass( @"class Sample { @future(CallOut=true) @Some(Name='test') public Datetime SomeMethod() { } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { [Future(CallOut=true)] [Some(Name=""test"")] public DateTime SomeMethod() { } } }"); }
public void ParseZip(string fileName) { var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var filePath = Path.Combine(currentPath, "ApexTestLibraries", fileName); var file = File.OpenRead(filePath); var zip = new ZipArchive(file, ZipArchiveMode.Read, false); var apexClasses = from entry in zip.Entries.OfType <ZipArchiveEntry>() where entry.Name.EndsWith(".cls", StringComparison.InvariantCultureIgnoreCase) select entry; // Process all Apex files, don't stop after the first error Assert.Multiple(() => { foreach (var entry in apexClasses) { using (var stream = entry.Open()) using (var reader = new StreamReader(stream)) { // Report failing file names along with the parse exception var fileContents = reader.ReadToEnd(); Assert.DoesNotThrow(() => Apex.ParseFile(fileContents), $"Parsing failure on file: {entry.FullName}"); } } }); }
public void SomeDotClassGotReplacedWithTypeofSome() { var apex = Apex.ParseClass( @"class Sample { public Datetime SomeMethod() { Type type = Sample.class; AnotherMethod(String.class); return Datetime.Now(); } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class Sample { public DateTime SomeMethod() { Type type = typeof(Sample); AnotherMethod(typeof(string)); return DateTime.Now(); } } }"); }
public void ClassInnerCommentsAfterInnerClassAreGenerated() { var apex = Apex.ParseClass( @"class Test { // leading class InnerTest { // inner comment } // trailing comment // inner comments } // trailing"); Check(apex, @"class Test { // leading class InnerTest { // inner comment } // trailing comment // inner comments } // trailing"); }
public void CustomCSharpNamespaceIsSupported() { var apex = Apex.ParseClass(@"// custom namespace public global class TestClass { private with sharing class TestInner { } }"); CompareLineByLine(apex.ToCSharp(@namespace: "MyNamespace"), @"namespace MyNamespace { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; // custom namespace [Global] public class TestClass { [WithSharing] private class TestInner { } } }"); }
public void ClassInnerEnumsAreGenerated() { var apex = Apex.ParseClass( @"class Test { // leading public enum Boo { // true Tru, // false Fa // inner enum comment } // trailing comment // inner comments } // trailing"); Check(apex, @"class Test { // leading public enum Boo { // true Tru, // false Fa // inner enum comment } // trailing comment // inner comments } // trailing"); }
public void InitializeIsoGrid(BoundingBox bound) { Apex.GetComponent <Renderer>( ).material.color = DefaultColor; InitializeIsoGrid( ); //AxialLabelSystem.Initialize( ); // May need to intialize the 'view' (visualizer) here? HideBackgrounds(!DrawBackgrounds); }
public void LeadingAndTrailingCommentsForStatements() { var apex = Apex.ParseClass(@" @isTest public class ClassUnitTest { static testMethod void StaticTestMethodOne() { //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); } static testMethod void StaticTestMethodTwo() { //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); } }"); Check(apex, @"@IsTest public class ClassUnitTest { static testMethod void StaticTestMethodOne() { //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); } static testMethod void StaticTestMethodTwo() { //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); } }"); var md = apex.Methods.First(); CompareLineByLine(md.GetCodeInsideMethod(), @"//System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal'); //System.AssertNotEquals(5, 0, 'Assert Not Equal'); System.AssertNotEquals(5, 0, 'Assert Not Equal');"); }
public void SwitchStatementIsGenerated() { var apex = Apex.ParseClass( @"class Test { public void T() { // brand new switch statement switch on CalculateSomeValue() { // a bunch of expressions when 1, 2, Hello() { // oh, great return 0; } // sObject when Contact x { return -1; } /* nothing matched */ when else { return 1; // no way } // when else } // switch } }"); Check(apex, @"class Test { public void T() { // brand new switch statement switch on CalculateSomeValue() { // a bunch of expressions when 1, 2, Hello() { // oh, great return 0; } // sObject when Contact x { return -1; } /* nothing matched */ when else { return 1; // no way } // when else } // switch } }"); }
public void ClassWithConstructorMethodAndPropertyIsGenerated() { var apex = Apex.ParseClass(@" public class MyDemo { private MyDemo(float s) { Size = s;while(true){break;} } public void Test(string name, int age) { Contact c = new Contact(name, age); insert c; } public float Size { get; private set { System.debug('trying to set'); } } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; public class MyDemo { private MyDemo(float s) { Size = s; while (true) { break; } } public void Test(string name, int age) { Contact c = new Contact(name, age); Soql.insert(c); } public float Size { get; private set { System.debug(""trying to set""); } } } }"); }
public void ParseAll(string repoURL) { var apexFiles = GitHubHelper.GetCodeFromGitFolder(repoURL, ".cls"); // Process all Apex files, don't stop after the first error Assert.Multiple(() => { foreach (var apexFile in apexFiles) { // Report failing file names along with the parse exception Assert.DoesNotThrow(() => Apex.ParseFile(apexFile.Value), $"Parsing failure on file: {apexFile.Key}"); } }); }
public void CommentsPrefixedWithNoApexAreCopiedAsIs() { var apex = Apex.ParseClass(@" public class MyDemo { private MyDemo(float s) { Size = s;while(true){break;} } public void Test(string name, int age) { Contact c = new Contact(name, age); insert c; } //:NoApex public float Size //:NoApex { //:NoApex get; //:NoApex private set; //:NoApex } }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; public class MyDemo { private MyDemo(float s) { Size = s; while (true) { break; } } public void Test(string name, int age) { Contact c = new Contact(name, age); Soql.insert(c); } public float Size { get; private set; } } }"); }
public void MultipleStaticInitializersAreGeneratedAsStaticConstructorWithSeveralBlocks() { var apex = Apex.ParseClass(@" class MultipleStaticInitializers { // the first initializer static { System.debug(1); } // the second initializer static { System.debug(2); } // the last initializer static { System.debug(3); } // trailing comment }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; class MultipleStaticInitializers { // the first initializer static MultipleStaticInitializers() { // the first initializer { System.debug(1); } // the second initializer { System.debug(2); } // the last initializer { System.debug(3); } // trailing comment } } }"); }
public void JsonStringGeneratorIsGenerated3() { var text = @" class TestClass { public void Test() { tmp.requestBody = Blob.valueof('{test}'); tmp.requestBody = Blob.valueof('{test}'); tmp.setBody('{""name"":""name""}'); tmp.tmpName = new List<String> {'test1', 'test2'}; tmp.tmpDesc = new List<String> {'test1', 'test2'}; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = ' {}8236kjah{}{'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = 'value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = ' : ""Temp"" } ] }'; tmp.requestBody = Blob.valueOf('{ ""checklist"": [ { ""checklistItem"": [ { ""id"": ""' + existingChecklist0.id + '"", ""isChecked"": false }, { ""id"": ""' + newChecklist0.id + '"", ""isChecked"": true }, { ""id"": ""' + newChecklist1.id + '"", ""isChecked"": false } ] } ] }'); result = Something.replace(new List<tmp.SomeRequest>{req}, tmp); } }"; var apex = Apex.ParseFile(text); Check(apex, @"class TestClass { public void Test() { tmp.requestBody = Blob.valueof('{test}'); tmp.requestBody = Blob.valueof('{test}'); tmp.setBody('{""name"":""name""}'); tmp.tmpName = new List<String>{'test1', 'test2'}; tmp.tmpDesc = new List<String>{'test1', 'test2'}; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = ' {}8236kjah{}{'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = 'value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = '{ ""SegmentationFault"" : [ { ""key"" : ""Age"", ""value"" : ""1234"" }, { ""key"" : ""Species"", ""value"" : ""Beaver"" } ] }'; tmp.SomeIdentifier__tmp = ' : ""Temp"" } ] }'; tmp.requestBody = Blob.valueOf('{ ""checklist"": [ { ""checklistItem"": [ { ""id"": ""'+ existingChecklist0.id + '"", ""isChecked"": false }, { ""id"": ""'+ newChecklist0.id + '"", ""isChecked"": true }, { ""id"": ""'+ newChecklist1.id + '"", ""isChecked"": false } ] } ] }'); result = Something.replace(new List<tmp.SomeRequest>{req}, tmp); } }"); }
// Define Curve points private PointF[] getCurvePoints(Apex apexLocation, int i, int i2) { PointF[] points = new PointF[7]; switch (apexLocation) { case Apex.Right: points[0] = new PointF((float)(100 * scale + gridScale * i + puzzleRect.X), (float)(0 * scale + gridScale * i2 + puzzleRect.Y)); points[1] = new PointF((float)(99 * scale + gridScale * i + puzzleRect.X), (float)(40 * scale + gridScale * i2 + puzzleRect.Y)); points[2] = new PointF((float)(121 * scale + gridScale * i + puzzleRect.X), (float)(36 * scale + gridScale * i2 + puzzleRect.Y)); points[3] = new PointF((float)(133 * scale + gridScale * i + puzzleRect.X), (float)(50 * scale + gridScale * i2 + puzzleRect.Y)); points[4] = new PointF((float)(121 * scale + gridScale * i + puzzleRect.X), (float)(64 * scale + gridScale * i2 + puzzleRect.Y)); points[5] = new PointF((float)(99 * scale + gridScale * i + puzzleRect.X), (float)(60 * scale + gridScale * i2 + puzzleRect.Y)); points[6] = new PointF((float)(100 * scale + gridScale * i + puzzleRect.X), (float)(100 * scale + gridScale * i2 + puzzleRect.Y)); break; case Apex.Down: points[0] = new PointF((float)(0 * scale + gridScale * i2 + puzzleRect.X), (float)(100 * scale + gridScale * i + puzzleRect.Y)); points[1] = new PointF((float)(40 * scale + gridScale * i2 + puzzleRect.X), (float)(99 * scale + gridScale * i + puzzleRect.Y)); points[2] = new PointF((float)(36 * scale + gridScale * i2 + puzzleRect.X), (float)(121 * scale + gridScale * i + puzzleRect.Y)); points[3] = new PointF((float)(50 * scale + gridScale * i2 + puzzleRect.X), (float)(133 * scale + gridScale * i + puzzleRect.Y)); points[4] = new PointF((float)(64 * scale + gridScale * i2 + puzzleRect.X), (float)(121 * scale + gridScale * i + puzzleRect.Y)); points[5] = new PointF((float)(60 * scale + gridScale * i2 + puzzleRect.X), (float)(99 * scale + gridScale * i + puzzleRect.Y)); points[6] = new PointF((float)(100 * scale + gridScale * i2 + puzzleRect.X), (float)(100 * scale + gridScale * i + puzzleRect.Y)); break; case Apex.Left: points[0] = new PointF((float)(100 * scale + gridScale * i + puzzleRect.X), (float)(0 * scale + gridScale * i2 + puzzleRect.Y)); points[1] = new PointF((float)(101 * scale + gridScale * i + puzzleRect.X), (float)(40 * scale + gridScale * i2 + puzzleRect.Y)); points[2] = new PointF((float)(79 * scale + gridScale * i + puzzleRect.X), (float)(36 * scale + gridScale * i2 + puzzleRect.Y)); points[3] = new PointF((float)(67 * scale + gridScale * i + puzzleRect.X), (float)(50 * scale + gridScale * i2 + puzzleRect.Y)); points[4] = new PointF((float)(79 * scale + gridScale * i + puzzleRect.X), (float)(64 * scale + gridScale * i2 + puzzleRect.Y)); points[5] = new PointF((float)(101 * scale + gridScale * i + puzzleRect.X), (float)(60 * scale + gridScale * i2 + puzzleRect.Y)); points[6] = new PointF((float)(100 * scale + gridScale * i + puzzleRect.X), (float)(100 * scale + gridScale * i2 + puzzleRect.Y)); break; case Apex.Up: default: points[0] = new PointF((float)(0 * scale + gridScale * i2 + puzzleRect.X), (float)(100 * scale + gridScale * i + puzzleRect.Y)); points[1] = new PointF((float)(40 * scale + gridScale * i2 + puzzleRect.X), (float)(101 * scale + gridScale * i + puzzleRect.Y)); points[2] = new PointF((float)(36 * scale + gridScale * i2 + puzzleRect.X), (float)(79 * scale + gridScale * i + puzzleRect.Y)); points[3] = new PointF((float)(50 * scale + gridScale * i2 + puzzleRect.X), (float)(67 * scale + gridScale * i + puzzleRect.Y)); points[4] = new PointF((float)(64 * scale + gridScale * i2 + puzzleRect.X), (float)(79 * scale + gridScale * i + puzzleRect.Y)); points[5] = new PointF((float)(60 * scale + gridScale * i2 + puzzleRect.X), (float)(101 * scale + gridScale * i + puzzleRect.Y)); points[6] = new PointF((float)(100 * scale + gridScale * i2 + puzzleRect.X), (float)(100 * scale + gridScale * i + puzzleRect.Y)); break; } return(points); }
public void UnsupportedModifiersGetConvertedIntoAttributes() { var apex = Apex.ParseClass(@"// unsupported modifiers public global class TestClass { private with sharing class Inner1 { } public without sharing class Inner2 { } private testMethod void MyTest(final int x) { } public webservice void MyService() { } transient int TransientField = 0; }"); Check(apex, @"namespace ApexSharpDemo.ApexCode { using Apex.ApexSharp; using Apex.ApexSharp.ApexAttributes; using Apex.System; using ApexSharpApi.ApexApi; using SObjects; // unsupported modifiers [Global] public class TestClass { [WithSharing] private class Inner1 { } [WithoutSharing] public class Inner2 { } [Test] private void MyTest([Final] int x) { } [WebService] public void MyService() { } [Transient] int TransientField = 0; } }"); }
public void ClassWithConstructorMethodAndPropertyIsGenerated() { var apex = Apex.ParseClass(@" // this is my demo public class MyDemo { private MyDemo(float s) { Size = s;while(true){break;} } public void Test(string name, int age) { Contact c = new Contact(name, age); insert c; } public float Size { get; private set { System.debug('trying to set'); } } }"); Check(apex, @"// this is my demo public class MyDemo { private MyDemo(float s) { Size = s; while (true) { break; } } public void Test(String name, int age) { Contact c = new Contact(name, age); insert c; } public float Size { get; private set { System.debug('trying to set'); } } }"); }
static Tuple2<Vector3, Vector3> GetTangentPoints(Apex apex1, Apex apex2, float radius) { return GetTangentPoints(apex1.type, apex1.position, apex2.type, apex2.position, radius); }
/// <summary> /// Handles the Executed event of the GoToSpiderSolitaireCommsand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void GoToSpiderSolitaireCommsand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { mainPivot.SelectedPivotItem = mainPivot.PivotItems[2]; }
/// <summary> /// Handles the Executed event of the SettingsCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> private void SettingsCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { mainPivot.SelectedPivotItem = mainPivot.PivotItems[3]; }
/// <summary> /// Handles the Executed event of the GoToCasinoCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void GoToCasinoCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { mainPivot.SelectedPivotItem = mainPivot.PivotItems[1]; }
/// <summary> /// Handles the Executed event of the GoToKlondikeSolitaireCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void GoToKlondikeSolitaireCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { mainPivot.SelectedPivotItem = mainPivot.PivotItems[0]; }
/// <summary> /// Handles the Executed event of the StopProcessCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void StopProcessCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { consoleControl.StopProcess(); UpdateProcessState(); }
/// <summary> /// Handles the Executed event of the ClearOutputCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void ClearOutputCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { consoleControl.ClearOutput(); }
// This algorithm is basically the Simple Stupid Funnel Algorithm posted by // Mikko in the Digesting Duck blog. This one has been modified to account for agent radius. public static List<Vector3> Funnel(List<Vector3> portals, float radius) { // In some special cases, it is possible that the tangents of the apexes will // cause the funnel to collapse to the left or right portal right before going to // the final position. This happens when the final position is more 'outward' than // the vector from the apex to the portal extremity, and the final position is // actually 'closer' to the previous portal than the 'current' portal extremity. // If that happens, we remove the portal before the last from the list. I have no // proof that this guarantees the correct behavior, though. if (portals.Count >= 8) { // This seems to be possible to happen only when there are 4 or more // portals (first and last are start and destination) int basePortal = portals.Count - 6; int lastPortal = portals.Count - 4; int destinationPortal = portals.Count - 2; // First, check left Vector3 baseLast = portals[lastPortal] - portals[basePortal]; Vector3 baseDest = portals[destinationPortal] - portals[basePortal]; if (baseDest.sqrMagnitude2() < baseLast.sqrMagnitude2()) { portals.RemoveRange(lastPortal, 2); } else { // Now check right baseLast = portals[lastPortal + 1] - portals[basePortal + 1]; baseDest = portals[destinationPortal + 1] - portals[basePortal + 1]; if (baseDest.sqrMagnitude2() < baseLast.sqrMagnitude2()) { portals.RemoveRange(lastPortal, 2); } } } Vector3 portalApex = portals[0]; Vector3 portalLeft = portals[0]; Vector3 portalRight = portals[1]; int portalLeftIndex = 0; int portalRightIndex = 0; // Put the first point into the contact list Apex startApex = new Apex(); startApex.position = portalApex; startApex.type = ApexType.Point; List<Apex> contactVertices = new List<Apex>(); contactVertices.Add(startApex); ApexType currentType = ApexType.Point; Vector3 previousValidLSegment = Vector3.zero; Vector3 previousValidRSegment = Vector3.zero; for (int i = 2; i < portals.Count; i += 2) { Vector3 left = portals[i]; Vector3 right = portals[i + 1]; ApexType nextLeft = ApexType.Left; ApexType nextRight = ApexType.Right; if (i >= portals.Count - 2) { // Correct next apex type if we are at the end of the channel nextLeft = ApexType.Point; nextRight = ApexType.Point; } // Build radius-inflated line segments Tuple2<Vector3, Vector3> tuple = new Tuple2<Vector3, Vector3>(portalApex, left); tuple = GetTangentPoints(currentType, tuple.First, nextLeft, tuple.Second, radius); Vector3 currentLSegment = tuple.Second - tuple.First; tuple.Set(portalApex, right); tuple = GetTangentPoints(currentType, tuple.First, nextRight, tuple.Second, radius); Vector3 currentRSegment = tuple.Second - tuple.First; //Right side // Does new 'right' reduce the funnel? if (previousValidRSegment.cross2(currentRSegment) >= 0) { // Does it NOT cross the left side? // Is the apex the same as portal right? (if true, no chance but to move) if (portalApex.equals2(portalRight) || previousValidLSegment.cross2(currentRSegment) <= 0) { portalRight = right; previousValidRSegment = currentRSegment; portalRightIndex = i; } else { // Collapse if (currentRSegment.sqrMagnitude2() > previousValidLSegment.sqrMagnitude2()) { portalApex = portalLeft; portalRight = portalApex; Apex apex = new Apex(); apex.position = portalApex; apex.type = ApexType.Left; contactVertices.Add(apex); currentType = ApexType.Left; portalRightIndex = portalLeftIndex; i = portalLeftIndex; } else { portalRight = right; previousValidRSegment = currentRSegment; portalRightIndex = i; portalApex = portalRight; portalLeft = portalApex; Apex apex = new Apex(); apex.position = portalApex; apex.type = ApexType.Right; contactVertices.Add(apex); currentType = ApexType.Right; portalLeftIndex = portalRightIndex; i = portalRightIndex; } previousValidLSegment = Vector3.zero; previousValidRSegment = Vector3.zero; continue; } } // Left Side // Does new 'left' reduce the funnel? if (previousValidLSegment.cross2(currentLSegment) <= 0) { // Does it NOT cross the right side? // Is the apex the same as portal left? (if true, no chance but to move) if (portalApex.equals2(portalLeft) || previousValidRSegment.cross2(currentLSegment) >= 0 ) { portalLeft = left; previousValidLSegment = currentLSegment; portalLeftIndex = i; } else { // Collapse if (currentLSegment.sqrMagnitude2() > previousValidRSegment.sqrMagnitude2()) { portalApex = portalRight; portalLeft = portalApex; Apex apex = new Apex(); apex.position = portalApex; apex.type = ApexType.Right; contactVertices.Add(apex); currentType = ApexType.Right; portalLeftIndex = portalRightIndex; i = portalRightIndex; } else { portalLeft = left; previousValidLSegment = currentLSegment; portalLeftIndex = i; portalApex = portalLeft; portalRight = portalApex; Apex apex = new Apex(); apex.position = portalApex; apex.type = ApexType.Left; contactVertices.Add(apex); currentType = ApexType.Left; portalRightIndex = portalLeftIndex; i = portalLeftIndex; } previousValidLSegment = Vector3.zero; previousValidRSegment = Vector3.zero; continue; } } } // Put the last point into the contact list if (contactVertices[contactVertices.Count - 1].position.equals2(portals[portals.Count - 1])) { // Last point was added to funnel, so we need to change its type to point Apex endApex = new Apex(); endApex.position = portals[portals.Count - 1]; endApex.type = ApexType.Point; contactVertices[contactVertices.Count - 1] = endApex; } else { // Last point was not added to funnel, so we add it Apex endApex = new Apex(); endApex.position = portals[portals.Count - 1]; endApex.type = ApexType.Point; contactVertices.Add(endApex); } return BuildPath(radius, contactVertices); }
/// <summary> /// Handles the Executed event of the ClearOutputCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void ClearOutputCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { }
/// <summary> /// Handles the Executed event of the StopProcessCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void StopProcessCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { }
/// <summary> /// Handles the Executed event of the StartCommandPromptCommand control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">The <see cref="Apex.MVVM.CommandEventArgs"/> instance containing the event data.</param> void StartCommandPromptCommand_Executed(object sender, Apex.MVVM.CommandEventArgs args) { consoleControl.StartProcess("cmd.exe", string.Empty); }