File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed
tooling/metamodel-generator/src
main/java/org/hibernate/processor/util
test/java/org/hibernate/processor/test/uppercase Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -109,13 +109,19 @@ public static String nameToMethodName(String name) {
109
109
public static String getUpperUnderscoreCaseFromLowerCamelCase (String lowerCamelCaseString ) {
110
110
final StringBuilder result = new StringBuilder ();
111
111
int position = 0 ;
112
+ boolean wasLowerCase = false ;
112
113
while ( position < lowerCamelCaseString .length () ) {
113
114
final int codePoint = lowerCamelCaseString .codePointAt ( position );
114
- if ( position >0 && isUpperCase ( codePoint ) ) {
115
+ final boolean isUpperCase = isUpperCase ( codePoint );
116
+ if ( wasLowerCase && isUpperCase ) {
115
117
result .append ('_' );
116
118
}
117
119
result .appendCodePoint ( toUpperCase ( codePoint ) );
118
120
position += charCount ( codePoint );
121
+ wasLowerCase = !isUpperCase ;
122
+ }
123
+ if ( result .toString ().equals ( lowerCamelCaseString ) ) {
124
+ result .insert (0 , '_' );
119
125
}
120
126
return result .toString ();
121
127
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .uppercase ;
6
+
7
+ import jakarta .persistence .Entity ;
8
+ import jakarta .persistence .Id ;
9
+
10
+ @ Entity
11
+ public class Person {
12
+ @ Id String SSN ;
13
+ String UserID ;
14
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .uppercase ;
6
+
7
+ import org .hibernate .processor .test .util .CompilationTest ;
8
+ import org .hibernate .processor .test .util .WithClasses ;
9
+ import org .junit .Test ;
10
+
11
+ import static org .hibernate .processor .test .util .TestUtil .assertMetamodelClassGeneratedFor ;
12
+ import static org .hibernate .processor .test .util .TestUtil .assertPresenceOfFieldInMetamodelFor ;
13
+ import static org .hibernate .processor .test .util .TestUtil .getMetaModelSourceAsString ;
14
+
15
+ public class UppercaseTest extends CompilationTest {
16
+
17
+ @ Test
18
+ @ WithClasses (value = Person .class )
19
+ public void test () {
20
+ System .out .println ( getMetaModelSourceAsString ( Person .class ) );
21
+
22
+ assertMetamodelClassGeneratedFor ( Person .class );
23
+
24
+ assertPresenceOfFieldInMetamodelFor ( Person .class , "SSN" );
25
+ assertPresenceOfFieldInMetamodelFor ( Person .class , "_SSN" );
26
+ assertPresenceOfFieldInMetamodelFor ( Person .class , "UserID" );
27
+ assertPresenceOfFieldInMetamodelFor ( Person .class , "USER_ID" );
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments