@@ -10,17 +10,11 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.Java
10
10
11
11
public static class TypeHelperJava
12
12
{
13
- private static Logger logger = LogManager . GetCurrentClassLogger ( ) ;
13
+ private static readonly Logger logger = LogManager . GetCurrentClassLogger ( ) ;
14
14
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
+ } ) ;
24
18
25
19
public static string GetReservedPrefix ( this OdcmType @type )
26
20
{
@@ -73,7 +67,7 @@ public static string GetTypeString(this OdcmProperty property)
73
67
{
74
68
var propertyType = property . Projection . Type ;
75
69
var typeString = GetTypeString ( propertyType ) ;
76
- if ( propertyType . Namespace != OdcmNamespace . Edm && ReservedNames . Contains ( typeString ) )
70
+ if ( propertyType . Namespace != OdcmNamespace . Edm && ReservedNames . Value . Contains ( typeString ) )
77
71
{
78
72
typeString = "com.microsoft.graph.models.extensions." + typeString ;
79
73
}
@@ -95,27 +89,19 @@ public static string GetToLowerFirstCharName(this OdcmProperty property)
95
89
96
90
public static string SanitizePropertyName ( this string property , OdcmObject odcmProperty = null )
97
91
{
98
- if ( ReservedNames . Contains ( property ) )
92
+ if ( ReservedNames . Value . Contains ( property ) )
99
93
{
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 ;
102
97
}
103
-
104
- if ( odcmProperty != null && property == odcmProperty . Name . ToUpperFirstChar ( ) )
98
+ else if ( property == odcmProperty ? . Name ? . ToUpperFirstChar ( ) && ! ( odcmProperty ? . Name ? . StartsWith ( "_" ) ?? false ) )
105
99
{
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
-
114
100
// 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 ( ) ;
116
102
}
117
-
118
- return property . Replace ( "@" , string . Empty ) . Replace ( "." , string . Empty ) ;
103
+ else
104
+ return property ? . Replace ( "@" , string . Empty ) ? . Replace ( "." , string . Empty ) ;
119
105
}
120
106
121
107
public static string GetToLowerImport ( this OdcmProperty property )
0 commit comments