Skip to content

Commit 4c7238f

Browse files
author
Peter Nied
committed
Update to Android Generation
- Prevented incorrect generation of singular requests for collections methods - Prevented incorrect generation of collections requests for singular methods - Added logging to indicate which sub processor is running
1 parent d48ded5 commit 4c7238f

File tree

8 files changed

+70
-40
lines changed

8 files changed

+70
-40
lines changed

Templates/Android/BaseModel.template.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public string MethodFullName(OdcmObject c) {
3636
if (c is OdcmMethod){
3737
return String.Format("{0}.{1}", ((OdcmMethod)c).Class.Namespace.Name,
38-
c.Name.Substring(c.Name.IndexOf(".") + 1).ToUpperFirstChar());
38+
c.Name.Substring(c.Name.IndexOf(".") + 1));
3939
}
4040
return c.Name.Substring(c.Name.IndexOf(".") + 1).ToUpperFirstChar();
4141
}
@@ -439,7 +439,7 @@
439439

440440
public string CollectionPageGeneric(OdcmObject c) {
441441
if (c is OdcmMethod) {
442-
return "<" + ClassTypeName(c) + ", " + ITypeRequestBuilder(c) + ">";
442+
return "<" + ClassTypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
443443
}
444444
return "<" + TypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
445445
}

Templates/Android/extensions/MethodCollectionPage.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @param response The serialized <#=BaseTypeCollectionResponse(c)#> from the service
1515
* @param builder The request builder for the next collection page
1616
*/
17-
public <#=TypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeRequestBuilder(c)#> builder) {
17+
public <#=TypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionRequestBuilder(c)#> builder) {
1818
super(response, builder);
1919
}
2020

Templates/Android/generated/BaseMethodBodyRequest.java.tt

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@
22
<#@ template debug="true" hostspecific="true" language="C#" #>
33
<#@ include file="BaseModel.template.tt"#>
44
<#@ output extension="\\" #>
5-
<#host.TemplateName = BaseTypeRequest(c);#>
5+
<#
6+
var baseClass = "BaseRequest";
7+
var typeRequest = TypeRequest(c);
8+
var iTypeRequest = ITypeRequest(c);
9+
var baseTypeRequest = BaseTypeRequest(c);
10+
var iBaseTypeRequest = IBaseTypeRequest(c);
11+
var returnType = ReturnType(c);
12+
13+
if (c.AsOdcmMethod().IsCollection)
14+
{
15+
baseClass = "BaseCollectionRequest";
16+
typeRequest = TypeCollectionRequest(c);
17+
iTypeRequest = ITypeCollectionRequest(c);
18+
baseTypeRequest = BaseTypeCollectionRequest(c);
19+
iBaseTypeRequest = IBaseTypeCollectionRequest(c);
20+
}
21+
#>
22+
<#host.TemplateName = baseTypeRequest;#>
623
<#=writer.WriteHeader()#>
724
<#=CreatePackageDef(host)#>
825

9-
<#=CreateClassDef(BaseTypeRequest(c), "BaseRequest", IBaseTypeRequest(c))#>
26+
<#=CreateClassDef(baseTypeRequest, baseClass, iBaseTypeRequest)#>
1027
protected final <#=TypeBody(c)#> mBody;
1128

