Skip to content

Commit 252b70c

Browse files
committed
HHH-18693 Changed name generation for metamodel classes and sources
Generated metadata for inner class A.B is A_.B_ Path source for inner class is identical to path source for enclosing class
1 parent 21089c1 commit 252b70c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ private List<File> getCompilationUnits(List<Class<?>> classesToCompile, List<Str
103103
}
104104

105105
private String getPathToSource(Class<?> testClass) {
106+
if ( testClass.isMemberClass() ) {
107+
return getPathToSource( testClass.getDeclaringClass() );
108+
}
106109
return TestUtil.getSourceBaseDir( testClass ).getAbsolutePath() + File.separator + testClass.getName()
107110
.replace( PACKAGE_SEPARATOR, File.separator ) + ".java";
108111
}

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ public static Class<?> getMetamodelClassFor(String className) {
337337
}
338338

339339
public static File getMetaModelSourceFileFor(Class<?> clazz, boolean prefix) {
340+
if ( clazz.isMemberClass() ) {
341+
return getMetaModelSourceFileFor( clazz.getEnclosingClass(), prefix );
342+
}
340343
String metaModelClassName = getMetaModelClassName(clazz, prefix);
341344
// generate the file name
342345
String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
@@ -353,13 +356,17 @@ public static File getMetaModelSourceFileFor(String className) {
353356
}
354357

355358
private static String getMetaModelClassName(Class<?> clazz, boolean prefix) {
356-
return prefix
357-
? clazz.getPackageName() + '.' + META_MODEL_CLASS_POSTFIX + clazz.getSimpleName()
358-
: clazz.getName() + META_MODEL_CLASS_POSTFIX;
359+
final String packageName = clazz.getPackageName();
360+
return prefix ? packageName + '.' + META_MODEL_CLASS_POSTFIX + clazz.getName().substring( packageName.length() + 1 )
361+
.replaceAll( "\\$", "\\$_" )
362+
: packageName + clazz.getName().substring( packageName.length() )
363+
.replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX;
359364
}
360365

361366
private static String getMetaModelClassName(String className) {
362-
return className + META_MODEL_CLASS_POSTFIX;
367+
final int index = className.lastIndexOf( '.' );
368+
final String packageName = className.substring( 0, index + 1 );
369+
return packageName + className.substring( packageName.length() ).replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX;
363370
}
364371

365372
public static String getMetaModelSourceAsString(Class<?> clazz) {

0 commit comments

Comments
 (0)