@@ -10,17 +10,11 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.Java
1010
1111 public static class TypeHelperJava
1212 {
13- private static Logger logger = LogManager . GetCurrentClassLogger ( ) ;
13+ private static readonly Logger logger = LogManager . GetCurrentClassLogger ( ) ;
1414 public const string ReservedPrefix = "msgraph" ;
15- public static HashSet < string > ReservedNames
16- {
17- get
18- {
19- return new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) {
20- "abstract" , "continue" , "for" , "new" , "switch" , "assert" , "default" , "if" , "package" , "synchronized" , "boolean" , "do" , "goto" , "private" , "this" , "break" , "double" , "implements" , "protected" , "throw" , "byte" , "else" , "import" , "public" , "throws" , "case" , "enum" , "instanceof" , "return" , "transient" , "catch" , "extends" , "int" , "short" , "try" , "char" , "final" , "interface" , "static" , "void" , "class" , "finally" , "long" , "strictfp" , "volatile" , "const" , "float" , "native" , "super" , "while" , "true" , "false" , "null"
21- } ;
22- }
23- }
15+ public static Lazy < HashSet < string > > ReservedNames { get ; private set ; } = new Lazy < HashSet < string > > ( ( ) => new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) {
16+ "abstract" , "continue" , "for" , "new" , "switch" , "assert" , "default" , "if" , "package" , "synchronized" , "boolean" , "do" , "goto" , "private" , "this" , "break" , "double" , "implements" , "protected" , "throw" , "byte" , "else" , "import" , "public" , "throws" , "case" , "enum" , "instanceof" , "return" , "transient" , "catch" , "extends" , "int" , "short" , "try" , "char" , "final" , "interface" , "static" , "void" , "class" , "finally" , "long" , "strictfp" , "volatile" , "const" , "float" , "native" , "super" , "while" , "true" , "false" , "null" , "import"
17+ } ) ;
2418
2519 public static string GetReservedPrefix ( this OdcmType @type )
2620 {
@@ -73,7 +67,7 @@ public static string GetTypeString(this OdcmProperty property)
7367 {
7468 var propertyType = property . Projection . Type ;
7569 var typeString = GetTypeString ( propertyType ) ;
76- if ( propertyType . Namespace != OdcmNamespace . Edm && ReservedNames . Contains ( typeString ) )
70+ if ( propertyType . Namespace != OdcmNamespace . Edm && ReservedNames . Value . Contains ( typeString ) )
7771 {
7872 typeString = "com.microsoft.graph.models.extensions." + typeString ;
7973 }
@@ -95,27 +89,19 @@ public static string GetToLowerFirstCharName(this OdcmProperty property)
9589
9690 public static string SanitizePropertyName ( this string property , OdcmObject odcmProperty = null )
9791 {
98- if ( ReservedNames . Contains ( property ) )
92+ if ( ReservedNames . Value . Contains ( property ) )
9993 {
100- logger . Info ( "Property \" {0}\" is a reserved word in Java. Converting to \" {1}{0}\" " , property , ReservedPrefix ) ;
101- return ReservedPrefix + property ;
94+ var result = ReservedPrefix + property . ToUpperFirstChar ( ) ;
95+ logger . Info ( $ "Property \" { property } \" is a reserved word in Java. Converting to \" { result } \" ") ;
96+ return result ;
10297 }
103-
104- if ( odcmProperty != null && property == odcmProperty . Name . ToUpperFirstChar ( ) )
98+ else if ( property == odcmProperty ? . Name ? . ToUpperFirstChar ( ) && ! ( odcmProperty ? . Name ? . StartsWith ( "_" ) ?? false ) )
10599 {
106- // Check whether the property type is the same as the class name.
107- if ( odcmProperty . Projection . Type . Name . ToUpperFirstChar ( ) == odcmProperty . Name . ToUpperFirstChar ( ) )
108- {
109- // Name the property: {metadataName} + "Property"
110- logger . Info ( "Property type \" {0}\" has the same name as the class. Converting to \" {0}Property\" " , property ) ;
111- return string . Concat ( property , "Property" ) ;
112- }
113-
114100 // Name the property by its type. Sanitize it in case the type is a reserved name.
115- return odcmProperty . Projection . Type . Name . ToUpperFirstChar ( ) . SanitizePropertyName ( odcmProperty ) ;
101+ return odcmProperty ? . Projection ? . Type ? . Name ? . ToUpperFirstChar ( ) ? . SanitizePropertyName ( odcmProperty ) ?? odcmProperty ? . Name ? . SanitizePropertyName ( ) ;
116102 }
117-
118- return property . Replace ( "@" , string . Empty ) . Replace ( "." , string . Empty ) ;
103+ else
104+ return property ? . Replace ( "@" , string . Empty ) ? . Replace ( "." , string . Empty ) ;
119105 }
120106
121107 public static string GetToLowerImport ( this OdcmProperty property )
0 commit comments