Skip to content

Commit 990a76d

Browse files
committed
Updated the grammar to be able to parse the standard APIs.
1 parent 8ddc0b2 commit 990a76d

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

ApexParser/Parser/ApexKeywords.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static string Normalized(this string keyword) =>
4343
////public const string Activate = "activate"; // reserved for future use
4444
public const string And = "and";
4545
////public const string Any = "any"; // reserved for future use
46-
public const string Array = "array";
46+
////public const string Array = "array"; // hack, see below
4747
public const string As = "as";
4848
public const string Asc = "asc";
4949
////public const string Autonomous = "autonomous"; // reserved for future use
@@ -79,7 +79,7 @@ public static string Normalized(this string keyword) =>
7979
public const string False = "false";
8080
public const string Final = "final";
8181
public const string Finally = "finally";
82-
public const string Float = "float"; // reserved for future use
82+
////public const string Float = "float"; // hack, see below
8383
public const string For = "for";
8484
public const string From = "from";
8585
////public const string Future = "future"; // annotation, see below
@@ -109,7 +109,7 @@ public static string Normalized(this string keyword) =>
109109
////public const string Loop = "loop"; // reserved for future use
110110
////public const string Map = "Map"; // Map<...> is a built-in generic type
111111
////public const string Merge = "merge"; // hack, see below
112-
public const string New = "new";
112+
////public const string New = "new"; // hack, see below
113113
public const string Next90Days = "next_90_days";
114114
public const string NextMonth = "next_month";
115115
public const string NextNDays = "next_n_days";
@@ -124,7 +124,7 @@ public static string Normalized(this string keyword) =>
124124
public const string Or = "or";
125125
////public const string Outer = "outer"; // reserved for future use
126126
public const string Override = "override";
127-
public const string Package = "package";
127+
////public const string Package = "package"; // hack, see below
128128
////public const string Parallel = "parallel"; // reserved for future use
129129
////public const string Pragma = "pragma"; // reserved for future use
130130
public const string Private = "private";
@@ -158,7 +158,7 @@ public static string Normalized(this string keyword) =>
158158
public const string Tolabel = "tolabel";
159159
public const string Tomorrow = "tomorrow";
160160
////public const string Transaction = "transaction"; // reserved for future use
161-
public const string Trigger = "trigger";
161+
////public const string Trigger = "trigger"; // hack, see below
162162
public const string True = "true";
163163
public const string Try = "try";
164164
////public const string Type = "type"; // reserved for future use
@@ -186,18 +186,20 @@ public static string Normalized(this string keyword) =>
186186
public static string Last => "last";
187187
public static string Limit => "limit"; // SuggestionOption.setLimit(limit) parameter name
188188
public static string Merge => "merge"; // System.Database class method
189+
public static string New => "new"; // System.Trigger class property name
189190
public static string Order => "order";
191+
public static string Package => "package"; // Package is a built-in namespace
190192
public static string Rollback => "rollback"; // System.Database class method
191193
public static string Savepoint => "savepoint"; // System.Savepoint class
192194
public static string Sharing => "sharing";
193-
public static string String => "String"; // built-in type
194195
public static string System => "System"; // used in qualified identifier: System.debug
195196
public static string Undelete => "undelete"; // System.Database class method
196197
public static string Update => "update"; // System.Database class method
197198
public static string Upsert => "upsert"; // System.Database class method
198199
public static string With => "with";
199200

200201
// 3. Not listed in the official documentation but apparently used
202+
public static string Array => "array"; // used as SoapType enum member
201203
public static string Blob => "Blob"; // built-in type
202204
public static string Boolean => "Boolean"; // built-in type
203205
public static string ConvertCurrency => "convertcurrency"; // seems to be a valid method name
@@ -206,6 +208,7 @@ public static string Normalized(this string keyword) =>
206208
public static string Datetime => "Datetime"; // built-in type
207209
public static string Decimal => "Decimal"; // built-int type
208210
public static string Double => "Double"; // built-in type
211+
public static string Float => "float"; // reserved for the future use, but is used as ParameterType enum member
209212
public static string Get => "get"; // "get" seems to be a valid method name
210213
public static string ID => "ID"; // built-in type
211214
public static string Integer => "Integer"; // built-in type
@@ -219,9 +222,11 @@ public static string Normalized(this string keyword) =>
219222
public static string Set => "set"; // "set" seems to be a valid method name
220223
public static string SetType => "Set"; // Set<...> is a built-in generic type
221224
public static string Sort => "sort"; // seems to be valid method name
225+
public static string String => "String"; // built-in type
222226
public static string Time => "Time"; // built-in type
223227
public static string Today => "today"; // System.today() method
224228
public static string Transient => "transient"; // variable modifier
229+
public static string Trigger => "trigger"; // built-in Trigger class
225230
public static string Void => "void";
226231
////public const string Volatile = "volatile"; // the status is unclear
227232
public static string WebService => "webservice"; // method modifier

ApexParser/Toolbox/GenericExpressionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public static string ConvertCSharpIsTypeExpressionToApex(string expression)
228228
{ ApexKeywords.Boolean, "bool" },
229229
{ ApexKeywords.Byte, "byte" },
230230
{ ApexKeywords.Char, "char" },
231-
{ ApexKeywords.Datetime, "DateTime" },
231+
{ ApexKeywords.Datetime, "Datetime" },
232232
{ ApexKeywords.Date, "Date" },
233233
{ ApexKeywords.Decimal, "decimal" },
234234
{ ApexKeywords.Double, "double" },

