-
Notifications
You must be signed in to change notification settings - Fork 76
Fixing templates for java model generated files import statement for … #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,6 +506,153 @@ | |
| } | ||
| return "<" + BaseTypeCollectionResponse(c) + ", " + ITypeCollectionPage(c) + ">"; | ||
| } | ||
|
|
||
| //Creating package definition for Enum.java.tt template file | ||
| public string CreatePackageDefForEnum(CustomT4Host host) | ||
| { | ||
| var sb = new StringBuilder(); | ||
| var packageFormat = @"package {0}.{1};"; | ||
| sb.AppendFormat(packageFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| host.TemplateInfo.OutputParentDirectory.Replace("_", ".")); | ||
| sb.Append("\n"); | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| //Getting import prefix using property name for model classes | ||
| public string getPrefixForModels(string propertyName) | ||
| { | ||
| if(propertyName.StartsWith("Base")) | ||
| { | ||
| if(propertyName == "BaseItem" || propertyName == "BaseItemVersion") | ||
| return "models.extensions"; | ||
| else | ||
| return "models.generated"; | ||
| } | ||
|
|
||
| return "models.extensions"; | ||
| } | ||
|
|
||
| //Getting import prefix using property name for Request classes | ||
| public string getPrefixForRequests(string propertyName) | ||
| { | ||
| if(propertyName == "BaseItemCollectionPage") | ||
| return "requests.extensions"; | ||
|
|
||
| if(propertyName.StartsWith("Base") || propertyName.StartsWith("IBase")) | ||
| return "requests.generated"; | ||
|
|
||
| return "requests.extensions"; | ||
| } | ||
|
|
||
| //Get package prefix using OdcmProperty for model classes | ||
| public string getPackagePrefix(OdcmProperty property) | ||
| { | ||
| var propertyType = property.GetTypeString(); | ||
|
|
||
| if(property.Type is OdcmEnum) | ||
| return "models.generated"; | ||
|
|
||
| return getPrefixForModels(propertyType); | ||
| } | ||
|
|
||
| //Fixing package and import statement for model classes | ||
| public string CreatePackageDefForEntity(CustomT4Host host) | ||
| { | ||
| IEnumerable<OdcmProperty> properties = ((OdcmClass)host.CurrentType).Properties; | ||
| var sb = new StringBuilder(); | ||
| var packageFormat = @"package {0}.{1};"; | ||
| sb.AppendFormat(packageFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| host.TemplateInfo.OutputParentDirectory.Replace("_", ".")); | ||
| sb.Append("\n"); | ||
|
|
||
| sb.AppendFormat(@"import {0}.concurrency.*; | ||
| import {0}.core.*; | ||
| import {0}.http.*; | ||
| import {0}.options.*; | ||
| import {0}.serializer.*; | ||
| import java.util.Arrays; | ||
| import java.util.EnumSet;", host.CurrentModel.NamespaceName()); | ||
|
|
||
| sb.Append("\n"); | ||
| var importFormat = @"import {0}.{1}.{2};"; | ||
|
|
||
| foreach (var property in properties.Where(p => !p.Projection.Type.Name.Equals("Stream"))) | ||
| { | ||
| var propertyType = property.GetTypeString(); | ||
| if(property.Type is OdcmPrimitiveType) | ||
| continue; | ||
|
|
||
| if(propertyType == "com.google.gson.JsonElement" || propertyType == "com.google.gson.JsonElement" || propertyType.StartsWith("com.microsoft.graph.models")) | ||
| continue; | ||
|
|
||
| if(propertyType.StartsWith("EnumSet")) | ||
| propertyType = propertyType.Substring("EnumSet<".Length, propertyType.Length-("EnumSet<".Length+1)); | ||
|
|
||
| string prefixValue = getPackagePrefix(property); | ||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| prefixValue, | ||
| propertyType); | ||
| sb.Append("\n"); | ||
|
|
||
| } | ||
|
|
||
| string baseClassNameType = BaseClassName(host.CurrentType); | ||
| if(baseClassNameType != "") | ||
| { | ||
| string prefixValue = getPrefixForModels(baseClassNameType); | ||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| prefixValue, | ||
| baseClassNameType); | ||
| sb.Append("\n"); | ||
| } | ||
|
|
||
| string baseTypeNameStr = BaseTypeName(host.CurrentType); | ||
| if(baseTypeNameStr == "BasePlannerAssignments") | ||
| { | ||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| "models.extensions", | ||
| "PlannerAssignment"); | ||
| sb.Append("\n"); | ||
| } | ||
| if(baseTypeNameStr == "BasePlannerChecklistItems") | ||
| { | ||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| "models.extensions", | ||
| "PlannerChecklistItem"); | ||
| sb.Append("\n"); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we special casing BasePlannerAssignments and BasePlannerChecklistItems? What are we getting here that we don't get from within the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are due to overrides present in CustomOverwrites.cs file. Needed to handle these cases separately. |
||
|
|
||
| if (properties != null) | ||
| { | ||
| foreach (var property in properties.Where(p => p.IsCollection() && p.IsNavigation())) | ||
| { | ||
| if(property.Type is OdcmPrimitiveType) | ||
| continue; | ||
|
|
||
| var propertyType = BaseTypeCollectionResponse(property); | ||
|
|
||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| getPrefixForRequests(propertyType), | ||
| propertyType); | ||
| sb.Append("\n"); | ||
|
|
||
| string propertyValue = TypeCollectionPage(property); | ||
| sb.AppendFormat(importFormat, | ||
| host.CurrentModel.NamespaceName(), | ||
| getPrefixForRequests(propertyValue), | ||
| propertyValue); | ||
| sb.Append("\n"); | ||
| } | ||
| } | ||
| return sb.ToString(); | ||
| } | ||
|
|
||
| public string CreatePackageDef(CustomT4Host host) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide comments for the functions you add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments