HHH-18949 fix underscores within uppercase names
This commit is contained in:
parent
f7e3177dba
commit
b712fa0296
|
@ -98,18 +98,21 @@ public final class StringUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString) {
|
public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString) {
|
||||||
if ( lowerCamelCaseString.length() == 1 && isUpperCase( lowerCamelCaseString.charAt( 0 ) ) ) {
|
|
||||||
return "_" + lowerCamelCaseString;
|
|
||||||
}
|
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
boolean wasLowerCase = false;
|
||||||
while ( position < lowerCamelCaseString.length() ) {
|
while ( position < lowerCamelCaseString.length() ) {
|
||||||
final int codePoint = lowerCamelCaseString.codePointAt( position );
|
final int codePoint = lowerCamelCaseString.codePointAt( position );
|
||||||
if ( position>0 && isUpperCase( codePoint ) ) {
|
final boolean isUpperCase = isUpperCase( codePoint );
|
||||||
|
if ( wasLowerCase && isUpperCase ) {
|
||||||
result.append('_');
|
result.append('_');
|
||||||
}
|
}
|
||||||
result.appendCodePoint( toUpperCase( codePoint ) );
|
result.appendCodePoint( toUpperCase( codePoint ) );
|
||||||
position += charCount( codePoint );
|
position += charCount( codePoint );
|
||||||
|
wasLowerCase = !isUpperCase;
|
||||||
|
}
|
||||||
|
if ( result.toString().equals( lowerCamelCaseString ) ) {
|
||||||
|
result.insert(0, '_');
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Copyright Red Hat Inc. and Hibernate Authors
|
||||||
|
*/
|
||||||
|
package org.hibernate.processor.test.uppercase;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Person {
|
||||||
|
@Id String SSN;
|
||||||
|
String UserID;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
* Copyright Red Hat Inc. and Hibernate Authors
|
||||||
|
*/
|
||||||
|
package org.hibernate.processor.test.uppercase;
|
||||||
|
|
||||||
|
import org.hibernate.processor.test.util.CompilationTest;
|
||||||
|
import org.hibernate.processor.test.util.WithClasses;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||||
|
import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
|
||||||
|
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
|
||||||
|
|
||||||
|
public class UppercaseTest extends CompilationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithClasses(value = Person.class)
|
||||||
|
public void test() {
|
||||||
|
System.out.println( getMetaModelSourceAsString( Person.class ) );
|
||||||
|
|
||||||
|
assertMetamodelClassGeneratedFor( Person.class );
|
||||||
|
|
||||||
|
assertPresenceOfFieldInMetamodelFor( Person.class, "SSN" );
|
||||||
|
assertPresenceOfFieldInMetamodelFor( Person.class, "_SSN" );
|
||||||
|
assertPresenceOfFieldInMetamodelFor( Person.class, "UserID" );
|
||||||
|
assertPresenceOfFieldInMetamodelFor( Person.class, "USER_ID" );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue