Skip to content

Commit ca3ab96

Browse files
committed
Revert collection specialization
1 parent bffc3d8 commit ca3ab96

File tree

12 files changed

+82
-237
lines changed

12 files changed

+82
-237
lines changed

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,11 @@ private string GetObjCTypeIdentifier(OdcmObject o, bool getUnderlyingType=false)
2929
OdcmProperty prop=(OdcmProperty)o;
3030
if(prop.IsCollection && !getUnderlyingType)
3131
{
32-
if(IsNSJSONSerializable(prop.Type))
33-
{
34-
return GetStaticCollectionObject();
35-
}
36-
else
37-
{
38-
return prop.Type.GetCollectionTypeString();
39-
}
32+
return GetStaticCollectionObject();
4033
}
4134

4235
return GetObjCTypeIdentifier(prop.Type,getUnderlyingType);
4336
}
44-
else if(o is OdcmMethod)
45-
{
46-
OdcmMethod method = (OdcmMethod)o;
47-
if (method.IsCollection && !getUnderlyingType)
48-
{
49-
if (IsNSJSONSerializable(method.ReturnType))
50-
{
51-
return GetStaticCollectionObject();
52-
}
53-
else
54-
{
55-
return method.ReturnType.GetCollectionTypeString();
56-
}
57-
}
58-
59-
return GetObjCTypeIdentifier(method.ReturnType, getUnderlyingType);
60-
}
6137
else if(o is OdcmType)
6238
{
6339
return ((OdcmType)o).GetTypeString();
@@ -143,35 +119,6 @@ private string GetHydratedPropertyFromNSJSONSerializableExpression(string expr,O
143119
prop.Type.GetNSNumberValueMethod());
144120
}
145121

146-
private string GetHydratedPropertyFromNSJSONSerializableExpression(string expr,OdcmMethod method)
147-
{
148-
if(GetObjCTypeIdentifier(method,true)=="NSDate")
149-
{
150-
return String.Format(@"[NSDate ms_dateFromString: {0}]",expr);
151-
}
152-
153-
if(method.IsEnum())
154-
{
155-
return String.Format(
156-
@"[{0} to{1}]",
157-
expr,
158-
GetObjCTypeIdentifier(method,true));
159-
}
160-
//Complex catch-all
161-
if(method.IsComplex())
162-
{
163-
return String.Format(
164-
@"[[{0} alloc] initWithDictionary: {1} ]",
165-
GetObjCTypeIdentifier(method,true),
166-
expr);
167-
}
168-
169-
return String.Format(
170-
@"[{0} {1}]",
171-
expr,
172-
method.ReturnType.GetNSNumberValueMethod());
173-
}
174-
175122
private string GetHydratedPropertyFromDictionary(OdcmProperty prop)
176123
{
177124
return GetHydratedPropertyFromNSJSONSerializableExpression(String.Format(@"self.dictionary[@""{0}""]",prop.Name),prop);
@@ -230,7 +177,7 @@ private string GetHydratedIVarFromDictionary(OdcmProperty prop)
230177
GetObjCProperty(prop),
231178
prop.Name,
232179
GetObjCProperty(prop),
233-
GetObjCTypeIdentifier(prop));
180+
GetStaticCollectionObject());
234181
}
235182

236183
return String.Format(@"_{0} = {1};",GetObjCProperty(prop),GetHydratedPropertyFromDictionary(prop));

Templates/ObjC/Models/CollectionType.h.tt

Lines changed: 0 additions & 43 deletions
This file was deleted.

Templates/ObjC/Models/CollectionType.m.tt

Lines changed: 0 additions & 69 deletions
This file was deleted.

Templates/ObjC/Models/ComplexType.h.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<#
55
var entity = host.CurrentType.AsOdcmClass();
66
var baseEntity = entity.Base;
7-
87
#>
9-
<#=writer.GetImportsClass(entity.Properties,entity.Properties.Where(prop => prop.IsCollection).Select(prop => GetObjCTypeIdentifier(prop)).Distinct())#>
8+
9+
<#=writer.GetImportsClass(entity.Properties)#>
1010