ApexParserTest/ApexRoundtrip/PrimitiveTypes_CSharp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PrimitiveTypes
1414

1515
public Date MyDate = Date.Today();
1616

17-
public DateTime MyDateTime = DateTime.Now();
17+
public Datetime MyDateTime = Datetime.Now();
1818

1919
// public Decimal MyDecimal = 12.4567;
2020
public double d = 3.133433;

ApexParserTest/ApexRoundtrip/PropertyAndField_CSharp.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ namespace ApexSharpDemo.ApexCode
88

99
public class PropertyAndField
1010
{
11-
public DateTime DateTimeGetSet { get; set; }
11+
public Datetime DateTimeGetSet { get; set; }
1212

13-
public List<DateTime> DateTimeGetSetGeneric { get; set; }
13+
public List<Datetime> DateTimeGetSetGeneric { get; set; }
1414

15-
public DateTime[] DateTimeGetSetArray { get; set; }
15+
public Datetime[] DateTimeGetSetArray { get; set; }
1616

17-
public DateTime DateTimeEmpty;
17+
public Datetime DateTimeEmpty;
1818

19-
public DateTime DateTimeInitialized = DateTime.Now();
19+
public Datetime DateTimeInitialized = Datetime.Now();
2020

21-
public List<DateTime> DateTimeList = new List<DateTime>();
21+
public List<Datetime> DateTimeList = new List<Datetime>();
2222

23-
public DateTime[] DateTimeArray = new DateTime[5];
23+
public Datetime[] DateTimeArray = new Datetime[5];
2424

2525
public string Name = "jay";
2626

@@ -45,11 +45,11 @@ public class PropertyAndField
4545

4646
public void MethodOne()
4747
{
48-
DateTime dateTimeEmpty;
49-
dateTimeEmpty = DateTime.Now();
50-
DateTime dateTimeInitilized = DateTime.Now();
51-
List<DateTime> dateTimeList = new List<DateTime>();
52-
DateTime[] dateTimeArrary = new DateTime[5];
48+
Datetime dateTimeEmpty;
49+
dateTimeEmpty = Datetime.Now();
50+
Datetime dateTimeInitilized = Datetime.Now();
51+
List<Datetime> dateTimeList = new List<Datetime>();
52+
Datetime[] dateTimeArrary = new Datetime[5];
5353
string name;
5454
name = "Jay";
5555
}

ApexParserTest/Toolbox/GenericExpressionHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public void ConvertTypeNames()
396396

397397
Assert.AreEqual(ApexKeywords.Integer, ToApex("int"));
398398
Assert.AreEqual(ApexKeywords.String, ToApex("string"));
399-
Assert.AreEqual(ApexKeywords.Datetime, ToApex("DateTime"));
399+
Assert.AreEqual(ApexKeywords.Datetime, ToApex("Datetime")); // not sure if we convert System.DateTime to Apex.System.Datetime?
400400
Assert.AreEqual(ApexKeywords.Time, ToApex("Time"));
401401
}
402402

ApexParserTest/Visitors/CSharpGeneratorTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,9 @@ string Normalize(string id) =>
10091009

10101010
Assert.AreEqual("string", Normalize(ApexKeywords.String));
10111011
Assert.AreEqual("bool", Normalize(ApexKeywords.Boolean));
1012-
Assert.AreEqual(nameof(DateTime), Normalize(ApexKeywords.Datetime));
1012+
1013+
// not anymore: Apex.System.Datetime is used instead of System.DateTime
1014+
//Assert.AreEqual(nameof(DateTime), Normalize(ApexKeywords.Datetime));
10131015
}
10141016

10151017
[Test]
@@ -1107,7 +1109,7 @@ public void SomeDotClassGotReplacedWithTypeofSome()
11071109
public Datetime SomeMethod() {
11081110
Type type = Sample.class;
11091111
AnotherMethod(String.class);
1110-
return Datetime.Now();
1112+
return Datetime.now();
11111113
}
11121114
}");
11131115

@@ -1122,11 +1124,11 @@ public Datetime SomeMethod() {
11221124
11231125
class Sample
11241126
{
1125-
public DateTime SomeMethod()
1127+
public Datetime SomeMethod()
11261128
{
11271129
Type type = typeof(Sample);
11281130
AnotherMethod(typeof(string));
1129-
return DateTime.Now();
1131+
return Datetime.now();
11301132
}
11311133
}
11321134
}");
@@ -1189,7 +1191,7 @@ class Sample
11891191
{
11901192
[Future(CallOut=true)]
11911193
[Some(Name=""test"")]
1192-
public DateTime SomeMethod()
1194+
public Datetime SomeMethod()
11931195
{
11941196
}
11951197
}

Nuget/ApexParser.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>ApexParser</id>
5-
<version>0.6.1</version>
5+
<version>0.6.2</version>
66
<title>ApexParser</title>
77
<authors>ApexSharp.com</authors>
88
<owners>ApexSharp.com</owners>

0 commit comments

Comments
 (0)