1229
/**
@@ -16,19 +33,19 @@
1633
* @param client The service client
1734
* @param options The options for this request
1835
*/
19-
public <#=BaseTypeRequest(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options<#=MethodParametersSignature(c)#>) {
20-
super(requestUrl, client, options, <#=ReturnType(c)#>.class);
36+
public <#=baseTypeRequest#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options<#=MethodParametersSignature(c)#>) {
37+
super(requestUrl, client, options, <#=returnType#>.class);
2138
mBody = new <#=TypeBody(c)#>();
2239
<# foreach (var p in c.AsOdcmMethod().Parameters) { #>
2340
mBody.<#=ParamName(p)#> = <#=ParamName(p)#>;
2441
<# } #>
2542
}
2643

27-
public void post(final ICallback<<#=ReturnType(c)#>> callback) {
44+
public void post(final ICallback<<#=returnType#>> callback) {
2845
send(HttpMethod.POST, callback, mBody);
2946
}
3047

31-
public <#=ReturnType(c)#> post() throws ClientException {
48+
public <#=returnType#> post() throws ClientException {
3249
return send(HttpMethod.POST, mBody);
3350
}
3451

@@ -38,9 +55,9 @@
3855
* @param value The select clause
3956
* @return The updated request
4057
*/
41-
public <#=ITypeRequest(c)#> select(final String value) {
58+
public <#=iTypeRequest#> select(final String value) {
4259
getQueryOptions().add(new QueryOption("select", value));
43-
return (<#=TypeRequest(c)#>)this;
60+
return (<#=typeRequest#>)this;
4461
}
4562

4663
/**
@@ -49,9 +66,9 @@
4966
* @param value The max number of items to return
5067
* @return The updated request
5168
*/
52-
public <#=ITypeRequest(c)#> top(final int value) {
69+
public <#=iTypeRequest#> top(final int value) {
5370
getQueryOptions().add(new QueryOption("top", value+""));
54-
return (<#=TypeRequest(c)#>)this;
71+
return (<#=typeRequest#>)this;
5572
}
5673

5774
/**
@@ -60,8 +77,8 @@
6077
* @param value The expand clause
6178
* @return The updated request
6279
*/
63-
public <#=ITypeRequest(c)#> expand(final String value) {
80+
public <#=iTypeRequest#> expand(final String value) {
6481
getQueryOptions().add(new QueryOption("expand", value));
65-
return (<#=TypeRequest(c)#>)this;
82+
return (<#=typeRequest#>)this;
6683
}
6784
}

Templates/Android/generated/BaseMethodCollectionPage.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import com.google.gson.annotations.*;
1717
* @param response The serialized <#=BaseTypeCollectionResponse(c)#> from the service
1818
* @param builder The request builder for the next collection page
1919
*/
20-
public <#=BaseTypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeRequestBuilder(c)#> builder) {
20+
public <#=BaseTypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionRequestBuilder(c)#> builder) {
2121
super(response.value, builder);
2222
}
2323
}

Templates/Android/generated/BaseMethodCollectionRequest.java.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@
8888
<# } #>
8989

9090
public <#=ITypeCollectionPage(c)#> buildFromResponse(final <#=BaseTypeCollectionResponse(c)#> response) {
91-
final <#=ITypeRequestBuilder(c)#> builder;
91+
final <#=ITypeCollectionRequestBuilder(c)#> builder;
9292
if (response.nextLink != null) {
93-
builder = new <#=TypeRequestBuilder(c)#>(response.nextLink, getBaseRequest().getClient(), /* options */ null<#=MethodPageValues(c)#>);
93+
builder = new <#=TypeCollectionRequestBuilder(c)#>(response.nextLink, getBaseRequest().getClient(), /* options */ null<#=MethodPageValues(c)#>);
9494
} else {
9595
builder = null;
9696
}

Templates/Android/generated/IBaseMethodBodyRequest.java.tt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22
<#@ template debug="true" hostspecific="true" language="C#" #>
33
<#@ include file="BaseModel.template.tt"#>
44
<#@ output extension="\\" #>
5-
<#host.TemplateName = IBaseTypeRequest(c);#>
5+
<#
6+
var baseClass = "BaseRequest";
7+
var typeRequest = TypeRequest(c);
8+
var iTypeRequest = ITypeRequest(c);
9+
var baseTypeRequest = BaseTypeRequest(c);
10+
var iBaseTypeRequest = IBaseTypeRequest(c);
11+
var returnType = ReturnType(c);
12+
13+
if (c.AsOdcmMethod().IsCollection)
14+
{
15+
baseClass = "BaseCollectionRequest";
16+
typeRequest = TypeCollectionRequest(c);
17+
iTypeRequest = ITypeCollectionRequest(c);
18+
baseTypeRequest = BaseTypeCollectionRequest(c);
19+
iBaseTypeRequest = IBaseTypeCollectionRequest(c);
20+
}
21+
#>
22+
<#host.TemplateName = iBaseTypeRequest;#>
623
<#=writer.WriteHeader()#>
724
<#=CreatePackageDef(host)#>
825

926
import com.google.gson.JsonObject;
1027
import com.google.gson.annotations.*;
1128

12-
<#=CreateInterfaceDef(IBaseTypeRequest(c))#>
29+
<#=CreateInterfaceDef(iBaseTypeRequest)#>
1330

1431
void post(final ICallback<<#=ReturnType(c)#>> callback);
1532

@@ -21,21 +38,21 @@ import com.google.gson.annotations.*;
2138
* @param value The select clause
2239
* @return The updated request
2340
*/
24-
<#=ITypeRequest(c)#> select(final String value) ;
41+
<#=iTypeRequest#> select(final String value) ;
2542

2643
/**
2744
* Sets the top value for the request
2845
*
2946
* @param value The max number of items to return
3047
* @return The updated request
3148
*/
32-
<#=ITypeRequest(c)#> top(final int value);
49+
<#=iTypeRequest#> top(final int value);
3350

3451
/**
3552
* Sets the expand clause for the request
3653
*
3754
* @param value The expand clause
3855
* @return The updated request
3956
*/
40-
<#=ITypeRequest(c)#> expand(final String value);
57+
<#=iTypeRequest#> expand(final String value);
4158
}

src/GraphODataTemplateWriter/.config/AndroidSettings.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"TemplateMapping": {
3+
"Shared" : [ ],
34
"Android": [
45
{ "Template": "BaseModel", "SubProcessor": "Other", "Type": "Shared" },
56

@@ -8,22 +9,18 @@
89
{ "Template": "MethodBody", "SubProcessor": "MethodWithBody", "Name": "<Method>Body" },
910
{ "Template": "BaseMethodBody", "SubProcessor": "MethodWithBody", "Name": "Base<Method>Body" },
1011

11-
{ "Template": "MethodRequest", "SubProcessor": "Method", "Name": "<Method>Request" },
12-
{ "Template": "IEntityRequest", "SubProcessor": "Method", "Name": "I<Method>Request" },
13-
{ "Template": "BaseMethodRequest", "SubProcessor": "Method", "Name": "Base<Method>Request" },
14-
{ "Template": "BaseMethodBodyRequest", "SubProcessor": "MethodWithBody", "Name": "Base<Method>Request" },
15-
{ "Template": "IBaseMethodRequest", "SubProcessor": "Method", "Name": "IBase<Method>Request" },
16-
{ "Template": "IBaseMethodBodyRequest", "SubProcessor": "MethodWithBody", "Name": "IBase<Method>Request" },
12+
{ "Template": "MethodRequest", "SubProcessor": "NonCollectionMethod", "Name": "<Method>Request" },
13+
{ "Template": "IEntityRequest", "SubProcessor": "NonCollectionMethod", "Name": "I<Method>Request" },
14+
{ "Template": "BaseMethodRequest", "SubProcessor": "NonCollectionMethod", "Name": "Base<Method>Request" },
15+
{ "Template": "IBaseMethodRequest", "SubProcessor": "NonCollectionMethod", "Name": "IBase<Method>Request" },
1716

18-
{ "Template": "MethodRequestBuilder", "SubProcessor": "Method", "Name": "<Method>RequestBuilder" },
19-
{ "Template": "IEntityRequestBuilder", "SubProcessor": "Method", "Name": "I<Method>RequestBuilder" },
20-
{ "Template": "BaseMethodRequestBuilder", "SubProcessor": "Method", "Name": "Base<Method>RequestBuilder" },
21-
{ "Template": "IBaseMethodRequestBuilder", "SubProcessor": "Method", "Name": "IBase<Method>RequestBuilder" },
17+
{ "Template": "MethodRequestBuilder", "SubProcessor": "NonCollectionMethod", "Name": "<Method>RequestBuilder" },
18+
{ "Template": "IEntityRequestBuilder", "SubProcessor": "NonCollectionMethod", "Name": "I<Method>RequestBuilder" },
19+
{ "Template": "BaseMethodRequestBuilder", "SubProcessor": "NonCollectionMethod", "Name": "Base<Method>RequestBuilder" },
20+
{ "Template": "IBaseMethodRequestBuilder", "SubProcessor": "NonCollectionMethod", "Name": "IBase<Method>RequestBuilder" },
2221

23-
{ "Template": "IEntityCollectionPage", "SubProcessor": "Method", "Name": "I<Method>CollectionPage", "Ignore": "ignorableCollection"},
24-
{ "Template": "MethodCollectionPage", "SubProcessor": "Method", "Name": "<Method>CollectionPage", "Ignore": "ignorableCollection"},
25-
{ "Template": "IBaseMethodCollectionPage", "SubProcessor": "Method", "Name": "IBase<Method>CollectionPage", "Ignore": "ignorableCollection"},
26-
{ "Template": "BaseMethodCollectionPage", "SubProcessor": "Method", "Name": "Base<Method>CollectionPage", "Ignore": "ignorableCollection"},
22+
{ "Template": "BaseMethodBodyRequest", "SubProcessor": "MethodWithBody", "Name": "Base<Method>Request" },
23+
{ "Template": "IBaseMethodBodyRequest", "SubProcessor": "MethodWithBody", "Name": "IBase<Method>Request" },
2724

2825
{ "Template": "IEntityCollectionPage", "SubProcessor": "CollectionMethod", "Name": "I<Method>CollectionPage", "Ignore": "ignorableCollection" },
2926
{ "Template": "MethodCollectionPage", "SubProcessor": "CollectionMethod", "Name": "<Method>CollectionPage", "Ignore": "ignorableCollection" },
@@ -37,9 +34,7 @@
3734
{ "Template": "IBaseMethodCollectionRequestBuilder", "SubProcessor": "CollectionMethod", "Name": "IBase<PropertyType>CollectionRequestBuilder", "Exclude": "nextExpectedRanges;roles", "Ignore": "ignorableCollection" },
3835
{ "Template": "IMethodCollectionRequestBuilder", "SubProcessor": "CollectionMethod", "Name": "I<PropertyType>CollectionRequestBuilder", "Exclude": "nextExpectedRanges;roles", "Ignore": "ignorableCollection" },
3936
{ "Template": "MethodCollectionRequestBuilder", "SubProcessor": "CollectionMethod", "Name": "<PropertyType>CollectionRequestBuilder", "Exclude": "nextExpectedRanges;roles", "Ignore": "ignorableCollection" },
40-
4137
{ "Template": "BaseMethodCollectionResponse", "SubProcessor": "CollectionMethod", "Name": "Base<Method>CollectionResponse", "Ignore": "ignorableCollection" },
42-
{ "Template": "BaseMethodCollectionResponse", "SubProcessor": "Method", "Name": "Base<Method>CollectionResponse", "Ignore": "ignorableCollection" },
4338

4439
{ "Template": "IBaseEntityRequest", "SubProcessor": "EntityType", "Name": "IBase<Class>Request" },
4540
{ "Template": "BaseEntityRequest", "SubProcessor": "EntityType", "Name": "Base<Class>Request" },

src/GraphODataTemplateWriter/TemplateProcessor/TemplateProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public IEnumerable<TextFile> Process(ITemplateInfo templateInfo)
9696
{
9797
Func<ITemplateInfo, IEnumerable<TextFile>> subProcessor = this.ProcessTemplate;
9898
this.SubProcessors.TryGetValue(templateInfo.SubprocessorType, out subProcessor);
99+
Console.WriteLine("Current Subprocessor Type: {0}", templateInfo.SubprocessorType);
99100
return subProcessor(templateInfo);
100101
}
101102

@@ -203,7 +204,7 @@ protected virtual IEnumerable<TextFile> ProcessMethods(ITemplateInfo templateInf
203204

204205
protected virtual IEnumerable<OdcmMethod> NonCollectionMethods()
205206
{
206-
return this.CurrentModel.GetMethods().Where(method => !method.IsCollection && (method.ReturnType == null || method.ReturnType is OdcmPrimitiveType));
207+
return this.CurrentModel.GetMethods().Where(method => !method.IsCollection);
207208
}
208209

209210
protected virtual IEnumerable<OdcmMethod> MethodsWithBody()

0 commit comments

Comments
 (0)