1111
#import "<#=GetObjCTypeIdentifier(baseEntity)#>.h"
1212
#import "<#=GetStaticCollectionObject()#>.h"

Templates/ObjC/Models/EntityType.h.tt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
var entity = host.CurrentType.AsOdcmClass();
66
var baseEntity = entity.Base;
77

8+
IEnumerable<string> extraClasses = null;
9+
if (entity.Properties.Any(prop => prop.IsCollection))
10+
{
11+
extraClasses = new List<string> { GetStaticCollectionObject() };
12+
}
813
#>
9-
<#=writer.GetImportsClass(entity.Properties,entity.Properties.Where(prop => prop.IsCollection).Select(prop => GetObjCTypeIdentifier(prop)).Distinct())#>
14+
<#=writer.GetImportsClass(entity.Properties, extraClasses:extraClasses)#>
1015

1116
#import "<#=GetObjCTypeIdentifier(baseEntity)#>.h"
1217
#import "<#=GetStaticCollectionObject()#>.h"

Templates/ObjC/Requests/EntityCollectionRequest.h.tt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ if (innerEntityType.Equals(propName))
2323
}
2424
#>
2525

26-
#import "<#=GetObjCTypeIdentifier(prop)#>.h"
27-
2826
@class <#=entityRequest#>, <#=writer.GetStaticCodePrefix()#>URLSessionDataTask;
2927

