Skip to content

Commit 34ca886

Browse files
authored
Merge pull request #29 from microsoftgraph/iambmelt/working
For Android: Annotations + Function/Action Overloads + Bug Fixes
2 parents 432005a + 6422f1f commit 34ca886

File tree

44 files changed

+330
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+330
-141
lines changed

Templates/Android/BaseModel.template.tt

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,48 @@
55
CustomT4Host host = (CustomT4Host) Host;
66
var model = host.CurrentModel;
77
CodeWriterAndroid writer = (CodeWriterAndroid) host.CodeWriter;
8+
bool logTemplateSrc = false;
89
var c = host.CurrentType;
10+
#>
11+
<# if (logTemplateSrc) { #>
12+
// Template Source: <#= TemplateName(host.TemplateFile) #>
13+
<# } #>
14+
<#+
915

10-
if (c == null)
11-
{
12-
// throw new InvalidOperationException("Unable to get the current type!");
16+
/// Is this request type a post?
17+
public bool IsPostRequestType(OdcmMethod method) {
18+
return method.IsAction()
19+
&& null != method.Parameters
20+
&& method.Parameters.Any();
21+
}
22+
23+
/// Choose an intermediate class type based on GETs/POSTs
24+
public string RequestBuilderSuperClass(OdcmObject currentType) {
25+
var isPostAction =
26+
IsPostRequestType(
27+
currentType.AsOdcmMethod()
28+
);
29+
30+
string superClass;
31+
32+
if (isPostAction) {
33+
superClass = "BasePostMethodRequestBuilder";
34+
} else {
35+
superClass = "BaseGetMethodRequestBuilder";
36+
}
37+
38+
return superClass;
39+
}
40+
41+
/// <summary>
42+
/// Get the name of the current template being processed
43+
/// </summary>
44+
/// <param name="templateFile">The full path of the current template</param>
45+
/// <returns>The template name, relative to the Templates directory.</returns>
46+
public string TemplateName(string templateFile) {
47+
return templateFile.Substring(templateFile.LastIndexOf("Templates"));
1348
}
1449

15-
#>
16-
<# //="// Template Source: '" + host.TemplateFile + "', Name: '" + c.Name + "' , TypeName: '" + TypeName(c) + "'"#>
17-
<#+
1850
public string TypeName(OdcmObject c) {
1951
if (c is OdcmMethod) {
2052
return ((OdcmMethod)c).Class.Name.ToUpperFirstChar() + c.Name.Substring(c.Name.IndexOf(".") + 1).ToUpperFirstChar();
@@ -331,14 +363,18 @@
331363
return "Base" + TypeBody(c);
332364
}
333365

366+
/// Creates an 'm' prepended name for a field
367+
/// based on its name as defined by the service $metadata
334368
public string FieldName(OdcmParameter c) {
335369
return "m" + ParamName(c).ToUpperFirstChar();
336370
}
337371

372+
/// Returns the name of the service <parameter> with the first char lowercase
338373
public string ParamName(OdcmParameter c) {
339374
return c.Name.ToLowerFirstChar();
340375
}
341376

377+
/// The Type of this param, as a string
342378
public string ParamType(OdcmParameter c) {
343379
if (c.IsCollection){
344380
return String.Format("List<{0}>", c.Type.GetTypeString());
@@ -352,19 +388,19 @@
352388
}
353389
return "Void";
354390
}
355-
356-
public string MethodParametersSignature(OdcmObject c) {
391+
392+
public string MethodParametersSignature(OdcmMethod method) {
357393
var parameterSignatureBuilder = new StringBuilder();
358-
foreach (var p in c.AsOdcmMethod().Parameters)
394+
foreach (var p in method.Parameters)
359395
{
360396
parameterSignatureBuilder.AppendFormat(", final {0} {1}", ParamType(p), ParamName(p));
361397
}
362398
return parameterSignatureBuilder.ToString();
363399
}
364400

365-
public string MethodParametersValues(OdcmObject c) {
401+
public string MethodParametersValues(OdcmMethod method) {
366402
var parameterValuesBuilder = new StringBuilder();
367-
foreach (var p in c.AsOdcmMethod().Parameters)
403+
foreach (var p in method.Parameters)
368404
{
369405
parameterValuesBuilder.AppendFormat(", {0}", ParamName(p));
370406
}
@@ -477,6 +513,10 @@ import java.util.List;";
477513
host.TemplateInfo.OutputParentDirectory);
478514
}
479515

516+
/// Creates a class declaration
517+
/// name = the name of the class
518+
/// extends = the class it extends
519+
/// implements = the interface it extends
480520
public string CreateClassDef(string name, string extends = null, string implements = null)
481521
{
482522
return this.CreateClassOrInterface(name, true, extends, implements);
@@ -631,12 +671,13 @@ public {1} {2}{3}{4} {{";
631671
";
632672
foreach (var p in parameters)
633673
{
634-
var propertyType = p.IsCollection ? string.Format("List<{0}>", ParamType(p)) : ParamType(p);
635-
sb.AppendFormat(format,
674+
sb.AppendFormat(
675+
format,
636676
ParamName(p).SplitCamelCase(),
637677
ParamName(p),
638678
ParamType(p),
639-
p.SanitizePropertyName().ToLowerFirstChar());
679+
p.SanitizePropertyName().ToLowerFirstChar()
680+
);
640681
}
641682
return sb.ToString();
642683
}

Templates/Android/extensions/EntityCollectionPage.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
public <#=TypeCollectionPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionRequestBuilder(c)#> builder) {
1717
super(response, builder);
1818
}
19-
2019
}

Templates/Android/extensions/EntityCollectionWithReferencesPage.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
public <#=TypeCollectionWithReferencesPage(c)#>(final <#=BaseTypeCollectionResponse(c)#> response, final <#=ITypeCollectionWithReferencesRequestBuilder(c)#> builder) {
1717
super(response, builder);
1818
}
19-
2019
}

Templates/Android/extensions/EntityReferenceRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeReferenceRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityStreamRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeStreamRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/EntityWithReferenceRequestBuilder.java.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
public <#=TypeWithReferencesRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final List<Option> options) {
1919
super(requestUrl, client, options);
2020
}
21-
}
21+
}

Templates/Android/extensions/IEntityReferenceRequestBuilder.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<#@ include file="BaseModel.template.tt"#>
44
<#@ output extension="\\" #>
55
<#host.TemplateName = ITypeReferenceRequestBuilder(c);#>
6-
76
<#=writer.WriteHeader()#>
87
<#=CreatePackageDef(host)#>
98

Templates/Android/extensions/IEntityRequest.java.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<#=CreatePackageDef(host)#>
88

99
<#=CreateInterfaceDef(ITypeRequest(c), IBaseTypeRequest(c))#>
10+
1011
}

Templates/Android/extensions/IEntityRequestBuilder.java.tt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<#@ include file="BaseModel.template.tt"#>
44
<#@ output extension="\\" #>
55
<#host.TemplateName = ITypeRequestBuilder(c);#>
6-
76
<#=writer.WriteHeader()#>
87
<#=CreatePackageDef(host)#>
98

0 commit comments

Comments
 (0)