Skip to content

Commit 90c7dc3

Browse files
committed
- fixes a determinisic issue for java properties and methods names casing
- fixes an issue for properties starting with _ in java
1 parent 42572c0 commit 90c7dc3

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

Templates/Java/BaseJavaModel.template.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public {1} {2}{3}{4} {{";
10891089
propertyName.SplitCamelCase(),
10901090
property.Name,
10911091
propertyType,
1092-
property.Name.SanitizePropertyName(property).ToLowerFirstChar(),
1092+
property.Name.ToLowerFirstChar().SanitizePropertyName(property),
10931093
GetSanitizedDescription(property));
10941094
}
10951095
return sb.ToString();

src/GraphODataTemplateWriter/CodeHelpers/Java/TypeHelperJava.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,17 @@ public static string SanitizePropertyName(this string property, OdcmObject odcmP
9191
{
9292
if (ReservedNames.Value.Contains(property))
9393
{
94-
logger.Info("Property \"{0}\" is a reserved word in Java. Converting to \"{1}{0}\"", property, ReservedPrefix);
95-
return ReservedPrefix + property.ToUpperFirstChar();
94+
var result = ReservedPrefix + property.ToUpperFirstChar();
95+
logger.Info($"Property \"{property}\" is a reserved word in Java. Converting to \"{result}\"");
96+
return result;
9697
}
97-
98-
if (odcmProperty != null && property == odcmProperty.Name.ToUpperFirstChar())
98+
else if (property == odcmProperty?.Name?.ToUpperFirstChar() && !(odcmProperty?.Name?.StartsWith("_") ?? false))
9999
{
100-
// Check whether the property type is the same as the class name.
101-
if (odcmProperty.Projection.Type?.Name?.ToUpperFirstChar() == odcmProperty.Name.ToUpperFirstChar())
102-
{
103-
// Name the property: {metadataName} + "Property"
104-
logger.Info("Property type \"{0}\" has the same name as the class. Converting to \"{0}Property\"", property);
105-
return string.Concat(property, "Property");
106-
}
107-
108100
// Name the property by its type. Sanitize it in case the type is a reserved name.
109-
return odcmProperty.Projection.Type?.Name?.ToUpperFirstChar()?.SanitizePropertyName(odcmProperty) ?? property.SanitizePropertyName();
101+
return odcmProperty?.Projection?.Type?.Name?.ToUpperFirstChar()?.SanitizePropertyName(odcmProperty) ?? odcmProperty?.Name?.SanitizePropertyName();
110102
}
111-
112-
return property.Replace("@", string.Empty).Replace(".", string.Empty);
103+
else
104+
return property?.Replace("@", string.Empty)?.Replace(".", string.Empty);
113105
}
114106

115107
public static string GetToLowerImport(this OdcmProperty property)

0 commit comments

Comments
 (0)