3028
#import "<#=writer.GetPrefix()#>Models.h"
3129
#import "<#=writer.GetStaticCodePrefix()#>CollectionRequest.h"
30+
<#
31+
if(prop.IsReference()) {
32+
#>
33+
#import "<#=writer.GetStaticCodePrefix()#>CollectionReferences.h"
34+
<# } #>
3235

3336
typedef void (^<#=innerEntityType#>CompletionHandler)(<#=innerEntityType#> *response, NSError *error);
3437

35-
typedef void (^<#=propName + collectionNamer#>CompletionHandler)(<#=GetObjCTypeForVarDeclaration(prop)#> response, <#=propRequest#> *nextRequest, NSError *error);
38+
typedef void (^<#=propName + collectionNamer#>CompletionHandler)(<#=writer.GetStaticCodePrefix() + "Collection"#> *response, <#=propRequest#> *nextRequest, NSError *error);
3639

3740
@interface <#=propRequest#> : <#=writer.GetStaticCodePrefix()#>CollectionRequest
3841

Templates/ObjC/Requests/EntityCollectionRequest.m.tt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (innerEntityType.Equals(propName))
2222
#>
2323

2424
#import "<#=writer.GetPrefix()#>ODataEntities.h"
25+
#import "<#=writer.GetStaticCodePrefix()#>Collection.h"
2526
#import "<#=writer.GetStaticCodePrefix()#>URLSessionDataTask.h"
2627

2728
@interface <#=writer.GetStaticCodePrefix()#>CollectionRequest()
@@ -37,16 +38,6 @@ if (innerEntityType.Equals(propName))
3738
if(!collectionReference)
3839
{
3940
#>
40-
- (MSURLSessionDataTask *)<#=GetObjCTypeIdentifier(prop)#>TaskWithRequest:(NSMutableURLRequest *)request
41-
odObjectWithDictionary:(MSObject* (^)(NSDictionary *response))castBlock
42-
completion:(void (^)(<#=GetObjCTypeForVarDeclaration(prop)#> response, NSError *error))completionHandler
43-
{
44-
return [self collectionTaskWithRequest: request odObjectWithDictionary:castBlock
45-
completion:^(MSCollection* collectionResponse, NSError *error){
46-
completionHandler([<#=GetObjCTypeIdentifier(prop)#> fromMSCollection:collectionResponse],error);
47-
}];
48-
}
49-
5041
- (NSMutableURLRequest *)get
5142
{
5243
return [self requestWithMethod:@"GET"
@@ -57,11 +48,24 @@ if (innerEntityType.Equals(propName))
5748
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)getWithCompletion:(<#=propName+ collectionNamer#>CompletionHandler)completionHandler
5849
{
5950

60-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask * task = [self <#=GetObjCTypeIdentifier(prop)#>TaskWithRequest:[self get]
51+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask * task = [self collectionTaskWithRequest:[self get]
6152
odObjectWithDictionary:^(id response){
53+
<#
54+
if (prop.IsSystem())
55+
{
56+
#>
57+
6258
return [response copy];
59+
<#
60+
}
61+
else
62+
{
63+
#>
64+
return [[<#=innerEntityType#> alloc] initWithDictionary:response];
65+
<# }
66+
#>
6367
}
64-
completion:^(<#=GetObjCTypeForVarDeclaration(prop)#> collectionResponse, NSError *error){
68+
completion:^(<#=writer.GetStaticCodePrefix()#>Collection *collectionResponse, NSError *error){
6569
if(!error && collectionResponse.nextLink && completionHandler){
6670
<#=propNameRequest#> *nextRequest = [[<#=propNameRequest#> alloc] initWithURL:collectionResponse.nextLink options:nil client:self.client];
6771
completionHandler(collectionResponse, nextRequest, nil);

Templates/ObjC/Requests/MethodRequest.h.tt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,27 @@ else
1717
returnType = "NSDictionary";
1818
}
1919

20-
var superClass = writer.GetStaticCodePrefix() + (func.IsCollection ? "CollectionRequest" : "Request");
20+
var superClass = writer.GetStaticCodePrefix() + ((func.IsCollection || func.LongDescriptionContains("specialCollection")) ? "CollectionRequest" : "Request");
2121
var method = ((func.Verbs & OdcmAllowedVerbs.Get) != OdcmAllowedVerbs.Get) ? "POST" : "GET";
2222
var isAsync = func.LongDescriptionContains("async");
23+
var specialCollectionType = writer.GetPrefix() + func.Class.Name.ToUpperFirstChar() + func.Name.Substring(func.Name.IndexOf('.') + 1).ToUpperFirstChar() + "Collection";
2324

25+
if (func.LongDescriptionContains("specialCollection"))
26+
{
2427
#>
25-
@class <#=writer.GetStaticCodePrefix()#>URLSessionDataTask;
26-
27-
#import "<#=superClass#>.h"
28+
@class <#=writer.GetStaticCodePrefix()#>URLSessionDataTask, <#=specialCollectionType#>;
2829
<#
29-
if (func.ReturnType != null && func.IsCollection)
30+
}
31+
else
3032
{
3133
#>
32-
#import "<#=func.ReturnType.GetCollectionTypeString()#>.h"
34+
@class <#=writer.GetStaticCodePrefix()#>URLSessionDataTask;
3335
<#
3436
}
3537
#>
3638

39+
#import "<#=superClass#>.h"
40+
3741
@interface <#=requestType#> : <#=superClass#>
3842

3943
@property (readonly) NSMutableURLRequest *mutableRequest;
@@ -47,10 +51,15 @@ if (func.Parameters.Count > 0)
4751
}
4852
string completionHandler;
4953
string taskType = writer.GetStaticCodePrefix() + "URLSessionDataTask *";
50-
if (func.IsCollection)
54+
if (func.IsCollection || func.LongDescriptionContains("specialCollection"))
5155
{
52-
string collectionType = func.ReturnType.GetCollectionTypeString();
56+
string collectionType = writer.GetStaticCodePrefix() + "Collection";
57+
if (func.LongDescriptionContains("specialCollection"))
58+
{
59+
collectionType = specialCollectionType;
60+
}
5361
completionHandler = "(void (^)(" + collectionType + " *response, " + requestType + " *nextRequest, NSError *error))";
62+
5463
}
5564
else if(isAsync)
5665
{
@@ -59,6 +68,7 @@ else if(isAsync)
5968
}
6069
else
6170
{
71+
6272
completionHandler = writer.GetNetworkCompletionBlock(returnType, "response");
6373
}
6474
if (!returnType.Contains("Stream"))

0 commit comments

Comments
 (0)